-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathRecipeBootstrap.java
216 lines (175 loc) · 13 KB
/
RecipeBootstrap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package guru.springframework.bootstrap;
import guru.springframework.domain.*;
import guru.springframework.repositories.CategoryRepository;
import guru.springframework.repositories.RecipeRepository;
import guru.springframework.repositories.UnitOfMeasureRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Slf4j
@Component
public class RecipeBootstrap implements ApplicationListener<ContextRefreshedEvent> {
private final CategoryRepository categoryRepository;
private final RecipeRepository recipeRepository;
private final UnitOfMeasureRepository unitOfMeasureRepository;
public RecipeBootstrap(CategoryRepository categoryRepository, RecipeRepository recipeRepository, UnitOfMeasureRepository unitOfMeasureRepository) {
this.categoryRepository = categoryRepository;
this.recipeRepository = recipeRepository;
this.unitOfMeasureRepository = unitOfMeasureRepository;
}
@Override
@Transactional
public void onApplicationEvent(ContextRefreshedEvent event) {
recipeRepository.saveAll(getRecipes());
log.debug("Loading Bootstrap Data");
}
private List<Recipe> getRecipes() {
List<Recipe> recipes = new ArrayList<>(2);
//get UOMs
Optional<UnitOfMeasure> eachUomOptional = unitOfMeasureRepository.findByDescription("Each");
if(!eachUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
Optional<UnitOfMeasure> tableSpoonUomOptional = unitOfMeasureRepository.findByDescription("Tablespoon");
if(!tableSpoonUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
Optional<UnitOfMeasure> teaSpoonUomOptional = unitOfMeasureRepository.findByDescription("Teaspoon");
if(!teaSpoonUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
Optional<UnitOfMeasure> dashUomOptional = unitOfMeasureRepository.findByDescription("Dash");
if(!dashUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
Optional<UnitOfMeasure> pintUomOptional = unitOfMeasureRepository.findByDescription("Pint");
if(!pintUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
Optional<UnitOfMeasure> cupsUomOptional = unitOfMeasureRepository.findByDescription("Cup");
if(!cupsUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}
//get optionals
UnitOfMeasure eachUom = eachUomOptional.get();
UnitOfMeasure tableSpoonUom = tableSpoonUomOptional.get();
UnitOfMeasure teapoonUom = tableSpoonUomOptional.get();
UnitOfMeasure dashUom = dashUomOptional.get();
UnitOfMeasure pintUom = dashUomOptional.get();
UnitOfMeasure cupsUom = cupsUomOptional.get();
//get Categories
Optional<Category> americanCategoryOptional = categoryRepository.findByDescription("American");
if(!americanCategoryOptional.isPresent()){
throw new RuntimeException("Expected Category Not Found");
}
Optional<Category> mexicanCategoryOptional = categoryRepository.findByDescription("Mexican");
if(!mexicanCategoryOptional.isPresent()){
throw new RuntimeException("Expected Category Not Found");
}
Category americanCategory = americanCategoryOptional.get();
Category mexicanCategory = mexicanCategoryOptional.get();
//Yummy Guac
Recipe guacRecipe = new Recipe();
guacRecipe.setDescription("Perfect Guacamole");
guacRecipe.setPrepTime(10);
guacRecipe.setCookTime(0);
guacRecipe.setDifficulty(Difficulty.EASY);
guacRecipe.setDirections("1 Cut avocado, remove flesh: Cut the avocados in half. Remove seed. Score the inside of the avocado with a blunt knife and scoop out the flesh with a spoon" +
"\n" +
"2 Mash with a fork: Using a fork, roughly mash the avocado. (Don't overdo it! The guacamole should be a little chunky.)" +
"\n" +
"3 Add salt, lime juice, and the rest: Sprinkle with salt and lime (or lemon) juice. The acid in the lime juice will provide some balance to the richness of the avocado and will help delay the avocados from turning brown.\n" +
"Add the chopped onion, cilantro, black pepper, and chiles. Chili peppers vary individually in their hotness. So, start with a half of one chili pepper and add to the guacamole to your desired degree of hotness.\n" +
"Remember that much of this is done to taste because of the variability in the fresh ingredients. Start with this recipe and adjust to your taste.\n" +
"4 Cover with plastic and chill to store: Place plastic wrap on the surface of the guacamole cover it and to prevent air reaching it. (The oxygen in the air causes oxidation which will turn the guacamole brown.) Refrigerate until ready to serve.\n" +
"Chilling tomatoes hurts their flavor, so if you want to add chopped tomato to your guacamole, add it just before serving.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/perfect_guacamole/#ixzz4jvpiV9Sd");
Notes guacNotes = new Notes();
guacNotes.setRecipeNotes("For a very quick guacamole just take a 1/4 cup of salsa and mix it in with your mashed avocados.\n" +
"Feel free to experiment! One classic Mexican guacamole has pomegranate seeds and chunks of peaches in it (a Diana Kennedy favorite). Try guacamole with added pineapple, mango, or strawberries.\n" +
"The simplest version of guacamole is just mashed avocados with salt. Don't let the lack of availability of other ingredients stop you from making guacamole.\n" +
"To extend a limited supply of avocados, add either sour cream or cottage cheese to your guacamole dip. Purists may be horrified, but so what? It tastes great.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/perfect_guacamole/#ixzz4jvoun5ws");
guacRecipe.setNotes(guacNotes);
//very redundent - could add helper method, and make this simpler
guacRecipe.addIngredient(new Ingredient("ripe avocados", new BigDecimal(2), eachUom));
guacRecipe.addIngredient(new Ingredient("Kosher salt", new BigDecimal(".5"), teapoonUom));
guacRecipe.addIngredient(new Ingredient("fresh lime juice or lemon juice", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("minced red onion or thinly sliced green onion", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("serrano chiles, stems and seeds removed, minced", new BigDecimal(2), eachUom));
guacRecipe.addIngredient(new Ingredient("Cilantro", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("freshly grated black pepper", new BigDecimal(2), dashUom));
guacRecipe.addIngredient(new Ingredient("ripe tomato, seeds and pulp removed, chopped", new BigDecimal(".5"), eachUom));
guacRecipe.getCategories().add(americanCategory);
guacRecipe.getCategories().add(mexicanCategory);
guacRecipe.setUrl("http://www.simplyrecipes.com/recipes/perfect_guacamole/");
guacRecipe.setServings(4);
guacRecipe.setSource("Simply Recipes");
//add to return list
recipes.add(guacRecipe);
//Yummy Tacos
Recipe tacosRecipe = new Recipe();
tacosRecipe.setDescription("Spicy Grilled Chicken Taco");
tacosRecipe.setCookTime(9);
tacosRecipe.setPrepTime(20);
tacosRecipe.setDifficulty(Difficulty.MODERATE);
tacosRecipe.setDirections("1 Prepare a gas or charcoal grill for medium-high, direct heat.\n" +
"2 Make the marinade and coat the chicken: In a large bowl, stir together the chili powder, oregano, cumin, sugar, salt, garlic and orange zest. Stir in the orange juice and olive oil to make a loose paste. Add the chicken to the bowl and toss to coat all over.\n" +
"Set aside to marinate while the grill heats and you prepare the rest of the toppings.\n" +
"\n" +
"\n" +
"3 Grill the chicken: Grill the chicken for 3 to 4 minutes per side, or until a thermometer inserted into the thickest part of the meat registers 165F. Transfer to a plate and rest for 5 minutes.\n" +
"4 Warm the tortillas: Place each tortilla on the grill or on a hot, dry skillet over medium-high heat. As soon as you see pockets of the air start to puff up in the tortilla, turn it with tongs and heat for a few seconds on the other side.\n" +
"Wrap warmed tortillas in a tea towel to keep them warm until serving.\n" +
"5 Assemble the tacos: Slice the chicken into strips. On each tortilla, place a small handful of arugula. Top with chicken slices, sliced avocado, radishes, tomatoes, and onion slices. Drizzle with the thinned sour cream. Serve with lime wedges.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/#ixzz4jvtrAnNm");
Notes tacoNotes = new Notes();
tacoNotes.setRecipeNotes("We have a family motto and it is this: Everything goes better in a tortilla.\n" +
"Any and every kind of leftover can go inside a warm tortilla, usually with a healthy dose of pickled jalapenos. I can always sniff out a late-night snacker when the aroma of tortillas heating in a hot pan on the stove comes wafting through the house.\n" +
"Today’s tacos are more purposeful – a deliberate meal instead of a secretive midnight snack!\n" +
"First, I marinate the chicken briefly in a spicy paste of ancho chile powder, oregano, cumin, and sweet orange juice while the grill is heating. You can also use this time to prepare the taco toppings.\n" +
"Grill the chicken, then let it rest while you warm the tortillas. Now you are ready to assemble the tacos and dig in. The whole meal comes together in about 30 minutes!\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/#ixzz4jvu7Q0MJ");
tacosRecipe.setNotes(tacoNotes);
tacosRecipe.addIngredient(new Ingredient("Ancho Chili Powder", new BigDecimal(2), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("Dried Oregano", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Dried Cumin", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Sugar", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Salt", new BigDecimal(".5"), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Clove of Garlic, Choppedr", new BigDecimal(1), eachUom));
tacosRecipe.addIngredient(new Ingredient("finely grated orange zestr", new BigDecimal(1), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("fresh-squeezed orange juice", new BigDecimal(3), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("Olive Oil", new BigDecimal(2), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("boneless chicken thighs", new BigDecimal(4), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("small corn tortillasr", new BigDecimal(8), eachUom));
tacosRecipe.addIngredient(new Ingredient("packed baby arugula", new BigDecimal(3), cupsUom));
tacosRecipe.addIngredient(new Ingredient("medium ripe avocados, slic", new BigDecimal(2), eachUom));
tacosRecipe.addIngredient(new Ingredient("radishes, thinly sliced", new BigDecimal(4), eachUom));
tacosRecipe.addIngredient(new Ingredient("cherry tomatoes, halved", new BigDecimal(".5"), pintUom));
tacosRecipe.addIngredient(new Ingredient("red onion, thinly sliced", new BigDecimal(".25"), eachUom));
tacosRecipe.addIngredient(new Ingredient("Roughly chopped cilantro", new BigDecimal(4), eachUom));
tacosRecipe.addIngredient(new Ingredient("cup sour cream thinned with 1/4 cup milk", new BigDecimal(4), cupsUom));
tacosRecipe.addIngredient(new Ingredient("lime, cut into wedges", new BigDecimal(4), eachUom));
tacosRecipe.getCategories().add(americanCategory);
tacosRecipe.getCategories().add(mexicanCategory);
tacosRecipe.setUrl("http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/");
tacosRecipe.setServings(4);
tacosRecipe.setSource("Simply Recipes");
recipes.add(tacosRecipe);
return recipes;
}
}