Skip to content

Commit a87de64

Browse files
authored
chore: [ANDROSDK-2340] migrate batch 21 models and remove AutoValue (#2658)
2 parents 80e0cac + 81039f7 commit a87de64

15 files changed

Lines changed: 489 additions & 328 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ All commands should be run from the project root. The `core` module is the prima
6464

6565
Every domain feature (e.g., `program/`, `enrollment/`, `trackedentity/`) follows a consistent layout:
6666

67-
- **Root package** (public API): Domain model (`Program.java`), collection repository (`ProgramCollectionRepository.kt`), module interface (`ProgramModule.kt`)
67+
- **Root package** (public API): Domain model (`Program.kt`), collection repository (`ProgramCollectionRepository.kt`), module interface (`ProgramModule.kt`)
6868
- **`internal/`** subpackage: `*Handler.kt` (persists downloaded data), `*Store.kt` (SQL queries), `*Call.kt` (coordinates download), `*NetworkHandler.kt` (API fetch), `*DIModule.kt` (Koin bindings), `*ModuleDownloader.kt`, `*ModuleImpl.kt`, `*ModuleWiper.kt`
6969

7070
### Data Models
7171

72-
Domain models are mostly **Java AutoValue** classes (e.g., `Program.java`, `Enrollment.java`) — immutable with generated builders. Newer models use Kotlin data classes. Each model has a corresponding `*TableInfo` class defining column names used by stores and repositories.
72+
Domain models are **Kotlin data classes** annotated with `@ModelBuilder` (e.g., `Program.kt`, `Enrollment.kt`) — immutable, with a fluent builder (`XxxBuilder` parent class) generated by the KSP processor in `processor/`. Models keep Java-style accessor methods (`field(): Type`) alongside Kotlin properties for backwards compatibility. Each model has a corresponding `*TableInfo` class defining column names used by stores and repositories.
7373

7474
### Database & Migrations
7575

core/api/core.api

Lines changed: 306 additions & 62 deletions
Large diffs are not rendered by default.

core/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.jetbrains.dokka.gradle.DokkaTask
3333
plugins {
3434
id("com.android.library")
3535
id("kotlin-android")
36-
id("kotlin-kapt")
3736
id("maven-publish-conventions")
3837
id("jacoco-conventions")
3938
alias(libs.plugins.room)
@@ -168,10 +167,6 @@ dependencies {
168167
api(libs.androidx.annotation)
169168
api(libs.androidx.paging.runtime)
170169

171-
// Auto Value
172-
api(libs.google.auto.value.annotation)
173-
kapt(libs.google.auto.value)
174-
175170
// Koin
176171
implementation(libs.koin.core)
177172
implementation(libs.koin.annotations)
@@ -297,7 +292,7 @@ tasks.withType<DokkaTask>().configureEach {
297292
}
298293

299294
tasks.dokkaJavadoc.configure {
300-
dependsOn("kaptReleaseKotlin")
295+
dependsOn("kspReleaseKotlin")
301296
}
302297

303298
// Custom task to run code quality checks, unit tests, and instrumentation tests sequentially

core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/IdentifiableCollectionFiltersMockIntegrationShould.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,21 @@ class IdentifiableCollectionFiltersMockIntegrationShould : BaseMockIntegrationTe
246246
val inBetween = DateUtils.DATE_FORMAT.parse(inBetweenDate)
247247
val after = DateUtils.DATE_FORMAT.parse(afterDate)
248248

249-
val beforeDatePeriods = listOf(DatePeriod.create(before, inBetween))
249+
val beforeDatePeriods = listOf(DatePeriod(before, inBetween))
250250
val beforeCategories = d2.categoryModule().categories()
251251
.byLastUpdated().inDatePeriods(beforeDatePeriods)
252252
.blockingGet()
253253
assertThat(beforeCategories.size).isEqualTo(2)
254254

255-
val afterDatePeriods = listOf(DatePeriod.create(inBetween, after))
255+
val afterDatePeriods = listOf(DatePeriod(inBetween, after))
256256
val afterCategories = d2.categoryModule().categories()
257257
.byLastUpdated().inDatePeriods(afterDatePeriods)
258258
.blockingGet()
259259
assertThat(afterCategories.size).isEqualTo(2)
260260

261261
val datePeriods = listOf(
262-
DatePeriod.create(before, inBetween),
263-
DatePeriod.create(inBetween, after),
262+
DatePeriod(before, inBetween),
263+
DatePeriod(inBetween, after),
264264
)
265265
val categories = d2.categoryModule().categories()
266266
.byLastUpdated().inDatePeriods(datePeriods).blockingGet()

core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/DateFilterConnector.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import org.hisp.dhis.android.core.arch.repositories.scope.internal.FilterItemOpe
3535
import org.hisp.dhis.android.core.period.DatePeriod
3636
import org.hisp.dhis.android.core.period.Period
3737
import org.hisp.dhis.android.core.period.internal.InPeriodQueryHelper
38-
import java.util.*
38+
import java.util.Date
3939

4040
abstract class DateFilterConnector<R : BaseRepository> internal constructor(
4141
repositoryFactory: BaseRepositoryFactory<R>,
@@ -105,7 +105,9 @@ abstract class DateFilterConnector<R : BaseRepository> internal constructor(
105105
fun inPeriods(periods: List<Period>): R {
106106
val datePeriods: MutableList<DatePeriod> = ArrayList()
107107
for (period in periods) {
108-
datePeriods.add(DatePeriod.builder().startDate(period.startDate()).endDate(period.endDate()).build())
108+
if (period.startDate != null && period.endDate != null) {
109+
datePeriods.add(DatePeriod(period.startDate, period.endDate))
110+
}
109111
}
110112
return inDatePeriods(datePeriods)
111113
}

core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/ExpressionDimensionItem.java renamed to core/src/main/java/org/hisp/dhis/android/core/dataapproval/DataApproval.kt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@
2626
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29-
package org.hisp.dhis.android.core.expressiondimensionitem;
30-
31-
import androidx.annotation.Nullable;
32-
33-
import com.google.auto.value.AutoValue;
34-
35-
import org.hisp.dhis.android.core.common.BaseIdentifiableObAuVa;
36-
import org.hisp.dhis.android.core.common.CoreObject;
37-
38-
@AutoValue
39-
public abstract class ExpressionDimensionItem extends BaseIdentifiableObAuVa implements CoreObject {
40-
41-
@Nullable
42-
public abstract String expression();
43-
44-
public static Builder builder() {
45-
return new AutoValue_ExpressionDimensionItem.Builder();
46-
}
47-
48-
public abstract Builder toBuilder();
49-
50-
@AutoValue.Builder
51-
public abstract static class Builder extends BaseIdentifiableObAuVa.Builder<Builder> {
52-
public abstract Builder expression(String expression);
53-
54-
public abstract ExpressionDimensionItem build();
29+
package org.hisp.dhis.android.core.dataapproval
30+
31+
import org.hisp.dhis.android.annotations.ModelBuilder
32+
import org.hisp.dhis.android.core.common.CoreObject
33+
34+
@ModelBuilder
35+
data class DataApproval(
36+
val workflow: String,
37+
val organisationUnit: String,
38+
val period: String,
39+
val attributeOptionCombo: String,
40+
val state: DataApprovalState,
41+
) : CoreObject {
42+
fun workflow(): String = workflow
43+
fun organisationUnit(): String = organisationUnit
44+
fun period(): String = period
45+
fun attributeOptionCombo(): String = attributeOptionCombo
46+
fun state(): DataApprovalState = state
47+
48+
fun toBuilder(): Builder = DataApprovalBuilder.from(this)
49+
50+
class Builder : DataApprovalBuilder()
51+
52+
companion object {
53+
@JvmStatic
54+
fun builder(): Builder = Builder()
5555
}
5656
}

core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetCompleteRegistration.java

Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2004-2023, University of Oslo
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
*
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* Neither the name of the HISP project nor the names of its contributors may
14+
* be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
package org.hisp.dhis.android.core.dataset
30+
31+
import org.hisp.dhis.android.annotations.ModelBuilder
32+
import org.hisp.dhis.android.core.common.DataObjectKt
33+
import org.hisp.dhis.android.core.common.DeletableDataObjectKt
34+
import org.hisp.dhis.android.core.common.State
35+
import java.util.Date
36+
37+
@ModelBuilder
38+
data class DataSetCompleteRegistration(
39+
val period: String,
40+
val dataSet: String,
41+
val organisationUnit: String,
42+
val attributeOptionCombo: String,
43+
val date: Date?,
44+
val storedBy: String?,
45+
override val syncState: State?,
46+
override val deleted: Boolean?,
47+
) : DataObjectKt, DeletableDataObjectKt {
48+
fun period(): String = period
49+
fun dataSet(): String = dataSet
50+
fun organisationUnit(): String = organisationUnit
51+
fun attributeOptionCombo(): String = attributeOptionCombo
52+
fun date(): Date? = date
53+
fun storedBy(): String? = storedBy
54+
55+
@Deprecated("Use syncState() instead")
56+
override fun state(): State? = syncState
57+
58+
fun toBuilder(): Builder = DataSetCompleteRegistrationBuilder.from(this)
59+
60+
class Builder : DataSetCompleteRegistrationBuilder()
61+
62+
companion object {
63+
@JvmStatic
64+
fun builder(): Builder = Builder()
65+
.syncState(State.SYNCED)
66+
}
67+
}

core/src/main/java/org/hisp/dhis/android/core/period/Period.java renamed to core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/ExpressionDimensionItem.kt

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,33 @@
2626
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29-
package org.hisp.dhis.android.core.period;
30-
31-
import androidx.annotation.Nullable;
32-
33-
import com.google.auto.value.AutoValue;
34-
35-
import org.hisp.dhis.android.core.common.CoreObject;
36-
37-
import java.util.Date;
38-
39-
@AutoValue
40-
public abstract class Period implements CoreObject {
41-
42-
@Nullable
43-
public abstract String periodId();
44-
45-
@Nullable
46-
public abstract PeriodType periodType();
47-
48-
@Nullable
49-
public abstract Date startDate();
50-
51-
@Nullable
52-
public abstract Date endDate();
53-
54-
public abstract Builder toBuilder();
55-
56-
public static Builder builder() {
57-
return new AutoValue_Period.Builder();
58-
}
59-
60-
@AutoValue.Builder
61-
public abstract static class Builder {
62-
public abstract Builder periodId(String periodId);
63-
64-
public abstract Builder periodType(PeriodType periodType);
65-
66-
public abstract Builder startDate(Date startDate);
67-
68-
public abstract Builder endDate(Date endDate);
69-
70-
public abstract Period build();
29+
package org.hisp.dhis.android.core.expressiondimensionitem
30+
31+
import org.hisp.dhis.android.annotations.ModelBuilder
32+
import org.hisp.dhis.android.core.common.BaseIdentifiableObjectKt
33+
import org.hisp.dhis.android.core.common.CoreObject
34+
import java.util.Date
35+
36+
@ModelBuilder
37+
data class ExpressionDimensionItem(
38+
override val uid: String,
39+
override val code: String?,
40+
override val name: String?,
41+
override val displayName: String?,
42+
override val created: Date?,
43+
override val lastUpdated: Date?,
44+
override val deleted: Boolean?,
45+
val expression: String?,
46+
) : BaseIdentifiableObjectKt, CoreObject {
47+
48+
fun expression(): String? = expression
49+
50+
fun toBuilder(): Builder = ExpressionDimensionItemBuilder.from(this)
51+
52+
class Builder : ExpressionDimensionItemBuilder()
53+
54+
companion object {
55+
@JvmStatic
56+
fun builder(): Builder = Builder()
7157
}
7258
}

0 commit comments

Comments
 (0)