diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addDescriptorsAtGroupLevelForFacetDescriptorPathway.java b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addDescriptorsAtGroupLevelForFacetDescriptorPathway.java index 5dc71779..15818acb 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addDescriptorsAtGroupLevelForFacetDescriptorPathway.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addDescriptorsAtGroupLevelForFacetDescriptorPathway.java @@ -91,10 +91,10 @@ public Food act(@Parameter final FoodFacet foodFacet) { entity.setFoodSubSubgroupCode(subgroup.getFoodSubSubgroupCode()); }); - entity.setFacetCode(fd.getFacetCode()); + entity.setFoodFacetCode(fd.getFacetCode()); entity.setFacetDisplayOrder(-1); - entity.setDescriptorCode(fd.getCode()); + entity.setFoodDescriptorCode(fd.getCode()); entity.setDescriptorDisplayOrder(-1); entity.setDefaultFlag(null); @@ -131,7 +131,7 @@ public List choicesFoodFacet() { private Set foodFacetCodesAsDefinedByFoodClassification( final List pathwayForFoodGroup) { return pathwayForFoodGroup.stream() - .map(FacetDescriptorPathwayForFoodGroup::getFacetCode) + .map(FacetDescriptorPathwayForFoodGroup::getFoodFacetCode) .map(FoodFacet.SecondaryKey::new) .collect(Collectors.toSet()); } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addFoodFacetSelectionForFacetDescriptorPathway.java b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addFoodFacetSelectionForFacetDescriptorPathway.java index f9b5dce2..037d57ef 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addFoodFacetSelectionForFacetDescriptorPathway.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_addFoodFacetSelectionForFacetDescriptorPathway.java @@ -65,7 +65,7 @@ public Food act(@Parameter final FoodFacet foodFacet) { entity.setFoodCode(mixee.getCode()); entity.setDisplayOrder(-1); // TODO needs post processing - entity.setMandatoryInSequenceOfFacetsCode(foodFacet.getCode()); + entity.setSelectedFoodFacetCode(foodFacet.getCode()); repositoryService.persist(entity); foreignKeyLookupService.clearCache(FacetDescriptorPathwayForFood.class); postProcessDisplayOrder(); @@ -91,7 +91,7 @@ public List choicesFoodFacet() { private Set foodFacetCodesAsDefinedByFoodClassification( final List pathwayForFoodGroup) { return pathwayForFoodGroup.stream() - .map(FacetDescriptorPathwayForFoodGroup::getFacetCode) + .map(FacetDescriptorPathwayForFoodGroup::getFoodFacetCode) .map(FoodFacet.SecondaryKey::new) .collect(Collectors.toSet()); } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_effectiveFoodDescriptors.java b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_effectiveFoodDescriptors.java index a1ec8b8f..a6ddd368 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_effectiveFoodDescriptors.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/food/Food_effectiveFoodDescriptors.java @@ -78,7 +78,7 @@ public List coll() { return foodDescriptorsAsDefinedByFoodClassification; } final Set facetCodeSubset = facetDescriptorPathwayForFood.stream() - .map(FacetDescriptorPathwayForFood::getMandatoryInSequenceOfFacetsCode) + .map(FacetDescriptorPathwayForFood::getSelectedFoodFacetCode) .collect(Collectors.toSet()); return foodDescriptorsAsDefinedByFoodClassification.stream() .filter(foodDescriptor->facetCodeSubset.contains(foodDescriptor.getFacetCode())) @@ -91,8 +91,8 @@ public List coll() { private FoodDescriptor foodDescriptor(final FacetDescriptorPathwayForFoodGroup groupPathway) { return foreignKeyLookupService.unique(new FoodDescriptor.SecondaryKey( - groupPathway.getFacetCode(), - groupPathway.getDescriptorCode())); + groupPathway.getFoodFacetCode(), + groupPathway.getFoodDescriptorCode())); } } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_addEntry.java b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_addEntry.java index ab41e1a4..de164172 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_addEntry.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_addEntry.java @@ -71,9 +71,9 @@ public FacetDescriptorPathwayForFoodGroup act( e.setFoodSubSubgroupCode(foodSubSubgroupCode(p.foodSubgroup())); // cross reference - e.setFacetCode(p.facet().getCode()); + e.setFoodFacetCode(p.foodFacet().getCode()); e.setFacetDisplayOrder(p.facetDisplayOrder()); - e.setDescriptorCode(p.descriptor().getCode()); + e.setFoodDescriptorCode(p.foodDescriptor().getCode()); e.setDescriptorDisplayOrder(p.descriptorDisplayOrder()); // flags @@ -122,9 +122,9 @@ public FacetDescriptorPathwayForFoodGroup act( } @MemberSupport public List choicesDescriptor( final FacetDescriptorPathwayForFoodGroup.Params p) { - return p.facet()!=null + return p.foodFacet()!=null ? repositoryService.allMatches(FoodDescriptor.class, - fd->Objects.equals(fd.getFacetCode(), p.facet().getCode())) + fd->Objects.equals(fd.getFacetCode(), p.foodFacet().getCode())) : Collections.emptyList(); } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_fixDisplayOrder.java b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_fixDisplayOrder.java index 3a112161..e5e49883 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_fixDisplayOrder.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/editing/other/FacetDescriptorPathwayForFoodGroupManager_fixDisplayOrder.java @@ -80,9 +80,9 @@ public FacetDescriptorPathwayForFoodGroup.Manager act( // order by descriptor name, descriptor with Other=true comes last private int compare(final FacetDescriptorPathwayForFoodGroup a, final FacetDescriptorPathwayForFoodGroup b) { var descA = foreignKeyLookupService.unique( - new FoodDescriptor.SecondaryKey(a.getFacetCode(), a.getDescriptorCode())); + new FoodDescriptor.SecondaryKey(a.getFoodFacetCode(), a.getFoodDescriptorCode())); var descB = foreignKeyLookupService.unique( - new FoodDescriptor.SecondaryKey(b.getFacetCode(), b.getDescriptorCode())); + new FoodDescriptor.SecondaryKey(b.getFoodFacetCode(), b.getFoodDescriptorCode())); int c = Integer.compare(descA.getOtherQ().ordinal(), descB.getOtherQ().ordinal()); if(c!=0) return c; diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/services/food/FoodFacetHelperService.java b/globodiet/manager/src/main/java/dita/globodiet/manager/services/food/FoodFacetHelperService.java index 675395b6..ea72740f 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/services/food/FoodFacetHelperService.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/services/food/FoodFacetHelperService.java @@ -130,7 +130,7 @@ public List listFacetDescriptorPathwayForFood(fin public List facetCodesAllowedForFoodGrouping(final FoodGrouping foodGrouping) { return effectiveFacetDescriptorPathwayForFoodClassification(foodGrouping) .stream() - .map(FacetDescriptorPathwayForFoodGroup::getFacetCode) + .map(FacetDescriptorPathwayForFoodGroup::getFoodFacetCode) .toList(); } @@ -145,7 +145,7 @@ public Set selectedFacetDescriptorPathwayForFoodAsFoodFa final @Nullable Food food) { return selectedFacetDescriptorPathwayForFood(food) .stream() - .map(FacetDescriptorPathwayForFood::getMandatoryInSequenceOfFacetsCode) + .map(FacetDescriptorPathwayForFood::getSelectedFoodFacetCode) .map(FoodFacet.SecondaryKey::new) .collect(Collectors.toSet()); } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/services/grouping/GroupingHelperService.java b/globodiet/manager/src/main/java/dita/globodiet/manager/services/grouping/GroupingHelperService.java index dc6b67bc..933ee833 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/services/grouping/GroupingHelperService.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/services/grouping/GroupingHelperService.java @@ -31,6 +31,9 @@ import dita.globodiet.dom.params.food_list.Food; import dita.globodiet.dom.params.food_list.FoodGroup; import dita.globodiet.dom.params.food_list.FoodSubgroup; +import dita.globodiet.dom.params.recipe_list.Recipe; +import dita.globodiet.dom.params.recipe_list.RecipeGroup; +import dita.globodiet.dom.params.recipe_list.RecipeSubgroup; import dita.globodiet.manager.util.GroupingUtils; @Service @@ -74,4 +77,24 @@ public FoodSubgroup foodSubSubgroupToSubgroup(final @NonNull FoodSubgroup foodSu // -- RECIPE + public Either recipeClassification(final @NonNull Recipe recipe) { + var sub = recipeSubgroup(recipe); + return sub!=null + ? Either.right(sub) + : Either.left(recipeGroup(recipe)); + } + + public RecipeGroup recipeGroup(final @NonNull Recipe recipe) { + return foreignKeyLookupService.unique(GroupingUtils.recipeGroupKeyForRecipe(recipe)); + } + + public RecipeGroup recipeGroup(final @NonNull RecipeSubgroup recipeSubgroup) { + return foreignKeyLookupService.unique(GroupingUtils.recipeGroupKeyForSubgroup(recipeSubgroup)); + } + + @Nullable + public RecipeSubgroup recipeSubgroup(final @NonNull Recipe recipe) { + return foreignKeyLookupService.nullable(GroupingUtils.recipeSubgroupKeyForRecipe(recipe)); + } + } diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/services/recipe/RecipeFacetHelperService.java b/globodiet/manager/src/main/java/dita/globodiet/manager/services/recipe/RecipeFacetHelperService.java new file mode 100644 index 00000000..079562d6 --- /dev/null +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/services/recipe/RecipeFacetHelperService.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package dita.globodiet.manager.services.recipe; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import jakarta.inject.Inject; + +import org.springframework.lang.Nullable; +import org.springframework.stereotype.Service; + +import org.apache.causeway.applib.services.factory.FactoryService; +import org.apache.causeway.commons.functional.Either; + +import lombok.NonNull; + +import dita.globodiet.dom.params.classification.RecipeGrouping; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipeGroup; +import dita.globodiet.dom.params.recipe_description.RecipeFacet; +import dita.globodiet.dom.params.recipe_list.Recipe; +import dita.globodiet.dom.params.recipe_list.RecipeDeps.Recipe_dependentFacetDescriptorPathwayForRecipeMappedByRecipe; +import dita.globodiet.dom.params.recipe_list.RecipeGroup; +import dita.globodiet.dom.params.recipe_list.RecipeGroupDeps.RecipeGroup_dependentFacetDescriptorPathwayForRecipeGroupMappedByRecipeGroup; +import dita.globodiet.dom.params.recipe_list.RecipeSubgroup; +import dita.globodiet.dom.params.recipe_list.RecipeSubgroupDeps.RecipeSubgroup_dependentFacetDescriptorPathwayForRecipeGroupMappedByRecipeSubgroup; +import dita.globodiet.manager.services.grouping.GroupingHelperService; + +@Service +public class RecipeFacetHelperService { + + @Inject private FactoryService factoryService; + @Inject private GroupingHelperService groupingHelperService; + + public List effectiveFacetDescriptorPathwayForRecipeClassification( + final @NonNull RecipeGrouping recipeGrouping) { + final @NonNull Either recipeClassification = recipeGrouping.toEither(); + final List facetDescriptorPathwayForFoodGroup = recipeClassification + .fold( + recipeGroup->listFacetDescriptorPathwayForRecipeGroup(recipeGroup), + recipeSubgroup->{ + var lookupResult = listFacetDescriptorPathwayForRecipeSubgroup(recipeSubgroup); + // if lookup was too specific, fallback to top-level = FoodGroup + return lookupResult.isEmpty() + ? listFacetDescriptorPathwayForRecipeGroup(groupingHelperService.recipeGroup(recipeClassification.rightIfAny())) + : lookupResult; + }); + + return facetDescriptorPathwayForFoodGroup; + } + + public RecipeGrouping effectiveGroupingUsedForFacetDescriptorPathway(final @NonNull Recipe recipe) { + var recipeClassification = groupingHelperService.recipeClassification(recipe); + final RecipeGrouping recipeGrouping = recipeClassification + .fold( + recipeGroup->(RecipeGrouping)recipeGroup, + recipeSubgroup->{ + var groupingResult = recipeSubgroup; // assignment is non final + var lookupResult = listFacetDescriptorPathwayForRecipeSubgroup(recipeSubgroup); + // if lookup was too specific, fallback to top-level = FoodGroup + return lookupResult.isEmpty() + ? (RecipeGrouping)groupingHelperService.recipeGroup(recipeClassification.rightIfAny()) + : groupingResult; + }); + return recipeGrouping; + } + + public List effectiveFacetDescriptorPathwayForRecipeClassificationHonoringDisplayOrder( + final @NonNull RecipeGrouping recipeGrouping) { + return effectiveFacetDescriptorPathwayForRecipeClassification(recipeGrouping).stream() + .sorted(displayOrder()) + .toList(); + } + + public List effectiveFacetDescriptorPathwayForRecipeClassificationHonoringDisplayOrder( + final @NonNull Recipe recipe) { + return effectiveFacetDescriptorPathwayForRecipeClassificationHonoringDisplayOrder( + effectiveGroupingUsedForFacetDescriptorPathway(recipe)); + } + + public List listFacetDescriptorPathwayForRecipe(final @NonNull Recipe recipe) { + return factoryService.mixin(Recipe_dependentFacetDescriptorPathwayForRecipeMappedByRecipe.class, recipe) + .coll(); + } + + public List facetCodesAllowedForRecipeGrouping(final RecipeGrouping recipeGrouping) { + return effectiveFacetDescriptorPathwayForRecipeClassification(recipeGrouping) + .stream() + .map(FacetDescriptorPathwayForRecipeGroup::getRecipeFacetCode) + .toList(); + } + + public List selectedFacetDescriptorPathwayForRecipe( + final @Nullable Recipe recipe) { + if(recipe==null) return Collections.emptyList(); + var mixin = factoryService.mixin(Recipe_dependentFacetDescriptorPathwayForRecipeMappedByRecipe.class, recipe); + return mixin.coll(); + } + + public Set selectedFacetDescriptorPathwayForRecipeAsRecipeFacetSecondaryKeySet( + final @Nullable Recipe recipe) { + return selectedFacetDescriptorPathwayForRecipe(recipe) + .stream() + .map(FacetDescriptorPathwayForRecipe::getSelectedRecipeFacetCode) + .map(RecipeFacet.SecondaryKey::new) + .collect(Collectors.toSet()); + } + + // -- HELPER + + private List listFacetDescriptorPathwayForRecipeGroup( + final RecipeGroup recipeGroup) { + return factoryService.mixin( + RecipeGroup_dependentFacetDescriptorPathwayForRecipeGroupMappedByRecipeGroup.class, + recipeGroup) + .coll(); + } + + private List listFacetDescriptorPathwayForRecipeSubgroup( + final RecipeSubgroup recipeSubgroup) { + return factoryService.mixin( + RecipeSubgroup_dependentFacetDescriptorPathwayForRecipeGroupMappedByRecipeSubgroup.class, + recipeSubgroup) + .coll(); + } + + private Comparator displayOrder() { + return Comparator.comparing(FacetDescriptorPathwayForRecipeGroup::getFacetDisplayOrder) + .thenComparing(FacetDescriptorPathwayForRecipeGroup::getDescriptorDisplayOrder); + } + +} diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodDisplayOrderRuleChecker.java b/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodDisplayOrderRuleChecker.java index 0c566351..6948af9f 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodDisplayOrderRuleChecker.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodDisplayOrderRuleChecker.java @@ -101,7 +101,7 @@ private Can checkForGroup() { entry.getFoodGroupCode(), dita.commons.format.FormatUtils.emptyToDash(entry.getFoodSubgroupCode()), dita.commons.format.FormatUtils.emptyToDash(entry.getFoodSubSubgroupCode()), - entry.getFacetCode()); + entry.getFoodFacetCode()); displayOrdersByFacet1.putElement(foodGroupingPlusFacet, entry.getFacetDisplayOrder()); displayOrdersByFacet2.putElement(foodGroupingPlusFacet, entry.getDescriptorDisplayOrder()); urlByFoodGroupingPlusFacet.putElement(foodGroupingPlusFacet, deepLinkService.deepLinkFor(entry)); diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodSelectionExistsRuleChecker.java b/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodSelectionExistsRuleChecker.java index 5de450dc..086ea150 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodSelectionExistsRuleChecker.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/services/rule/FacetDescriptorPathwayForFoodSelectionExistsRuleChecker.java @@ -96,7 +96,7 @@ private Can checkForFood() { var entries = repositoryService.allInstances(FacetDescriptorPathwayForFood.class); for(var entry : entries) { - var referencedFacetCode = entry.getMandatoryInSequenceOfFacetsCode(); + var referencedFacetCode = entry.getSelectedFoodFacetCode(); if(referencedFacetCode==null) continue; //TODO should we report? var allowedFacetCodes = facetCodesAllowedByFoodKey.getOrElseEmpty(entry.getFoodCode()); // assert referencedFacetCode exists within effective group diff --git a/globodiet/manager/src/main/java/dita/globodiet/manager/util/GroupingUtils.java b/globodiet/manager/src/main/java/dita/globodiet/manager/util/GroupingUtils.java index 6969bcb2..c77a6454 100644 --- a/globodiet/manager/src/main/java/dita/globodiet/manager/util/GroupingUtils.java +++ b/globodiet/manager/src/main/java/dita/globodiet/manager/util/GroupingUtils.java @@ -26,10 +26,15 @@ import dita.globodiet.dom.params.food_list.Food; import dita.globodiet.dom.params.food_list.FoodGroup; import dita.globodiet.dom.params.food_list.FoodSubgroup; +import dita.globodiet.dom.params.recipe_list.Recipe; +import dita.globodiet.dom.params.recipe_list.RecipeGroup; +import dita.globodiet.dom.params.recipe_list.RecipeSubgroup; @UtilityClass public class GroupingUtils { + // -- FOOD + public FoodGroup.SecondaryKey foodGroupKeyForFood(final @NonNull Food food) { return new FoodGroup.SecondaryKey(food.getFoodGroupCode()); } @@ -75,4 +80,20 @@ public FoodSubgroup.SecondaryKey maskSubSubgroup(final @NonNull FoodSubgroup.Sec return key; } + // -- RECIPE + + public RecipeGroup.SecondaryKey recipeGroupKeyForRecipe(final @NonNull Recipe recipe) { + return new RecipeGroup.SecondaryKey(recipe.getRecipeGroupCode()); + } + + public RecipeGroup.SecondaryKey recipeGroupKeyForSubgroup(final @NonNull RecipeSubgroup recipeSubgroup) { + return new RecipeGroup.SecondaryKey(recipeSubgroup.getRecipeGroupCode()); + } + + public RecipeSubgroup.SecondaryKey recipeSubgroupKeyForRecipe(final @NonNull Recipe recipe) { + return new RecipeSubgroup.SecondaryKey( + recipe.getRecipeGroupCode(), + recipe.getRecipeSubgroupCode()); + } + } diff --git a/globodiet/params/src/main/java/dita/globodiet/dom/params/DitaModuleGdParams.java b/globodiet/params/src/main/java/dita/globodiet/dom/params/DitaModuleGdParams.java index 9681b822..4c2e99c6 100644 --- a/globodiet/params/src/main/java/dita/globodiet/dom/params/DitaModuleGdParams.java +++ b/globodiet/params/src/main/java/dita/globodiet/dom/params/DitaModuleGdParams.java @@ -147,14 +147,14 @@ import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroupDeps; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_delete; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_descriptor; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_facet; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodDescriptor; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodFacet; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodGroup; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodSubSubgroup; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodSubgroup; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_delete; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_food; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_mandatoryInSequenceOfFacets; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_selectedFoodFacet; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipeDeps; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipeGroup; @@ -166,7 +166,7 @@ import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipeGroup_recipeSubgroup; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe_delete; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe_recipe; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe_recipeFacet; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForRecipe_selectedRecipeFacet; import dita.globodiet.dom.params.pathway.ProbingQuestion; import dita.globodiet.dom.params.pathway.ProbingQuestionDeps; import dita.globodiet.dom.params.pathway.ProbingQuestionPathwayForFood; @@ -550,14 +550,14 @@ EdiblePartCoefficientForFood_facetDescriptor.class, EdiblePartCoefficientForFood_food.class, FacetDescriptorPathwayForFoodGroup_delete.class, - FacetDescriptorPathwayForFoodGroup_descriptor.class, - FacetDescriptorPathwayForFoodGroup_facet.class, + FacetDescriptorPathwayForFoodGroup_foodDescriptor.class, + FacetDescriptorPathwayForFoodGroup_foodFacet.class, FacetDescriptorPathwayForFoodGroup_foodGroup.class, FacetDescriptorPathwayForFoodGroup_foodSubSubgroup.class, FacetDescriptorPathwayForFoodGroup_foodSubgroup.class, FacetDescriptorPathwayForFood_delete.class, FacetDescriptorPathwayForFood_food.class, - FacetDescriptorPathwayForFood_mandatoryInSequenceOfFacets.class, + FacetDescriptorPathwayForFood_selectedFoodFacet.class, FacetDescriptorPathwayForRecipeGroup_delete.class, FacetDescriptorPathwayForRecipeGroup_recipeDescriptor.class, FacetDescriptorPathwayForRecipeGroup_recipeFacet.class, @@ -565,7 +565,7 @@ FacetDescriptorPathwayForRecipeGroup_recipeSubgroup.class, FacetDescriptorPathwayForRecipe_delete.class, FacetDescriptorPathwayForRecipe_recipe.class, - FacetDescriptorPathwayForRecipe_recipeFacet.class, + FacetDescriptorPathwayForRecipe_selectedRecipeFacet.class, FacetDescriptorThatCannotBeSubstituted_delete.class, FacetDescriptorThatCannotBeSubstituted_descriptor.class, FacetDescriptorThatCannotBeSubstituted_facet.class, diff --git a/globodiet/params/src/main/java/dita/globodiet/dom/params/classification/RecipeGrouping.java b/globodiet/params/src/main/java/dita/globodiet/dom/params/classification/RecipeGrouping.java index 51131982..404ce7c0 100644 --- a/globodiet/params/src/main/java/dita/globodiet/dom/params/classification/RecipeGrouping.java +++ b/globodiet/params/src/main/java/dita/globodiet/dom/params/classification/RecipeGrouping.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -19,5 +19,51 @@ // Auto-generated by DitA-Tooling package dita.globodiet.dom.params.classification; +import org.apache.causeway.commons.functional.Either; + +import dita.commons.format.FormatUtils; +import dita.globodiet.dom.params.recipe_list.RecipeGroup; +import dita.globodiet.dom.params.recipe_list.RecipeSubgroup; + +//don't purge source file via GdEntityGen public interface RecipeGrouping { + + default Either toEither() { + return this instanceof RecipeSubgroup recipeSubgroup + ? Either.right(recipeSubgroup) + : Either.left((RecipeGroup)this); + } + + default String title() { + return toEither() + .fold(RecipeGroup::title, RecipeSubgroup::title); + } + + /** + * Format {@code groupCode|subgroupCode} + * with null replaced by dash {@literal -}. + */ + public record RecipeGroupingKey(String value) { + } + + default RecipeGroupingKey groupingKey() { + return this instanceof RecipeSubgroup foodSubgroup + ? new RecipeGroupingKey(keyFor(foodSubgroup)) + : new RecipeGroupingKey(keyFor((RecipeGroup)this)); + } + + // -- HELPER + + private static String keyFor(final RecipeSubgroup recipeSubgroup) { + var secKey = recipeSubgroup.secondaryKey(); + return String.format("%s|%s", + FormatUtils.emptyToDash(secKey.recipeGroupCode()), + FormatUtils.emptyToDash(secKey.code())); + } + + private static String keyFor(final RecipeGroup recipeGroup) { + return String.format("%s|-", + FormatUtils.emptyToDash(recipeGroup.secondaryKey().code())); + } + } diff --git a/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodDescriptorDeps.java b/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodDescriptorDeps.java index b3a508da..e43f78af 100644 --- a/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodDescriptorDeps.java +++ b/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodDescriptorDeps.java @@ -30,7 +30,7 @@ import dita.globodiet.dom.params.food_coefficient.RawToCookedConversionFactorForFood; import dita.globodiet.dom.params.food_coefficient.RawToCookedConversionFactorForFood_facetDescriptors; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_descriptor; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodDescriptor; import dita.globodiet.dom.params.pathway.QuantificationMethodPathwayForFoodGroup; import dita.globodiet.dom.params.pathway.QuantificationMethodPathwayForFoodGroup_physicalStateFacetDescriptor; import dita.globodiet.dom.params.quantif.MaximumValueForFoodOrGroup; @@ -58,7 +58,7 @@ public static Can> mixinClasses() { FoodDescriptor_dependentRawToCookedConversionFactorForFoodMappedByFacetDescriptors.class, FoodDescriptor_dependentFoodFacetRuleMappedByFacetDescriptor.class, FoodDescriptor_dependentImprobableSequenceOfFacetAndDescriptorMappedByDescriptor.class, - FoodDescriptor_dependentFacetDescriptorPathwayForFoodGroupMappedByDescriptor.class, + FoodDescriptor_dependentFacetDescriptorPathwayForFoodGroupMappedByFoodDescriptor.class, FoodDescriptor_dependentQuantificationMethodPathwayForFoodGroupMappedByPhysicalStateFacetDescriptor.class, FoodDescriptor_dependentMaximumValueForFoodOrGroupMappedByFacetDescriptor.class, FoodDescriptor_dependentRecipeIngredientMappedByFacetDescriptors.class, @@ -196,7 +196,7 @@ public List coll() { tableDecorator = CollectionTitleDecorator.class ) @RequiredArgsConstructor - public static class FoodDescriptor_dependentFacetDescriptorPathwayForFoodGroupMappedByDescriptor { + public static class FoodDescriptor_dependentFacetDescriptorPathwayForFoodGroupMappedByFoodDescriptor { @Inject DependantLookupService dependantLookup; @@ -206,8 +206,8 @@ public static class FoodDescriptor_dependentFacetDescriptorPathwayForFoodGroupMa public List coll() { return dependantLookup.findDependants( FacetDescriptorPathwayForFoodGroup.class, - FacetDescriptorPathwayForFoodGroup_descriptor.class, - FacetDescriptorPathwayForFoodGroup_descriptor::prop, + FacetDescriptorPathwayForFoodGroup_foodDescriptor.class, + FacetDescriptorPathwayForFoodGroup_foodDescriptor::prop, mixee); } } diff --git a/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodFacetDeps.java b/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodFacetDeps.java index be9cc74e..d5d19b2d 100644 --- a/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodFacetDeps.java +++ b/globodiet/params/src/main/java/dita/globodiet/dom/params/food_descript/FoodFacetDeps.java @@ -23,8 +23,8 @@ import dita.commons.services.lookup.DependantLookupService; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood; import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_facet; -import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_mandatoryInSequenceOfFacets; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFoodGroup_foodFacet; +import dita.globodiet.dom.params.pathway.FacetDescriptorPathwayForFood_selectedFoodFacet; import dita.globodiet.dom.params.recipe_description.RecipeFacetRule; import dita.globodiet.dom.params.recipe_description.RecipeFacetRule_facetWhereTheRuleMustBeAppliedObj; import dita.globodiet.dom.params.setting.FacetDescriptorThatCannotBeSubstituted; @@ -45,8 +45,8 @@ public static Can> mixinClasses() { return Can.of(FoodFacet_dependentFoodDescriptorMappedByFacet.class, FoodFacet_dependentFoodFacetRuleMappedByFacet.class, FoodFacet_dependentImprobableSequenceOfFacetAndDescriptorMappedByFacet.class, - FoodFacet_dependentFacetDescriptorPathwayForFoodMappedByMandatoryInSequenceOfFacets.class, - FoodFacet_dependentFacetDescriptorPathwayForFoodGroupMappedByFacet.class, + FoodFacet_dependentFacetDescriptorPathwayForFoodMappedBySelectedFoodFacet.class, + FoodFacet_dependentFacetDescriptorPathwayForFoodGroupMappedByFoodFacet.class, FoodFacet_dependentRecipeFacetRuleMappedByFacetWhereTheRuleMustBeAppliedObj.class, FoodFacet_dependentFacetDescriptorThatCannotBeSubstitutedMappedByFacet.class); } @@ -119,7 +119,7 @@ public List coll() { tableDecorator = CollectionTitleDecorator.class ) @RequiredArgsConstructor - public static class FoodFacet_dependentFacetDescriptorPathwayForFoodMappedByMandatoryInSequenceOfFacets { + public static class FoodFacet_dependentFacetDescriptorPathwayForFoodMappedBySelectedFoodFacet { @Inject DependantLookupService dependantLookup; @@ -129,8 +129,8 @@ public static class FoodFacet_dependentFacetDescriptorPathwayForFoodMappedByMand public List coll() { return dependantLookup.findDependants( FacetDescriptorPathwayForFood.class, - FacetDescriptorPathwayForFood_mandatoryInSequenceOfFacets.class, - FacetDescriptorPathwayForFood_mandatoryInSequenceOfFacets::prop, + FacetDescriptorPathwayForFood_selectedFoodFacet.class, + FacetDescriptorPathwayForFood_selectedFoodFacet::prop, mixee); } } @@ -140,7 +140,7 @@ public List coll() { tableDecorator = CollectionTitleDecorator.class ) @RequiredArgsConstructor - public static class FoodFacet_dependentFacetDescriptorPathwayForFoodGroupMappedByFacet { + public static class FoodFacet_dependentFacetDescriptorPathwayForFoodGroupMappedByFoodFacet { @Inject DependantLookupService dependantLookup; @@ -150,8 +150,8 @@ public static class FoodFacet_dependentFacetDescriptorPathwayForFoodGroupMappedB public List coll() { return dependantLookup.findDependants( FacetDescriptorPathwayForFoodGroup.class, - FacetDescriptorPathwayForFoodGroup_facet.class, - FacetDescriptorPathwayForFoodGroup_facet::prop, + FacetDescriptorPathwayForFoodGroup_foodFacet.class, + FacetDescriptorPathwayForFoodGroup_foodFacet::prop, mixee); } } diff --git a/globodiet/params/src/main/java/dita/globodiet/dom/params/pathway/FacetDescriptorPathwayForFood.java b/globodiet/params/src/main/java/dita/globodiet/dom/params/pathway/FacetDescriptorPathwayForFood.java index f48cab0a..f0d537df 100644 --- a/globodiet/params/src/main/java/dita/globodiet/dom/params/pathway/FacetDescriptorPathwayForFood.java +++ b/globodiet/params/src/main/java/dita/globodiet/dom/params/pathway/FacetDescriptorPathwayForFood.java @@ -76,7 +76,7 @@ public class FacetDescriptorPathwayForFood implements Cloneable