diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/Category.java b/core/src/main/java/org/hisp/dhis/android/core/category/Category.java index bac8207357..b98ed5bb14 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/Category.java +++ b/core/src/main/java/org/hisp/dhis/android/core/category/Category.java @@ -32,9 +32,6 @@ import androidx.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.google.auto.value.AutoValue; @@ -45,15 +42,12 @@ import java.util.List; @AutoValue -@JsonDeserialize(builder = AutoValue_Category.Builder.class) public abstract class Category extends BaseIdentifiableObject implements CoreObject { @Nullable - @JsonProperty() public abstract String dataDimensionType(); @Nullable - @JsonProperty() @ColumnAdapter(IgnoreCategoryOptionListColumnAdapter.class) public abstract List categoryOptions(); @@ -68,7 +62,6 @@ public static Builder builder() { } @AutoValue.Builder - @JsonPOJOBuilder(withPrefix = "") public abstract static class Builder extends BaseIdentifiableObject.Builder { public abstract Builder id(Long id); diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryCombo.java b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryCombo.java index e20af41e85..b89c770ff2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryCombo.java +++ b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryCombo.java @@ -30,9 +30,8 @@ import android.database.Cursor; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import androidx.annotation.Nullable; + import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.google.auto.value.AutoValue; @@ -43,25 +42,19 @@ import java.util.List; -import androidx.annotation.Nullable; - @AutoValue -@JsonDeserialize(builder = AutoValue_CategoryCombo.Builder.class) public abstract class CategoryCombo extends BaseIdentifiableObject implements CoreObject { public static final String DEFAULT_UID = "p0KPaWEg3cf"; @Nullable - @JsonProperty() public abstract Boolean isDefault(); @Nullable - @JsonProperty() @ColumnAdapter(IgnoreCategoryListColumnAdapter.class) public abstract List categories(); @Nullable - @JsonProperty() @ColumnAdapter(IgnoreCategoryOptionComboListColumnAdapter.class) abstract List categoryOptionCombos(); @@ -76,7 +69,6 @@ public static Builder builder() { } @AutoValue.Builder - @JsonPOJOBuilder(withPrefix = "") public abstract static class Builder extends BaseIdentifiableObject.Builder { public abstract Builder id(Long id); diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryOptionCombo.java b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryOptionCombo.java index dd5e289241..4e53039fce 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryOptionCombo.java +++ b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryOptionCombo.java @@ -32,9 +32,6 @@ import androidx.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.google.auto.value.AutoValue; @@ -47,16 +44,13 @@ import java.util.List; @AutoValue -@JsonDeserialize(builder = $$AutoValue_CategoryOptionCombo.Builder.class) public abstract class CategoryOptionCombo extends BaseIdentifiableObject implements CoreObject { @Nullable - @JsonProperty() @ColumnAdapter(ObjectWithUidColumnAdapter.class) public abstract ObjectWithUid categoryCombo(); @Nullable - @JsonProperty() @ColumnAdapter(IgnoreCategoryOptionListColumnAdapter.class) public abstract List categoryOptions(); @@ -71,7 +65,6 @@ public static Builder builder() { } @AutoValue.Builder - @JsonPOJOBuilder(withPrefix = "") public abstract static class Builder extends BaseIdentifiableObject.Builder { public abstract Builder id(Long id); diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboCall.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboCall.kt index ba36092e18..32e32b7654 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboCall.kt @@ -34,13 +34,13 @@ import org.koin.core.annotation.Singleton @Singleton internal class CategoryComboCall( - private val service: CategoryComboService, + private val networkHandler: CategoryComboNetworkHandler, private val handler: CategoryComboHandler, private val apiDownloader: APIDownloader, ) : UidsCallCoroutines { override suspend fun download(uids: Set): List { return apiDownloader.downloadPartitioned(uids, MAX_UID_LIST_SIZE, handler) { partitionUids: Set -> - service.getCategoryCombos( + networkHandler.getCategoryCombos( CategoryComboFields.allFields, CategoryComboFields.uid.`in`(partitionUids), paging = false, diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboHandler.kt index 017d83ca78..5a797046ba 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboHandler.kt @@ -34,12 +34,10 @@ import org.hisp.dhis.android.core.category.Category import org.hisp.dhis.android.core.category.CategoryCategoryComboLink import org.hisp.dhis.android.core.category.CategoryCombo import org.hisp.dhis.android.core.category.CategoryComboInternalAccessor -import org.hisp.dhis.android.core.category.CategoryOptionCombo -import org.hisp.dhis.android.core.common.ObjectWithUid import org.koin.core.annotation.Singleton @Singleton -internal class CategoryComboHandler constructor( +internal class CategoryComboHandler( store: CategoryComboStore, private val optionComboHandler: CategoryOptionComboHandler, private val categoryCategoryComboLinkHandler: CategoryCategoryComboLinkHandler, @@ -47,13 +45,7 @@ internal class CategoryComboHandler constructor( ) : IdentifiableHandlerImpl(store) { override fun afterObjectHandled(o: CategoryCombo, action: HandleAction) { - optionComboHandler.handleMany( - CategoryComboInternalAccessor.accessCategoryOptionCombos(o), - ) { optionCombo: CategoryOptionCombo -> - optionCombo.toBuilder() - .categoryCombo(ObjectWithUid.create(o.uid())) - .build() - } + optionComboHandler.handleMany(CategoryComboInternalAccessor.accessCategoryOptionCombos(o)) categoryCategoryComboLinkHandler.handleMany( o.uid(), o.categories(), diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboNetworkHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboNetworkHandler.kt new file mode 100644 index 0000000000..455c542a49 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboNetworkHandler.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004-2024, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.category.internal + +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields +import org.hisp.dhis.android.core.arch.api.filters.internal.Filter +import org.hisp.dhis.android.core.arch.api.payload.internal.Payload +import org.hisp.dhis.android.core.category.CategoryCombo + +internal fun interface CategoryComboNetworkHandler { + suspend fun getCategoryCombos( + fields: Fields, + uids: Filter, + paging: Boolean, + ): Payload +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetHandler.kt index 81d86d78f5..1a247a0ea1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetHandler.kt @@ -29,26 +29,18 @@ package org.hisp.dhis.android.core.legendset.internal import org.hisp.dhis.android.core.arch.handlers.internal.HandleAction import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl -import org.hisp.dhis.android.core.common.ObjectWithUid -import org.hisp.dhis.android.core.legendset.Legend import org.hisp.dhis.android.core.legendset.LegendSet import org.koin.core.annotation.Singleton @Singleton -internal class LegendSetHandler constructor( +internal class LegendSetHandler( legendSetStore: LegendSetStore, private val legendHandler: LegendHandler, private val legendCleaner: LegendSetLegendOrphanCleaner, ) : IdentifiableHandlerImpl(legendSetStore) { override fun afterObjectHandled(o: LegendSet, action: HandleAction) { - legendHandler.handleMany( - o.legends(), - ) { legend: Legend -> - legend.toBuilder() - .legendSet(ObjectWithUid.create(o.uid())) - .build() - } + legendHandler.handleMany(o.legends()) if (action === HandleAction.Update) { legendCleaner.deleteOrphan(o, o.legends()) diff --git a/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeNetworkHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeNetworkHandlerImpl.kt index 73ab5813ca..0976c085fc 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeNetworkHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeNetworkHandlerImpl.kt @@ -46,7 +46,7 @@ internal class AttributeNetworkHandlerImpl( uids: Filter, paging: Boolean, ): PayloadJson { - val apiPayload = service.attributes(fields, uids, paging) + val apiPayload = service.getAttributes(fields, uids, paging) return apiPayload.mapItems(::attributeDtoToDomainMapper) } } diff --git a/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeService.kt b/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeService.kt index 7e4a2f5373..bdce280fc1 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeService.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/attribute/AttributeService.kt @@ -36,7 +36,7 @@ import org.koin.core.annotation.Singleton @Singleton internal class AttributeService(private val client: HttpServiceClientKotlinx) { - suspend fun attributes( + suspend fun getAttributes( fields: Fields, uids: Filter, paging: Boolean, diff --git a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboDTO.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboDTO.kt new file mode 100644 index 0000000000..93a89b6918 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboDTO.kt @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004-2024, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.network.category + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.hisp.dhis.android.network.common.BaseIdentifiableObjectDTO +import org.hisp.dhis.android.network.common.ObjectWithUidDTO +import org.hisp.dhis.android.network.common.PagerDTO +import org.hisp.dhis.android.network.common.PayloadJson + +@Serializable +internal data class CategoryComboDTO( + @SerialName("id") override val uid: String, + override val code: String? = BaseIdentifiableObjectDTO.CODE, + override val name: String? = BaseIdentifiableObjectDTO.NAME, + override val displayName: String? = BaseIdentifiableObjectDTO.DISPLAY_NAME, + override val created: String? = BaseIdentifiableObjectDTO.CREATED, + override val lastUpdated: String? = BaseIdentifiableObjectDTO.LAST_UPDATED, + override val deleted: Boolean? = BaseIdentifiableObjectDTO.DELETED, + val isDefault: Boolean? = null, + val categories: List = emptyList(), + val categoryOptionCombos: List = emptyList(), +) : BaseIdentifiableObjectDTO + +@Serializable +internal class CategoryComboPayload( + override val pager: PagerDTO? = null, + @SerialName("categoryCombos") override val items: List = emptyList(), +) : PayloadJson(pager, items) diff --git a/core/src/test/java/org/hisp/dhis/android/core/category/CategoryComboShould.java b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboNetworkHandlerImpl.kt similarity index 50% rename from core/src/test/java/org/hisp/dhis/android/core/category/CategoryComboShould.java rename to core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboNetworkHandlerImpl.kt index cdeca26ceb..c2300b735f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/category/CategoryComboShould.java +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboNetworkHandlerImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,42 +25,28 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -package org.hisp.dhis.android.core.category; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.common.BaseObjectShould; -import org.hisp.dhis.android.core.common.ObjectShould; -import org.junit.Test; - -import java.io.IOException; -import java.text.ParseException; - -import static com.google.common.truth.Truth.assertThat; - -public class CategoryComboShould extends BaseObjectShould implements ObjectShould { - - public CategoryComboShould() { - super("category/category_combo.json"); - } - - @Override - @Test - public void map_from_json_string() throws IOException, ParseException { - CategoryCombo combo = objectMapper.readValue(jsonStream, CategoryCombo.class); - - assertThat(combo.uid()).isEqualTo("m2jTvAj5kkm"); - assertThat(combo.code()).isEqualTo("BIRTHS"); - assertThat(combo.created()).isEqualTo( - BaseIdentifiableObject.DATE_FORMAT.parse("2011-12-24T12:24:25.203")); - assertThat(combo.lastUpdated()).isEqualTo( - BaseIdentifiableObject.DATE_FORMAT.parse("2016-04-18T16:04:34.745")); - assertThat(combo.name()).isEqualTo("Births"); - assertThat(combo.displayName()).isEqualTo("Births"); - assertThat(combo.isDefault()).isFalse(); - - // categories - assertThat(combo.categories().get(0).uid()).isEqualTo("KfdsGBcoiCa"); - assertThat(combo.categories().get(1).uid()).isEqualTo("cX5k9anHEHd"); +package org.hisp.dhis.android.network.category + +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields +import org.hisp.dhis.android.core.arch.api.filters.internal.Filter +import org.hisp.dhis.android.core.category.CategoryCombo +import org.hisp.dhis.android.core.category.internal.CategoryComboNetworkHandler +import org.hisp.dhis.android.network.common.HttpServiceClientKotlinx +import org.hisp.dhis.android.network.common.PayloadJson +import org.koin.core.annotation.Singleton + +@Singleton +internal class CategoryComboNetworkHandlerImpl( + httpClient: HttpServiceClientKotlinx, +) : CategoryComboNetworkHandler { + private val service: CategoryComboService = CategoryComboService(httpClient) + + override suspend fun getCategoryCombos( + fields: Fields, + uids: Filter, + paging: Boolean, + ): PayloadJson { + val apiPayload = service.getCategoryCombos(fields, uids, paging) + return apiPayload.mapItems(::categoryComboDtoToDomainMapper) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboService.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboService.kt similarity index 88% rename from core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboService.kt rename to core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboService.kt index 36bf634045..b01c22acbd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboService.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryComboService.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2023, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,22 +25,21 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.category.internal +package org.hisp.dhis.android.network.category -import org.hisp.dhis.android.core.arch.api.HttpServiceClient import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.api.filters.internal.Filter -import org.hisp.dhis.android.core.arch.api.payload.internal.PayloadJackson import org.hisp.dhis.android.core.category.CategoryCombo +import org.hisp.dhis.android.network.common.HttpServiceClientKotlinx import org.koin.core.annotation.Singleton @Singleton -internal class CategoryComboService(private val client: HttpServiceClient) { +internal class CategoryComboService(private val client: HttpServiceClientKotlinx) { suspend fun getCategoryCombos( fields: Fields, uids: Filter, paging: Boolean, - ): PayloadJackson { + ): CategoryComboPayload { return client.get { url("categoryCombos") parameters { diff --git a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryDTOMapper.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryDTOMapper.kt index e4bf07de4e..aa67ea0d71 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryDTOMapper.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryDTOMapper.kt @@ -29,7 +29,10 @@ package org.hisp.dhis.android.network.category import org.hisp.dhis.android.core.category.Category +import org.hisp.dhis.android.core.category.CategoryCombo import org.hisp.dhis.android.core.category.CategoryOption +import org.hisp.dhis.android.core.category.CategoryOptionCombo +import org.hisp.dhis.android.core.common.ObjectWithUid import org.hisp.dhis.android.network.common.applyBaseIdentifiableFields internal fun categoryDtoToDomainMapper(item: CategoryDTO): Category { @@ -39,3 +42,23 @@ internal fun categoryDtoToDomainMapper(item: CategoryDTO): Category { .categoryOptions(item.categoryOptions.map { CategoryOption.builder().uid(it.uid).build() }) .build() } + +internal fun categoryComboDtoToDomainMapper(item: CategoryComboDTO): CategoryCombo { + return CategoryCombo.builder() + .applyBaseIdentifiableFields(item) + .isDefault(item.isDefault) + .categories(item.categories.map { Category.builder().uid(it.uid).build() }) + .categoryOptionCombos(item.categoryOptionCombos.map { categoryOptionComboDtoToDomainMapper(it, item.uid) }) + .build() +} + +internal fun categoryOptionComboDtoToDomainMapper( + item: CategoryOptionComboDTO, + categoryComboUid: String, +): CategoryOptionCombo { + return CategoryOptionCombo.builder() + .applyBaseIdentifiableFields(item) + .categoryCombo(ObjectWithUid.create(categoryComboUid)) + .categoryOptions(item.categoryOptions.map { CategoryOption.builder().uid(it.uid).build() }) + .build() +} diff --git a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryNetworkHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryNetworkHandlerImpl.kt index 88dbc97abb..00944a0734 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryNetworkHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryNetworkHandlerImpl.kt @@ -46,7 +46,7 @@ internal class CategoryNetworkHandlerImpl( uids: Filter, paging: Boolean, ): PayloadJson { - val apiPayload = service.categories(fields, uids, paging) + val apiPayload = service.getCategories(fields, uids, paging) return apiPayload.mapItems(::categoryDtoToDomainMapper) } } diff --git a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryOptionComboDTO.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryOptionComboDTO.kt new file mode 100644 index 0000000000..06a57b4fb7 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryOptionComboDTO.kt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004-2024, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.network.category + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.hisp.dhis.android.network.common.BaseIdentifiableObjectDTO +import org.hisp.dhis.android.network.common.ObjectWithUidDTO + +@Serializable +internal data class CategoryOptionComboDTO( + @SerialName("id") override val uid: String, + override val code: String? = BaseIdentifiableObjectDTO.CODE, + override val name: String? = BaseIdentifiableObjectDTO.NAME, + override val displayName: String? = BaseIdentifiableObjectDTO.DISPLAY_NAME, + override val created: String? = BaseIdentifiableObjectDTO.CREATED, + override val lastUpdated: String? = BaseIdentifiableObjectDTO.LAST_UPDATED, + override val deleted: Boolean? = BaseIdentifiableObjectDTO.DELETED, + val categoryOptions: List = emptyList(), +) : BaseIdentifiableObjectDTO diff --git a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryService.kt b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryService.kt index e364e854b1..222df49216 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/category/CategoryService.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/category/CategoryService.kt @@ -35,7 +35,7 @@ import org.koin.core.annotation.Singleton @Singleton internal class CategoryService(private val client: HttpServiceClientKotlinx) { - suspend fun categories( + suspend fun getCategories( fields: Fields, uids: Filter, paging: Boolean, diff --git a/core/src/main/java/org/hisp/dhis/android/network/common/BaseIdentifiableObjectDTO.kt b/core/src/main/java/org/hisp/dhis/android/network/common/BaseIdentifiableObjectDTO.kt index aa887444db..805f4ef870 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/common/BaseIdentifiableObjectDTO.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/common/BaseIdentifiableObjectDTO.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.network.common import org.hisp.dhis.android.core.common.BaseIdentifiableObject -// @Serializable internal interface BaseIdentifiableObjectDTO { val uid: String val code: String? diff --git a/core/src/main/java/org/hisp/dhis/android/network/common/BaseNameableObjectDTO.kt b/core/src/main/java/org/hisp/dhis/android/network/common/BaseNameableObjectDTO.kt index 4adccd064d..b8df3e391b 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/common/BaseNameableObjectDTO.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/common/BaseNameableObjectDTO.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.network.common import org.hisp.dhis.android.core.common.BaseNameableObject -// @Serializable internal interface BaseNameableObjectDTO : BaseIdentifiableObjectDTO { val shortName: String? val displayShortName: String? diff --git a/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantNetworkHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantNetworkHandlerImpl.kt index d2c0599d0e..8d75e7d396 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantNetworkHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantNetworkHandlerImpl.kt @@ -41,7 +41,7 @@ internal class ConstantNetworkHandlerImpl( private val service: ConstantService = ConstantService(httpClient) override suspend fun getConstants(): List { - val constantDtoList = service.constants(ConstantFields.allFields, false) + val constantDtoList = service.getConstants(ConstantFields.allFields, false) return constantDtoList.items.map { item -> constantDtoToDomainMapper(item) } } } diff --git a/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantService.kt b/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantService.kt index a4763ee7c3..31448b2435 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantService.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/constant/ConstantService.kt @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.constant.Constant import org.hisp.dhis.android.network.common.HttpServiceClientKotlinx internal class ConstantService(private val client: HttpServiceClientKotlinx) { - suspend fun constants(fields: Fields, paging: Boolean): ConstantPayload { + suspend fun getConstants(fields: Fields, paging: Boolean): ConstantPayload { return client.get { url("constants") parameters { diff --git a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetDTOMapper.kt b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetDTOMapper.kt index db29916bc3..ef85592e5f 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetDTOMapper.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetDTOMapper.kt @@ -28,6 +28,7 @@ package org.hisp.dhis.android.network.legendset +import org.hisp.dhis.android.core.common.ObjectWithUid import org.hisp.dhis.android.core.legendset.Legend import org.hisp.dhis.android.core.legendset.LegendSet import org.hisp.dhis.android.network.common.applyBaseIdentifiableFields @@ -36,13 +37,14 @@ internal fun legendSetDtoToDomainMapper(item: LegendSetDTO): LegendSet { return LegendSet.builder() .applyBaseIdentifiableFields(item) .symbolizer(item.symbolizer) - .legends(item.legends.map { legendDtoToDomainMapper(it) }) + .legends(item.legends.map { legendDtoToDomainMapper(it, item.uid) }) .build() } -internal fun legendDtoToDomainMapper(item: LegendDTO): Legend { +internal fun legendDtoToDomainMapper(item: LegendDTO, legendSetUid: String): Legend { return Legend.builder() .applyBaseIdentifiableFields(item) + .legendSet(ObjectWithUid.create(legendSetUid)) .startValue(item.startValue) .endValue(item.endValue) .color(item.color) diff --git a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetNetworkHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetNetworkHandlerImpl.kt index abab48ea3a..5e5dcf0084 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetNetworkHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetNetworkHandlerImpl.kt @@ -46,7 +46,7 @@ internal class LegendSetNetworkHandlerImpl( uids: Filter, paging: Boolean, ): PayloadJson { - val apiPayload = service.legendSets(fields, uids, paging) + val apiPayload = service.getLegendSets(fields, uids, paging) return apiPayload.mapItems(::legendSetDtoToDomainMapper) } } diff --git a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetService.kt b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetService.kt index f2fc2fd987..0358e13ff2 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetService.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/legendset/LegendSetService.kt @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.legendset.LegendSet import org.hisp.dhis.android.network.common.HttpServiceClientKotlinx internal class LegendSetService(private val client: HttpServiceClientKotlinx) { - suspend fun legendSets( + suspend fun getLegendSets( fields: Fields, uids: Filter, paging: Boolean, diff --git a/core/src/main/java/org/hisp/dhis/android/network/option/OptionNetworkHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/network/option/OptionNetworkHandlerImpl.kt index 109dd76a2c..141b64f292 100644 --- a/core/src/main/java/org/hisp/dhis/android/network/option/OptionNetworkHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/network/option/OptionNetworkHandlerImpl.kt @@ -47,7 +47,7 @@ internal class OptionNetworkHandlerImpl( page: Int, pageSize: Int, ): PayloadJson