diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.java b/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.java deleted file mode 100644 index 5f3db280..00000000 --- a/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hisp.dhis.rules.models; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public record RuleActionCreateEvent( - @Nonnull String data, - @Nonnull String content, - @Nonnull String programStage -) implements RuleAction { - - @Nonnull - public static RuleActionCreateEvent create(@CheckForNull String content, - @CheckForNull String data, @Nonnull String programStage) { - return new RuleActionCreateEvent(data == null ? "" : data, content == null ? "" : content, programStage); - } -} diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.kt b/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.kt new file mode 100644 index 00000000..e921e994 --- /dev/null +++ b/src/main/java/org/hisp/dhis/rules/models/RuleActionCreateEvent.kt @@ -0,0 +1,11 @@ +package org.hisp.dhis.rules.models + +data class RuleActionCreateEvent( + val programStage: String, + val content: String = "", + val data: String = "" +) : RuleAction { + override fun data(): String { + return data + } +} diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionError.java b/src/main/java/org/hisp/dhis/rules/models/RuleActionError.java deleted file mode 100644 index b18b247c..00000000 --- a/src/main/java/org/hisp/dhis/rules/models/RuleActionError.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.hisp.dhis.rules.models; - -import javax.annotation.Nonnull; - -public record RuleActionError(@Nonnull String data) implements RuleAction { - - @Nonnull - public static RuleActionError create( @Nonnull String data ) - { - return new RuleActionError( data ); - } -} diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleActionError.kt b/src/main/java/org/hisp/dhis/rules/models/RuleActionError.kt new file mode 100644 index 00000000..89ac9a7f --- /dev/null +++ b/src/main/java/org/hisp/dhis/rules/models/RuleActionError.kt @@ -0,0 +1,7 @@ +package org.hisp.dhis.rules.models + +data class RuleActionError(val data: String) : RuleAction { + override fun data(): String { + return data + } +} diff --git a/src/main/java/org/hisp/dhis/rules/models/RuleEvaluationResult.kt b/src/main/java/org/hisp/dhis/rules/models/RuleEvaluationResult.kt index b48ae203..74f823e4 100644 --- a/src/main/java/org/hisp/dhis/rules/models/RuleEvaluationResult.kt +++ b/src/main/java/org/hisp/dhis/rules/models/RuleEvaluationResult.kt @@ -33,7 +33,7 @@ data class RuleEvaluationResult( } fun errorRule(rule: Rule, errorMessage: String): RuleEvaluationResult { - val effects = listOf(RuleEffect(rule.uid, RuleActionError.create(errorMessage), errorMessage)) + val effects = listOf(RuleEffect(rule.uid, RuleActionError(errorMessage), errorMessage)) return RuleEvaluationResult(rule, effects, false, true) } } diff --git a/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt b/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt index dfb8f52e..92cf6d06 100644 --- a/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt +++ b/src/test/java/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt @@ -51,8 +51,9 @@ class RuleEngineEffectTypesTest { @Test fun simpleConditionMustResultInCreateEventEffect() { - val ruleAction: RuleAction = RuleActionCreateEvent.create( - "test_action_content", "'event_uid;test_data_value_one'", "test_program_stage" + val ruleAction: RuleAction = RuleActionCreateEvent( + "test_program_stage", + "test_action_content", "'event_uid;test_data_value_one'" ) val rule = Rule("true", listOf(ruleAction)) val ruleEngine = getRuleEngine(rule) diff --git a/src/test/java/org/hisp/dhis/rules/models/RuleActionCreateEventTest.java b/src/test/java/org/hisp/dhis/rules/models/RuleActionCreateEventTest.java deleted file mode 100644 index c5199fd3..00000000 --- a/src/test/java/org/hisp/dhis/rules/models/RuleActionCreateEventTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hisp.dhis.rules.models; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import static org.junit.Assert.assertEquals; - -@RunWith( JUnit4.class ) -public class RuleActionCreateEventTest -{ - @Test - public void createMustSubstituteEmptyStringsForNullArguments() - { - RuleActionCreateEvent ruleActionAssignNoContent = RuleActionCreateEvent - .create( null, "test_data", "test_program_stage" ); - RuleActionCreateEvent ruleActionAssignNoField = RuleActionCreateEvent - .create( "test_content", null, "test_program_stage" ); - - assertEquals( "" , ruleActionAssignNoContent.content() ); - assertEquals( "test_data" , ruleActionAssignNoContent.data() ); - assertEquals( "test_program_stage" , ruleActionAssignNoContent.programStage() ); - - assertEquals( "test_content" , ruleActionAssignNoField.content() ); - assertEquals( "" , ruleActionAssignNoField.data() ); - assertEquals( "test_program_stage" , ruleActionAssignNoField.programStage() ); - } -}