Skip to content

Commit

Permalink
schema update: some fields renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Mar 19, 2024
1 parent a7ba701 commit 7f67753
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
import dita.globodiet.dom.params.DitaModuleGdParams;
import dita.globodiet.manager.dashboard.Dashboard;
import dita.globodiet.manager.editing.food.Food_addFacetDescriptorPathwayToGroup;
import dita.globodiet.manager.editing.food.Food_selectFacetDescriptorPathwayForFood;
import dita.globodiet.manager.editing.food.Food_addStandardUnit;
import dita.globodiet.manager.editing.food.Food_clone;
import dita.globodiet.manager.editing.food.Food_effectiveFoodDescriptors;
import dita.globodiet.manager.editing.food.Food_effectiveGroupingUsedForFacetDescriptorPathway;
import dita.globodiet.manager.editing.food.Food_inspectPathway;
import dita.globodiet.manager.editing.food.Food_selectFacetDescriptorPathwayForFood;
import dita.globodiet.manager.editing.other.FacetDescriptorPathwayForFoodGroupManager_addEntry;
import dita.globodiet.manager.editing.other.FacetDescriptorPathwayForFoodGroupManager_fixDisplayOrder;
import dita.globodiet.manager.editing.other.FacetDescriptorPathwayForFoodGroupManager_shiftFacetDisplayOrder;
Expand All @@ -79,6 +79,7 @@
import dita.globodiet.manager.services.rule.FoodHasDensityFactorRuleChecker;
import dita.globodiet.manager.services.rule.ResolvableDependenciesRuleChecker;
import dita.globodiet.manager.services.search.SearchServiceGdParams;
import dita.globodiet.manager.services.thickness.ThicknessLookupService;
import dita.globodiet.manager.versions.ParameterDataVersion_updateDescription;
import dita.globodiet.manager.versions.ParameterDataVersion_updateName;
import dita.globodiet.schema.GdEntityGen;
Expand Down Expand Up @@ -135,6 +136,7 @@
IdGeneratorGdParams.class,
IconFaServiceGdParams.class,
FoodFacetHelperService.class,
ThicknessLookupService.class,

// Rulecheckers
FacetDescriptorPathwayForFoodSelectionExistsRuleChecker.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ private String quantificationPathwayAsYaml(
yaml.append(" physicalStateFacetDescriptor: ").append(qmPathway.getPhysicalStateFacetDescriptorLookupKey()).append("\n");
yaml.append(" rawOrCookedAsConsumed: ").append(qmPathway.getRawOrCookedAsConsumed()).append("\n");
var qmpKey = QuantificationMethodPathwayKey.valueOf(qmPathway);
if(qmpKey.quantificationMethod().isPhotoOrShape()) {
yaml.append(" photoOrShape: ").append(qmPathway.getPhotoOrShapeCode()).append("\n");
if(qmpKey.quantificationMethod().isPhoto()) {
yaml.append(" photoCode: ").append(qmPathway.getPhotoOrShapeCode()).append("\n");
}
if(qmpKey.quantificationMethod().isShape()) {
yaml.append(" shapeCode: ").append(qmPathway.getPhotoOrShapeCode()).append("\n");
}
});

//

return yaml.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.thickness;

import jakarta.inject.Inject;

import org.apache.causeway.applib.services.repository.RepositoryService;
import org.apache.causeway.commons.collections.Can;

import dita.globodiet.dom.params.classification.FoodGrouping.FoodGroupingKey;
import dita.globodiet.dom.params.classification.RecipeGrouping.RecipeGroupingKey;
import dita.globodiet.dom.params.quantif.ThicknessForShape;

