Skip to content

Commit

Permalink
chore: [ANDROAPP-6135] Update rule engine and expression parser to re… (
Browse files Browse the repository at this point in the history
#3623)

* 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 <[email protected]>
  • Loading branch information
2 people authored and andresmr committed May 21, 2024
1 parent dd26143 commit 4a5d8c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -164,7 +165,7 @@ class TroubleshootingRepository(
condition: String,
valueMap: Map<String, RuleVariableValue>,
ruleActionType: String? = null,
mode: Expression.Mode,
mode: ExpressionMode,
): String {
if (condition.isEmpty()) {
return if (ruleActionType != null) {
Expand Down Expand Up @@ -230,7 +231,7 @@ class TroubleshootingRepository(
ruleAction.data ?: "",
valueMap,
ruleAction.ruleActionType(),
Expression.Mode.RULE_ENGINE_ACTION,
ExpressionMode.RULE_ENGINE_ACTION,
)
actionConditionResult.ifEmpty {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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),
Expand Down Expand Up @@ -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() ?: "",
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,7 +126,7 @@ class ProgramRuleTests {
"test_program",
Date().toRuleEngineLocalDate(),
Date().toRuleEngineLocalDate(),
RuleEnrollment.Status.ACTIVE,
RuleEnrollmentStatus.ACTIVE,
"test_ou",
"test_ou_code",
emptyList(),
Expand All @@ -134,7 +136,7 @@ class ProgramRuleTests {
"test_event",
"test_program_stage",
"",
RuleEvent.Status.ACTIVE,
RuleEventStatus.ACTIVE,
Date().toRuleEngineInstant(),
Date().toRuleEngineLocalDate(),
null,
Expand Down

0 comments on commit 4a5d8c6

Please sign in to comment.