Skip to content

Commit

Permalink
fix: [ANDROAPP-6535] filter in RelationshipsRepository by relationshi…
Browse files Browse the repository at this point in the history
…p type

Signed-off-by: andresmr <[email protected]>
  • Loading branch information
andresmr committed Dec 18, 2024
1 parent e669698 commit f15a858
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 65 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin = '2.0.20'
hilt = '2.47'
jacoco = '0.8.10'
designSystem = "0.4.1-SNAPSHOT"
dhis2sdk = "1.11.1-20241213.081754-8"
dhis2sdk = "1.11.1-20241218.080719-10"
ruleEngine = "3.0.0"
expressionParser = "1.1.0"
appcompat = "1.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ class EventRelationshipsRepository(
.blockingGet()

val relationships = d2.relationshipModule().relationships()
.getByItem(
.byItem(
RelationshipItem.builder()
.event(
RelationshipItemEvent.builder().event(eventUid).build(),
).relationshipItemType(constraintType)
.build(),
).filter {
it.relationshipType() == relationshipSection.uid
}.mapNotNull { relationship ->
).byRelationshipType().eq(relationshipSection.uid)
.byDeleted().isFalse
.withItems()
.blockingGet()
.mapNotNull { relationship ->
mapToRelationshipModel(
relationship = relationship,
relationshipType = relationshipType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TrackerRelationshipsRepository(
.blockingGet()

val relationships = d2.relationshipModule().relationships()
.getByItem(
.byItem(
RelationshipItem.builder()
.trackedEntityInstance(
RelationshipItemTrackedEntityInstance.builder()
Expand All @@ -88,9 +88,11 @@ class TrackerRelationshipsRepository(
).relationshipItemType(constraintType)
.build(),
)
.filter {
it.relationshipType() == relationshipSection.uid
}.mapNotNull { relationship ->
.byRelationshipType().eq(relationshipSection.uid)
.byDeleted().isFalse
.withItems()
.blockingGet()
.mapNotNull { relationship ->
mapToRelationshipModel(
relationship = relationship,
relationshipType = relationshipType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import org.dhis2.tracker.relationships.model.RelationshipDirection
import org.dhis2.tracker.relationships.model.RelationshipModel
import org.dhis2.tracker.relationships.model.RelationshipOwnerType
import org.dhis2.tracker.relationships.model.RelationshipSection
import org.hisp.dhis.android.core.common.ObjectWithUid
import org.hisp.dhis.android.core.relationship.Relationship
import org.hisp.dhis.android.core.relationship.RelationshipConstraint
import org.hisp.dhis.android.core.relationship.RelationshipType
import org.mockito.kotlin.mock
import java.util.Date

val relationshipSection1 = RelationshipSection(
uid = "uid1",
title = "Relationship title 1",
uid = "relationshipTypeUid1",
title = "RelationshipType1 FROM",
relationships = emptyList(),
side = RelationshipConstraintSide.FROM,
entityToAdd = null,
entityToAdd = "trackedEntityType2",
)

val relationshipSection2 =
RelationshipSection(
uid = "uid2",
title = "Relationship title 2",
uid = "relationshipTypeUid2",
title = "RelationshipType2 FROM",
relationships = emptyList(),
side = RelationshipConstraintSide.FROM,
entityToAdd = null,
entityToAdd = "trackedEntityType2",
)

val relationshipModel1 = RelationshipModel(
Expand Down Expand Up @@ -72,4 +75,45 @@ val relationshipSection2 =
toGeometry = null,
direction = RelationshipDirection.FROM,
relationship = Relationship.builder().uid("uid2").build()
)
)

val relationshipTypeTeiToTei = RelationshipType.builder()
.uid("relationshipTypeUid1")
.fromToName("RelationshipType1 FROM")
.toFromName("RelationshipType1 TO")
.displayName("Tei to Tei relationship")
.fromConstraint(
RelationshipConstraint.builder()
.trackedEntityType(
ObjectWithUid.create("trackedEntityType1")
).build()
)
.toConstraint(
RelationshipConstraint.builder()
.trackedEntityType(
ObjectWithUid.create("trackedEntityType2")
)
.build()
)
.build()

val relationshipTypeEventToTei = RelationshipType.builder()
.uid("relationshipTypeUid2")
.fromToName("RelationshipType2 FROM")
.toFromName("RelationshipType2 TO")
.displayName("Event to Tei relationship")
.fromConstraint(
RelationshipConstraint.builder()
.programStage(
ObjectWithUid.create("programStageUid")
)
.build()
)
.toConstraint(
RelationshipConstraint.builder()
.trackedEntityType(
ObjectWithUid.create("trackedEntityType2")
)
.build()
)
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import org.dhis2.commons.resources.ResourceManager
import org.dhis2.tracker.data.ProfilePictureProvider
import org.dhis2.tracker.relationships.relationshipSection1
import org.dhis2.tracker.relationships.relationshipSection2
import org.dhis2.tracker.relationships.relationshipTypeEventToTei
import org.dhis2.tracker.relationships.relationshipTypeTeiToTei
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.common.ObjectWithUid
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.relationship.RelationshipConstraint
import org.hisp.dhis.android.core.relationship.RelationshipConstraintType
import org.hisp.dhis.android.core.relationship.RelationshipType
import org.hisp.dhis.android.core.relationship.RelationshipTypeWithEntitySide
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
import org.junit.Assert.assertEquals
Expand All @@ -34,7 +33,7 @@ class TrackerRelationshipsRepositoryTest {

private val teiUid = "teiUid"
private val enrollmentUid = "enrollmentUid"
private val trackedEntityType = "trackedEntityType"
private val trackedEntityType = "trackedEntityType1"

@Before
fun setup() {
Expand Down Expand Up @@ -85,49 +84,21 @@ class TrackerRelationshipsRepositoryTest {


//Then a relationshipSectionList is returned
assertEquals(relationshipTypes, expectedResult)
}



private val relationshipTypeTeiToTei = RelationshipType.builder()
.uid("relationshipTypeUid1")
.fromToName("RelationshipType1 FROM")
.toFromName("RelationshipType1 TO")
.displayName("Tei to Tei relationship")
.fromConstraint(
RelationshipConstraint.builder()
.trackedEntityType(
ObjectWithUid.create(trackedEntityType)
).build()
val expectedResult = listOf(
relationshipSection1,
relationshipSection2,
)
.toConstraint(
RelationshipConstraint.builder()
.trackedEntityType(
ObjectWithUid.create("trackedEntityTypeUid2")
)
.build()
)
.build()
assertEquals(expectedResult, relationshipTypes)
}

private val relationshipWithEntitySideList = listOf(
RelationshipTypeWithEntitySide(
relationshipType = relationshipTypeTeiToTei,
entitySide = RelationshipConstraintType.FROM
),
RelationshipTypeWithEntitySide(
relationshipType = RelationshipType.builder()
.uid("relationshipTypeUid2")
.fromToName("RelationshipType2 FROM")
.toFromName("RelationshipType2 TO")
.displayName("relationshipType2")
.build(),
relationshipType = relationshipTypeEventToTei,
entitySide = RelationshipConstraintType.FROM
)
)

private val expectedResult = listOf(
relationshipSection1,
relationshipSection2,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GetRelationshipsByTypeTest {

@Test
fun `invoke should return relationship sections grouped by type`() = runTest {

//Given a list of relationship types and relationships
whenever(relationshipsRepository.getRelationshipTypes()) doReturn getRelationshipSectionsMock()
whenever(
Expand All @@ -52,22 +53,20 @@ class GetRelationshipsByTypeTest {

// When calling the use case to get the relationships grouped by type
val result = getRelationshipsByType()
assertEquals(expectedResult, result)


// Then a list of RelationshipSections with their relationships should be returned
val expectedResult = listOf(
relationshipSection1.copy(
relationships = listOf(relationshipModel1),
),
relationshipSection2.copy(
relationships = listOf(relationshipModel2),
)
)
assertEquals(expectedResult, result)

}

private val expectedResult = listOf(
relationshipSection1.copy(
relationships = listOf(relationshipModel1),
),
relationshipSection2.copy(
relationships = listOf(relationshipModel2),
)
)

private fun getRelationshipSectionsMock(): List<RelationshipSection> {
return listOf(
relationshipSection1,
Expand Down

0 comments on commit f15a858

Please sign in to comment.