public class ThicknessLookupService {

@Inject RepositoryService repositoryService;

public Can<ThicknessForShape> lookupThicknessForFood(final FoodGroupingKey key) {
return Can.ofCollection(repositoryService.allMatches(ThicknessForShape.class, thickness->
key.equalsOrIsContainedIn(thickness.getFoodGroupingLookupKey())));
}

public Can<ThicknessForShape> lookupThicknessForRecipe(final RecipeGroupingKey key) {
return Can.ofCollection(repositoryService.allMatches(ThicknessForShape.class, thickness->
key.equalsOrIsContainedIn(thickness.getRecipeGroupingLookupKey())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public enum QuantificationMethod {
STANDARD_PORTION,
SHAPE;

// -- FACTORIES

public static QuantificationMethod valueOf(final QuantificationMethodPathwayForFoodGroup.QuantificationMethod qm) {
return QuantificationMethod.valueOf(qm.name());
}
Expand All @@ -54,11 +56,14 @@ public static QuantificationMethod valueOf(final QuantificationMethodPathwayForR
return QuantificationMethod.valueOf(qm.name());
}

// -- PREDICATES

public boolean isPhoto() { return this == PHOTO; }
public boolean isShape() { return this == SHAPE; }
public boolean isPhotoOrShape() {
return this == PHOTO
|| this == SHAPE;
return isPhoto()
|| isShape();
}

}

// -- FOOD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@
import dita.globodiet.dom.params.quantif.ThicknessForShape;
import dita.globodiet.dom.params.quantif.ThicknessForShapeDeps;
import dita.globodiet.dom.params.quantif.ThicknessForShape_delete;
import dita.globodiet.dom.params.quantif.ThicknessForShape_foodSubgroups;
import dita.globodiet.dom.params.quantif.ThicknessForShape_recipeSubgroups;
import dita.globodiet.dom.params.quantif.ThicknessForShape_foodGrouping;
import dita.globodiet.dom.params.quantif.ThicknessForShape_recipeGrouping;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipe;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipeDeps;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipe_delete;
Expand Down Expand Up @@ -736,8 +736,8 @@
SubjectToBeInterviewed_country.class,
SubjectToBeInterviewed_delete.class,
ThicknessForShape_delete.class,
ThicknessForShape_foodSubgroups.class,
ThicknessForShape_recipeSubgroups.class,
ThicknessForShape_foodGrouping.class,
ThicknessForShape_recipeGrouping.class,
TranslationInCountryLanguage_delete.class
})
public class DitaModuleGdParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
// Auto-generated by DitA-Tooling
package dita.globodiet.dom.params.classification;

import org.springframework.lang.Nullable;

import org.apache.causeway.commons.functional.Either;
import org.apache.causeway.commons.internal.assertions._Assert;
import org.apache.causeway.commons.internal.base._Strings;

import dita.commons.format.FormatUtils;
import dita.globodiet.dom.params.food_list.FoodGroup;
Expand Down Expand Up @@ -48,17 +52,44 @@ public record FoodGroupingKey(
* Format {@code groupCode|subgroupCode|subSubgroupCode}
* with null replaced by dash {@literal -}.
*/
String combinedKey) {
String combinedKey,
String lookupKey) {

public FoodGroupingKey(
final String foodGroupCode,
final String foodSubgroupCode,
final String foodSubSubgroupCode) {
this(foodGroupCode, foodSubgroupCode, foodSubSubgroupCode,
this(
validateGroup(foodGroupCode, foodSubgroupCode),
validateSubGroup(foodSubgroupCode, foodSubSubgroupCode),
foodSubSubgroupCode,
String.format("%s|%s|%s",
FormatUtils.emptyToDash(foodGroupCode),
FormatUtils.emptyToDash(foodSubgroupCode),
FormatUtils.emptyToDash(foodSubSubgroupCode)));
FormatUtils.emptyToDash(foodSubSubgroupCode)),
String.format("%s%s%s",
_Strings.nullToEmpty(foodGroupCode),
_Strings.nullToEmpty(foodSubgroupCode),
_Strings.nullToEmpty(foodSubSubgroupCode)));
}

public boolean equalsOrIsContainedIn(final @Nullable String foodGroupingLookupKey) {
return _Strings.splitThenStream(foodGroupingLookupKey, ",")
.anyMatch(lookupKey()::equals);
}

private static String validateGroup(final String foodGroupCode, final String foodSubgroupCode) {
if(_Strings.isNullOrEmpty(foodGroupCode)) {
_Assert.assertTrue(_Strings.isNullOrEmpty(foodSubgroupCode));
}
return foodGroupCode;
}

private static String validateSubGroup(final String foodSubgroupCode, final String foodSubSubgroupCode) {
if(_Strings.isNullOrEmpty(foodSubgroupCode)) {
_Assert.assertTrue(_Strings.isNullOrEmpty(foodSubSubgroupCode));
}
return foodSubgroupCode;
}

private FoodGroupingKey(
Expand All @@ -70,7 +101,6 @@ private FoodGroupingKey(
final FoodSubgroup.SecondaryKey secKey) {
this(secKey.foodGroupCode(), secKey.foodSubgroupCode(), secKey.foodSubSubgroupCode());
}

}

default FoodGroupingKey groupingKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package dita.globodiet.dom.params.classification;

import org.apache.causeway.commons.functional.Either;
import org.apache.causeway.commons.internal.assertions._Assert;
import org.apache.causeway.commons.internal.base._Strings;

import dita.commons.format.FormatUtils;
import dita.globodiet.dom.params.recipe_list.RecipeGroup;
Expand All @@ -40,30 +42,52 @@ default String title() {
}

/**
* Format {@code groupCode|subgroupCode}
* combinedKey: Format {@code groupCode|subgroupCode}
* with null replaced by dash {@literal -}.
*/
public record RecipeGroupingKey(String value) {
public record RecipeGroupingKey(
String combinedKey,
String lookupKey) {

public boolean equalsOrIsContainedIn(final String recipeGroupingLookupKey) {
return _Strings.splitThenStream(recipeGroupingLookupKey, ",")
.anyMatch(lookupKey()::equals);
}
}

default RecipeGroupingKey groupingKey() {
return this instanceof RecipeSubgroup foodSubgroup
? new RecipeGroupingKey(keyFor(foodSubgroup))
: new RecipeGroupingKey(keyFor((RecipeGroup)this));
? new RecipeGroupingKey(combinedKey(foodSubgroup), lookupKey(foodSubgroup))
: new RecipeGroupingKey(combinedKey((RecipeGroup)this), lookupKey((RecipeGroup)this));
}

// -- HELPER

private static String keyFor(final RecipeSubgroup recipeSubgroup) {
private static String combinedKey(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) {
private static String combinedKey(final RecipeGroup recipeGroup) {
return String.format("%s|-",
FormatUtils.emptyToDash(recipeGroup.secondaryKey().code()));
}

private static String lookupKey(final RecipeSubgroup recipeSubgroup) {
var secKey = recipeSubgroup.secondaryKey();
if(_Strings.isNullOrEmpty(secKey.recipeGroupCode())) {
_Assert.assertTrue(_Strings.isNullOrEmpty(secKey.code()));
}
return String.format("%s%s",
_Strings.nullToEmpty(secKey.recipeGroupCode()),
_Strings.nullToEmpty(secKey.code()));
}

private static String lookupKey(final RecipeGroup recipeGroup) {
return String.format("%s",
_Strings.nullToEmpty(recipeGroup.secondaryKey().code()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import dita.globodiet.dom.params.quantif.MaximumValueForFoodOrGroup_foodSubSubgroup;
import dita.globodiet.dom.params.quantif.MaximumValueForFoodOrGroup_foodSubgroup;
import dita.globodiet.dom.params.quantif.ThicknessForShape;
import dita.globodiet.dom.params.quantif.ThicknessForShape_foodSubgroups;
import dita.globodiet.dom.params.quantif.ThicknessForShape_foodGrouping;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipe;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipe_fssSubSubgroup;
import dita.globodiet.dom.params.recipe_coefficient.PercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipe_fssSubgroup;
Expand Down Expand Up @@ -111,7 +111,7 @@ public static Can<Class<?>> mixinClasses() {
FoodSubgroup_dependentQuantificationMethodPathwayForFoodGroupMappedByFoodSubSubgroup.class,
FoodSubgroup_dependentMaximumValueForFoodOrGroupMappedByFoodSubgroup.class,
FoodSubgroup_dependentMaximumValueForFoodOrGroupMappedByFoodSubSubgroup.class,
FoodSubgroup_dependentThicknessForShapeMappedByFoodSubgroups.class,
FoodSubgroup_dependentThicknessForShapeMappedByFoodGrouping.class,
FoodSubgroup_dependentPercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipeMappedByFssSubgroup.class,
FoodSubgroup_dependentPercentOfFatOrSauceOrSweetenerAddedAfterCookingForRecipeMappedByFssSubSubgroup.class,
FoodSubgroup_dependentRecipeIngredientMappedByFoodOrRecipeSubgroup.class,
Expand Down Expand Up @@ -714,7 +714,7 @@ public List<MaximumValueForFoodOrGroup> coll() {
tableDecorator = CollectionTitleDecorator.class
)
@RequiredArgsConstructor
public static class FoodSubgroup_dependentThicknessForShapeMappedByFoodSubgroups {
public static class FoodSubgroup_dependentThicknessForShapeMappedByFoodGrouping {
@Inject
DependantLookupService dependantLookup;

Expand All @@ -724,8 +724,8 @@ public static class FoodSubgroup_dependentThicknessForShapeMappedByFoodSubgroups
public List<ThicknessForShape> coll() {
return dependantLookup.findDependants(
ThicknessForShape.class,
ThicknessForShape_foodSubgroups.class,
ThicknessForShape_foodSubgroups::coll,
ThicknessForShape_foodGrouping.class,
ThicknessForShape_foodGrouping::coll,
mixee);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public class ThicknessForShape implements Cloneable<ThicknessForShape>, HasSecon
)
@Getter
@Setter
private String foodSubgroupsLookupKey;
private String foodGroupingLookupKey;

/**
* For the recipe items, the recipe (sub)groups for which this thickness has to be proposed.
Expand Down Expand Up @@ -208,7 +208,7 @@ public class ThicknessForShape implements Cloneable<ThicknessForShape>, HasSecon
)
@Getter
@Setter
private String recipeSubgroupsLookupKey;
private String recipeGroupingLookupKey;

@ObjectSupport
public String title() {
Expand All @@ -220,8 +220,8 @@ public String toString() {
return "ThicknessForShape(" + "code=" + getCode() + ","
+"thickness=" + getThickness() + ","
+"comment=" + getComment() + ","
+"foodSubgroupsLookupKey=" + getFoodSubgroupsLookupKey() + ","
+"recipeSubgroupsLookupKey=" + getRecipeSubgroupsLookupKey() + ")";
+"foodGroupingLookupKey=" + getFoodGroupingLookupKey() + ","
+"recipeGroupingLookupKey=" + getRecipeGroupingLookupKey() + ")";
}

@Programmatic
Expand All @@ -231,8 +231,8 @@ public ThicknessForShape copy() {
copy.setCode(getCode());
copy.setThickness(getThickness());
copy.setComment(getComment());
copy.setFoodSubgroupsLookupKey(getFoodSubgroupsLookupKey());
copy.setRecipeSubgroupsLookupKey(getRecipeSubgroupsLookupKey());
copy.setFoodGroupingLookupKey(getFoodGroupingLookupKey());
copy.setRecipeGroupingLookupKey(getRecipeGroupingLookupKey());
return copy;
}

Expand Down Expand Up @@ -297,13 +297,13 @@ public final String viewModelMemento() {
* @param code Thickness code (e.g. A,B,C,58_1,58_2...)
* @param thickness has no description
* @param comment Comment attached to the thickness (e.g. small, medium, large…)
* @param foodSubgroups For the food items, the food (sub)groups for which this thickness has to be proposed.
* @param foodGrouping For the food items, the food (sub)groups for which this thickness has to be proposed.
* These (sub)groups have to be separated with a comma (e.g. 0603,1002,1003,1101)
* When this field is empty, that means that this thickness has always to be proposed
* whatever the food classification.
* Multiple subgroup.group and/or subgroup.subgroup1
* and/or subgroup.subgroup2 comma-separated (e.g. 0603,10,1102)
* @param recipeSubgroups For the recipe items, the recipe (sub)groups for which this thickness has to be proposed.
* @param recipeGrouping For the recipe items, the recipe (sub)groups for which this thickness has to be proposed.
* These (sub)groups have to be separated with a comma (e.g. 01,02,0301)
* When this field is empty, that means that this thickness has always to be proposed
* whatever the recipe classification.
Expand Down Expand Up @@ -346,7 +346,7 @@ public final record Params(
+ "Multiple subgroup.group and/or subgroup.subgroup1\n"
+ "and/or subgroup.subgroup2 comma-separated (e.g. 0603,10,1102)"
)
FoodSubgroup foodSubgroups,
FoodSubgroup foodGrouping,
@Parameter(
precedingParamsPolicy = PrecedingParamsPolicy.PRESERVE_CHANGES,
optionality = Optionality.OPTIONAL
Expand All @@ -358,7 +358,7 @@ public final record Params(
+ "whatever the recipe classification.\n"
+ "Muliple rsubgr.group and/or rsubgr.subgroup comma-separated (e.g. 01,0601)"
)
RecipeSubgroup recipeSubgroups) {
RecipeSubgroup recipeGrouping) {
}

/**
Expand Down
Loading

0 comments on commit 7f67753

Please sign in to comment.