Skip to content

Commit

Permalink
chore: [ANDROSDK-1968] Move EventFilter api logic to network (#2272)
Browse files Browse the repository at this point in the history
  • Loading branch information
taridepaco authored Jan 13, 2025
2 parents b4a549d + 33fca98 commit c1c7d35
Show file tree
Hide file tree
Showing 41 changed files with 725 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,24 @@

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.google.auto.value.AutoValue;

import org.hisp.dhis.android.core.common.CoreObject;
import org.hisp.dhis.android.core.common.FilterOperators;

@AutoValue
@JsonDeserialize(builder = $$AutoValue_EventDataFilter.Builder.class)
public abstract class EventDataFilter extends FilterOperators implements CoreObject {

/**
* The related event filter
*/
@Nullable
@JsonProperty()
public abstract String eventFilter();

/**
* The data element id or data item
*/
@Nullable
@JsonProperty()
public abstract String dataItem();

public static Builder builder() {
Expand All @@ -69,7 +63,6 @@ public static EventDataFilter create(Cursor cursor) {
public abstract Builder toBuilder();

@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "")
public abstract static class Builder extends FilterOperators.Builder<Builder> {
public abstract Builder id(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,23 +40,18 @@
import org.hisp.dhis.android.core.common.CoreObject;

@AutoValue
@JsonDeserialize(builder = $$AutoValue_EventFilter.Builder.class)
public abstract class EventFilter extends BaseIdentifiableObject implements CoreObject {

@Nullable
@JsonProperty()
public abstract String program();

@Nullable
@JsonProperty()
public abstract String programStage();

@Nullable
@JsonProperty()
public abstract String description();

@Nullable
@JsonProperty()
@ColumnAdapter(EventQueryCriteriaColumnAdapter.class)
public abstract EventQueryCriteria eventQueryCriteria();

Expand All @@ -74,7 +66,6 @@ public static EventFilter create(Cursor cursor) {
public abstract Builder toBuilder();

@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "")
public abstract static class Builder extends BaseIdentifiableObject.Builder<Builder> {

public abstract Builder id(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,26 +45,21 @@
import java.util.List;

@AutoValue
@JsonDeserialize(builder = $$AutoValue_EventQueryCriteria.Builder.class)
public abstract class EventQueryCriteria extends FilterQueryCriteria implements CoreObject {

@Nullable
@JsonProperty()
@ColumnAdapter(IgnoreEventDataFilterListColumnAdapter.class)
public abstract List<EventDataFilter> dataFilters();

@Nullable
@JsonProperty()
@ColumnAdapter(StringListColumnAdapter.class)
public abstract List<String> events();

@Nullable
@JsonProperty()
@ColumnAdapter(DateFilterPeriodColumnAdapter.class)
public abstract DateFilterPeriod dueDate();

@Nullable
@JsonProperty()
@ColumnAdapter(DateFilterPeriodColumnAdapter.class)
public abstract DateFilterPeriod completedDate();

Expand All @@ -82,7 +74,6 @@ public static EventQueryCriteria create(Cursor cursor) {
public abstract Builder toBuilder();

@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "")
public abstract static class Builder extends FilterQueryCriteria.Builder<Builder> {
public abstract Builder id(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,27 @@ package org.hisp.dhis.android.core.event.internal

import org.hisp.dhis.android.core.arch.api.executors.internal.APIDownloader
import org.hisp.dhis.android.core.arch.call.factories.internal.UidsCallCoroutines
import org.hisp.dhis.android.core.common.internal.DataAccessFields
import org.hisp.dhis.android.core.event.EventFilter
import org.hisp.dhis.android.core.systeminfo.DHISVersion
import org.hisp.dhis.android.core.systeminfo.DHISVersionManager
import org.koin.core.annotation.Singleton

@Singleton
internal class EventFilterCall internal constructor(
private val service: EventFilterService,
private val networkHandler: EventFilterNetworkHandler,
val handler: EventFilterHandler,
val apiDownloader: APIDownloader,
val versionManager: DHISVersionManager,
) : UidsCallCoroutines<EventFilter> {

override suspend fun download(programUids: Set<String>): List<EventFilter> {
return if (versionManager.isGreaterThan(DHISVersion.V2_31)) {
val accessDataReadFilter = "access." + DataAccessFields.read.eq(true).generateString()
apiDownloader.downloadPartitioned(
programUids,
MAX_UID_LIST_SIZE,
handler,
) { partitionUids: Set<String> ->
service.getEventFilters(
EventFilterFields.programUid.`in`(partitionUids),
accessDataReadFilter,
EventFilterFields.allFields,
false,
)
}
networkHandler::getEventFilters,
)
} else {
arrayListOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.event.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.event.EventDataFilter
import org.hisp.dhis.android.core.event.EventFilter
import org.koin.core.annotation.Singleton

Expand All @@ -46,9 +45,7 @@ internal class EventFilterHandler constructor(

override fun afterObjectHandled(o: EventFilter, action: HandleAction) {
if (action !== HandleAction.Delete && o.eventQueryCriteria() != null) {
eventDataFilterHandler.handleMany(
o.eventQueryCriteria()!!.dataFilters(),
) { edf: EventDataFilter -> edf.toBuilder().eventFilter(o.uid()).build() }
eventDataFilterHandler.handleMany(o.eventQueryCriteria()!!.dataFilters())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2004-2025, 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.event.internal

import org.hisp.dhis.android.core.arch.api.payload.internal.Payload
import org.hisp.dhis.android.core.event.EventFilter

internal fun interface EventFilterNetworkHandler {
suspend fun getEventFilters(
partitionUids: Set<String>,
): Payload<EventFilter>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,35 @@ import kotlinx.serialization.Serializable
import org.hisp.dhis.android.core.attribute.Attribute
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.network.common.PayloadJson
import org.hisp.dhis.android.network.common.dto.BaseIdentifiableObjectDTO
import org.hisp.dhis.android.network.common.dto.BaseNameableObjectDTO
import org.hisp.dhis.android.network.common.dto.PagerDTO
import org.hisp.dhis.android.network.common.dto.applyBaseNameableFields

@Serializable
internal data class AttributeDTO(
@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,
override val shortName: String? = BaseNameableObjectDTO.SHORT_NAME,
override val displayShortName: String? = BaseNameableObjectDTO.DISPLAY_SHORT_NAME,
override val description: String? = BaseNameableObjectDTO.DESCRIPTION,
override val displayDescription: String? = BaseNameableObjectDTO.DISPLAY_DESCRIPTION,
val valueType: String? = null,
val unique: Boolean? = null,
val mandatory: Boolean? = null,
val indicatorAttribute: Boolean? = null,
val indicatorGroupAttribute: Boolean? = null,
val userGroupAttribute: Boolean? = null,
val dataElementAttribute: Boolean? = null,
val constantAttribute: Boolean? = null,
val categoryOptionAttribute: Boolean? = null,
val optionSetAttribute: Boolean? = null,
val sqlViewAttribute: Boolean? = null,
val legendSetAttribute: Boolean? = null,
override val code: String?,
override val name: String?,
override val displayName: String?,
override val created: String?,
override val lastUpdated: String?,
override val deleted: Boolean?,
override val shortName: String?,
override val displayShortName: String?,
override val description: String?,
override val displayDescription: String?,
val valueType: String?,
val unique: Boolean?,
val mandatory: Boolean?,
val indicatorAttribute: Boolean?,
val indicatorGroupAttribute: Boolean?,
val userGroupAttribute: Boolean?,
val dataElementAttribute: Boolean?,
val constantAttribute: Boolean?,
val categoryOptionAttribute: Boolean?,
val optionSetAttribute: Boolean?,
val sqlViewAttribute: Boolean?,
val legendSetAttribute: Boolean?,
val trackedEntityAttributeAttribute: Boolean? = null,
val organisationUnitAttribute: Boolean? = null,
val dataSetAttribute: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ import org.hisp.dhis.android.network.common.dto.applyBaseIdentifiableFields
@Serializable
internal data class CategoryDTO(
@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 dataDimensionType: String? = null,
override val code: String?,
override val name: String?,
override val displayName: String?,
override val created: String?,
override val lastUpdated: String?,
override val deleted: Boolean?,
val dataDimensionType: String?,
val categoryOptions: List<ObjectWithUidDTO> = emptyList(),
) : BaseIdentifiableObjectDTO {
fun toDomain(): Category {
Expand All @@ -61,6 +61,6 @@ internal data class CategoryDTO(

@Serializable
internal class CategoryPayload(
override val pager: PagerDTO? = null,
override val pager: PagerDTO?,
@SerialName("categories") override val items: List<CategoryDTO> = emptyList(),
) : PayloadJson<CategoryDTO>(pager, items)
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import org.hisp.dhis.android.network.common.dto.applyBaseIdentifiableFields
@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,
override val code: String?,
override val name: String?,
override val displayName: String?,
override val created: String?,
override val lastUpdated: String?,
override val deleted: Boolean?,
val categoryOptions: List<ObjectWithUidDTO> = emptyList(),
) : BaseIdentifiableObjectDTO {
fun toDomain(categoryComboUid: String): CategoryOptionCombo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import org.hisp.dhis.android.network.common.dto.applyBaseIdentifiableFields
@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,
override val code: String?,
override val name: String?,
override val displayName: String?,
override val created: String?,
override val lastUpdated: String?,
override val deleted: Boolean?,
val isDefault: Boolean?,
val categories: List<ObjectWithUidDTO> = emptyList(),
val categoryOptionCombos: List<CategoryOptionComboDTO> = emptyList(),
) : BaseIdentifiableObjectDTO {
Expand All @@ -64,6 +64,6 @@ internal data class CategoryComboDTO(

@Serializable
internal class CategoryComboPayload(
override val pager: PagerDTO? = null,
override val pager: PagerDTO?,
@SerialName("categoryCombos") override val items: List<CategoryComboDTO> = emptyList(),
) : PayloadJson<CategoryComboDTO>(pager, items)
Loading

0 comments on commit c1c7d35

Please # to comment.