Skip to content

Commit

Permalink
[ANDROAPP-6028] Remove rule engine duplicate extensions (#3628)
Browse files Browse the repository at this point in the history
* [ANDROAPP-6028] Remove rule engine duplicate extensions

Signed-off-by: Pablo <[email protected]>

* [ANDROAPP-6028] move test to correct module

Signed-off-by: Pablo <[email protected]>

* [ANDROAPP-6028] fix import

Signed-off-by: Pablo <[email protected]>

---------

Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan authored May 17, 2024
1 parent 2227466 commit 0660193
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 1,290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.dhis2.data.forms.dataentry.SearchTEIRepositoryImpl;
import org.dhis2.form.data.FileController;
import org.dhis2.form.data.FormValueStore;
import org.dhis2.form.data.RulesRepository;
import org.dhis2.form.data.UniqueAttributeController;
import org.dhis2.form.model.RowAction;
import org.dhis2.form.ui.FieldViewModelFactory;
Expand Down Expand Up @@ -75,12 +74,6 @@ EventCaptureContract.EventCaptureRepository provideRepository(D2 d2) {
return new EventCaptureRepositoryImpl(eventUid, d2);
}

@Provides
@PerActivity
RulesRepository rulesRepository(@NonNull D2 d2) {
return new RulesRepository(d2);
}

@Provides
@PerActivity
RuleEngineHelper ruleEngineRepository(D2 d2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.dhis2.commons.resources.MetadataIconProvider;
import org.dhis2.commons.resources.ResourceManager;
import org.dhis2.commons.schedulers.SchedulerProvider;
import org.dhis2.form.data.RulesRepository;
import org.dhis2.form.data.RulesUtilsProvider;
import org.dhis2.form.data.metadata.FileResourceConfiguration;
import org.dhis2.form.data.metadata.OptionSetConfiguration;
Expand Down Expand Up @@ -116,11 +115,6 @@ FieldViewModelFactory fieldFactory(
);
}

@Provides
RulesRepository rulesRepository(@NonNull D2 d2) {
return new RulesRepository(d2);
}

@Provides
@PerActivity
EventInitialRepository eventDetailRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.resources.MetadataIconProvider
import org.dhis2.commons.schedulers.SchedulerProvider
import org.dhis2.commons.viewmodel.DispatcherProvider
import org.dhis2.form.data.RulesRepository
import org.dhis2.mobileProgramRules.EvaluationType
import org.dhis2.mobileProgramRules.RuleEngineHelper
import org.dhis2.utils.analytics.AnalyticsHelper
Expand Down Expand Up @@ -71,12 +70,6 @@ class TeiDashboardModule(
)
}

@Provides
@PerActivity
fun rulesRepository(d2: D2): RulesRepository {
return RulesRepository(d2)
}

@Provides
@PerActivity
fun ruleEngineRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.dhis2.usescases.troubleshooting

import org.dhis2.commons.resources.MetadataIconProvider
import org.dhis2.form.bindings.toRuleEngineObject
import org.dhis2.form.bindings.toRuleVariableList
import org.dhis2.mobileProgramRules.toRuleEngineObject
import org.dhis2.mobileProgramRules.toRuleVariableList
import org.dhis2.usescases.development.ProgramRuleValidation
import org.dhis2.usescases.development.RuleValidation
import org.hisp.dhis.android.core.D2
Expand Down

This file was deleted.

