diff --git a/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java b/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java index 2648642cafecb4e3f2949f153f330eb5bbec0beb..fb76b98538849532fa245eeb23ece73d465d5fd7 100644 --- a/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java +++ b/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java @@ -840,7 +840,7 @@ public final class Evaluation extends CompositeIndicator { */ public boolean isOnErrorOrIncomplete(final boolean fire) { final boolean hasClimaticIndicator = containsClimaticIndicator(fire); - final boolean isToAggregate = toAggregate(fire); + final boolean isToAggregate = isAggregationMissing(fire); final boolean isComputable = isComputable(); return !hasClimaticIndicator || isToAggregate || !isComputable; diff --git a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java index 1de200579ef216ec319b9b70322c1678a21d9fdb..173d70baec44dc0cce0427acd42d39b0c1678ba5 100644 --- a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java +++ b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java @@ -478,6 +478,36 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { .forEach(ind -> ((CompositeIndicator) ind).initializeParent()); } + /** + * Detect if aggregation function is needed but missing. + * + * @param fire fire events while checking + * @return true if aggregation function is needed but missing + */ + public final boolean isAggregationMissing(final boolean fire) { + if (getType() == EvaluationType.WITHOUT_AGGREGATION) { + return false; + } + boolean isMissing = false; + final AggregationFunction aggregation = getAggregationFunction(); + if (isAggregationNeeded() + && (aggregation == null || !aggregation.isValid())) { + if (fire) { + fireIndicatorEvent(IndicatorEvent.Type.AGGREGATION_MISSING + .event(this)); + } + isMissing = true; + } + + for (final Indicator indicator : getIndicators()) { + if (indicator instanceof CompositeIndicator compositeIndicator + && compositeIndicator.isAggregationMissing(fire)) { + isMissing = true; + } + } + return isMissing; + } + /** * @return if aggregation is needed, according to category and number of * composed indicators @@ -588,7 +618,7 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { fireAggregationFunctionUpdated(); } fireIndicatorEvent(IndicatorEvent.Type.REMOVE.event(i)); - toAggregate(true); + isAggregationMissing(true); if (!containsClimaticIndicator()) { /* Ne contient pas d'indicateur climatique */ fireIndicatorEvent( @@ -619,29 +649,11 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { * * @param fire fire events while checking * @return true if aggregation function is needed but missing + * @deprecated use {@link CompositeIndicator#isAggregationMissing(boolean)}. */ + @Deprecated(since = "2.0.1", forRemoval = true) public final boolean toAggregate(final boolean fire) { - if (getType() == EvaluationType.WITHOUT_AGGREGATION) { - return false; - } - boolean toAggregate = false; - final AggregationFunction aggregation = getAggregationFunction(); - if (isAggregationNeeded() - && (aggregation == null || !aggregation.isValid())) { - if (fire) { - fireIndicatorEvent(IndicatorEvent.Type.AGGREGATION_MISSING - .event(this)); - } - toAggregate = true; - } - - for (final Indicator indicator : getIndicators()) { - if (indicator instanceof CompositeIndicator compositeIndicator - && compositeIndicator.toAggregate(fire)) { - toAggregate = true; - } - } - return toAggregate; + return isAggregationMissing(fire); } @Override diff --git a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java index a7bf99dde53422c0617e118b6146a4f9cca33bfb..a3f975d440362218c78939090d20dd93caa464e9 100644 --- a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java +++ b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java @@ -449,14 +449,14 @@ public final class EvaluationTest extends DataTestHelper { } /** - * Test toAggregate(). + * Test isAggregationMissing(). */ @Test - public void toAggregate() { + public void isAggregationMissing() { assertTrue("Evaluation must not be null!", evaluation != null); - boolean found = evaluation.toAggregate(false); + boolean found = evaluation.isAggregationMissing(false); assertFalse("evaluation do not need to be aggregated!", found); - found = evaluation.toAggregate(true); + found = evaluation.isAggregationMissing(true); assertFalse("evaluation do not need to be aggregated!", found); } diff --git a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java index 6bc188249d87bbd0d0e6a57bd195d3171cb5b7f0..2394bd379df1817037d83edc2cac6601e3be6f41 100644 --- a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java +++ b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java @@ -138,14 +138,14 @@ public class EvaluationWithoutAggregationTest extends DataTestHelper { } /** - * Test toAggregate(). + * Test isAggregationMissing(). */ @Test - public void toAggregate() { + public void isAggregationMissing() { assertNotNull("Evaluation must not be null!", evaluation); - boolean found = evaluation.toAggregate(false); + boolean found = evaluation.isAggregationMissing(false); assertFalse("evaluation do not need to be aggregated!", found); - found = evaluation.toAggregate(true); + found = evaluation.isAggregationMissing(true); assertFalse("evaluation do not need to be aggregated!", found); }