From 899451874cd46f1feed2d79e102e64d6ce919375 Mon Sep 17 00:00:00 2001 From: Enrico Date: Mon, 23 Dec 2024 15:31:06 -0300 Subject: [PATCH] fix: Use correct value type for dates [DHIS2-15891] --- build.gradle.kts | 2 +- .../engine/RuleVariableValueMapBuilder.kt | 12 +-- .../models/RuleVariableValueMapBuilderTest.kt | 82 +++++++++---------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 545d2f87..4f201226 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ repositories { maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } } -version = "3.2.1-SNAPSHOT" +version = "3.2.2-SNAPSHOT" group = "org.hisp.dhis.rules" if (project.hasProperty("removeSnapshotSuffix")) { diff --git a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleVariableValueMapBuilder.kt b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleVariableValueMapBuilder.kt index b9756264..2180c058 100644 --- a/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleVariableValueMapBuilder.kt +++ b/src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleVariableValueMapBuilder.kt @@ -103,7 +103,7 @@ internal class RuleVariableValueMapBuilder { val valueMap: MutableMap = HashMap() valueMap[RuleEngineUtils.ENV_VAR_CURRENT_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, currentDate.toString(), listOf(currentDate.toString()), currentDate.toString(), @@ -140,7 +140,7 @@ internal class RuleVariableValueMapBuilder { .toString() valueMap[RuleEngineUtils.ENV_VAR_EVENT_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, eventDate, listOf(eventDate), currentDate.toString(), @@ -149,7 +149,7 @@ internal class RuleVariableValueMapBuilder { val dueDate = ruleEvent.dueDate valueMap[RuleEngineUtils.ENV_VAR_DUE_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, dueDate.toString(), listOf(dueDate.toString()), currentDate.toString(), @@ -159,7 +159,7 @@ internal class RuleVariableValueMapBuilder { val completedDate = ruleEvent.completedDate valueMap[RuleEngineUtils.ENV_VAR_COMPLETED_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, completedDate.toString(), listOf(completedDate.toString()), currentDate.toString(), @@ -231,7 +231,7 @@ internal class RuleVariableValueMapBuilder { val enrollmentDate = ruleEnrollment.enrollmentDate valueMap[RuleEngineUtils.ENV_VAR_ENROLLMENT_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, enrollmentDate.toString(), listOf(enrollmentDate.toString()), currentDate.toString(), @@ -239,7 +239,7 @@ internal class RuleVariableValueMapBuilder { val incidentDate = ruleEnrollment.incidentDate valueMap[RuleEngineUtils.ENV_VAR_INCIDENT_DATE] = RuleVariableValue( - RuleValueType.TEXT, + RuleValueType.DATE, incidentDate.toString(), listOf(incidentDate.toString()), currentDate.toString(), diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt index fd7a7c35..48b26b3e 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt @@ -169,13 +169,13 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue( eventDate.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(eventDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_status"]!!) @@ -198,7 +198,7 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["due_date"]!!) .hasValue( dueDate.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(dueDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable_one"]!!) @@ -312,12 +312,12 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue(currentEventDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(currentEventDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -450,12 +450,12 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -470,7 +470,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["due_date"]!!) .hasValue(dateEventDueCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventDueCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable_one"]!!) @@ -593,12 +593,12 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -613,7 +613,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["due_date"]!!) .hasValue(dateEventDueCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventDueCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable"]!!) @@ -683,13 +683,13 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue( dateEventTwo.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventTwo.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -705,7 +705,7 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["due_date"]!!) .hasValue( dueDateEventTwo.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(dueDateEventTwo.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable"]!!) @@ -806,12 +806,12 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -826,7 +826,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["due_date"]!!) .hasValue(dueDateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dueDateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable"]!!) @@ -927,12 +927,12 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -947,7 +947,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["due_date"]!!) .hasValue(dueDateEventCurrent.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(dueDateEventCurrent.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["test_variable"]!!) @@ -1046,13 +1046,13 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["current_date"]!!) .hasValue( LocalDate.Companion.currentDate().toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(LocalDate.Companion.currentDate().toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_date"]!!) .hasValue( eventDate.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(eventDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -1068,7 +1068,7 @@ class RuleVariableValueMapBuilderTest { .assertThatVariable(valueMap["due_date"]!!) .hasValue( dueEventDate.toString(), - ).isTypeOf(RuleValueType.TEXT) + ).isTypeOf(RuleValueType.DATE) .hasCandidates(dueEventDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["enrollment_status"]!!) @@ -1078,7 +1078,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["enrollment_id"]!!) @@ -1093,7 +1093,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["incident_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["tei_count"]!!) @@ -1196,7 +1196,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["current_date"]!!) .hasValue(currentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(currentDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["event_count"]!!) @@ -1206,7 +1206,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["enrollment_id"]!!) @@ -1221,7 +1221,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(valueMap["incident_date"]!!) .hasValue(incidentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(incidentDate.toString()) RuleVariableValueAssert .assertThatVariable(valueMap["tei_count"]!!) @@ -1337,7 +1337,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(enrollmentValueMap!!["current_date"]!!) .hasValue(currentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(currentDate.toString()) RuleVariableValueAssert .assertThatVariable(enrollmentValueMap["event_count"]!!) @@ -1347,7 +1347,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(enrollmentValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(enrollmentValueMap["enrollment_id"]!!) @@ -1362,7 +1362,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(enrollmentValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(incidentDate.toString()) RuleVariableValueAssert .assertThatVariable(enrollmentValueMap["tei_count"]!!) @@ -1384,7 +1384,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventOneValueMap!!["current_date"]!!) .hasValue(currentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(currentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventOneValueMap["event_count"]!!) @@ -1394,7 +1394,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventOneValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventOneValueMap["enrollment_id"]!!) @@ -1409,7 +1409,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventOneValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(incidentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventOneValueMap["tei_count"]!!) @@ -1430,19 +1430,19 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventOneValueMap["event_date"]!!) .hasValue(eventOneDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(eventOneDate.toString()) RuleVariableValueAssert .assertThatVariable(eventOneValueMap["due_date"]!!) .hasValue(eventOneDueDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(eventOneDueDate.toString()) // Event two RuleVariableValueAssert .assertThatVariable(eventTwoValueMap!!["current_date"]!!) .hasValue(currentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(currentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["event_count"]!!) @@ -1452,7 +1452,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(enrollmentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["enrollment_id"]!!) @@ -1467,7 +1467,7 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(incidentDate.toString()) RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["tei_count"]!!) @@ -1488,12 +1488,12 @@ class RuleVariableValueMapBuilderTest { RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["event_date"]!!) .hasValue(eventTwoDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(eventTwoDate.toString()) RuleVariableValueAssert .assertThatVariable(eventTwoValueMap["due_date"]!!) .hasValue(eventTwoDueDate.toString()) - .isTypeOf(RuleValueType.TEXT) + .isTypeOf(RuleValueType.DATE) .hasCandidates(eventTwoDueDate.toString()) } }