Skip to content

Commit

Permalink
(#21): further prepare pathway view support
Browse files Browse the repository at this point in the history
- calculate effective groups
  • Loading branch information
andi-huber committed Mar 10, 2024
1 parent 61629a4 commit 22df287
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/
// Auto-generated by DitA-Tooling
package dita.globodiet.manager.editing.recipe;

import jakarta.inject.Inject;

import org.apache.causeway.applib.annotation.MemberSupport;
import org.apache.causeway.applib.annotation.Property;
import org.apache.causeway.applib.annotation.PropertyLayout;
import org.apache.causeway.applib.annotation.Snapshot;
import org.apache.causeway.applib.annotation.Where;

import lombok.RequiredArgsConstructor;

import dita.globodiet.dom.params.classification.RecipeGrouping;
import dita.globodiet.dom.params.recipe_list.Recipe;
import dita.globodiet.manager.services.recipe.RecipeFacetHelperService;

@Property(
snapshot = Snapshot.EXCLUDED
)
@PropertyLayout(
fieldSetId = "details",
sequence = "90.0",
describedAs = "Indicates the RecipeGroup or RecipeSubgroup, "
+ "that is used to calculate the 'Effective Recipe Descriptors' list.",
hidden = Where.ALL_TABLES
)
@RequiredArgsConstructor
public class Recipe_effectiveGroupingUsedForFacetDescriptorPathway {

@Inject private RecipeFacetHelperService recipeFacetHelperService;

private final Recipe mixee;

@MemberSupport
public RecipeGrouping prop() {
return recipeFacetHelperService.effectiveGroupingUsedForFacetDescriptorPathway(mixee);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/
// Auto-generated by DitA-Tooling
package dita.globodiet.manager.editing.recipe;

import jakarta.inject.Inject;

import org.apache.causeway.applib.annotation.MemberSupport;
import org.apache.causeway.applib.annotation.Property;
import org.apache.causeway.applib.annotation.PropertyLayout;
import org.apache.causeway.applib.annotation.Snapshot;
import org.apache.causeway.applib.annotation.Where;

import lombok.RequiredArgsConstructor;

import dita.globodiet.dom.params.recipe_list.Recipe;
import dita.globodiet.dom.params.recipe_list.RecipeGroup;
import dita.globodiet.manager.services.recipe.RecipeQuantificationHelperService;

@Property(
snapshot = Snapshot.EXCLUDED
)
@PropertyLayout(
fieldSetId = "details",
sequence = "91.0",
describedAs = "Indicates the RecipeGroup, "
+ "that is used to calculate the 'Effective Quantification' list.",
hidden = Where.ALL_TABLES
)
@RequiredArgsConstructor
public class Recipe_effectiveGroupingUsedForQuantificationPathway {

@Inject private RecipeQuantificationHelperService recipeQuantificationHelperService;

private final Recipe mixee;

@MemberSupport
public RecipeGroup prop() {
return recipeQuantificationHelperService.effectiveGroupingUsedForQuantificationPathway(mixee);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private List<FacetDescriptorPathwayForFoodGroup> listFacetDescriptorPathwayForFo
FoodGroup_dependentFacetDescriptorPathwayForFoodGroupMappedByFoodGroup.class,
foodGroup);
// include only those, that have no subgroup (or sub-subgroup)
return _Lists.filter(mixin.coll(), groupPathway->groupPathway.getFoodSubgroupCode()==null);
return _Lists.filter(mixin.coll(), groupPathway->groupPathway.getFoodSubgroupCode()==null
&& groupPathway.getFoodSubSubgroupCode()==null);
}

private List<FacetDescriptorPathwayForFoodGroup> listFacetDescriptorPathwayForFoodSubgroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.causeway.applib.services.factory.FactoryService;
import org.apache.causeway.commons.functional.Either;
import org.apache.causeway.commons.internal.collections._Lists;

import lombok.NonNull;

Expand Down Expand Up @@ -130,10 +131,11 @@ public Set<RecipeFacet.SecondaryKey> selectedFacetDescriptorPathwayForRecipeAsRe

private List<FacetDescriptorPathwayForRecipeGroup> listFacetDescriptorPathwayForRecipeGroup(
final RecipeGroup recipeGroup) {
return factoryService.mixin(
var mixin = factoryService.mixin(
RecipeGroup_dependentFacetDescriptorPathwayForRecipeGroupMappedByRecipeGroup.class,
recipeGroup)
.coll();
recipeGroup);
// include only those, that have no subgroup
return _Lists.filter(mixin.coll(), groupPathway->groupPathway.getRecipeSubgroupCode()==null);
}

private List<FacetDescriptorPathwayForRecipeGroup> listFacetDescriptorPathwayForRecipeSubgroup(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.List;

import jakarta.inject.Inject;

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.QuantificationMethodPathwayForRecipe;
import dita.globodiet.dom.params.pathway.QuantificationMethodPathwayForRecipeGroup;
import dita.globodiet.dom.params.recipe_list.Recipe;
import dita.globodiet.dom.params.recipe_list.RecipeDeps.Recipe_dependentQuantificationMethodPathwayForRecipeMappedByRecipe;
import dita.globodiet.dom.params.recipe_list.RecipeGroup;
import dita.globodiet.dom.params.recipe_list.RecipeGroupDeps.RecipeGroup_dependentQuantificationMethodPathwayForRecipeGroupMappedByRecipeGroup;
import dita.globodiet.dom.params.recipe_list.RecipeSubgroup;
import dita.globodiet.manager.services.grouping.GroupingHelperService;

@Service
public class RecipeQuantificationHelperService {

@Inject private FactoryService factoryService;
@Inject private GroupingHelperService groupingHelperService;

public List<QuantificationMethodPathwayForRecipeGroup> effectiveQuantificationMethodPathwayForRecipeClassification(
final @NonNull RecipeGrouping recipeGrouping) {
final @NonNull Either<RecipeGroup, RecipeSubgroup> recipeClassification = recipeGrouping.toEither();
final List<QuantificationMethodPathwayForRecipeGroup> facetQuantificationMethodForRecipeGroup =
recipeClassification
.fold(
recipeGroup->
listQuantificationMethodPathwayForRecipeGroup(recipeGroup),
recipeSubgroup->
listQuantificationMethodPathwayForRecipeGroup(
groupingHelperService.recipeGroup(recipeClassification.rightIfAny())));

return facetQuantificationMethodForRecipeGroup;
}

public RecipeGroup effectiveGroupingUsedForQuantificationPathway(final Recipe recipe) {
var recipeClassification = groupingHelperService.recipeClassification(recipe);
return recipeClassification
.fold(
recipeGroup->recipeGroup,
recipeSubgroup->groupingHelperService.recipeGroup(recipeClassification.rightIfAny()));
}

public List<QuantificationMethodPathwayForRecipe> listQuantificationMethodPathwayForRecipe(final @NonNull Recipe recipe) {
var mixin = factoryService.mixin(Recipe_dependentQuantificationMethodPathwayForRecipeMappedByRecipe.class, recipe);
return mixin.coll();
}

// -- HELPER

private List<QuantificationMethodPathwayForRecipeGroup> listQuantificationMethodPathwayForRecipeGroup(
final RecipeGroup recipeGroup) {
var mixin = factoryService.mixin(
RecipeGroup_dependentQuantificationMethodPathwayForRecipeGroupMappedByRecipeGroup.class,
recipeGroup);
return mixin.coll();
}

}

0 comments on commit 22df287

Please sign in to comment.