Skip to content

Commit 28e43d8

Browse files
committed
[ANDROSDK-2329] Fix lastUpdated evaluation for limitByOrgunit
1 parent a1b7b0c commit 28e43d8

8 files changed

Lines changed: 98 additions & 27 deletions

File tree

core/api/core.api

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ public final class org/hisp/dhis/android/core/arch/db/stores/OrgHispDhisAndroidC
18611861
public abstract interface class org/hisp/dhis/android/core/arch/db/stores/internal/ReadableStore {
18621862
public abstract fun count (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
18631863
public abstract fun countWhere (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1864+
public abstract fun exists (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
18641865
public abstract fun groupAndGetCountBy (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
18651866
public abstract fun selectAll (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
18661867
public abstract fun selectFirst (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -29419,3 +29420,60 @@ public final class org/koin/plugin/hints/Koin_hints_org_hisp_dhis_android_persis
2941929420
public static final synthetic fun componentscan_org_hisp_dhis_android_persistence_dependencyinjection_PersistenceDIModule_single (Lorg/hisp/dhis/android/persistence/visualization/VisualizationStoreImpl;Lorg/hisp/dhis/android/core/visualization/internal/VisualizationStore;)V
2942029421
}
2942129422

29423+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreAnalyticsAnalyticsDIModuleModuleKt {
29424+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_analytics_AnalyticsDIModule__emptyAnalyticsParams (Lorg/hisp/dhis/android/core/analytics/aggregated/internal/AnalyticsRepositoryParams;)V
29425+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_analytics_AnalyticsDIModule__emptyAnalyticsVisualizationsParam (Lorg/hisp/dhis/android/core/analytics/aggregated/internal/AnalyticsVisualizationsRepositoryParams;)V
29426+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_analytics_AnalyticsDIModule__emptyTrackerLineListParams (Lorg/hisp/dhis/android/core/analytics/trackerlinelist/internal/TrackerLineListParams;)V
29427+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_analytics_AnalyticsDIModule__eventLineListParams (Lorg/hisp/dhis/android/core/analytics/linelist/EventLineListParams;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29428+
}
29429+
29430+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreArchApiInternalAPIClientDIModuleModuleKt {
29431+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_arch_api_internal_APIClientDIModule__ktor (Lio/ktor/client/HttpClient;Lkotlinx/coroutines/CoroutineScope;Ljava/io/Closeable;)V
29432+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_arch_api_internal_APIClientDIModule__okHttpClient (Lokhttp3/OkHttpClient;Lokhttp3/Call$Factory;Lokhttp3/WebSocket$Factory;)V
29433+
}
29434+
29435+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreArchRepositoriesDiInternalRepositoriesDIModuleModuleKt {
29436+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_arch_repositories_di_internal_RepositoriesDIModule__emptyScope (Lorg/hisp/dhis/android/core/arch/repositories/scope/RepositoryScope;)V
29437+
}
29438+
29439+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreCommonCommonDIModuleModuleKt {
29440+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_common_CommonDIModule__genericCallData (Lorg/hisp/dhis/android/core/arch/call/internal/GenericCallData;)V
29441+
}
29442+
29443+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreConfigurationInternalConfigurationDIModuleModuleKt {
29444+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_configuration_internal_ConfigurationDIModule__dateProvider (Lorg/hisp/dhis/android/core/configuration/internal/DateProvider;)V
29445+
}
29446+
29447+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreDatastoreDataStoreDIModuleModuleKt {
29448+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_datastore_DataStoreDIModule__downloaderParams (Lorg/hisp/dhis/android/core/datastore/internal/DataStoreDownloadParams;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29449+
}
29450+
29451+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreEventEventDIModuleModuleKt {
29452+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_event_EventDIModule__empty (Lorg/hisp/dhis/android/core/event/search/EventQueryRepositoryScope;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29453+
}
29454+
29455+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreFileresourceFileResourceDIModuleModuleKt {
29456+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_fileresource_FileResourceDIModule__downloadParams (Lorg/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadParams;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29457+
}
29458+
29459+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCorePeriodPeriodDIModuleModuleKt {
29460+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_period_PeriodDIModule__clockProvider (Lorg/hisp/dhis/android/core/period/clock/internal/ClockProvider;)V
29461+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_period_PeriodDIModule__parentPeriodGenerator (Lorg/hisp/dhis/android/core/period/internal/ParentPeriodGenerator;)V
29462+
}
29463+
29464+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreProgramProgramDIModuleModuleKt {
29465+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_program_ProgramDIModule__programDataDownloadParams (Lorg/hisp/dhis/android/core/program/internal/ProgramDataDownloadParams;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29466+
}
29467+
29468+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreSmsSmsDIModuleModuleKt {
29469+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_sms_SmsDIModule__deviceStateRepository (Lorg/hisp/dhis/android/core/sms/domain/repository/internal/DeviceStateRepository;)V
29470+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_sms_SmsDIModule__localDbRepository (Lorg/hisp/dhis/android/core/sms/domain/repository/internal/LocalDbRepository;)V
29471+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_sms_SmsDIModule__smsRepository (Lorg/hisp/dhis/android/core/sms/domain/repository/SmsRepository;)V
29472+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_sms_SmsDIModule__webApiRepository (Lorg/hisp/dhis/android/core/sms/domain/repository/WebApiRepository;)V
29473+
}
29474+
29475+
public final class org/koin/plugin/hints/OrgHispDhisAndroidCoreTrackedentityTrackedEntityDIModuleModuleKt {
29476+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_trackedentity_TrackedEntityDIModule__empty (Lorg/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryRepositoryScope;Lorg/hisp/dhis/android/core/arch/repositories/scope/BaseScope;)V
29477+
public static final synthetic fun moduledef_org_hisp_dhis_android_core_trackedentity_TrackedEntityDIModule__onlineCache (Lorg/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceOnlineCache;)V
29478+
}
29479+

core/src/main/java/org/hisp/dhis/android/core/event/internal/EventDownloadCall.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ internal class EventDownloadCall internal constructor(
190190
limit = limit,
191191
ouMode = ouMode,
192192
),
193-
lastUpdatedStr = lastUpdatedManager.getLastUpdatedStr(bundle.commonParams),
193+
lastUpdatedStr = lastUpdatedManager.getLastUpdatedStr(bundle),
194194
orgUnit = orgunit?.uid,
195195
uids = eventUids.distinct(),
196196
)

core/src/main/java/org/hisp/dhis/android/core/event/internal/EventLastUpdatedManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal class EventLastUpdatedManager(
3939
suspend fun update(bundle: EventQueryBundle, syncDate: Date) {
4040
val sync = EventSync.builder()
4141
.program(bundle.commonParams.program)
42-
.organisationUnitIdsHash(bundle.orgUnits.toSet().hashCode())
42+
.organisationUnitIdsHash(bundle.orgUnitUids.toSet().hashCode())
4343
.downloadLimit(bundle.commonParams.limit)
4444
.workingListsHash(bundle.commonParams.workingListsHash)
4545
.lastUpdated(syncDate)

core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceDownloadCall.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ internal class TrackedEntityInstanceDownloadCall(
266266
ouMode = ouMode,
267267
),
268268
programStatus = bundle.programStatus,
269-
lastUpdatedStr = lastUpdatedManager.getLastUpdatedStr(bundle.commonParams),
269+
lastUpdatedStr = lastUpdatedManager.getLastUpdatedStr(bundle),
270270
orgUnit = orgunit?.uid,
271271
uids = teiUids.distinct(),
272272
)

core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceLastUpdatedManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal class TrackedEntityInstanceLastUpdatedManager(
3838
suspend fun update(trackerQuery: TrackerQueryBundle, syncDate: Date) {
3939
val sync = TrackedEntityInstanceSync.builder()
4040
.program(trackerQuery.commonParams.program)
41-
.organisationUnitIdsHash(trackerQuery.orgUnits.toSet().hashCode())
41+
.organisationUnitIdsHash(trackerQuery.orgUnitUids.toSet().hashCode())
4242
.downloadLimit(trackerQuery.commonParams.limit)
4343
.workingListsHash(trackerQuery.commonParams.workingListsHash)
4444
.lastUpdated(syncDate)

core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManager.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.program.internal.ProgramDataDownloadParams
3434
import org.hisp.dhis.android.core.settings.DownloadPeriod
3535
import org.hisp.dhis.android.core.settings.ProgramSetting
3636
import org.hisp.dhis.android.core.settings.ProgramSettings
37+
import org.hisp.dhis.android.core.tracker.exporter.BaseTrackerQueryBundle
3738
import java.util.Date
3839

3940
internal open class TrackerSyncLastUpdatedManager<S : TrackerBaseSync>(private val store: TrackerBaseSyncStore<S>) {
@@ -49,16 +50,16 @@ internal open class TrackerSyncLastUpdatedManager<S : TrackerBaseSync>(private v
4950
}
5051
}
5152

52-
fun getLastUpdatedStr(commonParams: TrackerQueryCommonParams): String? {
53-
return getLastUpdated(commonParams)?.let { BaseIdentifiableObject.dateToDateStr(it) }
53+
fun getLastUpdatedStr(bundle: BaseTrackerQueryBundle): String? {
54+
return getLastUpdated(bundle)?.let { BaseIdentifiableObject.dateToDateStr(it) }
5455
}
5556

56-
private fun getLastUpdated(commonParams: TrackerQueryCommonParams): Date? {
57+
private fun getLastUpdated(bundle: BaseTrackerQueryBundle): Date? {
5758
return getLastUpdated(
58-
commonParams.program,
59-
commonParams.orgUnitsBeforeDivision.toSet(),
60-
commonParams.limit,
61-
commonParams.workingListsHash,
59+
bundle.commonParams.program,
60+
bundle.orgUnitUids.toSet(),
61+
bundle.commonParams.limit,
62+
bundle.commonParams.workingListsHash,
6263
)
6364
}
6465

core/src/main/java/org/hisp/dhis/android/core/tracker/exporter/BaseTrackerQueryBundle.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import org.hisp.dhis.android.core.trackedentity.internal.TrackerQueryCommonParam
3333
internal interface BaseTrackerQueryBundle {
3434
val commonParams: TrackerQueryCommonParams
3535
val orgUnits: List<DownloadOrgunit>
36+
val orgUnitUids: List<String>
37+
get() = orgUnits.map { it.uid }
3638
}
3739

3840
internal data class DownloadOrgunit(

core/src/test/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManagerShould.kt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import org.hisp.dhis.android.core.arch.db.stores.internal.TrackerBaseSyncStore
3333
import org.hisp.dhis.android.core.arch.helpers.DateUtils
3434
import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode
3535
import org.hisp.dhis.android.core.program.internal.ProgramDataDownloadParams
36+
import org.hisp.dhis.android.core.tracker.exporter.BaseTrackerQueryBundle
37+
import org.hisp.dhis.android.core.tracker.exporter.DownloadOrgunit
3638
import org.junit.Before
3739
import org.junit.Test
3840
import org.junit.runner.RunWith
@@ -47,9 +49,10 @@ class TrackerSyncLastUpdatedManagerShould {
4749
private val params: ProgramDataDownloadParams = mock()
4850

4951
private val program = "program_uid"
50-
private val orgUnits = listOf("org_unit_1", "org_unit_2")
51-
private val orgUnitsHash = orgUnits.toSet().hashCode()
52-
private val limit = 500
52+
private val orgUnitsBeforeDivision = listOf("org_unit_1", "org_unit_2", "org_unit_3")
53+
private val ouUids = listOf("org_unit_1", "org_unit_2")
54+
private val orgUnitsHash = ouUids.toSet().hashCode()
55+
private val defaultLimit = 500
5356
private val workingListsHash = 12345
5457
private val lastUpdated = DateUtils.DATE_FORMAT.parse("2017-11-29T11:27:46.935")
5558

@@ -65,7 +68,7 @@ class TrackerSyncLastUpdatedManagerShould {
6568
fun return_last_updated_when_working_lists_hash_matches() = runTest {
6669
prepareWithSync(storedHash = workingListsHash)
6770

68-
val result = manager.getLastUpdatedStr(createCommonParams(workingListsHash))
71+
val result = manager.getLastUpdatedStr(createBundle(workingListsHash))
6972

7073
assertThat(result).isNotNull()
7174
}
@@ -74,7 +77,7 @@ class TrackerSyncLastUpdatedManagerShould {
7477
fun return_null_when_working_lists_hash_changes() = runTest {
7578
prepareWithSync(storedHash = workingListsHash)
7679

77-
val result = manager.getLastUpdatedStr(createCommonParams(99999))
80+
val result = manager.getLastUpdatedStr(createBundle(99999))
7881

7982
assertThat(result).isNull()
8083
}
@@ -83,7 +86,7 @@ class TrackerSyncLastUpdatedManagerShould {
8386
fun return_null_when_stored_hash_is_null_but_current_is_not() = runTest {
8487
prepareWithSync(storedHash = null)
8588

86-
val result = manager.getLastUpdatedStr(createCommonParams(workingListsHash))
89+
val result = manager.getLastUpdatedStr(createBundle(workingListsHash))
8790

8891
assertThat(result).isNull()
8992
}
@@ -92,7 +95,7 @@ class TrackerSyncLastUpdatedManagerShould {
9295
fun return_null_when_current_hash_is_null_but_stored_is_not() = runTest {
9396
prepareWithSync(storedHash = workingListsHash)
9497

95-
val result = manager.getLastUpdatedStr(createCommonParams(null))
98+
val result = manager.getLastUpdatedStr(createBundle(null))
9699

97100
assertThat(result).isNull()
98101
}
@@ -101,7 +104,7 @@ class TrackerSyncLastUpdatedManagerShould {
101104
fun return_last_updated_when_both_hashes_are_null() = runTest {
102105
prepareWithSync(storedHash = null)
103106

104-
val result = manager.getLastUpdatedStr(createCommonParams(null))
107+
val result = manager.getLastUpdatedStr(createBundle(null))
105108

106109
assertThat(result).isNotNull()
107110
}
@@ -110,7 +113,7 @@ class TrackerSyncLastUpdatedManagerShould {
110113
fun return_null_when_no_sync_record_exists() = runTest {
111114
prepareWithSync(sync = null)
112115

113-
val result = manager.getLastUpdatedStr(createCommonParams(workingListsHash))
116+
val result = manager.getLastUpdatedStr(createBundle(workingListsHash))
114117

115118
assertThat(result).isNull()
116119
}
@@ -119,7 +122,7 @@ class TrackerSyncLastUpdatedManagerShould {
119122
fun return_null_when_download_limit_increased() = runTest {
120123
prepareWithSync(storedHash = workingListsHash)
121124

122-
val result = manager.getLastUpdatedStr(createCommonParams(workingListsHash).copy(limit = limit + 100))
125+
val result = manager.getLastUpdatedStr(createBundle(workingListsHash, limit = defaultLimit + 100))
123126

124127
assertThat(result).isNull()
125128
}
@@ -128,7 +131,7 @@ class TrackerSyncLastUpdatedManagerShould {
128131
fun return_last_updated_when_download_limit_decreased() = runTest {
129132
prepareWithSync(storedHash = workingListsHash)
130133

131-
val result = manager.getLastUpdatedStr(createCommonParams(workingListsHash).copy(limit = limit - 100))
134+
val result = manager.getLastUpdatedStr(createBundle(workingListsHash, limit = defaultLimit - 100))
132135

133136
assertThat(result).isNotNull()
134137
}
@@ -147,23 +150,30 @@ class TrackerSyncLastUpdatedManagerShould {
147150
return TrackedEntityInstanceSync.builder()
148151
.program(program)
149152
.organisationUnitIdsHash(orgUnitsHash)
150-
.downloadLimit(limit)
153+
.downloadLimit(defaultLimit)
151154
.workingListsHash(hash)
152155
.lastUpdated(lastUpdated)
153156
.build()
154157
}
155158

156-
private fun createCommonParams(hash: Int?): TrackerQueryCommonParams {
157-
return TrackerQueryCommonParams(
159+
private fun createBundle(hash: Int? = null, limit: Int? = null ): BaseTrackerQueryBundle {
160+
val commonParams = TrackerQueryCommonParams(
158161
uids = emptyList(),
159162
programs = listOf(program),
160163
program = program,
161164
startDate = null,
162165
hasLimitByOrgUnit = false,
163166
ouMode = OrganisationUnitMode.SELECTED,
164-
orgUnitsBeforeDivision = orgUnits,
165-
limit = limit,
167+
orgUnitsBeforeDivision = orgUnitsBeforeDivision,
168+
limit = limit ?: defaultLimit,
166169
workingListsHash = hash,
167170
)
171+
172+
return object : BaseTrackerQueryBundle {
173+
override val commonParams: TrackerQueryCommonParams
174+
get() = commonParams
175+
override val orgUnits: List<DownloadOrgunit>
176+
get() = ouUids.map { DownloadOrgunit(it, false) }
177+
}
168178
}
169179
}

0 commit comments

Comments
 (0)