From 144607746a1cc7378c5b65dfada80ab7b1e8be39 Mon Sep 17 00:00:00 2001 From: Enrico Date: Wed, 23 Oct 2024 10:20:39 +0200 Subject: [PATCH] chore: Use UID in enrollment exporter [DHIS2-17790] --- .../hisp/dhis/feedback/NotFoundException.java | 5 ++ .../deduplication/DeduplicationHelper.java | 4 +- .../enrollment/DefaultEnrollmentService.java | 16 ++-- .../enrollment/EnrollmentOperationParams.java | 11 +-- .../EnrollmentOperationParamsMapper.java | 14 +++- .../enrollment/EnrollmentQueryParams.java | 11 +-- .../export/enrollment/EnrollmentService.java | 9 ++- .../enrollment/HibernateEnrollmentStore.java | 3 +- .../RelationshipOperationParams.java | 3 +- .../RelationshipOperationParamsMapper.java | 5 +- .../DefaultTrackedEntityService.java | 2 +- .../sms/ProgramStageDataEntrySMSListener.java | 5 +- .../DeduplicationHelperTest.java | 14 +++- .../EnrollmentOperationParamsMapperTest.java | 3 +- ...RelationshipOperationParamsMapperTest.java | 18 +++-- .../maintenance/MaintenanceServiceTest.java | 3 +- ...ntialDuplicateRemoveTrackedEntityTest.java | 9 ++- .../OrderAndPaginationExporterTest.java | 24 +++--- .../enrollment/EnrollmentServiceTest.java | 80 ++++++++++--------- .../relationship/RelationshipServiceTest.java | 15 ++-- .../imports/bundle/EnrollmentImportTest.java | 5 +- .../imports/TrackerEnrollmentSMSTest.java | 11 +-- .../tracker/imports/TrackerEventSMSTest.java | 4 +- ...ProgramNotificationInstanceController.java | 2 +- .../EnrollmentRequestParamsMapper.java | 12 ++- .../EnrollmentsExportController.java | 3 +- .../RelationshipRequestParamsMapper.java | 7 +- .../EnrollmentRequestParamsMapperTest.java | 24 +++--- .../RelationshipRequestParamsMapperTest.java | 6 +- 29 files changed, 178 insertions(+), 150 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java index 3ef0609c05fa..0a5501a0006b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java @@ -35,6 +35,7 @@ import lombok.Getter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; +import org.hisp.dhis.common.UID; import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @@ -58,6 +59,10 @@ public NotFoundException(Class type, String uid) { this(type.getSimpleName() + " with id " + uid + " could not be found."); } + public NotFoundException(Class type, UID uid) { + this(type.getSimpleName() + " with id " + uid + " could not be found."); + } + public NotFoundException(String message) { super(message); this.code = ErrorCode.E1005; 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 b0d78b3e0c97..8acdd51ae9fe 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 @@ -37,6 +37,7 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.common.UID; import org.hisp.dhis.commons.collection.ListUtils; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -281,7 +282,8 @@ public String getUserAccessErrors( return "Missing data write access to one or more Relationship Types."; } - List enrollments = enrollmentService.getEnrollments(mergeObject.getEnrollments()); + List enrollments = + enrollmentService.getEnrollments(UID.of(mergeObject.getEnrollments())); if (enrollments.stream() .anyMatch(e -> !aclService.canDataWrite(currentUserDetails, e.getProgram()))) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java index fc85d31b7594..989dd65f3593 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java @@ -38,6 +38,7 @@ import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -71,17 +72,16 @@ class DefaultEnrollmentService implements EnrollmentService { private final EnrollmentOperationParamsMapper paramsMapper; @Override - public Enrollment getEnrollment(@Nonnull String uid) - throws ForbiddenException, NotFoundException { + public Enrollment getEnrollment(@Nonnull UID uid) throws ForbiddenException, NotFoundException { return getEnrollment(uid, EnrollmentParams.FALSE, false); } @Override public Enrollment getEnrollment( - @Nonnull String uid, @Nonnull EnrollmentParams params, boolean includeDeleted) + @Nonnull UID uid, @Nonnull EnrollmentParams params, boolean includeDeleted) throws NotFoundException, ForbiddenException { UserDetails currentUser = getCurrentUserDetails(); - Enrollment enrollment = enrollmentStore.getByUid(uid); + Enrollment enrollment = enrollmentStore.getByUid(uid.getValue()); if (enrollment == null) { throw new NotFoundException(Enrollment.class, uid); @@ -146,11 +146,11 @@ private Enrollment getEnrollment( @Override public RelationshipItem getEnrollmentInRelationshipItem( - @Nonnull String uid, @Nonnull EnrollmentParams params, boolean includeDeleted) + @Nonnull UID uid, @Nonnull EnrollmentParams params, boolean includeDeleted) throws NotFoundException { RelationshipItem relationshipItem = new RelationshipItem(); - Enrollment enrollment = enrollmentStore.getByUid(uid); + Enrollment enrollment = enrollmentStore.getByUid(uid.getValue()); if (enrollment == null) { throw new NotFoundException(Enrollment.class, uid); @@ -211,8 +211,8 @@ private Set getTrackedEntityAttributeValues( } @Override - public List getEnrollments(@Nonnull List uids) throws ForbiddenException { - List enrollments = enrollmentStore.getByUid(uids); + public List getEnrollments(@Nonnull Set uids) throws ForbiddenException { + List enrollments = enrollmentStore.getByUid(UID.toValueList(uids)); UserDetails user = getCurrentUserDetails(); List errors = enrollments.stream() diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParams.java index 786ec4a48644..b911482204a1 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParams.java @@ -38,6 +38,7 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.OrganisationUnitSelectionMode; import org.hisp.dhis.common.SortDirection; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.EnrollmentStatus; import org.hisp.dhis.tracker.export.Order; @@ -50,7 +51,7 @@ public class EnrollmentOperationParams { @Builder.Default private final EnrollmentParams enrollmentParams = EnrollmentParams.FALSE; /** Set of te uids to explicitly select. */ - @Builder.Default private final Set enrollmentUids = new HashSet<>(); + @Builder.Default private final Set enrollmentUids = new HashSet<>(); /** Last updated for enrollment. */ private final Date lastUpdated; @@ -62,13 +63,13 @@ public class EnrollmentOperationParams { * Organisation units for which instances in the response were registered at. Is related to the * specified OrganisationUnitMode. */ - @Builder.Default private final Set orgUnitUids = new HashSet<>(); + @Builder.Default private final Set orgUnitUids = new HashSet<>(); /** Selection mode for the specified organisation units. */ private final OrganisationUnitSelectionMode orgUnitMode; /** Enrollments must be enrolled into this program. */ - private final String programUid; + private final UID programUid; /** Status of a tracked entities enrollment into a given program. */ private final EnrollmentStatus enrollmentStatus; @@ -83,10 +84,10 @@ public class EnrollmentOperationParams { private final Date programEndDate; /** Tracked entity type of the tracked entity in the response. */ - private final String trackedEntityTypeUid; + private final UID trackedEntityTypeUid; /** Tracked entity. */ - private final String trackedEntityUid; + private final UID trackedEntityUid; /** Indicates whether to include soft-deleted enrollments */ private final boolean includeDeleted; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapper.java index fe2b18bce0ec..8253bad44f4f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapper.java @@ -31,11 +31,13 @@ import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CAPTURE; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.DESCENDANTS; import static org.hisp.dhis.tracker.export.OperationsParamsValidator.validateOrgUnitMode; +import static org.hisp.dhis.util.ObjectUtils.applyIfNotNull; import java.util.HashSet; 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.organisationunit.OrganisationUnit; @@ -63,14 +65,18 @@ class EnrollmentOperationParamsMapper { public EnrollmentQueryParams map( @Nonnull EnrollmentOperationParams operationParams, @Nonnull UserDetails user) throws BadRequestException, ForbiddenException { - Program program = paramsValidator.validateTrackerProgram(operationParams.getProgramUid(), user); + Program program = + paramsValidator.validateTrackerProgram( + applyIfNotNull(operationParams.getProgramUid(), UID::getValue), user); TrackedEntityType trackedEntityType = - paramsValidator.validateTrackedEntityType(operationParams.getTrackedEntityTypeUid(), user); + paramsValidator.validateTrackedEntityType( + applyIfNotNull(operationParams.getTrackedEntityTypeUid(), UID::getValue), user); TrackedEntity trackedEntity = - paramsValidator.validateTrackedEntity(operationParams.getTrackedEntityUid(), user); + paramsValidator.validateTrackedEntity( + applyIfNotNull(operationParams.getTrackedEntityUid(), UID::getValue), user); Set orgUnits = - paramsValidator.validateOrgUnits(operationParams.getOrgUnitUids(), user); + paramsValidator.validateOrgUnits(UID.toValueSet(operationParams.getOrgUnitUids()), user); validateOrgUnitMode(operationParams.getOrgUnitMode(), program, user); EnrollmentQueryParams params = new EnrollmentQueryParams(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentQueryParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentQueryParams.java index bc9d954329ff..4fb8122fba1a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentQueryParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentQueryParams.java @@ -37,13 +37,13 @@ import lombok.experimental.Accessors; import org.hisp.dhis.common.OrganisationUnitSelectionMode; import org.hisp.dhis.common.SortDirection; +import org.hisp.dhis.common.UID; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.EnrollmentStatus; import org.hisp.dhis.program.Program; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.tracker.export.Order; -import org.hisp.dhis.user.User; /** * @author Morten Olav Hansen @@ -53,7 +53,7 @@ class EnrollmentQueryParams { /** Set of enrollment uids to explicitly select. */ - private Set enrollmentUids = new HashSet<>(); + private Set enrollmentUids = new HashSet<>(); /** Last updated for enrollment. */ private Date lastUpdated; @@ -95,13 +95,6 @@ class EnrollmentQueryParams { private List order; - // ------------------------------------------------------------------------- - // Transient properties - // ------------------------------------------------------------------------- - - /** Current user for query. */ - private transient User user; - // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java index fadb4bcc7206..c3f78b007957 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.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; @@ -39,13 +40,13 @@ import org.hisp.dhis.tracker.export.PageParams; public interface EnrollmentService { - Enrollment getEnrollment(String uid) throws ForbiddenException, NotFoundException; + Enrollment getEnrollment(UID uid) throws ForbiddenException, NotFoundException; - Enrollment getEnrollment(String uid, EnrollmentParams params, boolean includeDeleted) + Enrollment getEnrollment(UID uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException, ForbiddenException; RelationshipItem getEnrollmentInRelationshipItem( - String uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException; + UID uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException; /** Get all enrollments matching given params. */ List getEnrollments(EnrollmentOperationParams params) @@ -59,7 +60,7 @@ Page getEnrollments(EnrollmentOperationParams params, PageParams pag * Get event matching given {@code UID} under the privileges the user in the context. This method * does not get the events relationships. */ - List getEnrollments(@Nonnull List uids) throws ForbiddenException; + List getEnrollments(@Nonnull Set uids) throws ForbiddenException; /** * Fields the {@link #getEnrollments(EnrollmentOperationParams)} can order enrollments by. diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java index 2eb044a0abb1..cabad10bee81 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java @@ -51,6 +51,7 @@ import org.apache.commons.lang3.StringUtils; import org.hibernate.query.Query; import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.hibernate.SoftDeleteHibernateObjectStore; import org.hisp.dhis.commons.util.SqlHelper; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -146,7 +147,7 @@ private QueryWithOrderBy buildEnrollmentHql(EnrollmentQueryParams params) { hql += hlp.whereAnd() + "en.uid in (" - + getQuotedCommaDelimitedString(params.getEnrollmentUids()) + + getQuotedCommaDelimitedString(UID.toValueList(params.getEnrollmentUids())) + ")"; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java index b4c5f618b778..c6f1891e396f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java @@ -34,6 +34,7 @@ import lombok.Builder; import lombok.Getter; import org.hisp.dhis.common.SortDirection; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.export.Order; @@ -43,7 +44,7 @@ public class RelationshipOperationParams { private TrackerType type; - private String identifier; + private UID identifier; private List order; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java index 47916daf8f60..b822df22b89a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java @@ -60,9 +60,10 @@ public RelationshipQueryParams map(@Nonnull RelationshipOperationParams params) IdentifiableObject entity = switch (params.getType()) { - case TRACKED_ENTITY -> trackedEntityService.getTrackedEntity(params.getIdentifier()); + case TRACKED_ENTITY -> + trackedEntityService.getTrackedEntity(params.getIdentifier().getValue()); case ENROLLMENT -> enrollmentService.getEnrollment(params.getIdentifier()); - case EVENT -> eventService.getEvent(UID.of(params.getIdentifier())); + case EVENT -> eventService.getEvent(UID.of(params.getIdentifier().getValue())); case RELATIONSHIP -> throw new IllegalArgumentException("Unsupported type"); }; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java index 9303a4dbcc75..306e7572fe44 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java @@ -445,7 +445,7 @@ private RelationshipItem withNestedEntity( } else if (item.getEnrollment() != null) { result = enrollmentService.getEnrollmentInRelationshipItem( - item.getEnrollment().getUid(), + UID.of(item.getEnrollment().getUid()), EnrollmentParams.TRUE.withIncludeRelationships(false), false); } else if (item.getEvent() != null) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/ProgramStageDataEntrySMSListener.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/ProgramStageDataEntrySMSListener.java index 213ef1dc77bd..66485de34a91 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/ProgramStageDataEntrySMSListener.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/ProgramStageDataEntrySMSListener.java @@ -40,6 +40,7 @@ import org.hisp.dhis.common.OrganisationUnitSelectionMode; import org.hisp.dhis.common.QueryFilter; import org.hisp.dhis.common.QueryOperator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; @@ -145,8 +146,8 @@ public void postProcess( Page enrollmentPage = enrollmentService.getEnrollments( EnrollmentOperationParams.builder() - .trackedEntityUid(trackedEntity.getUid()) - .programUid(smsCommand.getProgram().getUid()) + .trackedEntityUid(UID.of(trackedEntity)) + .programUid(UID.of(smsCommand.getProgram())) .enrollmentStatus(EnrollmentStatus.ACTIVE) .orgUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE) .build(), 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 4b7fc9ec5d66..40570b0a16c5 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 @@ -37,7 +37,10 @@ import com.google.common.collect.Lists; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -106,9 +109,12 @@ class DeduplicationHelperTest extends TestBase { @BeforeEach public void setUp() throws ForbiddenException, NotFoundException { - List relationshipUids = Lists.newArrayList("REL_A", "REL_B"); - List attributeUids = Lists.newArrayList("ATTR_A", "ATTR_B"); - List enrollmentUids = Lists.newArrayList("PI_A", "PI_B"); + List relationshipUids = + Lists.newArrayList(CodeGenerator.generateUid(), CodeGenerator.generateUid()); + List attributeUids = + Lists.newArrayList(CodeGenerator.generateUid(), CodeGenerator.generateUid()); + Set enrollmentUids = + Set.of(UID.of(CodeGenerator.generateUid()), UID.of(CodeGenerator.generateUid())); organisationUnitA = createOrganisationUnit('A'); organisationUnitB = createOrganisationUnit('B'); @@ -122,7 +128,7 @@ public void setUp() throws ForbiddenException, NotFoundException { MergeObject.builder() .relationships(relationshipUids) .trackedEntityAttributes(attributeUids) - .enrollments(enrollmentUids) + .enrollments(UID.toValueList(enrollmentUids)) .build(); user = makeUser("A", Lists.newArrayList("F_TRACKED_ENTITY_MERGE")); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapperTest.java index 34d35afa6e93..7a28a15aa014 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentOperationParamsMapperTest.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.SortDirection; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -227,7 +228,7 @@ void shouldMapChildrenOrgUnitModeWhenChildrenProvided() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit1.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit1))) .orgUnitMode(CHILDREN) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java index 8fd771d67ede..290023476517 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapperTest.java @@ -104,7 +104,10 @@ void shouldMapTrackedEntityWhenATrackedEntityIsPassed() throws NotFoundException, ForbiddenException, BadRequestException { when(trackedEntityService.getTrackedEntity(TE_UID)).thenReturn(trackedEntity); RelationshipOperationParams params = - RelationshipOperationParams.builder().type(TRACKED_ENTITY).identifier(TE_UID).build(); + RelationshipOperationParams.builder() + .type(TRACKED_ENTITY) + .identifier(UID.of(TE_UID)) + .build(); RelationshipQueryParams queryParams = mapper.map(params); @@ -115,9 +118,9 @@ void shouldMapTrackedEntityWhenATrackedEntityIsPassed() @Test void shouldMapEnrollmentWhenAEnrollmentIsPassed() throws NotFoundException, ForbiddenException, BadRequestException { - when(enrollmentService.getEnrollment(EN_UID)).thenReturn(enrollment); + when(enrollmentService.getEnrollment(UID.of(EN_UID))).thenReturn(enrollment); RelationshipOperationParams params = - RelationshipOperationParams.builder().type(ENROLLMENT).identifier(EN_UID).build(); + RelationshipOperationParams.builder().type(ENROLLMENT).identifier(UID.of(EN_UID)).build(); RelationshipQueryParams queryParams = mapper.map(params); @@ -130,7 +133,7 @@ void shouldMapEventWhenAEventIsPassed() throws NotFoundException, ForbiddenException, BadRequestException { when(eventService.getEvent(UID.of(EV_UID))).thenReturn(event); RelationshipOperationParams params = - RelationshipOperationParams.builder().type(EVENT).identifier(EV_UID).build(); + RelationshipOperationParams.builder().type(EVENT).identifier(UID.of(EV_UID)).build(); RelationshipQueryParams queryParams = mapper.map(params); @@ -146,7 +149,7 @@ void shouldMapOrderInGivenOrder() RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(TRACKED_ENTITY) - .identifier(TE_UID) + .identifier(UID.of(TE_UID)) .orderBy("created", SortDirection.DESC) .build(); @@ -161,7 +164,10 @@ void shouldMapNullOrderingParamsWhenNoOrderingParamsAreSpecified() when(trackedEntityService.getTrackedEntity(TE_UID)).thenReturn(trackedEntity); RelationshipOperationParams operationParams = - RelationshipOperationParams.builder().type(TRACKED_ENTITY).identifier(TE_UID).build(); + RelationshipOperationParams.builder() + .type(TRACKED_ENTITY) + .identifier(UID.of(TE_UID)) + .build(); RelationshipQueryParams queryParams = mapper.map(operationParams); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java index 072179f7baff..0dc502d94e0c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java @@ -51,6 +51,7 @@ import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DeliveryChannel; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.feedback.BadRequestException; @@ -504,7 +505,7 @@ private boolean enrollmentExistsIncludingDeleted(Enrollment enrollment) throws ForbiddenException, BadRequestException, NotFoundException { EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .enrollmentUids(Set.of(enrollment.getUid())) + .enrollmentUids(Set.of(UID.of(enrollment))) .orgUnitMode(ALL) .includeDeleted(true) .build(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java index ebf9914240c3..dc82ee7a0735 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/PotentialDuplicateRemoveTrackedEntityTest.java @@ -33,6 +33,7 @@ import java.util.List; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dbms.DbmsManager; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -176,10 +177,10 @@ void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException { assertNotNull(manager.get(TrackedEntity.class, control2.getUid())); removeTrackedEntity(duplicate); assertThrows( - NotFoundException.class, () -> enrollmentService.getEnrollment(enrollment2.getUid())); - assertNotNull(enrollmentService.getEnrollment(enrollment1.getUid())); - assertNotNull(enrollmentService.getEnrollment(enrollment3.getUid())); - assertNotNull(enrollmentService.getEnrollment(enrollment4.getUid())); + NotFoundException.class, () -> enrollmentService.getEnrollment(UID.of(enrollment2))); + assertNotNull(enrollmentService.getEnrollment(UID.of(enrollment1))); + assertNotNull(enrollmentService.getEnrollment(UID.of(enrollment3))); + assertNotNull(enrollmentService.getEnrollment(UID.of(enrollment4))); assertNull(manager.get(TrackedEntity.class, duplicate.getUid())); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java index fb687ce4a5a1..f71525325790 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java @@ -571,7 +571,7 @@ void shouldReturnPaginatedEnrollmentsGivenNonDefaultPageSize() throws ForbiddenException, BadRequestException, NotFoundException { EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit))) .orgUnitMode(SELECTED) .orderBy("enrollmentDate", SortDirection.ASC) .build(); @@ -603,7 +603,7 @@ void shouldReturnPaginatedEnrollmentsGivenNonDefaultPageSizeAndTotalPages() throws ForbiddenException, BadRequestException, NotFoundException { EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit))) .orgUnitMode(SELECTED) .orderBy("enrollmentDate", SortDirection.ASC) .build(); @@ -643,7 +643,7 @@ void shouldOrderEnrollmentsByPrimaryKeyDescByDefault() EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit))) .orgUnitMode(SELECTED) .build(); @@ -657,7 +657,7 @@ void shouldOrderEnrollmentsByEnrolledAtAsc() throws ForbiddenException, BadRequestException, NotFoundException { EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit))) .orgUnitMode(SELECTED) .orderBy("enrollmentDate", SortDirection.ASC) .build(); @@ -672,7 +672,7 @@ void shouldOrderEnrollmentsByEnrolledAtDesc() throws ForbiddenException, BadRequestException, NotFoundException { EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnit.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnit))) .orgUnitMode(SELECTED) .orderBy("enrollmentDate", SortDirection.DESC) .build(); @@ -1317,7 +1317,7 @@ void shouldOrderRelationshipsByPrimaryKeyDescByDefault() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .build(); List relationships = getRelationships(params); @@ -1331,7 +1331,7 @@ void shouldOrderRelationshipsByUpdatedAtClientInDescOrder() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .orderBy("createdAtClient", SortDirection.DESC) .build(); @@ -1346,7 +1346,7 @@ void shouldOrderRelationshipsByUpdatedAtClientInAscOrder() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .orderBy("createdAtClient", SortDirection.ASC) .build(); @@ -1375,7 +1375,7 @@ void shouldReturnPaginatedRelationshipsGivenNonDefaultPageSize() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .build(); Page firstPage = @@ -1420,7 +1420,7 @@ void shouldReturnPaginatedRelationshipsGivenNonDefaultPageSizeAndTotalPages() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .build(); Page firstPage = @@ -1454,7 +1454,7 @@ void shouldOrderRelationshipsByCreatedAsc() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .orderBy("created", SortDirection.ASC) .build(); @@ -1484,7 +1484,7 @@ void shouldOrderRelationshipsByCreatedDesc() RelationshipOperationParams params = RelationshipOperationParams.builder() .type(TrackerType.EVENT) - .identifier("pTzf9KYMk72") + .identifier(UID.of("pTzf9KYMk72")) .orderBy("created", SortDirection.DESC) .build(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java index e6462b26a597..ecde64bddd9a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentServiceTest.java @@ -53,6 +53,7 @@ import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -279,7 +280,7 @@ void shouldGetEnrollmentWhenUserHasReadWriteAccessToProgramAndAccessToOrgUnit() manager.updateNoAcl(programA); Enrollment enrollment = - enrollmentService.getEnrollment(enrollmentA.getUid(), EnrollmentParams.FALSE, false); + enrollmentService.getEnrollment(UID.of(enrollmentA), EnrollmentParams.FALSE, false); assertNotNull(enrollment); assertEquals(enrollmentA.getUid(), enrollment.getUid()); @@ -292,7 +293,7 @@ void shouldGetEnrollmentWhenUserHasReadAccessToProgramAndAccessToOrgUnit() manager.updateNoAcl(programA); Enrollment enrollment = - enrollmentService.getEnrollment(enrollmentA.getUid(), EnrollmentParams.FALSE, false); + enrollmentService.getEnrollment(UID.of(enrollmentA), EnrollmentParams.FALSE, false); assertNotNull(enrollment); assertEquals(enrollmentA.getUid(), enrollment.getUid()); @@ -304,7 +305,7 @@ void shouldGetEnrollmentWithEventsWhenUserHasAccessToEvent() EnrollmentParams params = EnrollmentParams.FALSE; params = params.withEnrollmentEventsParams(EnrollmentEventsParams.TRUE); - Enrollment enrollment = enrollmentService.getEnrollment(enrollmentA.getUid(), params, false); + Enrollment enrollment = enrollmentService.getEnrollment(UID.of(enrollmentA), params, false); assertNotNull(enrollment); assertContainsOnly( @@ -322,7 +323,7 @@ void shouldGetEnrollmentWithoutEventsWhenUserHasNoAccessToProgramStage() EnrollmentParams params = EnrollmentParams.FALSE; params = params.withIncludeEvents(true); - Enrollment enrollment = enrollmentService.getEnrollment(enrollmentA.getUid(), params, false); + Enrollment enrollment = enrollmentService.getEnrollment(UID.of(enrollmentA), params, false); assertNotNull(enrollment); assertIsEmpty(enrollment.getEvents()); @@ -334,7 +335,7 @@ void shouldGetEnrollmentWithRelationshipsWhenUserHasAccessToThem() EnrollmentParams params = EnrollmentParams.FALSE; params = params.withIncludeRelationships(true); - Enrollment enrollment = enrollmentService.getEnrollment(enrollmentA.getUid(), params, false); + Enrollment enrollment = enrollmentService.getEnrollment(UID.of(enrollmentA), params, false); assertNotNull(enrollment); assertContainsOnly(Set.of(relationshipA.getUid()), relationshipUids(enrollment)); @@ -349,7 +350,7 @@ void shouldGetEnrollmentWithoutRelationshipsWhenUserHasAccessToThem() EnrollmentParams params = EnrollmentParams.FALSE; params = params.withIncludeRelationships(true); - Enrollment enrollment = enrollmentService.getEnrollment(enrollmentA.getUid(), params, false); + Enrollment enrollment = enrollmentService.getEnrollment(UID.of(enrollmentA), params, false); assertNotNull(enrollment); assertIsEmpty(enrollment.getRelationshipItems()); @@ -361,7 +362,7 @@ void shouldGetEnrollmentWithAttributesWhenUserHasAccessToThem() EnrollmentParams params = EnrollmentParams.FALSE; params = params.withIncludeAttributes(true); - Enrollment enrollment = enrollmentService.getEnrollment(enrollmentA.getUid(), params, false); + Enrollment enrollment = enrollmentService.getEnrollment(UID.of(enrollmentA), params, false); assertNotNull(enrollment); assertContainsOnly(List.of(trackedEntityAttributeA.getUid()), attributeUids(enrollment)); @@ -378,7 +379,7 @@ void shouldFailGettingEnrollmentWhenUserHasNoAccessToProgramsTrackedEntityType() ForbiddenException.class, () -> enrollmentService.getEnrollment( - enrollmentA.getUid(), EnrollmentParams.FALSE, false)); + UID.of(enrollmentA), EnrollmentParams.FALSE, false)); assertContains("access to tracked entity type", exception.getMessage()); } @@ -388,13 +389,16 @@ void shouldFailGettingEnrollmentWhenDoesNotExist() { trackedEntityTypeA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT); manager.updateNoAcl(trackedEntityTypeA); + String nonExistentUid = CodeGenerator.generateUid(); + NotFoundException exception = assertThrows( NotFoundException.class, () -> - enrollmentService.getEnrollment("non existent UID", EnrollmentParams.FALSE, false)); + enrollmentService.getEnrollment( + UID.of(nonExistentUid), EnrollmentParams.FALSE, false)); assertContains( - "Enrollment with id non existent UID could not be found.", exception.getMessage()); + "Enrollment with id " + nonExistentUid + " could not be found.", exception.getMessage()); } @Test @@ -409,7 +413,7 @@ void shouldFailGettingEnrollmentWhenUserHasReadAccessToProgramButNoAccessToOrgUn ForbiddenException.class, () -> enrollmentService.getEnrollment( - enrollmentA.getUid(), EnrollmentParams.FALSE, false)); + UID.of(enrollmentA), EnrollmentParams.FALSE, false)); assertContains("OWNERSHIP_ACCESS_DENIED", exception.getMessage()); } @@ -425,7 +429,7 @@ void shouldFailGettingEnrollmentWhenUserHasReadWriteAccessToProgramButNoAccessTo ForbiddenException.class, () -> enrollmentService.getEnrollment( - enrollmentA.getUid(), EnrollmentParams.FALSE, false)); + UID.of(enrollmentA), EnrollmentParams.FALSE, false)); assertContains("OWNERSHIP_ACCESS_DENIED", exception.getMessage()); } @@ -439,7 +443,7 @@ void shouldFailGettingEnrollmentWhenUserHasNoAccessToProgramButAccessToOrgUnit() ForbiddenException.class, () -> enrollmentService.getEnrollment( - enrollmentA.getUid(), EnrollmentParams.FALSE, false)); + UID.of(enrollmentA), EnrollmentParams.FALSE, false)); assertContains("access to program", exception.getMessage()); } @@ -452,7 +456,7 @@ void shouldGetEnrollmentsWhenUserHasReadAccessToProgramAndSearchScopeAccessToOrg EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .orgUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE) .build(); @@ -473,7 +477,7 @@ void shouldGetEnrollmentsWhenUserHasReadAccessToProgramAndNoOrgUnitNorOrgUnitMod EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .orgUnitMode(ACCESSIBLE) .build(); @@ -512,8 +516,8 @@ void shouldGetEnrollmentWhenEnrollmentsAndOtherParamsAreSpecified() EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .programUid(programA.getUid()) - .enrollmentUids(Set.of(enrollmentA.getUid())) + .programUid(UID.of(programA)) + .enrollmentUids(Set.of(UID.of(enrollmentA))) .orgUnitMode(ACCESSIBLE) .build(); @@ -531,9 +535,9 @@ void shouldGetEnrollmentsByTrackedEntityWhenUserHasAccessToTrackedEntityType() EnrollmentOperationParams params = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(trackedEntityA.getOrganisationUnit().getUid())) + .orgUnitUids(Set.of(UID.of(trackedEntityA.getOrganisationUnit()))) .orgUnitMode(SELECTED) - .trackedEntityUid(trackedEntityA.getUid()) + .trackedEntityUid(UID.of(trackedEntityA)) .build(); List enrollments = enrollmentService.getEnrollments(params); @@ -549,7 +553,7 @@ void shouldReturnEnrollmentIfEnrollmentWasUpdatedBeforePassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) .lastUpdated(oneHourBeforeLastUpdated) .build(); @@ -566,7 +570,7 @@ void shouldReturnEmptyIfEnrollmentWasUpdatedAfterPassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) .lastUpdated(oneHourAfterLastUpdated) .build(); @@ -584,9 +588,9 @@ void shouldReturnEnrollmentIfEnrollmentStartedBeforePassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .programStartDate(oneHourBeforeEnrollmentDate) .build(); @@ -603,9 +607,9 @@ void shouldReturnEmptyIfEnrollmentStartedAfterPassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .programStartDate(oneHourAfterEnrollmentDate) .build(); @@ -622,9 +626,9 @@ void shouldReturnEnrollmentIfEnrollmentEndedAfterPassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .programEndDate(oneHourAfterEnrollmentDate) .build(); @@ -641,9 +645,9 @@ void shouldReturnEmptyIfEnrollmentEndedBeforePassedDateAndTime() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(SELECTED) - .programUid(programA.getUid()) + .programUid(UID.of(programA)) .programEndDate(oneHourBeforeEnrollmentDate) .build(); @@ -685,7 +689,7 @@ void shouldFailWhenUserCanSearchEverywhereModeDescendantsAndOrgUnitNotInSearchSc EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() .orgUnitMode(DESCENDANTS) - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .build(); ForbiddenException exception = @@ -715,7 +719,7 @@ void shouldReturnAllDescendantsOfSelectedOrgUnitWhenOrgUnitModeDescendants() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(DESCENDANTS) .build(); @@ -731,7 +735,7 @@ void shouldReturnChildrenOfRootOrgUnitWhenOrgUnitModeChildren() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitA))) .orgUnitMode(CHILDREN) .build(); @@ -745,7 +749,7 @@ void shouldReturnChildrenOfRequestedOrgUnitWhenOrgUnitModeChildren() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitChildA.getUid())) + .orgUnitUids(Set.of(UID.of(orgUnitChildA))) .orgUnitMode(CHILDREN) .build(); @@ -761,7 +765,7 @@ void shouldReturnChildrenOfRequestedOrgUnitWhenOrgUnitModeChildren() EnrollmentOperationParams operationParams = EnrollmentOperationParams.builder() - .orgUnitUids(Set.of(orgUnitA.getUid(), orgUnitChildA.getUid())) + .orgUnitUids(UID.of(orgUnitA, orgUnitChildA)) .orgUnitMode(CHILDREN) .build(); @@ -781,9 +785,7 @@ void shouldFailWhenRequestingListOfEnrollmentsAndAtLeastOneNotAccessible() { ForbiddenException exception = assertThrows( ForbiddenException.class, - () -> - enrollmentService.getEnrollments( - List.of(enrollmentA.getUid(), enrollmentB.getUid()))); + () -> enrollmentService.getEnrollments(UID.of(enrollmentA, enrollmentB))); assertContains( String.format("User has no data read access to program: %s", programA.getUid()), exception.getMessage()); @@ -799,12 +801,12 @@ void shouldNotDeleteNoteWhenDeletingEnrollment() throws ForbiddenException, NotF manager.save(enrollmentA); - assertNotNull(enrollmentService.getEnrollment(enrollmentA.getUid())); + assertNotNull(enrollmentService.getEnrollment(UID.of(enrollmentA))); manager.delete(enrollmentA); assertThrows( - NotFoundException.class, () -> enrollmentService.getEnrollment(enrollmentA.getUid())); + NotFoundException.class, () -> enrollmentService.getEnrollment(UID.of(enrollmentA))); assertTrue(manager.exists(Note.class, note.getUid())); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java index d480eb03f15e..5cb54c6b1411 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java @@ -41,6 +41,7 @@ import org.hisp.dhis.common.AccessLevel; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -244,7 +245,7 @@ void shouldNotReturnRelationshipByTrackedEntityIfUserHasNoAccessToTrackedEntityT relationship(teA, inaccessibleTe, teToInaccessibleTeType); RelationshipOperationParams operationParams = - RelationshipOperationParams.builder().type(TRACKED_ENTITY).identifier(teA.getUid()).build(); + RelationshipOperationParams.builder().type(TRACKED_ENTITY).identifier(UID.of(teA)).build(); List relationships = relationshipService.getRelationships(operationParams); @@ -262,7 +263,7 @@ void shouldNotReturnRelationshipByEnrollmentIfUserHasNoAccessToRelationshipType( RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(ENROLLMENT) - .identifier(enrollmentA.getUid()) + .identifier(UID.of(enrollmentA)) .build(); List relationships = relationshipService.getRelationships(operationParams); @@ -279,7 +280,7 @@ void shouldNotReturnRelationshipByEventIfUserHasNoAccessToProgramStage() relationship(eventA, inaccessibleEvent); RelationshipOperationParams operationParams = - RelationshipOperationParams.builder().type(EVENT).identifier(eventA.getUid()).build(); + RelationshipOperationParams.builder().type(EVENT).identifier(UID.of(eventA)).build(); List relationships = relationshipService.getRelationships(operationParams); @@ -324,7 +325,7 @@ void shouldNotReturnRelationshipWhenTeIsTransferredAndUserHasNoAccessToAtLeastOn RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(TRACKED_ENTITY) - .identifier(trackedEntityFrom.getUid()) + .identifier(UID.of(trackedEntityFrom)) .build(); assertThrows( @@ -361,7 +362,7 @@ void shouldExcludeRelationshipWhenProgramIsProtectedAndUserHasNoAccess() RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(TRACKED_ENTITY) - .identifier(trackedEntityFrom.getUid()) + .identifier(UID.of(trackedEntityFrom)) .build(); List relationships = relationshipService.getRelationships(operationParams); @@ -402,7 +403,7 @@ void shouldNotReturnRelationshipWhenUserHasNoMetadataAccessToProgram() { RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(TRACKED_ENTITY) - .identifier(trackedEntityFrom.getUid()) + .identifier(UID.of(trackedEntityFrom)) .build(); assertThrows( @@ -441,7 +442,7 @@ void shouldNotReturnRelationshipWhenUserHasNoDataReadAccessToProgram() { RelationshipOperationParams operationParams = RelationshipOperationParams.builder() .type(TRACKED_ENTITY) - .identifier(trackedEntityFrom.getUid()) + .identifier(UID.of(trackedEntityFrom)) .build(); assertThrows( diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EnrollmentImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EnrollmentImportTest.java index def546289b75..ac1115bc31c3 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EnrollmentImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EnrollmentImportTest.java @@ -37,6 +37,7 @@ import java.io.IOException; import java.util.stream.Stream; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.program.Enrollment; @@ -82,7 +83,7 @@ void shouldCorrectlyPopulateCompletedDataWhenCreatingAnEnrollment(EnrollmentStat assertNoErrors(importReport); Enrollment enrollment = - enrollmentService.getEnrollment(trackerObjects.getEnrollments().get(0).getUid()); + enrollmentService.getEnrollment(UID.of(trackerObjects.getEnrollments().get(0).getUid())); assertEnrollmentCompletedData(enrollment); } @@ -106,7 +107,7 @@ void shouldCorrectlyPopulateCompletedDataWhenUpdatingAnEnrollment( assertNoErrors(importReport); Enrollment enrollment = - enrollmentService.getEnrollment(trackerObjects.getEnrollments().get(0).getUid()); + enrollmentService.getEnrollment(UID.of(trackerObjects.getEnrollments().get(0).getUid())); assertEnrollmentCompletedData(enrollment); } diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java index 91e5218b4069..2d6ec969f4b8 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEnrollmentSMSTest.java @@ -48,6 +48,7 @@ import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.feedback.BadRequestException; @@ -227,8 +228,8 @@ void shouldCreateTrackedEntityAndEnrollIt() submission.setTrackerProgram(trackerProgram.getUid()); submission.setTrackedEntityInstance(CodeGenerator.generateUid()); submission.setTrackedEntityType(trackedEntityType.getUid()); - String enrollmentUid = CodeGenerator.generateUid(); - submission.setEnrollment(enrollmentUid); + UID enrollmentUid = UID.of(CodeGenerator.generateUid()); + submission.setEnrollment(enrollmentUid.getValue()); submission.setEnrollmentDate(DateUtils.getDate(2024, 9, 2, 10, 15)); submission.setIncidentDate(DateUtils.getDate(2024, 9, 3, 16, 23)); submission.setEnrollmentStatus(SmsEnrollmentStatus.COMPLETED); @@ -261,7 +262,7 @@ void shouldCreateTrackedEntityAndEnrollIt() Enrollment actual = enrollmentService.getEnrollment(enrollmentUid); assertAll( "created enrollment", - () -> assertEquals(enrollmentUid, actual.getUid()), + () -> assertEquals(enrollmentUid.getValue(), actual.getUid()), () -> assertEqualUids(submission.getTrackedEntityInstance(), actual.getTrackedEntity())); assertDoesNotThrow( () -> @@ -359,7 +360,7 @@ void shouldEnrollExistingTrackedEntityAndAddUpdateAndDeleteAttributes() assertSmsResponse(submissionId + ":" + SmsResponse.SUCCESS, originator, messageSender)); Enrollment actual = enrollmentService.getEnrollment( - enrollment.getUid(), EnrollmentParams.FALSE.withIncludeAttributes(true), false); + UID.of(enrollment), EnrollmentParams.FALSE.withIncludeAttributes(true), false); assertAll( "update enrollment and program attributes", () -> assertEqualUids(submission.getTrackedEntityInstance(), actual.getTrackedEntity())); @@ -438,7 +439,7 @@ void shouldCreateTrackedEntityAndEnrollItViaTrackedEntityRegistrationParserComma List enrollments = enrollmentService.getEnrollments( EnrollmentOperationParams.builder() - .programUid(trackerProgram.getUid()) + .programUid(UID.of(trackerProgram)) .orgUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE) .build()); assertHasSize(1, enrollments); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java index 5ddeb74dda99..9bc5009ed32f 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerEventSMSTest.java @@ -714,8 +714,8 @@ void shouldCreateEventAndEnrollmentInTrackerProgramViaProgramStageDataEntryComma List enrollments = enrollmentService.getEnrollments( EnrollmentOperationParams.builder() - .trackedEntityUid(trackedEntity.getUid()) - .programUid(trackerProgram.getUid()) + .trackedEntityUid(UID.of(trackedEntity)) + .programUid(UID.of(trackerProgram)) .orgUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE) .build()); assertHasSize(1, enrollments); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/notification/ProgramNotificationInstanceController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/notification/ProgramNotificationInstanceController.java index cdd60d9620d7..6ade1035c43c 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/notification/ProgramNotificationInstanceController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/notification/ProgramNotificationInstanceController.java @@ -114,7 +114,7 @@ public ProgramNotificationInstanceController( Enrollment storedEnrollment = null; if (enrollmentUid != null) { storedEnrollment = - enrollmentService.getEnrollment(enrollmentUid.getValue(), EnrollmentParams.FALSE, false); + enrollmentService.getEnrollment(enrollmentUid, EnrollmentParams.FALSE, false); } ProgramNotificationInstanceParam params = ProgramNotificationInstanceParam.builder() diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapper.java index 4395b66555f4..467df7add1d7 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapper.java @@ -98,7 +98,7 @@ public EnrollmentOperationParams map(EnrollmentRequestParams enrollmentRequestPa EnrollmentOperationParamsBuilder builder = EnrollmentOperationParams.builder() - .programUid(applyIfNotNull(enrollmentRequestParams.getProgram(), UID::getValue)) + .programUid(enrollmentRequestParams.getProgram()) .enrollmentStatus(enrollmentStatus) .followUp(enrollmentRequestParams.getFollowUp()) .lastUpdated( @@ -108,14 +108,12 @@ public EnrollmentOperationParams map(EnrollmentRequestParams enrollmentRequestPa applyIfNotNull(enrollmentRequestParams.getEnrolledAfter(), StartDateTime::toDate)) .programEndDate( applyIfNotNull(enrollmentRequestParams.getEnrolledBefore(), EndDateTime::toDate)) - .trackedEntityTypeUid( - applyIfNotNull(enrollmentRequestParams.getTrackedEntityType(), UID::getValue)) - .trackedEntityUid( - applyIfNotNull(enrollmentRequestParams.getTrackedEntity(), UID::getValue)) - .orgUnitUids(UID.toValueSet(orgUnits)) + .trackedEntityTypeUid(enrollmentRequestParams.getTrackedEntityType()) + .trackedEntityUid(enrollmentRequestParams.getTrackedEntity()) + .orgUnitUids(orgUnits) .orgUnitMode(orgUnitMode) .includeDeleted(enrollmentRequestParams.isIncludeDeleted()) - .enrollmentUids(UID.toValueSet(enrollmentUids)) + .enrollmentUids(enrollmentUids) .enrollmentParams(fieldsParamMapper.map(enrollmentRequestParams.getFields())); mapOrderParam(builder, enrollmentRequestParams.getOrder()); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportController.java index 04a3bddfa2bf..b71f5b873d1f 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentsExportController.java @@ -142,8 +142,7 @@ public ResponseEntity getEnrollmentByUid( throws NotFoundException, ForbiddenException { EnrollmentParams enrollmentParams = fieldsMapper.map(fields); Enrollment enrollment = - ENROLLMENT_MAPPER.from( - enrollmentService.getEnrollment(uid.getValue(), enrollmentParams, false)); + ENROLLMENT_MAPPER.from(enrollmentService.getEnrollment(uid, enrollmentParams, false)); return ResponseEntity.ok(fieldFilterService.toObjectNode(enrollment, fields)); } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java index 6e9a6d50eb10..22794a800da3 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java @@ -95,10 +95,9 @@ public RelationshipOperationParams map(RelationshipRequestParams relationshipReq relationshipRequestParams.getEvent())) .identifier( ObjectUtils.firstNonNull( - trackedEntity, - relationshipRequestParams.getEnrollment(), - relationshipRequestParams.getEvent()) - .getValue()); + trackedEntity, + relationshipRequestParams.getEnrollment(), + relationshipRequestParams.getEvent())); mapOrderParam(builder, relationshipRequestParams.getOrder()); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapperTest.java index 24dfb6883fbf..71e774d4e979 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentRequestParamsMapperTest.java @@ -68,15 +68,15 @@ @ExtendWith(MockitoExtension.class) class EnrollmentRequestParamsMapperTest { - private static final String ORG_UNIT_1_UID = "lW0T2U7gZUi"; + private static final UID ORG_UNIT_1_UID = UID.of("lW0T2U7gZUi"); - private static final String ORG_UNIT_2_UID = "TK4KA0IIWqa"; + private static final UID ORG_UNIT_2_UID = UID.of("TK4KA0IIWqa"); - private static final String PROGRAM_UID = "XhBYIraw7sv"; + private static final UID PROGRAM_UID = UID.of("XhBYIraw7sv"); - private static final String TRACKED_ENTITY_TYPE_UID = "Dp8baZYrLtr"; + private static final UID TRACKED_ENTITY_TYPE_UID = UID.of("Dp8baZYrLtr"); - private static final String TRACKED_ENTITY_UID = "DGbr8GHG4li"; + private static final UID TRACKED_ENTITY_UID = UID.of("DGbr8GHG4li"); @Mock private EnrollmentFieldsParamMapper fieldsParamMapper; @@ -99,8 +99,8 @@ void testMappingDoesNotFetchOptionalEmptyQueryParametersFromDB() throws BadReque @Test void testMappingOrgUnit() throws BadRequestException { EnrollmentRequestParams enrollmentRequestParams = new EnrollmentRequestParams(); - enrollmentRequestParams.setOrgUnit(ORG_UNIT_1_UID + ";" + ORG_UNIT_2_UID); - enrollmentRequestParams.setProgram(UID.of(PROGRAM_UID)); + enrollmentRequestParams.setOrgUnit(ORG_UNIT_1_UID.getValue() + ";" + ORG_UNIT_2_UID.getValue()); + enrollmentRequestParams.setProgram(PROGRAM_UID); EnrollmentOperationParams params = mapper.map(enrollmentRequestParams); @@ -110,8 +110,8 @@ void testMappingOrgUnit() throws BadRequestException { @Test void testMappingOrgUnits() throws BadRequestException { EnrollmentRequestParams enrollmentRequestParams = new EnrollmentRequestParams(); - enrollmentRequestParams.setOrgUnits(Set.of(UID.of(ORG_UNIT_1_UID), UID.of(ORG_UNIT_2_UID))); - enrollmentRequestParams.setProgram(UID.of(PROGRAM_UID)); + enrollmentRequestParams.setOrgUnits(Set.of(ORG_UNIT_1_UID, ORG_UNIT_2_UID)); + enrollmentRequestParams.setProgram(PROGRAM_UID); EnrollmentOperationParams params = mapper.map(enrollmentRequestParams); @@ -165,7 +165,7 @@ void shouldFailIfDeprecatedAndNewStatusParameterIsSet() { @Test void testMappingProgram() throws BadRequestException { EnrollmentRequestParams enrollmentRequestParams = new EnrollmentRequestParams(); - enrollmentRequestParams.setProgram(UID.of(PROGRAM_UID)); + enrollmentRequestParams.setProgram(PROGRAM_UID); EnrollmentOperationParams params = mapper.map(enrollmentRequestParams); @@ -175,7 +175,7 @@ void testMappingProgram() throws BadRequestException { @Test void testMappingTrackedEntityType() throws BadRequestException { EnrollmentRequestParams enrollmentRequestParams = new EnrollmentRequestParams(); - enrollmentRequestParams.setTrackedEntityType(UID.of(TRACKED_ENTITY_TYPE_UID)); + enrollmentRequestParams.setTrackedEntityType(TRACKED_ENTITY_TYPE_UID); EnrollmentOperationParams params = mapper.map(enrollmentRequestParams); @@ -185,7 +185,7 @@ void testMappingTrackedEntityType() throws BadRequestException { @Test void testMappingTrackedEntity() throws BadRequestException { EnrollmentRequestParams enrollmentRequestParams = new EnrollmentRequestParams(); - enrollmentRequestParams.setTrackedEntity(UID.of(TRACKED_ENTITY_UID)); + enrollmentRequestParams.setTrackedEntity(TRACKED_ENTITY_UID); EnrollmentOperationParams params = mapper.map(enrollmentRequestParams); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapperTest.java index 2cbc11189111..05485020273f 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapperTest.java @@ -137,7 +137,7 @@ void shouldMapCorrectIdentifierWhenTrackedEntityIsSet() throws BadRequestExcepti RelationshipOperationParams operationParams = mapper.map(relationshipRequestParams); - assertEquals("Hq3Kc6HK4OZ", operationParams.getIdentifier()); + assertEquals(UID.of("Hq3Kc6HK4OZ"), operationParams.getIdentifier()); } @Test @@ -157,7 +157,7 @@ void shouldMapCorrectIdentifierWhenEnrollmentIsSet() throws BadRequestException RelationshipOperationParams operationParams = mapper.map(relationshipRequestParams); - assertEquals("Hq3Kc6HK4OZ", operationParams.getIdentifier()); + assertEquals(UID.of("Hq3Kc6HK4OZ"), operationParams.getIdentifier()); } @Test @@ -177,7 +177,7 @@ void shouldMapCorrectIdentifierWhenEventIsSet() throws BadRequestException { RelationshipOperationParams operationParams = mapper.map(relationshipRequestParams); - assertEquals("Hq3Kc6HK4OZ", operationParams.getIdentifier()); + assertEquals(UID.of("Hq3Kc6HK4OZ"), operationParams.getIdentifier()); } @Test