9 changes: 6 additions & 3 deletions dhis2-mobile-program-rules/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ android {
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

dependencies {
implementation(project(":commons"))
testImplementation(libs.test.mockitoCore)
testImplementation(libs.test.mockitoInline)
testImplementation(libs.test.mockitoKotlin)
coreLibraryDesugaring(libs.desugar)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.dhis2.mobileProgramRules
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.dhis2.commons.rules.toRuleEngineInstant
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.dataelement.DataElementCollectionRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import org.dhis2.commons.bindings.event
import org.dhis2.commons.bindings.organisationUnit
import org.dhis2.commons.bindings.program
import org.dhis2.commons.bindings.programStage
import org.dhis2.commons.rules.toRuleEngineInstant
import org.dhis2.commons.rules.toRuleEngineLocalDate
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.helpers.UidsHelper
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.dhis2.bindings
package org.dhis2.mobileProgramRules

import org.dhis2.form.bindings.toRuleActionList
import org.dhis2.form.bindings.toRuleAttributeValue
import org.dhis2.form.bindings.toRuleDataValue
import org.dhis2.form.bindings.toRuleEngineObject
import org.dhis2.form.bindings.toRuleVariable
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.common.ObjectWithUid
import org.hisp.dhis.android.core.common.ValueType
Expand All @@ -14,7 +9,6 @@ import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.option.Option
import org.hisp.dhis.android.core.option.OptionCollectionRepository
import org.hisp.dhis.android.core.program.ProgramRuleAction
import org.hisp.dhis.android.core.program.ProgramRuleActionType.SHOWERROR
import org.hisp.dhis.android.core.program.ProgramRuleVariable
import org.hisp.dhis.android.core.program.ProgramRuleVariableCollectionRepository
import org.hisp.dhis.android.core.program.ProgramRuleVariableSourceType
Expand All @@ -32,7 +26,7 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.util.Date

class RuleExtensionsTest {
class RuleEngineExtensionsTest {

private val dataElementRepository: DataElementCollectionRepository = Mockito.mock(
DataElementCollectionRepository::class.java,
Expand Down Expand Up @@ -374,16 +368,6 @@ class RuleExtensionsTest {
assertTrue(ruleEngineAction.type == "unsupported")
}

@Test
fun `Should parse program rule error`() {
val programRuleAction = ProgramRuleAction.builder()
.uid("uid")
.programRuleActionType(SHOWERROR)
.build()
val ruleActionList = listOf<ProgramRuleAction>(programRuleAction).toRuleActionList()
assertTrue(ruleActionList.first().type == "error")
}

@Test
fun `should parse ProgramRuleVariable to RuleVariable`() {
val programRuleVariable = ProgramRuleVariable.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.dhis2.data.forms
package org.dhis2.mobileProgramRules

import org.dhis2.form.data.RulesRepository
import kotlinx.coroutines.runBlocking
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.organisationunit.OrganisationUnitGroup
import org.hisp.dhis.android.core.user.UserRole
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
Expand All @@ -31,24 +32,23 @@ class RulesRepositoryTest {
.blockingGet(),
) doReturn getTestOrgUnit()
whenever(d2.userModule().userRoles().blockingGet()) doReturn getTestUserRoles()
val testObserver = repository.supplementaryData("org_unit_test")
.test()

testObserver.assertValueCount(1)
testObserver.assertValue { supplData ->

supplData.containsKey("USER")
supplData.containsKey("org_unit_group_test_code")
supplData.containsKey("org_unit_group_test")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role1")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role2")
val supplData = runBlocking {
repository.supplementaryData("org_unit_test")
}
assertTrue(supplData.isNotEmpty())
assertTrue(supplData.containsKey("USER"))
assertTrue(supplData.containsKey("org_unit_group_test_code"))
assertTrue(supplData.containsKey("org_unit_group_test"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role1"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role2"))
assertTrue(
supplData.getOrElse("org_unit_group_test") { arrayListOf() }
.contains("org_unit_test")
.contains("org_unit_test"),
)
assertTrue(
supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }
.contains("org_unit_test")
}
.contains("org_unit_test"),
)
}

@Test
Expand All @@ -60,24 +60,22 @@ class RulesRepositoryTest {
.blockingGet(),
) doReturn getTestOrgUnitWithNullCodeGroup()
whenever(d2.userModule().userRoles().blockingGet()) doReturn getTestUserRoles()
val testObserver = repository.supplementaryData("org_unit_test")
.test()
val supplData = runBlocking {
repository.supplementaryData("org_unit_test")
}

testObserver.assertValueCount(1)
testObserver.assertValue { supplData ->
assertTrue(supplData.isNotEmpty())

supplData.containsKey("USER")
!supplData.containsKey("org_unit_group_test_code")
supplData.containsKey("org_unit_group_test")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role1")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role2")
assertTrue(supplData.containsKey("USER"))
assertTrue(!supplData.containsKey("org_unit_group_test_code"))
assertTrue(supplData.containsKey("org_unit_group_test"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role1"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role2"))
assertTrue(
supplData.getOrElse("org_unit_group_test") { arrayListOf() }
.contains("org_unit_test")
supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }
.isEmpty()
}
.contains("org_unit_test"),
)
assertTrue(supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }.isEmpty())
}

private fun getTestUserRoles(): List<UserRole> {
Expand Down
Loading

0 comments on commit 0660193

Please sign in to comment.