Skip to content

Commit

Permalink
[ANDROSDK-1954] Add method to filter by item in RelationshipRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarciabnz committed Dec 17, 2024
1 parent b223e47 commit 43d4db9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -10829,6 +10829,9 @@ public final class org/hisp/dhis/android/core/relationship/RelationshipCollectio
public synthetic fun blockingAdd (Ljava/lang/Object;)Ljava/lang/String;
public fun blockingAdd (Lorg/hisp/dhis/android/core/relationship/Relationship;)Ljava/lang/String;
public final fun byCreated ()Lorg/hisp/dhis/android/core/arch/repositories/filters/internal/DateFilterConnector;
public final fun byDeleted ()Lorg/hisp/dhis/android/core/arch/repositories/filters/internal/BooleanFilterConnector;
public final fun byItem (Lorg/hisp/dhis/android/core/relationship/RelationshipItem;)Lorg/hisp/dhis/android/core/relationship/RelationshipCollectionRepository;
public final fun byItem (Lorg/hisp/dhis/android/core/relationship/RelationshipItem;Z)Lorg/hisp/dhis/android/core/relationship/RelationshipCollectionRepository;
public final fun byLastUpdated ()Lorg/hisp/dhis/android/core/arch/repositories/filters/internal/DateFilterConnector;
public final fun byName ()Lorg/hisp/dhis/android/core/arch/repositories/filters/internal/StringFilterConnector;
public final fun byRelationshipType ()Lorg/hisp/dhis/android/core/arch/repositories/filters/internal/StringFilterConnector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ public void get_by_item_including_all_linked() {
assertThat(relationships.size()).isEqualTo(2);
}

@Test
public void filter_by_item() {
RelationshipItem item = RelationshipItem.builder()
.trackedEntityInstance(
RelationshipItemTrackedEntityInstance.builder().trackedEntityInstance("nWrB0TfWlvh").build()
)
.relationshipItemType(RelationshipConstraintType.FROM)
.build();

List<Relationship> relationships = d2.relationshipModule().relationships()
.byItem(item)
.blockingGet();

assertThat(relationships.size()).isEqualTo(1);
}

@Test
public void filter_by_object_repository() {
Relationship relationship =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ package org.hisp.dhis.android.core.relationship

import io.reactivex.Single
import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter
import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder
import org.hisp.dhis.android.core.arch.handlers.internal.HandleAction
import org.hisp.dhis.android.core.arch.helpers.DateUtils.toJavaDate
import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl
import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderGetter
import org.hisp.dhis.android.core.arch.repositories.collection.ReadWriteWithUidCollectionRepository
import org.hisp.dhis.android.core.arch.repositories.collection.internal.BaseReadOnlyWithUidCollectionRepositoryImpl
import org.hisp.dhis.android.core.arch.repositories.filters.internal.BooleanFilterConnector
import org.hisp.dhis.android.core.arch.repositories.filters.internal.DateFilterConnector
import org.hisp.dhis.android.core.arch.repositories.filters.internal.EnumFilterConnector
import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory
Expand Down Expand Up @@ -195,6 +197,32 @@ class RelationshipCollectionRepository internal constructor(
return relationshipManager.getByItem(searchItem, includeDeleted, onlyAccessible)
}

fun byItem(searchItem: RelationshipItem): RelationshipCollectionRepository {
return byItem(searchItem, includeDeleted = false)
}

fun byItem(searchItem: RelationshipItem, includeDeleted: Boolean): RelationshipCollectionRepository {
return cf.subQuery(IdentifiableColumns.UID).inTableWhere(
RelationshipItemTableInfo.TABLE_INFO.name(),
RelationshipItemTableInfo.Columns.RELATIONSHIP,
WhereClauseBuilder().apply {
searchItem.relationship()?.uid()?.let { relationshipUid ->
appendKeyStringValue(RelationshipItemTableInfo.Columns.RELATIONSHIP, relationshipUid)
}
searchItem.relationshipItemType()?.let { itemType ->
appendKeyStringValue(RelationshipItemTableInfo.Columns.RELATIONSHIP_ITEM_TYPE, itemType.name)
}
searchItem.elementUid()?.let { elementId ->
appendKeyStringValue(searchItem.elementType(), elementId)
}
}.build(),
).apply {
if (!includeDeleted) {
byDeleted().isFalse
}
}
}

fun byUid(): StringFilterConnector<RelationshipCollectionRepository> {
return cf.string(IdentifiableColumns.UID)
}
Expand All @@ -219,6 +247,10 @@ class RelationshipCollectionRepository internal constructor(
return cf.enumC(RelationshipTableInfo.Columns.SYNC_STATE)
}

fun byDeleted(): BooleanFilterConnector<RelationshipCollectionRepository> {
return cf.bool(RelationshipTableInfo.Columns.DELETED)
}

fun withItems(): RelationshipCollectionRepository {
return cf.withChild(RelationshipFields.ITEMS)
}
Expand Down

0 comments on commit 43d4db9

Please sign in to comment.