diff --git a/application.properties b/application.properties index 0dc6c5f..10eb6fb 100644 --- a/application.properties +++ b/application.properties @@ -2,7 +2,8 @@ joinfaces.jsf.project-stage=development joinfaces.primefaces.theme=bluesky -#spring.thymeleaf.enabled=false +spring.thymeleaf.enabled=false +server.error.whitelabel.enabled=false spring.datasource.url=jdbc:sqlite:/home/timh/foo/bazz/recipes.db #spring.datasource.username=dbuser diff --git a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java index 0b8a279..4e46892 100644 --- a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java +++ b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java @@ -131,12 +131,21 @@ public class AdminMainBean implements Serializable { /** - * Remove images from recipe + * Search, driven by AJAX * @param event Notused */ public void ajaxUpdateList(AjaxBehaviorEvent event) { this.doFind(); } + + /** + * Reset search and display + */ + public void ajaxClearList() { + this.setSearchText(""); + this.doFind(); + } + /** * Finder diff --git a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java index 87df82e..ec467af 100644 --- a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java +++ b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java @@ -225,16 +225,17 @@ public class RecipeDetailBean implements Serializable { if (rid != null) { this.recipe = loadRecipe(rid); } else { - // alternative (and probably dead) version of "new + // alternative (and probably dead) version of + // "new // recipe". this.recipe = new Recipe(); return; } } userSession.setRecipe(this.recipe); - + getIngredients().setWrappedData( - buildIngredientFacade(recipe.getIngredientHash())); + buildIngredientFacade(recipe.getIngredientHash())); } /** @@ -245,7 +246,7 @@ public class RecipeDetailBean implements Serializable { */ private Recipe loadRecipe(Long recipeId) { Recipe recipe = recipeService.findDetails(recipeId); - if ( recipe == null ) { + if (recipe == null) { return null; } @@ -658,7 +659,7 @@ public class RecipeDetailBean implements Serializable { * * Use this to assemble the suggestion list. */ - private String cuisinePartial; + private String cuisinePartial = ""; /** * @return the cuisinePartial @@ -667,13 +668,22 @@ public class RecipeDetailBean implements Serializable { return cuisinePartial; } + public List cuisineSuggestions(String query) { + if (!query.equals(cuisinePartial)) { + setCuisinePartial(query); + } + return getCuisineList(); + } + /** + * Set query for eligibility, force list to rebuild. + * * @param cuisinePartial the cuisinePartial to set */ public void setCuisinePartial(String cuisinePartial) { this.cuisinePartial = cuisinePartial; - this.cuisineList = null; // trigger construction of new - // list. + // trigger construction of new list. + this.cuisineList = null; } private List masterCuisineList = null; @@ -701,7 +711,7 @@ public class RecipeDetailBean implements Serializable { /** * @return the cuisineList built by matching the master list - * agaist the partial cuisine names. + * against the partial cuisine names. */ public List getCuisineList() { if (this.cuisineList == null) { @@ -856,7 +866,7 @@ public class RecipeDetailBean implements Serializable { this.category += catToAdd; catToAdd = ""; } - + // *** Part imageFile = null; @@ -877,6 +887,7 @@ public class RecipeDetailBean implements Serializable { /** * Load/replace images. Computes thumbnail. + * * @param event Notused */ public void ajaxUploadImage(AjaxBehaviorEvent event) { @@ -886,16 +897,17 @@ public class RecipeDetailBean implements Serializable { /** * Remove images from recipe + * * @param event Notused */ public void ajaxDeleteImage(AjaxBehaviorEvent event) { this.recipe.setImage(null); this.recipe.setThumb(null); } - + /** - * Return marker for image. Unlike normal JSF, I don't - * care if it gets multiple times and returns different values. + * Return marker for image. Unlike normal JSF, I don't care + * if it gets multiple times and returns different values. * * @return "random" string */ diff --git a/src/main/java/com/mousetech/gourmetj/persistence/dao/RecipeRepository.java b/src/main/java/com/mousetech/gourmetj/persistence/dao/RecipeRepository.java index f39deed..37bc10c 100644 --- a/src/main/java/com/mousetech/gourmetj/persistence/dao/RecipeRepository.java +++ b/src/main/java/com/mousetech/gourmetj/persistence/dao/RecipeRepository.java @@ -29,6 +29,9 @@ public interface RecipeRepository @EntityGraph(value="Recipe.findWorkingSet") public Recipe findDetailsById(Long recipeId); + @Query(name = "Recipe.findCusines", nativeQuery = true) + List FindCuisinesNative(); + // final static String SQL_FIND_CATEGORIES = // "SELECT DISTINCT category from categories" diff --git a/src/main/java/com/mousetech/gourmetj/persistence/model/Ingredient.java b/src/main/java/com/mousetech/gourmetj/persistence/model/Ingredient.java index 4ec7adb..8ae92af 100644 --- a/src/main/java/com/mousetech/gourmetj/persistence/model/Ingredient.java +++ b/src/main/java/com/mousetech/gourmetj/persistence/model/Ingredient.java @@ -2,6 +2,7 @@ package com.mousetech.gourmetj.persistence.model; import java.io.Serializable; import javax.persistence.*; +import javax.validation.constraints.NotNull; /** * The persistent class for the "ingredients" database table. @@ -55,6 +56,7 @@ public class Ingredient implements Serializable, IngredientIF { private String item; @Column(name = "optional") + @NotNull private Integer optional; @Column(name = "position") diff --git a/src/main/java/com/mousetech/gourmetj/persistence/model/Recipe.java b/src/main/java/com/mousetech/gourmetj/persistence/model/Recipe.java index 8ba3d75..0ff35e9 100644 --- a/src/main/java/com/mousetech/gourmetj/persistence/model/Recipe.java +++ b/src/main/java/com/mousetech/gourmetj/persistence/model/Recipe.java @@ -17,6 +17,9 @@ import javax.persistence.*; @NamedQueries({ @NamedQuery(name = "Recipe.findAll", query = "SELECT r FROM Recipe r"), @NamedQuery(name = "Recipe.findByTitle", query = "SELECT r FROM Recipe r WHERE r.title LIKE concat('%', :searchText,'%')") }) +@NamedNativeQuery(name = "Recipe.findCusines", query = "SELECT DISTINCT cuisine from recipe" + + " where cuisine is not null and cuisine <> ''" + + " ORDER BY cuisine ASC") @NamedEntityGraph(name = "Recipe.findWorkingSet", attributeNodes = { @NamedAttributeNode(value = "categories"), @NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.shopcat") }, subgraphs = { @@ -89,8 +92,7 @@ public class Recipe implements Serializable { private Double yields; @OneToMany(fetch = FetchType.EAGER, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true) - private Set categories = - new HashSet(); + private Set categories = new HashSet(); /** * @param categories the categories to set diff --git a/src/main/java/com/mousetech/gourmetj/persistence/service/RecipeService.java b/src/main/java/com/mousetech/gourmetj/persistence/service/RecipeService.java index d7a49df..db32a16 100644 --- a/src/main/java/com/mousetech/gourmetj/persistence/service/RecipeService.java +++ b/src/main/java/com/mousetech/gourmetj/persistence/service/RecipeService.java @@ -8,6 +8,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.inject.Named; import javax.persistence.NamedEntityGraph; +import javax.persistence.NamedNativeQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,7 @@ public class RecipeService implements Serializable { @Inject private RecipeRepository recipeRepository; - + public List findAll() { return recipeRepository.findAll(); } @@ -51,9 +52,17 @@ public class RecipeService implements Serializable { return recipeRepository.findDetailsById(recipeId); } + + + /** + * final String sql = "SELECT DISTINCT cuisine from recipe" + + " where cuisine is not null and cuisine <> ''" + + " ORDER BY cuisine ASC"; + * @return + */ + public List findCuisines() { - // TODO Auto-generated method stub - return null; + return recipeRepository.FindCuisinesNative(); } diff --git a/src/main/resources/META-INF/resources/detailEdit.xhtml b/src/main/resources/META-INF/resources/detailEdit.xhtml index f9751ad..a0ef9dc 100644 --- a/src/main/resources/META-INF/resources/detailEdit.xhtml +++ b/src/main/resources/META-INF/resources/detailEdit.xhtml @@ -73,7 +73,7 @@ /> Gourmet Recipe Manager - - - - - - - + - - - - - + + + + + + + +