From 169960b3b9d0fd09821aa231836f1c2e88b931f5 Mon Sep 17 00:00:00 2001 From: Xavier Molloy Date: Thu, 2 May 2024 14:30:29 +0200 Subject: [PATCH 1/3] chore: [ANDROAPP-6135] Update rule engine and expression parser to release version for 3.0 --- .../TroubleshootingRepository.kt | 7 ++++--- .../mobileProgramRules/RulesRepository.kt | 18 ++++++++++-------- .../org/dhis2/form/data/RulesRepository.kt | 14 ++++++++------ gradle/libs.versions.toml | 4 ++-- .../services/rules/RuleValidationHelperImpl.kt | 7 ++++--- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt b/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt index f7b881d9cf..34a06d2656 100644 --- a/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt @@ -10,6 +10,7 @@ import org.hisp.dhis.android.core.program.Program import org.hisp.dhis.android.core.program.ProgramRuleActionType import org.hisp.dhis.antlr.ParserExceptionWithoutContext import org.hisp.dhis.lib.expression.Expression +import org.hisp.dhis.lib.expression.ExpressionMode import org.hisp.dhis.lib.expression.spi.ExpressionData import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.hisp.dhis.rules.api.EnvironmentVariables.ENV_VARIABLES @@ -40,7 +41,7 @@ class TroubleshootingRepository( rule.condition, valueMap, null, - Expression.Mode.RULE_ENGINE_CONDITION, + ExpressionMode.RULE_ENGINE_CONDITION, ) if (ruleConditionResult.isNotEmpty()) { ruleValidationItem = ruleValidationItem.copy(conditionError = ruleConditionResult) @@ -164,7 +165,7 @@ class TroubleshootingRepository( condition: String, valueMap: Map, ruleActionType: String? = null, - mode: Expression.Mode, + mode: ExpressionMode, ): String { if (condition.isEmpty()) { return if (ruleActionType != null) { @@ -230,7 +231,7 @@ class TroubleshootingRepository( ruleAction.data ?: "", valueMap, ruleAction.ruleActionType(), - Expression.Mode.RULE_ENGINE_ACTION, + ExpressionMode.RULE_ENGINE_ACTION, ) actionConditionResult.ifEmpty { null diff --git a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RulesRepository.kt b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RulesRepository.kt index 73e75d0c98..f651041278 100644 --- a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RulesRepository.kt +++ b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RulesRepository.kt @@ -24,7 +24,9 @@ import org.hisp.dhis.rules.models.Rule import org.hisp.dhis.rules.models.RuleAttributeValue import org.hisp.dhis.rules.models.RuleDataValue import org.hisp.dhis.rules.models.RuleEnrollment +import org.hisp.dhis.rules.models.RuleEnrollmentStatus import org.hisp.dhis.rules.models.RuleEvent +import org.hisp.dhis.rules.models.RuleEventStatus import org.hisp.dhis.rules.models.RuleVariable import java.util.Calendar import java.util.Date @@ -112,9 +114,9 @@ class RulesRepository(private val d2: D2) { .uid(event.programStage()) .blockingGet()!!.name()!!, status = if (event.status() == EventStatus.VISITED) { - RuleEvent.Status.ACTIVE + RuleEventStatus.ACTIVE } else { - RuleEvent.Status.valueOf(event.status()!!.name) + RuleEventStatus.valueOf(event.status()!!.name) }, eventDate = Instant.fromEpochMilliseconds(event.eventDate()!!.time), dueDate = event.dueDate()?.let { @@ -206,9 +208,9 @@ class RulesRepository(private val d2: D2) { .blockingGet()!!.name()!!, status = if (event.status() == EventStatus.VISITED) { - RuleEvent.Status.ACTIVE + RuleEventStatus.ACTIVE } else { - RuleEvent.Status.valueOf(event.status()!!.name) + RuleEventStatus.valueOf(event.status()!!.name) }, eventDate = event.eventDate()!!.toRuleEngineInstant(), dueDate = event.dueDate()?.toRuleEngineLocalDate(), @@ -242,7 +244,7 @@ class RulesRepository(private val d2: D2) { programName!!, Calendar.getInstance().time.toRuleEngineLocalDate(), Calendar.getInstance().time.toRuleEngineLocalDate(), - RuleEnrollment.Status.CANCELLED, + RuleEnrollmentStatus.CANCELLED, event.organisationUnit()!!, ouCode, ArrayList(), @@ -255,7 +257,7 @@ class RulesRepository(private val d2: D2) { programName!!, (enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(), enrollment.enrollmentDate()!!.toRuleEngineLocalDate(), - RuleEnrollment.Status.valueOf(enrollment.status()!!.name), + RuleEnrollmentStatus.valueOf(enrollment.status()!!.name), event.organisationUnit()!!, ouCode, getAttributesValues(enrollment), @@ -314,7 +316,7 @@ class RulesRepository(private val d2: D2) { programName = d2.program(enrollment.program()!!)?.name()!!, incidentDate = (enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(), enrollmentDate = (enrollment.enrollmentDate() ?: Date()).toRuleEngineLocalDate(), - status = RuleEnrollment.Status.valueOf(enrollment.status()!!.name), + status = RuleEnrollmentStatus.valueOf(enrollment.status()!!.name), organisationUnit = enrollment.organisationUnit()!!, organisationUnitCode = d2.organisationUnit(enrollment.organisationUnit()!!) ?.code() ?: "", @@ -328,7 +330,7 @@ class RulesRepository(private val d2: D2) { event = event.uid(), programStage = event.programStage()!!, programStageName = d2.programStage(event.programStage()!!)?.name()!!, - status = RuleEvent.Status.valueOf(event.status()!!.name), + status = RuleEventStatus.valueOf(event.status()!!.name), eventDate = event.eventDate()!!.toRuleEngineInstant(), dueDate = event.dueDate()?.toRuleEngineLocalDate(), completedDate = event.completedDate()?.toRuleEngineLocalDate(), diff --git a/form/src/main/java/org/dhis2/form/data/RulesRepository.kt b/form/src/main/java/org/dhis2/form/data/RulesRepository.kt index 87d6f8aed0..f9957226ed 100644 --- a/form/src/main/java/org/dhis2/form/data/RulesRepository.kt +++ b/form/src/main/java/org/dhis2/form/data/RulesRepository.kt @@ -23,7 +23,9 @@ import org.hisp.dhis.android.core.program.ProgramRule import org.hisp.dhis.rules.models.Rule import org.hisp.dhis.rules.models.RuleAttributeValue import org.hisp.dhis.rules.models.RuleEnrollment +import org.hisp.dhis.rules.models.RuleEnrollmentStatus import org.hisp.dhis.rules.models.RuleEvent +import org.hisp.dhis.rules.models.RuleEventStatus import org.hisp.dhis.rules.models.RuleVariable import java.util.Calendar import java.util.Date @@ -131,9 +133,9 @@ class RulesRepository(private val d2: D2) { .uid(event.programStage()) .blockingGet()!!.name()!!, status = if (event.status() == EventStatus.VISITED) { - RuleEvent.Status.ACTIVE + RuleEventStatus.ACTIVE } else { - RuleEvent.Status.valueOf(event.status()!!.name) + RuleEventStatus.valueOf(event.status()!!.name) }, eventDate = Instant.fromEpochMilliseconds(event.eventDate()!!.time), dueDate = event.dueDate()?.let { @@ -226,9 +228,9 @@ class RulesRepository(private val d2: D2) { .blockingGet()!!.name()!!, status = if (event.status() == EventStatus.VISITED) { - RuleEvent.Status.ACTIVE + RuleEventStatus.ACTIVE } else { - RuleEvent.Status.valueOf(event.status()!!.name) + RuleEventStatus.valueOf(event.status()!!.name) }, eventDate = event.eventDate()!!.toRuleEngineInstant(), dueDate = event.dueDate()?.toRuleEngineLocalDate(), @@ -263,7 +265,7 @@ class RulesRepository(private val d2: D2) { programName!!, Calendar.getInstance().time.toRuleEngineLocalDate(), Calendar.getInstance().time.toRuleEngineLocalDate(), - RuleEnrollment.Status.CANCELLED, + RuleEnrollmentStatus.CANCELLED, event.organisationUnit()!!, ouCode, ArrayList(), @@ -278,7 +280,7 @@ class RulesRepository(private val d2: D2) { programName!!, (enrollment.incidentDate() ?: Date()).toRuleEngineLocalDate(), enrollment.enrollmentDate()!!.toRuleEngineLocalDate(), - RuleEnrollment.Status.valueOf(enrollment.status()!!.name), + RuleEnrollmentStatus.valueOf(enrollment.status()!!.name), event.organisationUnit()!!, ouCode, getAttributesValues(enrollment), diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a3fcea4135..355224d9ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,8 +12,8 @@ hiltCompiler = '1.0.0' jacoco = '0.8.10' designSystem = "0.2-20240430.062706-60" dhis2sdk = "1.10.0-20240426.151240-44" -ruleEngine = "3.0.0-20240119.134348-12" -expressionParser = "1.1.0-20240219.115041-14" +ruleEngine = "2.3.0" +expressionParser = "1.1.0" appcompat = "1.6.1" annotation = "1.6.0" cardview = "1.0.0" diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/rules/RuleValidationHelperImpl.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/rules/RuleValidationHelperImpl.kt index 7b649394b9..eaa1cf88fa 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/rules/RuleValidationHelperImpl.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/rules/RuleValidationHelperImpl.kt @@ -27,6 +27,7 @@ import org.hisp.dhis.rules.api.RuleEngine import org.hisp.dhis.rules.models.RuleDataValue import org.hisp.dhis.rules.models.RuleEffect import org.hisp.dhis.rules.models.RuleEvent +import org.hisp.dhis.rules.models.RuleEventStatus import org.hisp.dhis.rules.models.RuleVariable import timber.log.Timber import java.util.Date @@ -129,7 +130,7 @@ class RuleValidationHelperImpl @Inject constructor( eventUid ?: UUID.randomUUID().toString(), programStage.uid(), programStage.name()!!, - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, period.toRuleEngineInstant(), period.toRuleEngineLocalDate(), period.toRuleEngineLocalDate(), @@ -230,9 +231,9 @@ class RuleValidationHelperImpl @Inject constructor( d2.programModule().programStages().uid(event.programStage()) .blockingGet()!!.name()!!, if (event.status() == EventStatus.VISITED) { - RuleEvent.Status.ACTIVE + RuleEventStatus.ACTIVE } else { - RuleEvent.Status.valueOf(event.status()!!.name) + RuleEventStatus.valueOf(event.status()!!.name) }, (event.eventDate() ?: Date()).toRuleEngineInstant(), event.dueDate()?.toRuleEngineLocalDate(), From d3a2080089d9863c5d94f5ad21def66775b50568 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Fri, 3 May 2024 11:54:04 +0200 Subject: [PATCH 2/3] chore: update rule-engine version 3.0.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 355224d9ea..57459f3f46 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ hiltCompiler = '1.0.0' jacoco = '0.8.10' designSystem = "0.2-20240430.062706-60" dhis2sdk = "1.10.0-20240426.151240-44" -ruleEngine = "2.3.0" +ruleEngine = "3.0.0" expressionParser = "1.1.0" appcompat = "1.6.1" annotation = "1.6.0" From 69019382b30a11fd0b57c82e7c082253dfa71732 Mon Sep 17 00:00:00 2001 From: Xavier Molloy Date: Fri, 3 May 2024 12:25:48 +0200 Subject: [PATCH 3/3] fix: [ANDROAPP-6135] fix tests --- .../org/dhis2/android/rtsm/services/ProgramRuleTests.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stock-usecase/src/test/java/org/dhis2/android/rtsm/services/ProgramRuleTests.kt b/stock-usecase/src/test/java/org/dhis2/android/rtsm/services/ProgramRuleTests.kt index 5494967655..8b41b4af8b 100644 --- a/stock-usecase/src/test/java/org/dhis2/android/rtsm/services/ProgramRuleTests.kt +++ b/stock-usecase/src/test/java/org/dhis2/android/rtsm/services/ProgramRuleTests.kt @@ -10,7 +10,9 @@ import org.hisp.dhis.rules.models.Rule import org.hisp.dhis.rules.models.RuleAction import org.hisp.dhis.rules.models.RuleDataValue import org.hisp.dhis.rules.models.RuleEnrollment +import org.hisp.dhis.rules.models.RuleEnrollmentStatus import org.hisp.dhis.rules.models.RuleEvent +import org.hisp.dhis.rules.models.RuleEventStatus import org.hisp.dhis.rules.models.RuleValueType import org.hisp.dhis.rules.models.RuleVariable import org.hisp.dhis.rules.models.RuleVariableCurrentEvent @@ -124,7 +126,7 @@ class ProgramRuleTests { "test_program", Date().toRuleEngineLocalDate(), Date().toRuleEngineLocalDate(), - RuleEnrollment.Status.ACTIVE, + RuleEnrollmentStatus.ACTIVE, "test_ou", "test_ou_code", emptyList(), @@ -134,7 +136,7 @@ class ProgramRuleTests { "test_event", "test_program_stage", "", - RuleEvent.Status.ACTIVE, + RuleEventStatus.ACTIVE, Date().toRuleEngineInstant(), Date().toRuleEngineLocalDate(), null,