From 91ecac739e88f6136f6cee25c6744995323ddb09 Mon Sep 17 00:00:00 2001 From: Xavier Molloy <44061143+xavimolloy@users.noreply.github.com> Date: Tue, 7 May 2024 16:54:09 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20[ANDROAPP-6135]=20Update=20rule=20engi?= =?UTF-8?q?ne=20and=20expression=20parser=20to=20re=E2=80=A6=20(#3623)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: [ANDROAPP-6135] Update rule engine and expression parser to release version for 3.0 * chore: update rule-engine version 3.0.0 * fix: [ANDROAPP-6135] fix tests --------- Co-authored-by: Victor Garcia --- .../TroubleshootingRepository.kt | 7 ++++--- .../mobileProgramRules/RulesRepository.kt | 18 ++++++++++-------- gradle/libs.versions.toml | 4 ++-- .../services/rules/RuleValidationHelperImpl.kt | 7 ++++--- .../android/rtsm/services/ProgramRuleTests.kt | 6 ++++-- 5 files changed, 24 insertions(+), 18 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 6a1771468a..001af922db 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 8caa9372b2..65463724a2 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 @@ -22,7 +22,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 @@ -110,9 +112,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 { @@ -204,9 +206,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(), @@ -240,7 +242,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(), @@ -253,7 +255,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), @@ -312,7 +314,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() ?: "", @@ -326,7 +328,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/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0fdef41d62..4cd81b2216 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,8 +11,8 @@ hilt = '2.47' 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 = "3.0.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 e6a139c84c..436cc2495f 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(), 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 9a43bc52e5..b7b8f7bc86 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,