Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: align /tracker/relationships?trackedEntity= attributes DHIS2-18541 #19671

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ public TrackedEntity getTrackedEntity(
}
}

UserDetails user = getCurrentUserDetails();
TrackedEntity trackedEntity = getTrackedEntity(trackedEntityUid, program, params, user, false);
return trackedEntity;
return getTrackedEntity(trackedEntityUid, program, params, getCurrentUserDetails());
}

/**
Expand All @@ -249,11 +247,7 @@ public TrackedEntity getTrackedEntity(
* @throws ForbiddenException if TE owner is not in user's scope or not enough sharing access
*/
private TrackedEntity getTrackedEntity(
UID uid,
Program program,
TrackedEntityParams params,
UserDetails user,
boolean includeDeleted)
UID uid, Program program, TrackedEntityParams params, UserDetails user)
throws NotFoundException, ForbiddenException {
TrackedEntity trackedEntity = trackedEntityStore.getByUid(uid.getValue());
if (trackedEntity == null) {
Expand All @@ -280,32 +274,16 @@ private TrackedEntity getTrackedEntity(
}
}

TrackedEntity result = new TrackedEntity();
result.setId(trackedEntity.getId());
result.setUid(trackedEntity.getUid());
result.setOrganisationUnit(trackedEntity.getOrganisationUnit());
result.setTrackedEntityType(trackedEntity.getTrackedEntityType());
result.setCreated(trackedEntity.getCreated());
result.setCreatedAtClient(trackedEntity.getCreatedAtClient());
result.setLastUpdated(trackedEntity.getLastUpdated());
result.setLastUpdatedAtClient(trackedEntity.getLastUpdatedAtClient());
result.setInactive(trackedEntity.isInactive());
result.setGeometry(trackedEntity.getGeometry());
result.setDeleted(trackedEntity.isDeleted());
result.setPotentialDuplicate(trackedEntity.isPotentialDuplicate());
result.setStoredBy(trackedEntity.getStoredBy());
result.setCreatedByUserInfo(trackedEntity.getCreatedByUserInfo());
result.setLastUpdatedByUserInfo(trackedEntity.getLastUpdatedByUserInfo());
result.setGeometry(trackedEntity.getGeometry());
if (params.isIncludeEnrollments()) {
result.setEnrollments(getEnrollments(trackedEntity, user, includeDeleted, program));
trackedEntity.setEnrollments(getEnrollments(trackedEntity, user, false, program));
}
setRelationshipItems(result, trackedEntity, params, includeDeleted);
setRelationshipItems(trackedEntity, trackedEntity, params, false);
if (params.isIncludeProgramOwners()) {
result.setProgramOwners(getTrackedEntityProgramOwners(trackedEntity, program));
trackedEntity.setProgramOwners(getTrackedEntityProgramOwners(trackedEntity, program));
}
result.setTrackedEntityAttributeValues(getTrackedEntityAttributeValues(trackedEntity, program));
return result;
trackedEntity.setTrackedEntityAttributeValues(
getTrackedEntityAttributeValues(trackedEntity, program));
return trackedEntity;
}

private Set<Enrollment> getEnrollments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.webapi.controller.tracker.export.relationship;

import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty;
import static org.hisp.dhis.test.utils.Assertions.assertStartsWith;
import static org.hisp.dhis.webapi.controller.tracker.JsonAssertions.assertContainsAll;
import static org.hisp.dhis.webapi.controller.tracker.JsonAssertions.assertEnrollmentWithinRelationship;
Expand Down Expand Up @@ -652,7 +653,11 @@ void getRelationshipsByTrackedEntityWithEnrollments() {
}

@Test
void getRelationshipsByTrackedEntityAndEnrollmentWithAttributes() {
void getRelationshipsByTrackedEntityAndEnrollmentWithAttributesIsEmpty() {
// Tracked entity attribute values are owned by the tracked entity and only mapped onto the
// enrollment on export. Program tracked entity attributes are only returned by the underlying
// TE service if a program is
// provided which is not possible on the relationship endpoint.
TrackedEntity to = trackedEntity(orgUnit);
to.setTrackedEntityAttributeValues(
Set.of(attributeValue(tea, to, "12"), attributeValue(tea2, to, "24")));
Expand Down Expand Up @@ -689,13 +694,13 @@ void getRelationshipsByTrackedEntityAndEnrollmentWithAttributes() {

JsonList<JsonAttribute> enrollmentAttr =
relationships.get(0).getFrom().getEnrollment().getAttributes();
assertContainsAll(List.of(tea2.getUid()), enrollmentAttr, JsonAttribute::getAttribute);
assertContainsAll(List.of("24"), enrollmentAttr, JsonAttribute::getValue);
assertIsEmpty(
enrollmentAttr.toList(JsonAttribute::getAttribute),
"program attributes should not be returned as no program can be provided");
JsonList<JsonAttribute> teAttributes =
relationships.get(0).getTo().getTrackedEntity().getAttributes();
assertContainsAll(
List.of(tea.getUid(), tea2.getUid()), teAttributes, JsonAttribute::getAttribute);
assertContainsAll(List.of("12", "24"), teAttributes, JsonAttribute::getValue);
assertContainsAll(List.of(tea.getUid()), teAttributes, JsonAttribute::getAttribute);
assertContainsAll(List.of("12"), teAttributes, JsonAttribute::getValue);
}

@Test
Expand Down
Loading