diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelper.java index 8acdd51ae9fe..b81b4d108225 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelper.java @@ -272,7 +272,7 @@ public String getUserAccessErrors( } List relationshipTypes = - relationshipService.getRelationships(mergeObject.getRelationships()).stream() + relationshipService.getRelationships(UID.of(mergeObject.getRelationships())).stream() .map(Relationship::getRelationshipType) .distinct() .toList(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java index 363b04e8bcdd..1bae8b5e5285 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java @@ -32,6 +32,7 @@ import java.util.Set; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -76,9 +77,9 @@ public Page getRelationships( } @Override - public Relationship getRelationship(@Nonnull String uid) + public Relationship getRelationship(@Nonnull UID uid) throws ForbiddenException, NotFoundException { - Relationship relationship = relationshipStore.getByUid(uid); + Relationship relationship = relationshipStore.getByUid(uid.getValue()); if (relationship == null) { throw new NotFoundException(Relationship.class, uid); @@ -94,10 +95,10 @@ public Relationship getRelationship(@Nonnull String uid) } @Override - public List getRelationships(@Nonnull List uids) + public List getRelationships(@Nonnull Set uids) throws ForbiddenException, NotFoundException { List relationships = new ArrayList<>(); - for (String uid : uids) { + for (UID uid : uids) { relationships.add(getRelationship(uid)); } return relationships; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java index 5c0eee5ed393..fc6c0426b670 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Set; import javax.annotation.Nonnull; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -47,13 +48,13 @@ List getRelationships(RelationshipOperationParams params) Page getRelationships(RelationshipOperationParams params, PageParams pageParams) throws ForbiddenException, NotFoundException, BadRequestException; - Relationship getRelationship(String uid) throws ForbiddenException, NotFoundException; + Relationship getRelationship(UID uid) throws ForbiddenException, NotFoundException; /** * Get relationships matching given {@code UID}s under the privileges of the currently * authenticated user. */ - List getRelationships(@Nonnull List uids) + List getRelationships(@Nonnull Set uids) throws ForbiddenException, NotFoundException; /** diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java index 0229a61c6d11..004433765b09 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationHelperTest.java @@ -109,8 +109,7 @@ class DeduplicationHelperTest extends TestBase { @BeforeEach public void setUp() throws ForbiddenException, NotFoundException { - List relationshipUids = - List.of(CodeGenerator.generateUid(), CodeGenerator.generateUid()); + Set relationshipUids = UID.of(CodeGenerator.generateUid(), CodeGenerator.generateUid()); List attributeUids = List.of(CodeGenerator.generateUid(), CodeGenerator.generateUid()); Set enrollmentUids = UID.of(CodeGenerator.generateUid(), CodeGenerator.generateUid()); @@ -124,7 +123,7 @@ public void setUp() throws ForbiddenException, NotFoundException { enrollment = createEnrollment(createProgram('A'), getTrackedEntityA(), organisationUnitA); mergeObject = MergeObject.builder() - .relationships(relationshipUids) + .relationships(UID.toValueList(relationshipUids)) .trackedEntityAttributes(attributeUids) .enrollments(UID.toValueList(enrollmentUids)) .build(); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java index 4c117aeacb2a..a93543caa166 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerCreateRelationshipSMSTest.java @@ -42,6 +42,7 @@ import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.http.HttpStatus; @@ -197,7 +198,7 @@ void shouldCreateRelationship() throws SmsCompressionException { () -> assertEquals(originator, sms.getOriginator()), () -> assertEquals(user, sms.getCreatedBy()), () -> { - Relationship relationship = relationshipService.getRelationship(relationshipUid); + Relationship relationship = relationshipService.getRelationship(UID.of(relationshipUid)); assertAll( () -> assertEquals(relationshipUid, relationship.getUid()), () -> assertEquals(event1, relationship.getFrom().getEvent()), diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java index ccd8089e62a6..ee9a893ba28b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java @@ -138,8 +138,7 @@ ResponseEntity getRelationshipByUid( @OpenApi.Param(value = String[].class) @RequestParam(defaultValue = DEFAULT_FIELDS_PARAM) List fields) throws NotFoundException, ForbiddenException { - Relationship relationship = - RELATIONSHIP_MAPPER.from(relationshipService.getRelationship(uid.getValue())); + Relationship relationship = RELATIONSHIP_MAPPER.from(relationshipService.getRelationship(uid)); return ResponseEntity.ok(fieldFilterService.toObjectNode(relationship, fields)); }