diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 433a434c..dc1c2c9d 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -45,4 +45,4 @@ jobs:
nexus_username: ${{ secrets.nexus_username }}
nexus_password: ${{ secrets.nexus_password }}
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d391a094..a20001d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.hisp.dhis.rules
rule-engine
- 2.0.4-SNAPSHOT
+ 2.0.5-SNAPSHOT
jar
rule-engine
@@ -246,7 +246,7 @@
org.hisp.dhis.parser
dhis-antlr-expression-parser
- 1.0.7-SNAPSHOT
+ 1.0.7
diff --git a/src/main/java/org/hisp/dhis/rules/RuleEngine.java b/src/main/java/org/hisp/dhis/rules/RuleEngine.java
index 415024af..4a25a1fb 100644
--- a/src/main/java/org/hisp/dhis/rules/RuleEngine.java
+++ b/src/main/java/org/hisp/dhis/rules/RuleEngine.java
@@ -83,7 +83,6 @@ public Callable> evaluate( @Nonnull RuleEvent ruleEvent, @Nonnu
.ruleEnrollment( ruleEnrollment )
.triggerEnvironment( triggerEnvironment )
.ruleEvents( ruleEvents )
- .calculatedValueMap( ruleEngineContext.calculatedValueMap() )
.constantValueMap( ruleEngineContext.constantsValues() )
.build();
@@ -103,7 +102,6 @@ public Callable> evaluate( @Nonnull RuleEnrollment ruleEnrollme
.ruleVariables( ruleEngineContext.ruleVariables() )
.triggerEnvironment( triggerEnvironment )
.ruleEvents( ruleEvents )
- .calculatedValueMap( ruleEngineContext.calculatedValueMap() )
.constantValueMap( ruleEngineContext.constantsValues() )
.build();
diff --git a/src/main/java/org/hisp/dhis/rules/RuleEngineContext.java b/src/main/java/org/hisp/dhis/rules/RuleEngineContext.java
index d0ab3d22..01583289 100644
--- a/src/main/java/org/hisp/dhis/rules/RuleEngineContext.java
+++ b/src/main/java/org/hisp/dhis/rules/RuleEngineContext.java
@@ -22,20 +22,15 @@ public final class RuleEngineContext
@Nonnull
private final Map> supplementaryData;
- @Nonnull
- private final Map> calculatedValueMap;
-
@Nonnull
private final Map constantsValues;
RuleEngineContext( @Nonnull List rules, @Nonnull List ruleVariables,
- Map> supplementaryData,
- Map> calculatedValueMap, Map constantsValues )
+ Map> supplementaryData, Map constantsValues )
{
this.rules = rules;
this.ruleVariables = ruleVariables;
this.supplementaryData = supplementaryData;
- this.calculatedValueMap = calculatedValueMap;
this.constantsValues = constantsValues;
}
@@ -70,12 +65,6 @@ public Map> supplementaryData()
return supplementaryData;
}
- @Nonnull
- public Map> calculatedValueMap()
- {
- return calculatedValueMap;
- }
-
@Nonnull
public Map constantsValues()
{
@@ -100,9 +89,6 @@ public static class Builder
@Nullable
private Map> supplementaryData;
- @Nullable
- private Map> calculatedValueMap;
-
@Nullable
private Map constantsValues;
@@ -149,14 +135,9 @@ public Builder supplementaryData( Map> supplementaryData )
return this;
}
- @Nonnull
+ @Deprecated
public Builder calculatedValueMap( Map> calculatedValueMap )
{
- if ( calculatedValueMap == null )
- {
- throw new IllegalArgumentException( "calculatedValueMap == null" );
- }
- this.calculatedValueMap = calculatedValueMap;
return this;
}
@@ -184,8 +165,7 @@ public RuleEngineContext build()
ruleVariables = unmodifiableList( new ArrayList() );
}
- return new RuleEngineContext( rules, ruleVariables, supplementaryData, calculatedValueMap,
- constantsValues );
+ return new RuleEngineContext( rules, ruleVariables, supplementaryData, constantsValues );
}
}
}
diff --git a/src/main/java/org/hisp/dhis/rules/RuleEngineExecution.java b/src/main/java/org/hisp/dhis/rules/RuleEngineExecution.java
index d99d002c..2beb8eb7 100644
--- a/src/main/java/org/hisp/dhis/rules/RuleEngineExecution.java
+++ b/src/main/java/org/hisp/dhis/rules/RuleEngineExecution.java
@@ -160,6 +160,7 @@ private String process( String condition )
{
return "";
}
+
CommonExpressionVisitor commonExpressionVisitor = CommonExpressionVisitor.newBuilder()
.withFunctionMap( FUNCTIONS )
.withVariablesMap( valueMap )
diff --git a/src/main/java/org/hisp/dhis/rules/RuleVariableValueMapBuilder.java b/src/main/java/org/hisp/dhis/rules/RuleVariableValueMapBuilder.java
index 09825dd8..332f2606 100644
--- a/src/main/java/org/hisp/dhis/rules/RuleVariableValueMapBuilder.java
+++ b/src/main/java/org/hisp/dhis/rules/RuleVariableValueMapBuilder.java
@@ -54,9 +54,6 @@ public final class RuleVariableValueMapBuilder
@Nonnull
public final SimpleDateFormat dateFormat;
- @Nonnull
- public final Map> calculatedValueMap;
-
@Nonnull
private final Map allConstantValues;
@@ -82,7 +79,6 @@ private RuleVariableValueMapBuilder()
// collections used for construction of resulting variable value map
this.ruleVariables = new ArrayList<>();
this.ruleEvents = new ArrayList<>();
- this.calculatedValueMap = new HashMap<>();
this.allConstantValues = new HashMap<>();
}
@@ -159,13 +155,6 @@ RuleVariableValueMapBuilder ruleEvents( @Nonnull List ruleEvents )
return this;
}
- @Nonnull
- RuleVariableValueMapBuilder calculatedValueMap( @Nonnull Map> calculatedValueMap )
- {
- this.calculatedValueMap.putAll( calculatedValueMap );
- return this;
- }
-
@Nonnull
RuleVariableValueMapBuilder constantValueMap( @Nonnull Map constantValues )
{
diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionHideOptionGroup.java b/src/main/java/org/hisp/dhis/rules/models/RuleActionHideOptionGroup.java
index c6bb8d5c..71ccf67f 100644
--- a/src/main/java/org/hisp/dhis/rules/models/RuleActionHideOptionGroup.java
+++ b/src/main/java/org/hisp/dhis/rules/models/RuleActionHideOptionGroup.java
@@ -12,7 +12,7 @@ public abstract class RuleActionHideOptionGroup
@Nonnull
public static RuleActionHideOptionGroup create(
- @Nullable String content, @Nonnull String optionGroup, @Nonnull String field )
+ @Nullable String content, @Nonnull String optionGroup, @Nonnull String field )
{
return new AutoValue_RuleActionHideOptionGroup( "", content == null ? "" : content, optionGroup, field );
}
diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionMessage.java b/src/main/java/org/hisp/dhis/rules/models/RuleActionMessage.java
index fa828ef2..7021bd0c 100644
--- a/src/main/java/org/hisp/dhis/rules/models/RuleActionMessage.java
+++ b/src/main/java/org/hisp/dhis/rules/models/RuleActionMessage.java
@@ -2,7 +2,7 @@
import javax.annotation.Nonnull;
-abstract class RuleActionMessage
+public abstract class RuleActionMessage
extends RuleAction
{
diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.java b/src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.java
index d0733be5..9c96312a 100644
--- a/src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.java
+++ b/src/main/java/org/hisp/dhis/rules/models/RuleVariableCalculatedValue.java
@@ -69,32 +69,8 @@ public Map createValues( RuleVariableValueMapBuilder
Map currentEventValues )
{
Map valueMap = Maps.newHashMap();
- if ( builder.ruleEnrollment == null )
- {
- return valueMap;
- }
- RuleVariableValue variableValue;
- if ( builder.calculatedValueMap.containsKey( builder.ruleEnrollment.enrollment() ) )
- {
- if ( builder.calculatedValueMap.get( builder.ruleEnrollment.enrollment() ).containsKey( this.name() ) )
- {
- String value = builder.calculatedValueMap.get( builder.ruleEnrollment.enrollment() ).get( this.name() );
-
- variableValue = RuleVariableValue.create( value, this.calculatedValueType(),
- Arrays.asList( value ), dateFormat.format( new Date() ) );
- }
- else
- {
- variableValue = RuleVariableValue.create( this.calculatedValueType() );
- }
- }
- else
- {
- variableValue = RuleVariableValue.create( this.calculatedValueType() );
- }
-
- valueMap.put( this.name(), variableValue );
+ valueMap.put( this.name(), RuleVariableValue.create( this.calculatedValueType() ) );
return valueMap;
}
}
diff --git a/src/test/java/org/hisp/dhis/rules/ConstantsValueTests.java b/src/test/java/org/hisp/dhis/rules/ConstantsValueTests.java
index 396b677f..1018f284 100644
--- a/src/test/java/org/hisp/dhis/rules/ConstantsValueTests.java
+++ b/src/test/java/org/hisp/dhis/rules/ConstantsValueTests.java
@@ -54,7 +54,6 @@ public void shouldThrowExceptionIfConstantsValueMapIsNull()
.rules( Arrays.asList( mock( org.hisp.dhis.rules.models.Rule.class ) ) )
.ruleVariables( Arrays.asList( mock( RuleVariable.class ) ) )
.supplementaryData( new HashMap>() )
- .calculatedValueMap( new HashMap>() )
.constantsValue( null )
.build();
@@ -202,7 +201,6 @@ private RuleEngine.Builder getRuleEngine( List rules,
.builder()
.rules( rules )
.ruleVariables( Arrays.asList() )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( constantsValueMap )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );
diff --git a/src/test/java/org/hisp/dhis/rules/ProgramRuleVariableTest.java b/src/test/java/org/hisp/dhis/rules/ProgramRuleVariableTest.java
index a212b0a1..1b9b4935 100644
--- a/src/test/java/org/hisp/dhis/rules/ProgramRuleVariableTest.java
+++ b/src/test/java/org/hisp/dhis/rules/ProgramRuleVariableTest.java
@@ -348,7 +348,6 @@ private RuleEngine.Builder getRuleEngine( List rules )
.builder()
.rules( rules )
.ruleVariables( Arrays.asList() )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );
diff --git a/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTests.java b/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTests.java
index 368bedc5..45427bb6 100644
--- a/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTests.java
+++ b/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTests.java
@@ -132,7 +132,6 @@ public void simpleConditionMustResultInHideFieldEffect()
RuleEngine ruleEngine = RuleEngineContext
.builder()
.rules( Arrays.asList( rule, rule2 ) )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
@@ -331,7 +330,6 @@ private RuleEngine getRuleEngine( Rule rule )
return RuleEngineContext
.builder()
.rules( Arrays.asList( rule ) )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
diff --git a/src/test/java/org/hisp/dhis/rules/RuleEngineFunctionTests.java b/src/test/java/org/hisp/dhis/rules/RuleEngineFunctionTests.java
index a7e2a28f..8111ea41 100644
--- a/src/test/java/org/hisp/dhis/rules/RuleEngineFunctionTests.java
+++ b/src/test/java/org/hisp/dhis/rules/RuleEngineFunctionTests.java
@@ -187,7 +187,6 @@ public void evaluateD2InOrgUnitGroup()
.rules( Arrays.asList( rule ) )
.ruleVariables( Arrays.asList( ruleVariableOne ) )
.supplementaryData( supplementaryData )
- .calculatedValueMap( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
.build();
@@ -226,7 +225,6 @@ public void evaluateD2InOrgUnitGroupWithStringValue()
.rules( Arrays.asList( rule ) )
.ruleVariables( Arrays.asList( ruleVariableOne ) )
.supplementaryData( supplementaryData )
- .calculatedValueMap( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
.build();
@@ -264,7 +262,6 @@ public void evaluateD2HasUserRole()
.rules( Arrays.asList( rule ) )
.ruleVariables( Arrays.asList( ruleVariableOne ) )
.supplementaryData( supplementaryData )
- .calculatedValueMap( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
.build();
@@ -302,7 +299,6 @@ public void evaluateD2HasUserRoleWithStringValue()
.rules( Arrays.asList( rule ) )
.ruleVariables( Arrays.asList( ruleVariableOne ) )
.supplementaryData( supplementaryData )
- .calculatedValueMap( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
.build();
@@ -1346,7 +1342,6 @@ private RuleEngine.Builder getRuleEngineBuilder( Rule rule, List r
.builder()
.rules( Arrays.asList( rule ) )
.ruleVariables( ruleVariables )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );
diff --git a/src/test/java/org/hisp/dhis/rules/RuleEngineValueTypesTests.java b/src/test/java/org/hisp/dhis/rules/RuleEngineValueTypesTests.java
index 6e29073a..534c8d39 100644
--- a/src/test/java/org/hisp/dhis/rules/RuleEngineValueTypesTests.java
+++ b/src/test/java/org/hisp/dhis/rules/RuleEngineValueTypesTests.java
@@ -86,7 +86,6 @@ private RuleEngine getRuleEngine( Rule rule, List ruleVariables )
.builder()
.rules( Arrays.asList( rule ) )
.ruleVariables( ruleVariables )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER )
diff --git a/src/test/java/org/hisp/dhis/rules/RuleEngineVariableNameTests.java b/src/test/java/org/hisp/dhis/rules/RuleEngineVariableNameTests.java
index db359b76..3561be22 100644
--- a/src/test/java/org/hisp/dhis/rules/RuleEngineVariableNameTests.java
+++ b/src/test/java/org/hisp/dhis/rules/RuleEngineVariableNameTests.java
@@ -545,7 +545,6 @@ private RuleEngine.Builder getRuleEngineBuilder( Rule rule, List r
.builder()
.rules( Arrays.asList( rule ) )
.ruleVariables( ruleVariables )
- .calculatedValueMap( new HashMap>() )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );
diff --git a/src/test/java/org/hisp/dhis/rules/models/CalculatedValueTests.java b/src/test/java/org/hisp/dhis/rules/models/CalculatedValueTests.java
index 219dd089..931570a3 100644
--- a/src/test/java/org/hisp/dhis/rules/models/CalculatedValueTests.java
+++ b/src/test/java/org/hisp/dhis/rules/models/CalculatedValueTests.java
@@ -54,17 +54,6 @@
@RunWith( JUnit4.class )
public class CalculatedValueTests
{
- @Test( expected = IllegalArgumentException.class )
- public void shouldThrowExceptionIfCalculatedValueMapIsNull()
- {
- RuleEngineContext.builder()
- .ruleVariables( Arrays.asList( mock( RuleVariable.class ) ) )
- .supplementaryData( new HashMap>() )
- .calculatedValueMap( null )
- .rules( Arrays.asList( mock( org.hisp.dhis.rules.models.Rule.class ) ) )
- .build();
- }
-
@Test
public void evaluateTenThousandRulesTest()
throws Exception
@@ -138,23 +127,11 @@ public void sendMessageMustGetValueFromAssignAction()
new Date(), "test_program_stage", "test_data_element", "test_value" ) ) )
.build();
- Map> calculatedValueMap = new HashMap<>();
- Map valueMap = new HashMap<>();
- valueMap.put( "test_calculated_value", "4" );
- calculatedValueMap.put( enrollment.enrollment(), valueMap );
-
- RuleEngine.Builder ruleEngineBuilder = getRuleEngine( Lists.newArrayList( rule2 ), calculatedValueMap );
- RuleEngine ruleEngine = ruleEngineBuilder.enrollment( enrollment ).build();
+ RuleEngine ruleEngine = getRuleEngine( Arrays.asList( rule, rule2 ) ).enrollment( enrollment ).build();
List ruleEffects = ruleEngine.evaluate( ruleEvent ).call();
assertThat( ruleEffects.get( 0 ).data() ).isEqualTo( "4.0" );
assertThat( ruleEffects.get( 0 ).ruleAction() ).isEqualTo( sendMessageAction );
-
- RuleEngine ruleEngine2 = getRuleEngine( Arrays.asList( rule, rule2 ) ).enrollment( enrollment ).build();
- List ruleEffects2 = ruleEngine2.evaluate( ruleEvent ).call();
-
- assertThat( ruleEffects2.get( 0 ).data() ).isEqualTo( "4.0" );
- assertThat( ruleEffects2.get( 0 ).ruleAction() ).isEqualTo( sendMessageAction );
}
private List createRules( int i )
@@ -224,23 +201,6 @@ public void sendMessageMustGetValueFromAssignActionInSingleExecution()
}
private RuleEngine.Builder getRuleEngine( List rules )
- {
- RuleVariable ruleVariable = RuleVariableCalculatedValue
- .create( "test_calculated_value", "", RuleValueType.TEXT );
-
- Map> calculatedValueMap = new HashMap<>();
-
- return RuleEngineContext
- .builder()
- .rules( rules )
- .ruleVariables( Arrays.asList( ruleVariable ) )
- .calculatedValueMap( calculatedValueMap )
- .supplementaryData( new HashMap>() )
- .constantsValue( new HashMap() )
- .build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );
- }
-
- private RuleEngine.Builder getRuleEngine( List rules, Map> calculatedValueMap )
{
RuleVariable ruleVariable = RuleVariableCalculatedValue
.create( "test_calculated_value", "", RuleValueType.TEXT );
@@ -249,7 +209,6 @@ private RuleEngine.Builder getRuleEngine( List
.builder()
.rules( rules )
.ruleVariables( Arrays.asList( ruleVariable ) )
- .calculatedValueMap( calculatedValueMap )
.supplementaryData( new HashMap>() )
.constantsValue( new HashMap() )
.build().toEngineBuilder().triggerEnvironment( TriggerEnvironment.SERVER );