diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DefaultDeduplicationService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DefaultDeduplicationService.java index cae1da224de1..2d494c1a6a08 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DefaultDeduplicationService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/deduplication/DefaultDeduplicationService.java @@ -175,7 +175,7 @@ private void merge(DeduplicationMergeParams params) potentialDuplicateStore.moveRelationships(original, duplicate, mergeObject.getRelationships()); potentialDuplicateStore.moveEnrollments(original, duplicate, mergeObject.getEnrollments()); try { - trackerObjectDeletionService.deleteTrackedEntities(List.of(duplicate.getUid())); + trackerObjectDeletionService.deleteTrackedEntities(List.of(UID.of(duplicate))); } catch (NotFoundException e) { throw new RuntimeException("Could not find TrackedEntity: " + duplicate.getUid()); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java index 1ea39b946112..2e14d03817b7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java @@ -37,6 +37,7 @@ import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; @@ -199,4 +200,13 @@ private void addIdentifier( identifiers.computeIfAbsent(klass, k -> new HashSet<>()).add(identifier); } + + private void addIdentifier( + Map, Set> identifiers, Class klass, UID identifier) { + if (identifier == null || identifiers == null || klass == null) { + return; + } + + identifiers.computeIfAbsent(klass, k -> new HashSet<>()).add(identifier.getValue()); + } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundle.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundle.java index 1c41e5a9e85a..147f7ac9e6ed 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundle.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundle.java @@ -38,6 +38,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import javax.annotation.Nonnull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -147,8 +148,8 @@ public Optional findEnrollmentByUid(String uid) { return findById(this.enrollments, uid); } - public Optional findEventByUid(String uid) { - return findById(this.events, uid); + public Optional findEventByUid(@Nonnull UID uid) { + return findById(this.events, uid.getValue()); } public Optional findRelationshipByUid(String uid) { @@ -156,7 +157,7 @@ public Optional findRelationshipByUid(String uid) { } private static Optional findById(List entities, String uid) { - return entities.stream().filter(e -> Objects.equals(e.getUid(), uid)).findFirst(); + return entities.stream().filter(e -> Objects.equals(e.getStringUid(), uid)).findFirst(); } public Map> getEnrollmentNotifications() { @@ -168,11 +169,13 @@ public Map> getEventNotifications() { } public TrackerImportStrategy setStrategy(TrackerDto dto, TrackerImportStrategy strategy) { - return this.getResolvedStrategyMap().get(dto.getTrackerType()).put(dto.getUid(), strategy); + return this.getResolvedStrategyMap() + .get(dto.getTrackerType()) + .put(dto.getStringUid(), strategy); } public TrackerImportStrategy getStrategy(TrackerDto dto) { - return getResolvedStrategyMap().get(dto.getTrackerType()).get(dto.getUid()); + return getResolvedStrategyMap().get(dto.getTrackerType()).get(dto.getStringUid()); } @SuppressWarnings("unchecked") @@ -190,27 +193,4 @@ public List get(Class type) { // only reached if a new TrackerDto implementation is added throw new IllegalStateException("TrackerType " + type.getName() + " not yet supported."); } - - /** Checks if an entity exists in the payload. */ - public boolean exists(T entity) { - return exists(entity.getTrackerType(), entity.getUid()); - } - - /** - * Checks if an entity of given type and UID exists in the payload. - * - * @param type tracker type - * @param uid uid of entity to check - * @return true if an entity of given type and UID exists in the payload - */ - public boolean exists(TrackerType type, String uid) { - Objects.requireNonNull(type); - - return switch (type) { - case TRACKED_ENTITY -> findTrackedEntityByUid(uid).isPresent(); - case ENROLLMENT -> findEnrollmentByUid(uid).isPresent(); - case EVENT -> findEventByUid(uid).isPresent(); - case RELATIONSHIP -> findRelationshipByUid(uid).isPresent(); - }; - } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java index b446ed92da7e..7a096efc5f86 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java @@ -34,6 +34,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.hisp.dhis.category.CategoryOptionCombo; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.note.Note; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -182,7 +183,7 @@ private TrackerObjectsMapper() { if (dbEvent == null) { dbEvent = new Event(); - dbEvent.setUid(event.getEvent()); + dbEvent.setUid(event.getEvent().getValue()); dbEvent.setCreated(now); dbEvent.setStoredBy(event.getStoredBy()); dbEvent.setCreatedByUserInfo(UserInfoSnapshot.from(user)); @@ -276,7 +277,7 @@ private TrackerObjectsMapper() { case PROGRAM_INSTANCE -> fromItem.setEnrollment(preheat.getEnrollment(relationship.getFrom().getEnrollment())); case PROGRAM_STAGE_INSTANCE -> - fromItem.setEvent(preheat.getEvent(relationship.getFrom().getEvent())); + fromItem.setEvent(preheat.getEvent(UID.of(relationship.getFrom().getEvent()))); } dbRelationship.setFrom(fromItem); @@ -290,7 +291,7 @@ private TrackerObjectsMapper() { case PROGRAM_INSTANCE -> toItem.setEnrollment(preheat.getEnrollment(relationship.getTo().getEnrollment())); case PROGRAM_STAGE_INSTANCE -> - toItem.setEvent(preheat.getEvent(relationship.getTo().getEvent())); + toItem.setEvent(preheat.getEvent(UID.of(relationship.getTo().getEvent()))); } dbRelationship.setTo(toItem); @@ -319,10 +320,9 @@ private TrackerObjectsMapper() { return dbNote; } - private static Enrollment getEnrollment( - TrackerPreheat preheat, String enrollment, Program program) { + private static Enrollment getEnrollment(TrackerPreheat preheat, UID enrollment, Program program) { return switch (program.getProgramType()) { - case WITH_REGISTRATION -> preheat.getEnrollment(enrollment); + case WITH_REGISTRATION -> preheat.getEnrollment(enrollment.getValue()); case WITHOUT_REGISTRATION -> preheat.getEnrollmentsWithoutRegistration(program.getUid()); }; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java index c5618e757319..8c7c7b0ddd39 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java @@ -107,7 +107,7 @@ public TrackerTypeReport persist(EntityManager entityManager, TrackerBundle bund for (T trackerDto : dtos) { - Entity objectReport = new Entity(getType(), trackerDto.getUid()); + Entity objectReport = new Entity(getType(), trackerDto.getStringUid()); List triggers = determineNotificationTriggers(bundle.getPreheat(), trackerDto); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java index 64eb462ed012..52986b7fe7a8 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java @@ -37,6 +37,7 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; @@ -79,46 +80,17 @@ public class DefaultTrackerObjectsDeletionService implements TrackerObjectDeleti private final ProgramNotificationInstanceService programNotificationInstanceService; @Override - public TrackerTypeReport deleteEnrollments(List enrollments) throws NotFoundException { - UserInfoSnapshot userInfoSnapshot = UserInfoSnapshot.from(getCurrentUserDetails()); - TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.ENROLLMENT); + public TrackerTypeReport deleteRelationships(List relationships) throws NotFoundException { + TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.RELATIONSHIP); - for (String uid : enrollments) { - Entity objectReport = new Entity(TrackerType.ENROLLMENT, uid); + for (UID uid : relationships) { + Entity objectReport = new Entity(TrackerType.RELATIONSHIP, uid.getValue()); - Enrollment enrollment = manager.get(Enrollment.class, uid); - if (enrollment == null) { - throw new NotFoundException(Enrollment.class, uid); + Relationship relationship = manager.get(Relationship.class, uid.getValue()); + if (relationship == null) { + throw new NotFoundException(Relationship.class, uid); } - enrollment.setLastUpdatedByUserInfo(userInfoSnapshot); - - List events = - enrollment.getEvents().stream() - .filter(event -> !event.isDeleted()) - .map(BaseIdentifiableObject::getUid) - .toList(); - deleteEvents(events); - - RelationshipQueryParams params = RelationshipQueryParams.builder().entity(enrollment).build(); - List relationships = - relationshipStore.getByEnrollment(enrollment, params).stream() - .map(BaseIdentifiableObject::getUid) - .toList(); - - deleteRelationships(relationships); - - List notificationInstances = - programNotificationInstanceService.getProgramNotificationInstances( - ProgramNotificationInstanceParam.builder().enrollment(enrollment).build()); - - notificationInstances.forEach(programNotificationInstanceService::delete); - - TrackedEntity te = enrollment.getTrackedEntity(); - te.setLastUpdatedByUserInfo(userInfoSnapshot); - - manager.delete(enrollment); - - manager.update(te); + manager.delete(relationship); typeReport.getStats().incDeleted(); typeReport.addEntity(objectReport); @@ -128,19 +100,20 @@ public TrackerTypeReport deleteEnrollments(List enrollments) throws NotF } @Override - public TrackerTypeReport deleteEvents(List events) throws NotFoundException { + public TrackerTypeReport deleteEvents(List events) throws NotFoundException { UserInfoSnapshot userInfoSnapshot = UserInfoSnapshot.from(getCurrentUserDetails()); TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.EVENT); - for (String uid : events) { - Entity objectReport = new Entity(TrackerType.EVENT, uid); + for (UID uid : events) { + Entity objectReport = new Entity(TrackerType.EVENT, uid.getValue()); - Event event = manager.get(Event.class, uid); + Event event = manager.get(Event.class, uid.getValue()); event.setLastUpdatedByUserInfo(userInfoSnapshot); RelationshipQueryParams params = RelationshipQueryParams.builder().entity(event).build(); - List relationships = + List relationships = relationshipStore.getByEvent(event, params).stream() .map(BaseIdentifiableObject::getUid) + .map(UID::of) .toList(); deleteRelationships(relationships); @@ -177,15 +150,66 @@ public TrackerTypeReport deleteEvents(List events) throws NotFoundExcept } @Override - public TrackerTypeReport deleteTrackedEntities(List trackedEntities) + public TrackerTypeReport deleteEnrollments(List enrollments) throws NotFoundException { + UserInfoSnapshot userInfoSnapshot = UserInfoSnapshot.from(getCurrentUserDetails()); + TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.ENROLLMENT); + + for (UID uid : enrollments) { + Entity objectReport = new Entity(TrackerType.ENROLLMENT, uid.getValue()); + + Enrollment enrollment = manager.get(Enrollment.class, uid.getValue()); + if (enrollment == null) { + throw new NotFoundException(Enrollment.class, uid); + } + enrollment.setLastUpdatedByUserInfo(userInfoSnapshot); + + List events = + enrollment.getEvents().stream() + .filter(event -> !event.isDeleted()) + .map(BaseIdentifiableObject::getUid) + .map(UID::of) + .toList(); + deleteEvents(events); + + RelationshipQueryParams params = RelationshipQueryParams.builder().entity(enrollment).build(); + List relationships = + relationshipStore.getByEnrollment(enrollment, params).stream() + .map(BaseIdentifiableObject::getUid) + .map(UID::of) + .toList(); + + deleteRelationships(relationships); + + List notificationInstances = + programNotificationInstanceService.getProgramNotificationInstances( + ProgramNotificationInstanceParam.builder().enrollment(enrollment).build()); + + notificationInstances.forEach(programNotificationInstanceService::delete); + + TrackedEntity te = enrollment.getTrackedEntity(); + te.setLastUpdatedByUserInfo(userInfoSnapshot); + + manager.delete(enrollment); + + manager.update(te); + + typeReport.getStats().incDeleted(); + typeReport.addEntity(objectReport); + } + + return typeReport; + } + + @Override + public TrackerTypeReport deleteTrackedEntities(List trackedEntities) throws NotFoundException { UserInfoSnapshot userInfoSnapshot = UserInfoSnapshot.from(getCurrentUserDetails()); TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.TRACKED_ENTITY); - for (String uid : trackedEntities) { - Entity objectReport = new Entity(TrackerType.TRACKED_ENTITY, uid); + for (UID uid : trackedEntities) { + Entity objectReport = new Entity(TrackerType.TRACKED_ENTITY, uid.getValue()); - TrackedEntity entity = manager.get(TrackedEntity.class, uid); + TrackedEntity entity = manager.get(TrackedEntity.class, uid.getValue()); if (entity == null) { throw new NotFoundException(TrackedEntity.class, uid); } @@ -195,17 +219,19 @@ public TrackerTypeReport deleteTrackedEntities(List trackedEntities) Set daoEnrollments = entity.getEnrollments(); - List enrollments = + List enrollments = daoEnrollments.stream() .filter(enrollment -> !enrollment.isDeleted()) .map(BaseIdentifiableObject::getUid) + .map(UID::of) .toList(); deleteEnrollments(enrollments); RelationshipQueryParams params = RelationshipQueryParams.builder().entity(entity).build(); - List relationships = + List relationships = relationshipStore.getByTrackedEntity(entity, params).stream() .map(BaseIdentifiableObject::getUid) + .map(UID::of) .toList(); deleteRelationships(relationships); @@ -227,25 +253,4 @@ public TrackerTypeReport deleteTrackedEntities(List trackedEntities) return typeReport; } - - @Override - public TrackerTypeReport deleteRelationships(List relationships) - throws NotFoundException { - TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.RELATIONSHIP); - - for (String uid : relationships) { - Entity objectReport = new Entity(TrackerType.RELATIONSHIP, uid); - - Relationship relationship = manager.get(Relationship.class, uid); - if (relationship == null) { - throw new NotFoundException(Relationship.class, uid); - } - manager.delete(relationship); - - typeReport.getStats().incDeleted(); - typeReport.addEntity(objectReport); - } - - return typeReport; - } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java index 7f47bbe56030..81932369656a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java @@ -117,7 +117,7 @@ protected TrackerNotificationDataBundle handleNotifications( @Override protected List determineNotificationTriggers( TrackerPreheat preheat, org.hisp.dhis.tracker.imports.domain.Enrollment entity) { - Enrollment persistedEnrollment = preheat.getEnrollment(entity.getUid()); + Enrollment persistedEnrollment = preheat.getEnrollment(entity.getStringUid()); List triggers = new ArrayList<>(); if (persistedEnrollment == null) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java index 2b512f3db051..176b73adcd16 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java @@ -158,7 +158,7 @@ private void handleDataValues( Event event, UserDetails user) { Map dataValueDBMap = - Optional.ofNullable(preheat.getEvent(event.getUid())) + Optional.ofNullable(preheat.getEvent(UID.of(event))) .map( a -> a.getEventDataValues().stream() diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackerObjectDeletionService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackerObjectDeletionService.java index f1f73f7184f7..69b970b41987 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackerObjectDeletionService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackerObjectDeletionService.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.bundle.persister; import java.util.List; +import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.tracker.imports.report.TrackerTypeReport; @@ -35,11 +36,11 @@ * @author Zubair Asghar */ public interface TrackerObjectDeletionService { - TrackerTypeReport deleteTrackedEntities(List trackedEntities) throws NotFoundException; + TrackerTypeReport deleteTrackedEntities(List trackedEntities) throws NotFoundException; - TrackerTypeReport deleteEnrollments(List enrollments) throws NotFoundException; + TrackerTypeReport deleteEnrollments(List enrollments) throws NotFoundException; - TrackerTypeReport deleteEvents(List events) throws NotFoundException; + TrackerTypeReport deleteEvents(List events) throws NotFoundException; - TrackerTypeReport deleteRelationships(List relationships) throws NotFoundException; + TrackerTypeReport deleteRelationships(List relationships) throws NotFoundException; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java index 8af77cdcec24..59f3143c570c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java @@ -36,6 +36,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.EnrollmentStatus; import org.hisp.dhis.tracker.TrackerType; import org.locationtech.jts.geom.Geometry; @@ -79,8 +80,13 @@ public class Enrollment implements TrackerDto, Serializable { @JsonProperty @Builder.Default private List notes = new ArrayList<>(); @Override - public String getUid() { - return this.enrollment; + public UID getUid() { + return UID.of(enrollment); + } + + @Override + public String getStringUid() { + return enrollment; } @Override diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java index ca526d080edf..9950d28272a4 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java @@ -39,6 +39,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.tracker.TrackerType; import org.locationtech.jts.geom.Geometry; @@ -51,7 +52,7 @@ @NoArgsConstructor @AllArgsConstructor public class Event implements TrackerDto, Serializable { - @JsonProperty private String event; + @JsonProperty private UID event; @JsonProperty @Builder.Default private EventStatus status = EventStatus.ACTIVE; @@ -59,7 +60,7 @@ public class Event implements TrackerDto, Serializable { @JsonProperty private MetadataIdentifier programStage; - @JsonProperty private String enrollment; + @JsonProperty private UID enrollment; @JsonProperty private MetadataIdentifier orgUnit; @@ -96,10 +97,15 @@ public boolean isCreatableInSearchScope() { } @Override - public String getUid() { + public UID getUid() { return this.event; } + @Override + public String getStringUid() { + return event.getValue(); + } + @Override public TrackerType getTrackerType() { return TrackerType.EVENT; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java index 0b498be6a639..e1d8b0938e2f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java @@ -34,6 +34,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; /** @@ -55,7 +56,12 @@ public class Relationship implements TrackerDto, Serializable { @JsonProperty private RelationshipItem to; @Override - public String getUid() { + public UID getUid() { + return UID.of(relationship); + } + + @Override + public String getStringUid() { return relationship; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java index 1c16bdd93861..30b344bdb913 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java @@ -36,6 +36,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; import org.locationtech.jts.geom.Geometry; @@ -68,8 +69,13 @@ public class TrackedEntity implements TrackerDto, Serializable { @JsonProperty @Builder.Default private List attributes = new ArrayList<>(); @Override - public String getUid() { - return this.trackedEntity; + public UID getUid() { + return UID.of(trackedEntity); + } + + @Override + public String getStringUid() { + return trackedEntity; } @Override diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerDto.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerDto.java index 2c66e7b57c41..cadaafe938c9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerDto.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerDto.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.imports.domain; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; /** @@ -34,7 +35,9 @@ */ public interface TrackerDto { - String getUid(); + UID getUid(); + + String getStringUid(); TrackerType getTrackerType(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheat.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheat.java index 61765a2112ca..38ee74255908 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheat.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheat.java @@ -53,6 +53,7 @@ import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.hibernate.HibernateProxyUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -209,7 +210,7 @@ public MetadataIdentifier getCategoryOptionComboIdentifier( * Internal map of all preheated events, mainly used for confirming existence for updates, and * used for object merging. */ - @Getter private final Map events = new HashMap<>(); + @Getter private final Map events = new HashMap<>(); /** * Internal map of all preheated relationships, mainly used for confirming existence for updates, @@ -460,16 +461,16 @@ public void putEnrollment(String uid, Enrollment enrollment) { enrollments.put(uid, enrollment); } - public Event getEvent(String uid) { + public Event getEvent(UID uid) { return events.get(uid); } public void putEvents(List events) { - events.forEach(event -> putEvent(event.getUid(), event)); + events.forEach(this::putEvent); } - public void putEvent(String uid, Event event) { - events.put(uid, event); + public void putEvent(Event event) { + events.put(UID.of(event), event); } public void addNotes(Set notes) { @@ -490,7 +491,7 @@ public Relationship getRelationship(String relationshipUid) { public Relationship getRelationship( org.hisp.dhis.tracker.imports.domain.Relationship relationship) { - return relationships.get(relationship.getUid()); + return relationships.get(relationship.getStringUid()); } public boolean isDuplicate(org.hisp.dhis.tracker.imports.domain.Relationship relationship) { @@ -617,8 +618,7 @@ public TrackerPreheat addProgramStageWithEvents(String programStageUid, String e public boolean hasProgramStageWithEvents(MetadataIdentifier programStage, String enrollmentUid) { ProgramStage ps = this.getProgramStage(programStage); - Enrollment enrollment = this.getEnrollment(enrollmentUid); - return this.programStageWithEvents.contains(Pair.of(ps.getUid(), enrollment.getUid())); + return this.programStageWithEvents.contains(Pair.of(ps.getUid(), enrollmentUid)); } /** Checks if an entity exists in the DB. */ @@ -633,14 +633,14 @@ public boolean exists(T entity) { * @param uid uid of entity to check * @return true if an entity of given type and UID exists in the DB */ - public boolean exists(TrackerType type, String uid) { + public boolean exists(TrackerType type, UID uid) { Objects.requireNonNull(type); return switch (type) { - case TRACKED_ENTITY -> getTrackedEntity(uid) != null; - case ENROLLMENT -> getEnrollment(uid) != null; + case TRACKED_ENTITY -> getTrackedEntity(uid.getValue()) != null; + case ENROLLMENT -> getEnrollment(uid.getValue()) != null; case EVENT -> getEvent(uid) != null; - case RELATIONSHIP -> getRelationship(uid) != null; + case RELATIONSHIP -> getRelationship(uid.getValue()) != null; }; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java index 26d1727b9f38..352c0d30221b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Objects; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.TrackerObjects; @@ -88,7 +89,7 @@ public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { .distinct() .toList(); - List enrollmentUids = + List enrollmentUids = trackerObjects.getEvents().stream() .map(Event::getEnrollment) .filter(Objects::nonNull) @@ -98,7 +99,7 @@ public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { if (!notRepeatableProgramStageUids.isEmpty() && !enrollmentUids.isEmpty()) { MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("programStageUids", notRepeatableProgramStageUids); - parameters.addValue("enrollmentUids", enrollmentUids); + parameters.addValue("enrollmentUids", UID.toValueList(enrollmentUids)); jdbcTemplate.query( SQL, parameters, diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java index e651b799cd5c..25c58adc00f3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java @@ -33,6 +33,7 @@ import java.util.Set; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.trackedentity.TrackedEntity; @@ -55,7 +56,7 @@ public class ProgramOwnerSupplier extends AbstractPreheatSupplier { public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { final Map preheatedTrackedEntities = preheat.getTrackedEntities(); final Map preheatedEnrollments = preheat.getEnrollments(); - final Map preheatedEvents = preheat.getEvents(); + final Map preheatedEvents = preheat.getEvents(); Set teIds = new HashSet<>(); for (org.hisp.dhis.tracker.imports.domain.Enrollment en : trackerObjects.getEnrollments()) { Enrollment enrollment = preheatedEnrollments.get(en.getEnrollment()); @@ -72,7 +73,9 @@ public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { for (org.hisp.dhis.tracker.imports.domain.Event ev : trackerObjects.getEvents()) { Event event = preheatedEvents.get(ev.getEvent()); Enrollment enrollment = - event == null ? preheatedEnrollments.get(ev.getEnrollment()) : event.getEnrollment(); + event == null + ? preheatedEnrollments.get(ev.getEnrollment().getValue()) + : event.getEnrollment(); if (enrollment != null && enrollment.getTrackedEntity() != null) { teIds.add(enrollment.getTrackedEntity().getId()); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java index ae116c2925c0..c46426559519 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java @@ -221,7 +221,10 @@ private Collection buildUniqueAttributeValues( .map( te -> new UniqueAttributeValue( - te.getUid(), attribute.getAttribute(), attribute.getValue(), te.getOrgUnit())) + te.getStringUid(), + attribute.getAttribute(), + attribute.getValue(), + te.getOrgUnit())) .toList(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessor.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessor.java index d60d339b06fb..5f2ec45fce07 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessor.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessor.java @@ -29,6 +29,7 @@ import static java.util.Objects.nonNull; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; @@ -86,7 +87,7 @@ private void setEnrollment(TrackerBundle bundle, String uid, Event event) { Enrollment enrollment = bundle.getPreheat().getEnrollmentsWithoutRegistration(uid); if (enrollment != null) { - event.setEnrollment(enrollment.getUid()); + event.setEnrollment(UID.of(enrollment)); } } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessor.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessor.java index 26c6fc053d12..a8a223cb709d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessor.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessor.java @@ -108,7 +108,7 @@ public void preProcessRelationships(TrackerBundle bundle) { for (Relationship relationship : bundle.getRelationships()) { TrackerImportStrategy importStrategy = bundle.getImportStrategy(); org.hisp.dhis.relationship.Relationship existingRelationship = - bundle.getPreheat().getRelationship(relationship.getUid()); + bundle.getPreheat().getRelationship(relationship.getStringUid()); if (importStrategy.isCreateAndUpdate()) { if (existingRelationship == null) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/DefaultProgramRuleService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/DefaultProgramRuleService.java index 7bc293cd33c3..b98b4403f5ff 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/DefaultProgramRuleService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/DefaultProgramRuleService.java @@ -112,7 +112,7 @@ private RuleEngineEffects calculateEnrollmentRuleEffects( return programRuleEngine.evaluateEnrollmentAndEvents( enrollment, - getEventsFromEnrollment(enrollment.getEnrollment(), bundle, preheat), + getEventsFromEnrollment(e.getUid(), bundle, preheat), preheat.getProgram(e.getProgram()), bundle.getUser()); }) @@ -124,9 +124,9 @@ private RuleEngineEffects calculateTrackerEventRuleEffects( TrackerBundle bundle, TrackerPreheat preheat) { Set enrollments = bundle.getEvents().stream() - .filter(event -> bundle.findEnrollmentByUid(event.getEnrollment()).isEmpty()) + .filter(event -> bundle.findEnrollmentByUid(event.getEnrollment().getValue()).isEmpty()) .filter(event -> preheat.getProgram(event.getProgram()).isRegistration()) - .map(event -> preheat.getEnrollment(event.getEnrollment())) + .map(event -> preheat.getEnrollment(event.getEnrollment().getValue())) .collect(Collectors.toSet()); return enrollments.stream() @@ -137,7 +137,7 @@ private RuleEngineEffects calculateTrackerEventRuleEffects( RuleEnrollment enrollment = RuleEngineMapper.mapSavedEnrollment(e, attributes); return programRuleEngine.evaluateEnrollmentAndEvents( enrollment, - getEventsFromEnrollment(e.getUid(), bundle, preheat), + getEventsFromEnrollment(UID.of(e), bundle, preheat), e.getProgram(), bundle.getUser()); }) @@ -203,7 +203,7 @@ private List getAttributes( // Get all the events linked to enrollment from the payload and the DB, // using the one from payload if they are present in both places private List getEventsFromEnrollment( - String enrollmentUid, TrackerBundle bundle, TrackerPreheat preheat) { + UID enrollmentUid, TrackerBundle bundle, TrackerPreheat preheat) { Stream events; try { events = @@ -212,10 +212,10 @@ private List getEventsFromEnrollment( EventOperationParams.builder() .eventParams(EventParams.TRUE) .orgUnitMode(ACCESSIBLE) - .enrollments(Set.of(UID.of(enrollmentUid))) + .enrollments(Set.of(enrollmentUid)) .build()) .stream() - .filter(e -> bundle.findEventByUid(e.getUid()).isEmpty()); + .filter(e -> bundle.findEventByUid(UID.of(e)).isEmpty()); } catch (BadRequestException | ForbiddenException e) { throw new RuntimeException(e); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleActionEventMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleActionEventMapper.java index 05684a115803..25985b8ed6fe 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleActionEventMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleActionEventMapper.java @@ -60,15 +60,13 @@ class RuleActionEventMapper { public Map>> mapRuleEffects( Map> eventValidationEffects, TrackerBundle bundle) { return eventValidationEffects.keySet().stream() - .filter(e -> bundle.findEventByUid(e.getValue()).isPresent()) + .filter(e -> bundle.findEventByUid(e).isPresent()) .collect( Collectors.toMap( - e -> bundle.findEventByUid(e.getValue()).get(), + e -> bundle.findEventByUid(e).get(), e -> mapRuleEffects( - bundle.findEventByUid(e.getValue()).get(), - eventValidationEffects.get(e), - bundle))); + bundle.findEventByUid(e).get(), eventValidationEffects.get(e), bundle))); } private List> mapRuleEffects( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapper.java index 31f9d2990f90..208c391c769a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapper.java @@ -68,7 +68,7 @@ private RuleEngineMapper() { Program program = preheat.getProgram(enrollment.getProgram()); return new RuleEnrollment( - enrollment.getUid(), + enrollment.getStringUid(), program.getName(), getDate(ObjectUtils.firstNonNull(enrollment.getOccurredAt(), enrollment.getEnrolledAt())), getDate(enrollment.getEnrolledAt()), @@ -165,7 +165,7 @@ private static RuleEvent mapPayloadEvent( : Instant.Companion.fromEpochMilliseconds(event.getCreated().getTime()); return new RuleEvent( - eventToEvaluate.getUid(), + eventToEvaluate.getUid().getValue(), programStage.getUid(), programStage.getName(), RuleEventStatus.valueOf(eventToEvaluate.getStatus().toString()), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutor.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutor.java index cdb6cb5686b8..a57d302056f6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutor.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutor.java @@ -90,7 +90,11 @@ public Optional executeRuleAction(TrackerBundle bundle, Event || isEqual(value, payloadDataValue.getValue(), dataElement.getValueType())) { addOrOverwriteDataValue(event, bundle, dataElement, payloadDataValue); return Optional.of( - warning(ruleUid, ValidationCode.E1308, dataElementUid.getValue(), event.getEvent())); + warning( + ruleUid, + ValidationCode.E1308, + dataElementUid.getValue(), + event.getEvent().getValue())); } return Optional.of(error(ruleUid, ValidationCode.E1307, dataElementUid.getValue(), value)); } @@ -99,13 +103,21 @@ private Optional assignInvalidOptionDataElement( DataValue payloadDataValue, Boolean canOverwrite, Event event) { if (payloadDataValue == null || payloadDataValue.getValue() == null) { return Optional.of( - warning(ruleUid, ValidationCode.E1308, dataElementUid.getValue(), event.getEvent())); + warning( + ruleUid, + ValidationCode.E1308, + dataElementUid.getValue(), + event.getEvent().getValue())); } if (Boolean.TRUE.equals(canOverwrite)) { payloadDataValue.setValue(null); return Optional.of( - warning(ruleUid, ValidationCode.E1308, dataElementUid.getValue(), event.getEvent())); + warning( + ruleUid, + ValidationCode.E1308, + dataElementUid.getValue(), + event.getEvent().getValue())); } return Optional.of(error(ruleUid, ValidationCode.E1307, dataElementUid.getValue(), "")); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/DeleteEventSMSListener.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/DeleteEventSMSListener.java index 83e721561d81..103c0eb91d01 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/DeleteEventSMSListener.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/DeleteEventSMSListener.java @@ -31,6 +31,7 @@ import javax.annotation.Nonnull; import lombok.extern.slf4j.Slf4j; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.message.MessageSender; import org.hisp.dhis.sms.incoming.IncomingSms; import org.hisp.dhis.sms.incoming.IncomingSmsService; @@ -90,7 +91,7 @@ protected SmsResponse postProcess( @Nonnull private static TrackerObjects map(@Nonnull DeleteSmsSubmission submission) { return TrackerObjects.builder() - .events(List.of(Event.builder().event(submission.getEvent().getUid()).build())) + .events(List.of(Event.builder().event(UID.of(submission.getEvent().getUid())).build())) .build(); } 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 f4880f6cf1fa..4a6aafa4736e 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; @@ -165,9 +166,9 @@ public void postProcess( return; } - String enrollment = null; + UID enrollment = null; if (!enrollments.isEmpty()) { - enrollment = enrollments.get(0).getUid(); + enrollment = UID.of(enrollments.get(0).getUid()); } TrackerImportParams params = diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java index fa16817ae8c0..779e2119bba6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java @@ -46,6 +46,7 @@ import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.collection.CollectionUtils; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -277,8 +278,8 @@ static List mapProgramAttributeValues( private static Event mapToEvent( @Nonnull SmsEvent submission, @Nonnull String username, @Nonnull Uid enrollment) { return Event.builder() - .event(submission.getEvent().getUid()) - .enrollment(enrollment.getUid()) + .event(UID.of(submission.getEvent().getUid())) + .enrollment(UID.of(enrollment.getUid())) .orgUnit(metadataUid(submission.getOrgUnit())) .programStage(metadataUid(submission.getProgramStage())) .attributeOptionCombo(metadataUid(submission.getAttributeOptionCombo())) @@ -301,8 +302,8 @@ static TrackerObjects map( private static Event mapEvent( @Nonnull TrackerEventSmsSubmission submission, @Nonnull String username) { return Event.builder() - .event(submission.getEvent().getUid()) - .enrollment(submission.getEnrollment().getUid()) + .event(UID.of(submission.getEvent().getUid())) + .enrollment(UID.of(submission.getEnrollment().getUid())) .orgUnit(metadataUid(submission.getOrgUnit())) .programStage(metadataUid(submission.getProgramStage())) .attributeOptionCombo(metadataUid(submission.getAttributeOptionCombo())) @@ -325,7 +326,7 @@ static TrackerObjects map( private static Event mapEvent( @Nonnull SimpleEventSmsSubmission submission, @Nonnull String username) { return Event.builder() - .event(submission.getEvent().getUid()) + .event(UID.of(submission.getEvent().getUid())) .orgUnit(metadataUid(submission.getOrgUnit())) .program(metadataUid(submission.getEventProgram())) .attributeOptionCombo(metadataUid(submission.getAttributeOptionCombo())) @@ -405,14 +406,14 @@ private static EventStatus map(SmsEventStatus status) { @Nonnull String username, @Nonnull CategoryService dataElementCategoryService, @Nonnull String trackedEntity, - @CheckForNull String enrollmentUid) { + @CheckForNull UID enrollmentUid) { List enrollments = List.of(); if (enrollmentUid == null) { - enrollmentUid = CodeGenerator.generateUid(); + enrollmentUid = UID.generate(); Instant now = Instant.now(); Enrollment enrollment = Enrollment.builder() - .enrollment(enrollmentUid) + .enrollment(enrollmentUid.getValue()) .trackedEntity(trackedEntity) .program(metadataUid(smsCommand.getProgram())) .orgUnit(MetadataIdentifier.ofUid(orgUnit)) @@ -504,7 +505,7 @@ private static EventStatus map(SmsEventStatus status) { @Nonnull String username, @Nonnull CategoryService dataElementCategoryService) { return Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(orgUnit)) .program(metadataUid(smsCommand.getProgram())) .programStage(metadataUid(smsCommand.getProgramStage())) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/MessageFormatter.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/MessageFormatter.java index 764291cd5d3a..4673eb42672e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/MessageFormatter.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/MessageFormatter.java @@ -108,7 +108,7 @@ private static String formatArgument(TrackerIdSchemeParams idSchemes, Object arg if (Instant.class.isAssignableFrom(type)) return DateUtils.toIso8601NoTz(DateUtils.fromInstant((Instant) argument)); if (Enrollment.class.isAssignableFrom(type)) return ((Enrollment) argument).getEnrollment(); - if (Event.class.isAssignableFrom(type)) return ((Event) argument).getEvent(); + if (Event.class.isAssignableFrom(type)) return ((Event) argument).getEvent().getValue(); if (TrackedEntity.class.isAssignableFrom(type)) return ((TrackedEntity) argument).getTrackedEntity(); return argument.toString(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilter.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilter.java index 1181e2f2d45a..e9d0797f4339 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilter.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilter.java @@ -45,6 +45,7 @@ import java.util.function.Predicate; import lombok.Getter; import org.apache.commons.lang3.StringUtils; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; @@ -106,7 +107,7 @@ class PersistablesFilter { List.of(en -> TrackedEntity.builder().trackedEntity(en.getTrackedEntity()).build()); private static final List> EVENT_PARENTS = - List.of(ev -> Enrollment.builder().enrollment(ev.getEnrollment()).build()); + List.of(ev -> Enrollment.builder().enrollment(ev.getEnrollment().getValue()).build()); private static final List> RELATIONSHIP_PARENTS = List.of(rel -> toTrackerDto(rel.getFrom()), rel -> toTrackerDto(rel.getTo())); @@ -117,7 +118,7 @@ class PersistablesFilter { * example on DELETE event, enrollment, trackedEntity entities cannot be deleted if an invalid * relationship points to them. */ - private final EnumMap> markedEntities = + private final EnumMap> markedEntities = new EnumMap<>( Map.of( TRACKED_ENTITY, new HashSet<>(), @@ -197,10 +198,16 @@ private boolean isNotValid(TrackerDto entity) { } private boolean isValid(TrackerDto entity) { - return !isContained(this.invalidEntities, entity); + return !isContainedInInvalidEntities(this.invalidEntities, entity); } - private boolean isContained(EnumMap> map, TrackerDto entity) { + @Deprecated(forRemoval = true) + private boolean isContainedInInvalidEntities( + EnumMap> map, TrackerDto entity) { + return map.get(entity.getTrackerType()).contains(entity.getStringUid()); + } + + private boolean isContained(EnumMap> map, TrackerDto entity) { return map.get(entity.getTrackerType()).contains(entity.getUid()); } @@ -291,7 +298,11 @@ private static Error error(ValidationCode code, TrackerDto notPersistable, Track }; String message = MessageFormat.format(code.getMessage(), args); return new Error( - message, code, notPersistable.getTrackerType(), notPersistable.getUid(), List.of(args)); + message, + code, + notPersistable.getTrackerType(), + notPersistable.getStringUid(), + List.of(args)); } /** @@ -309,7 +320,7 @@ private static TrackerDto toTrackerDto(RelationshipItem item) { } else if (StringUtils.isNotEmpty(item.getEnrollment())) { return Enrollment.builder().enrollment(item.getEnrollment()).build(); } else if (StringUtils.isNotEmpty(item.getEvent())) { - return Event.builder().event(item.getEvent()).build(); + return Event.builder().event(UID.of(item.getEvent())).build(); } // only reached if a new TrackerDto implementation is added throw new IllegalStateException("TrackerType for relationship item not yet supported."); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/Reporter.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/Reporter.java index 73a38ca10724..3c83adc0207b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/Reporter.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/Reporter.java @@ -159,7 +159,7 @@ public boolean addError(TrackerDto dto, ValidationCode code, Object... args) { MessageFormatter.format(idSchemes, code.getMessage(), args), code, dto.getTrackerType(), - dto.getUid(), + dto.getStringUid(), args == null ? List.of() : Arrays.asList(args))); return true; } @@ -205,7 +205,7 @@ public void addWarning(TrackerDto dto, ValidationCode code, Object... args) { MessageFormatter.format(idSchemes, code.getMessage(), args), code, dto.getTrackerType(), - dto.getUid())); + dto.getStringUid())); } public void addWarning(Warning warning) { @@ -214,7 +214,7 @@ public void addWarning(Warning warning) { /** Checks if a TrackerDto is invalid (i.e. has at least one Error in the Reporter). */ public boolean isInvalid(TrackerDto dto) { - return this.isInvalid(dto.getTrackerType(), dto.getUid()); + return this.isInvalid(dto.getTrackerType(), dto.getStringUid()); } /** diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java index e633fa74938f..1f55c8992892 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java @@ -128,7 +128,7 @@ protected void validateFileNotAlreadyAssigned( () -> fileResource != null && fileResource.getFileResourceOwner() != null - && !fileResource.getFileResourceOwner().equals(trackerDto.getUid()), + && !fileResource.getFileResourceOwner().equals(trackerDto.getStringUid()), trackerDto, E1009, value); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/ValidationUtils.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/ValidationUtils.java index 78619953ee6a..ce091b4c0cd7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/ValidationUtils.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/ValidationUtils.java @@ -41,6 +41,7 @@ import java.util.stream.Stream; import javax.annotation.Nonnull; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.common.ValueTypedDimensionalItemObject; import org.hisp.dhis.event.EventStatus; @@ -215,7 +216,7 @@ public static boolean enrollmentExist(TrackerBundle bundle, String enrollmentUid || bundle.findEnrollmentByUid(enrollmentUid).isPresent(); } - public static boolean eventExist(TrackerBundle bundle, String eventUid) { + public static boolean eventExist(TrackerBundle bundle, UID eventUid) { return bundle.getPreheat().getEvent(eventUid) != null || bundle.findEventByUid(eventUid).isPresent(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidator.java index 9986aafae371..fce7f15069d8 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/SecurityOwnershipValidator.java @@ -112,7 +112,7 @@ private TrackedEntity getTrackedEntityWhenStrategyCreate( .map( entity -> { TrackedEntity newEntity = new TrackedEntity(); - newEntity.setUid(entity.getUid()); + newEntity.setUid(entity.getUid().getValue()); newEntity.setOrganisationUnit( bundle.getPreheat().getOrganisationUnit(entity.getOrgUnit())); return newEntity; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidator.java index edbf00e2c5cb..88333d60daa6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidator.java @@ -42,7 +42,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -94,7 +93,7 @@ private void validateRegistrationProgram( return; } - if (StringUtils.isEmpty(event.getEnrollment())) { + if (event.getEnrollment() == null) { reporter.addError(event, E1033, event.getEvent()); } else { Program enrollmentProgram = getEnrollmentProgramFromEvent(bundle, event); @@ -322,12 +321,13 @@ private boolean isAOCForCOs(CategoryOptionCombo aoc, Set categor } private Program getEnrollmentProgramFromEvent(TrackerBundle bundle, Event event) { - Enrollment preheatEnrollment = bundle.getPreheat().getEnrollment(event.getEnrollment()); + Enrollment preheatEnrollment = + bundle.getPreheat().getEnrollment(event.getEnrollment().getValue()); if (preheatEnrollment != null) { return preheatEnrollment.getProgram(); } else { final Optional enrollment = - bundle.findEnrollmentByUid(event.getEnrollment()); + bundle.findEnrollmentByUid(event.getEnrollment().getValue()); if (enrollment.isPresent()) { return bundle.getPreheat().getProgram(enrollment.get().getProgram()); } @@ -346,12 +346,16 @@ private Program getEnrollmentProgramFromEvent(TrackerBundle bundle, Event event) * @return whether the enrollment of the event has an existing tracked entity */ private boolean enrollmentFromEventHasTrackedEntity(TrackerBundle bundle, Event event) { - Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment()); + if (event.getEnrollment() == null) { + return true; + } + + Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment().getValue()); if (enrollment == null) { return !Objects.isNull( bundle - .findEnrollmentByUid(event.getEnrollment()) + .findEnrollmentByUid(event.getEnrollment().getValue()) .map(org.hisp.dhis.tracker.imports.domain.Enrollment::getTrackedEntity) .orElse(null)); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidator.java index 9b5afd9aab7b..16e4ea56aab7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidator.java @@ -161,7 +161,7 @@ private void validateFileNotAlreadyAssigned( () -> fileResource != null && fileResource.getFileResourceOwner() != null - && !fileResource.getFileResourceOwner().equals(event.getEvent()), + && !fileResource.getFileResourceOwner().equals(event.getEvent().getValue()), event, E1009, value); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/EventValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/EventValidator.java index e11190c10d32..f587c893b105 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/EventValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/EventValidator.java @@ -52,7 +52,6 @@ public EventValidator( each( TrackerBundle::getEvents, seq( - new UidValidator(), new ExistenceValidator(), new MandatoryFieldsValidator(), new MetaValidator(), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidator.java index e4c9a8a4d709..35e4043ce3a9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidator.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -50,22 +51,20 @@ class RepeatedEventsValidator implements Validator> { @Override public void validate(Reporter reporter, TrackerBundle bundle, List events) { - Map, List> - eventsByEnrollmentAndNotRepeatableProgramStage = - events.stream() - .filter(e -> !reporter.isInvalid(e)) - .filter(e -> !bundle.getStrategy(e).isDelete()) - .filter( - e -> { - ProgramStage programStage = - bundle.getPreheat().getProgramStage(e.getProgramStage()); - return programStage.getProgram().isRegistration() - && !programStage.getRepeatable(); - }) - .collect( - Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment()))); + Map, List> eventsByEnrollmentAndNotRepeatableProgramStage = + events.stream() + .filter(e -> !reporter.isInvalid(e)) + .filter(e -> !bundle.getStrategy(e).isDelete()) + .filter( + e -> { + ProgramStage programStage = + bundle.getPreheat().getProgramStage(e.getProgramStage()); + return programStage.getProgram().isRegistration() + && !programStage.getRepeatable(); + }) + .collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment()))); - for (Map.Entry, List> mapEntry : + for (Map.Entry, List> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) { if (mapEntry.getValue().size() > 1) { for (Event event : mapEntry.getValue()) { @@ -78,7 +77,7 @@ public void validate(Reporter reporter, TrackerBundle bundle, List events } private void validateNotMultipleEvents(Reporter reporter, TrackerBundle bundle, Event event) { - Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment()); + Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment().getValue()); ProgramStage programStage = bundle.getPreheat().getProgramStage(event.getProgramStage()); TrackerImportStrategy strategy = bundle.getStrategy(event); @@ -89,7 +88,7 @@ private void validateNotMultipleEvents(Reporter reporter, TrackerBundle bundle, && !programStage.getRepeatable() && bundle .getPreheat() - .hasProgramStageWithEvents(event.getProgramStage(), event.getEnrollment())) { + .hasProgramStageWithEvents(event.getProgramStage(), event.getEnrollment().getValue())) { reporter.addError(event, ValidationCode.E1039, event.getProgramStage()); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidator.java index ad7fddc717a6..562cf8ee9dca 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidator.java @@ -198,11 +198,20 @@ private String getTeUidFromEvent( return null; } - Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment()); + if (bundle.getStrategy(event).isUpdateOrDelete()) { + return bundle + .getPreheat() + .getEvent(event.getUid()) + .getEnrollment() + .getTrackedEntity() + .getUid(); + } + + Enrollment enrollment = bundle.getPreheat().getEnrollment(event.getEnrollment().getValue()); if (enrollment == null) { return bundle - .findEnrollmentByUid(event.getEnrollment()) + .findEnrollmentByUid(event.getEnrollment().getValue()) .map(org.hisp.dhis.tracker.imports.domain.Enrollment::getTrackedEntity) .orElse(null); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidator.java index a237e76d7315..0779671cefa6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidator.java @@ -51,7 +51,7 @@ public void validate( reporter.addErrorIf( () -> event.getEnrollment() != null - && !event.getEnrollment().equals(preheatEvent.getEnrollment().getUid()), + && !event.getEnrollment().getValue().equals(preheatEvent.getEnrollment().getUid()), event, E1128, "enrollment"); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/relationship/ConstraintValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/relationship/ConstraintValidator.java index 9c5521cf9712..088cabf89114 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/relationship/ConstraintValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/relationship/ConstraintValidator.java @@ -34,6 +34,7 @@ import static org.hisp.dhis.tracker.imports.validation.validator.relationship.ValidationUtils.relationshipItemValueType; import java.util.Optional; +import org.hisp.dhis.common.UID; import org.hisp.dhis.relationship.RelationshipConstraint; import org.hisp.dhis.relationship.RelationshipType; import org.hisp.dhis.trackedentity.TrackedEntity; @@ -146,7 +147,7 @@ private static void validateEventRelationship( relSide, TrackerType.EVENT.getName(), relationshipItemValueType(item).getName()); - } else if (!eventExist(bundle, item.getEvent())) { + } else if (!eventExist(bundle, UID.of(item.getEvent()))) { reporter.addError(relationship, E4012, TrackerType.EVENT.getName(), item.getEvent()); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java index b1fd7d638bc5..2158040c191e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java @@ -45,6 +45,7 @@ import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; @@ -81,7 +82,7 @@ void setUp() { void collectTrackedEntities() { TrackedEntity trackedEntity = TrackedEntity.builder() - .trackedEntity(uid()) + .trackedEntity(stringUid()) .trackedEntityType(ofAttribute("NTVsGflP5Ix", "sunshine")) .orgUnit(ofName("ward")) .attributes(teAttributes("VohJnvWfvyo", "qv9xOw8fBzy")) @@ -103,8 +104,8 @@ void collectTrackedEntities() { void collectEnrollments() { Enrollment enrollment = Enrollment.builder() - .enrollment(uid()) - .trackedEntity(uid()) + .enrollment(stringUid()) + .trackedEntity(stringUid()) .program(ofAttribute("NTVsGflP5Ix", "sunshine")) .orgUnit(ofName("ward")) .attributes(teAttributes("VohJnvWfvyo", "qv9xOw8fBzy")) @@ -116,7 +117,7 @@ void collectEnrollments() { Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); - assertContainsOnly(Set.of(enrollment.getUid()), ids.get(Enrollment.class)); + assertContainsOnly(Set.of(enrollment.getStringUid()), ids.get(Enrollment.class)); assertContainsOnly(Set.of(enrollment.getTrackedEntity()), ids.get(TrackedEntity.class)); assertContainsOnly(Set.of("sunshine"), ids.get(Program.class)); assertContainsOnly(Set.of("ward"), ids.get(OrganisationUnit.class)); @@ -143,8 +144,8 @@ void collectEvents() { Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); - assertContainsOnly(Set.of(event.getUid()), ids.get(Event.class)); - assertContainsOnly(Set.of(event.getEnrollment()), ids.get(Enrollment.class)); + assertContainsOnly(Set.of(event.getStringUid()), ids.get(Event.class)); + assertContainsOnly(Set.of(event.getEnrollment().getValue()), ids.get(Enrollment.class)); assertContainsOnly(Set.of("sunshine"), ids.get(Program.class)); assertContainsOnly(Set.of("flowers"), ids.get(ProgramStage.class)); assertContainsOnly(Set.of("ward"), ids.get(OrganisationUnit.class)); @@ -183,10 +184,10 @@ void collectEventsSkipsNotesWithoutAValue() { void collectRelationships() { Relationship relationship = Relationship.builder() - .relationship(uid()) + .relationship(stringUid()) .relationshipType(ofAttribute("NTVsGflP5Ix", "sunshine")) - .from(RelationshipItem.builder().enrollment(uid()).build()) - .to(RelationshipItem.builder().event(uid()).build()) + .from(RelationshipItem.builder().enrollment(stringUid()).build()) + .to(RelationshipItem.builder().event(stringUid()).build()) .build(); TrackerObjects trackerObjects = @@ -201,10 +202,14 @@ void collectRelationships() { assertContainsOnly(Set.of(relationship.getTo().getEvent()), ids.get(Event.class)); } - private String uid() { + private String stringUid() { return CodeGenerator.generateUid(); } + private UID uid() { + return UID.generate(); + } + private List teAttributes(String... uids) { List result = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceTest.java index 4ee8251169a8..518866e42de1 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceTest.java @@ -180,7 +180,7 @@ void shouldBeAutoMergeable() trackedEntityA, trackedEntityB, mergeObject.getTrackedEntityAttributes()); verify(potentialDuplicateStore) .moveRelationships(trackedEntityA, trackedEntityB, mergeObject.getRelationships()); - verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(trackedEntityB.getUid())); + verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(UID.of(trackedEntityB))); verify(potentialDuplicateStore) .update(argThat(t -> t.getStatus().equals(DeduplicationStatus.MERGED))); verify(potentialDuplicateStore).auditMerge(deduplicationMergeParams); @@ -313,7 +313,7 @@ void shouldtBeAutoMergeableAttributeValuesIsEmpty() trackedEntityA, trackedEntityB, mergeObject.getTrackedEntityAttributes()); verify(potentialDuplicateStore) .moveRelationships(trackedEntityA, trackedEntityB, mergeObject.getRelationships()); - verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(trackedEntityB.getUid())); + verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(UID.of(trackedEntityB))); verify(potentialDuplicateStore).auditMerge(deduplicationMergeParams); } @@ -341,7 +341,7 @@ void shouldBeManualMergeable() trackedEntityA, trackedEntityB, deduplicationMergeParams.getMergeObject().getRelationships()); - verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(trackedEntityB.getUid())); + verify(trackerObjectDeletionService).deleteTrackedEntities(List.of(UID.of(trackedEntityB))); verify(potentialDuplicateStore).auditMerge(deduplicationMergeParams); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleTest.java index 49ed482d507a..ec45cc2151e5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleTest.java @@ -29,13 +29,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.AtomicMode; import org.hisp.dhis.tracker.imports.ValidationMode; import org.hisp.dhis.tracker.imports.domain.Enrollment; @@ -93,17 +91,6 @@ void testGetTrackedEntityGivenNull() { assertTrue(bundle.findTrackedEntityByUid(null).isEmpty()); } - @Test - void testExistsTrackedEntity() { - TrackerBundle bundle = - TrackerBundle.builder() - .trackedEntities(List.of(TrackedEntity.builder().trackedEntity("uid").build())) - .build(); - - assertFalse(bundle.exists(TrackerType.TRACKED_ENTITY, "missing")); - assertTrue(bundle.exists(TrackedEntity.builder().trackedEntity("uid").build())); - } - @Test void testGetEnrollmentGivenNull() { TrackerBundle bundle = @@ -114,34 +101,6 @@ void testGetEnrollmentGivenNull() { assertTrue(bundle.findEnrollmentByUid(null).isEmpty()); } - @Test - void testExistsEnrollment() { - TrackerBundle bundle = - TrackerBundle.builder() - .enrollments(List.of(Enrollment.builder().enrollment("uid").build())) - .build(); - - assertFalse(bundle.exists(TrackerType.ENROLLMENT, "missing")); - assertTrue(bundle.exists(Enrollment.builder().enrollment("uid").build())); - } - - @Test - void testGetEventGivenNull() { - TrackerBundle bundle = - TrackerBundle.builder().events(List.of(Event.builder().event("uid").build())).build(); - - assertTrue(bundle.findEventByUid(null).isEmpty()); - } - - @Test - void testExistsEvent() { - TrackerBundle bundle = - TrackerBundle.builder().events(List.of(Event.builder().event("uid").build())).build(); - - assertFalse(bundle.exists(TrackerType.EVENT, "missing")); - assertTrue(bundle.exists(Event.builder().event("uid").build())); - } - @Test void testGetRelationshipGivenNull() { TrackerBundle bundle = @@ -159,22 +118,4 @@ void testGetRelationshipInBundleContainingNullUids() { assertTrue(bundle.findRelationshipByUid("uid").isEmpty()); } - - @Test - void testExistsRelationship() { - TrackerBundle bundle = - TrackerBundle.builder() - .relationships(List.of(Relationship.builder().relationship("uid").build())) - .build(); - - assertFalse(bundle.exists(TrackerType.RELATIONSHIP, "missing")); - assertTrue(bundle.exists(Relationship.builder().relationship("uid").build())); - } - - @Test - void testExistsFailsOnNullType() { - TrackerBundle bundle = TrackerBundle.builder().build(); - - assertThrows(NullPointerException.class, () -> bundle.exists(null, "uid")); - } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java index 419375d00b95..3c6baef0a62e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.List; +import org.hisp.dhis.common.UID; import org.hisp.dhis.scheduling.JobProgress; import org.hisp.dhis.scheduling.RecordingJobProgress; import org.hisp.dhis.tracker.imports.DefaultTrackerImportService; @@ -89,7 +90,7 @@ public void setUp() { injectSecurityContextNoSettings(user); Event event = new Event(); - event.setEvent("EventUid"); + event.setEvent(UID.generate()); final List events = List.of(event); params = TrackerImportParams.builder().build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapperTest.java index 90f164f7327f..d174b63700be 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapperTest.java @@ -37,6 +37,8 @@ import java.util.Set; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; +import org.hisp.dhis.common.UidObject; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.note.Note; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -71,9 +73,9 @@ class TrackerObjectsMapperTest extends TestBase { private static final String TE_UID = CodeGenerator.generateUid(); - private static final String ENROLLMENT_UID = CodeGenerator.generateUid(); + private static final UID ENROLLMENT_UID = UID.generate(); - private static final String EVENT_UID = CodeGenerator.generateUid(); + private static final UID EVENT_UID = UID.generate(); private static final String RELATIONSHIP_UID = CodeGenerator.generateUid(); @@ -196,7 +198,7 @@ void shouldMapEnrollmentWhenItIsACreation() { preheat.putTrackedEntities(List.of(trackedEntity())); org.hisp.dhis.tracker.imports.domain.Enrollment enrollment = org.hisp.dhis.tracker.imports.domain.Enrollment.builder() - .enrollment(ENROLLMENT_UID) + .enrollment(ENROLLMENT_UID.getValue()) .trackedEntity(TE_UID) .orgUnit(MetadataIdentifier.ofUid(organisationUnit)) .program(MetadataIdentifier.ofUid(program)) @@ -222,7 +224,7 @@ void shouldMapEnrollmentWhenItIsACreationAndOccurredDateIsNull() { preheat.putTrackedEntities(List.of(trackedEntity())); org.hisp.dhis.tracker.imports.domain.Enrollment enrollment = org.hisp.dhis.tracker.imports.domain.Enrollment.builder() - .enrollment(ENROLLMENT_UID) + .enrollment(ENROLLMENT_UID.getValue()) .trackedEntity(TE_UID) .orgUnit(MetadataIdentifier.ofUid(organisationUnit)) .program(MetadataIdentifier.ofUid(program)) @@ -249,7 +251,7 @@ void shouldMapEnrollmentWhenItIsAnUpdateAndEnrollmentGetCompleted() { preheat.putEnrollments(List.of(savedEnrollment)); org.hisp.dhis.tracker.imports.domain.Enrollment enrollment = org.hisp.dhis.tracker.imports.domain.Enrollment.builder() - .enrollment(ENROLLMENT_UID) + .enrollment(ENROLLMENT_UID.getValue()) .trackedEntity(TE_UID) .orgUnit(MetadataIdentifier.ofUid(organisationUnit)) .program(MetadataIdentifier.ofUid(program)) @@ -276,7 +278,7 @@ void shouldMapEnrollmentWhenItIsAnUpdateAndEnrollmentGetCancelled() { preheat.putEnrollments(List.of(savedEnrollment)); org.hisp.dhis.tracker.imports.domain.Enrollment enrollment = org.hisp.dhis.tracker.imports.domain.Enrollment.builder() - .enrollment(ENROLLMENT_UID) + .enrollment(ENROLLMENT_UID.getValue()) .trackedEntity(TE_UID) .orgUnit(MetadataIdentifier.ofUid(organisationUnit)) .program(MetadataIdentifier.ofUid(program)) @@ -303,7 +305,7 @@ void shouldMapEnrollmentWhenItIsAnUpdateAndEnrollmentGetUncompleted() { preheat.putEnrollments(List.of(savedEnrollment)); org.hisp.dhis.tracker.imports.domain.Enrollment enrollment = org.hisp.dhis.tracker.imports.domain.Enrollment.builder() - .enrollment(ENROLLMENT_UID) + .enrollment(ENROLLMENT_UID.getValue()) .trackedEntity(TE_UID) .orgUnit(MetadataIdentifier.ofUid(organisationUnit)) .program(MetadataIdentifier.ofUid(program)) @@ -468,7 +470,7 @@ void testMapRelationshipFromTEToEnrollment() { .relationship(RELATIONSHIP_UID) .relationshipType(MetadataIdentifier.ofUid(TE_TO_ENROLLMENT_RELATIONSHIP_TYPE)) .from(RelationshipItem.builder().trackedEntity(TE_UID).build()) - .to(RelationshipItem.builder().enrollment(ENROLLMENT_UID).build()) + .to(RelationshipItem.builder().enrollment(ENROLLMENT_UID.getValue()).build()) .build(); org.hisp.dhis.relationship.Relationship dbRelationship = @@ -486,7 +488,7 @@ void testMapRelationshipFromTEToEvent() { .relationship(RELATIONSHIP_UID) .relationshipType(MetadataIdentifier.ofUid(TE_TO_EVENT_RELATIONSHIP_TYPE)) .from(RelationshipItem.builder().trackedEntity(TE_UID).build()) - .to(RelationshipItem.builder().event(EVENT_UID).build()) + .to(RelationshipItem.builder().event(EVENT_UID.getValue()).build()) .build(); org.hisp.dhis.relationship.Relationship dbRelationship = @@ -520,7 +522,7 @@ private void assertMappedTrackedEntity( TrackedEntity actual, UserDetails createdBy, UserDetails updatedBy) { - assertEquals(trackedEntity.getUid(), actual.getUid()); + assertEquals(trackedEntity.getStringUid(), actual.getUid()); assertEquals(trackedEntity.getOrgUnit().getIdentifier(), actual.getOrganisationUnit().getUid()); assertEquals( trackedEntity.getTrackedEntityType().getIdentifier(), @@ -542,7 +544,7 @@ private void assertMappedEnrollment( Enrollment actual, UserDetails createdBy, UserDetails updatedBy) { - assertEquals(enrollment.getUid(), actual.getUid()); + assertEquals(enrollment.getStringUid(), actual.getUid()); assertEquals(enrollment.getTrackedEntity(), actual.getTrackedEntity().getUid()); assertEquals(enrollment.getOrgUnit().getIdentifier(), actual.getOrganisationUnit().getUid()); assertEquals(enrollment.getProgram().getIdentifier(), actual.getProgram().getUid()); @@ -565,8 +567,8 @@ private void assertMappedEvent( Event actual, UserDetails createdBy, UserDetails updatedBy) { - assertEquals(event.getUid(), actual.getUid()); - assertEquals(event.getEnrollment(), actual.getEnrollment().getUid()); + assertUids(event.getUid(), actual); + assertUids(event.getEnrollment(), actual.getEnrollment()); assertEquals(event.getOrgUnit().getIdentifier(), actual.getOrganisationUnit().getUid()); assertEquals(event.getProgramStage().getIdentifier(), actual.getProgramStage().getUid()); assertEquals(UserInfoSnapshot.from(createdBy), actual.getCreatedByUserInfo()); @@ -582,11 +584,15 @@ private void assertMappedEvent( assertNotes(event.getNotes(), actual.getNotes(), updatedBy); } + private void assertUids(UID uid, UidObject uidObject) { + assertEquals(uid.getValue(), uidObject.getUid()); + } + private void assertMappedRelationship( org.hisp.dhis.tracker.imports.domain.Relationship relationship, Relationship actual, UserDetails createdBy) { - assertEquals(relationship.getUid(), actual.getUid()); + assertEquals(relationship.getStringUid(), actual.getUid()); assertEquals(createdBy.getUid(), actual.getLastUpdatedBy().getUid()); assertEquals( DateUtils.fromInstant(relationship.getCreatedAtClient()), actual.getCreatedAtClient()); @@ -651,7 +657,7 @@ private TrackedEntity trackedEntity() { private Enrollment enrollment(EnrollmentStatus status) { Enrollment dbEnrollment = new Enrollment(); - dbEnrollment.setUid(ENROLLMENT_UID); + dbEnrollment.setUid(ENROLLMENT_UID.getValue()); dbEnrollment.setCreated(NOW); dbEnrollment.setCreatedByUserInfo(UserInfoSnapshot.from(creatingUser)); dbEnrollment.setLastUpdatedByUserInfo(UserInfoSnapshot.from(updatingUser)); @@ -669,7 +675,7 @@ private Enrollment enrollment(EnrollmentStatus status) { private Event event(EventStatus status) { Event dbEvent = new Event(); - dbEvent.setUid(EVENT_UID); + dbEvent.setUid(EVENT_UID.getValue()); dbEvent.setCreated(NOW); dbEvent.setCreatedByUserInfo(UserInfoSnapshot.from(creatingUser)); dbEvent.setLastUpdatedByUserInfo(UserInfoSnapshot.from(updatingUser)); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/NotificationSenderTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/NotificationSenderTest.java index 65287d3f6203..083cdda393c0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/NotificationSenderTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/NotificationSenderTest.java @@ -58,7 +58,7 @@ class NotificationSenderTest { private static final UID TEMPLATE_UID = UID.of("h4w96yEMlzO"); private static final String ENROLLMENT_UID = "enrollmentUid"; - private static final String EVENT_UID = "eventUid"; + private static final UID EVENT_UID = UID.generate(); @Mock private ProgramNotificationTemplateService programNotificationTemplateService; @@ -347,7 +347,7 @@ private Event event() { Program program = new Program(); program.setProgramType(ProgramType.WITH_REGISTRATION); Event event = new Event(); - event.setUid(EVENT_UID); + event.setUid(EVENT_UID.getValue()); event.setEnrollment(enrollment()); return event; } @@ -356,7 +356,7 @@ private Event programEvent() { Program program = new Program(); program.setProgramType(ProgramType.WITHOUT_REGISTRATION); Event event = new Event(); - event.setUid(EVENT_UID); + event.setUid(EVENT_UID.getValue()); event.setEnrollment(enrollment(program)); return event; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/TrackerSideValidationEffectDataBundleTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/TrackerSideValidationEffectDataBundleTest.java index a03a0a91e717..cc7c94c287b3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/TrackerSideValidationEffectDataBundleTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/job/TrackerSideValidationEffectDataBundleTest.java @@ -33,6 +33,7 @@ import java.util.List; import org.hisp.dhis.artemis.MessageType; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -69,7 +70,7 @@ void testNotificationDataBundleForEnrollment() { void testNotificationDataBundleForEvent() { org.hisp.dhis.tracker.imports.domain.Event event = new org.hisp.dhis.tracker.imports.domain.Event(); - event.setEvent("ja8NY4PW7Xm"); + event.setEvent(UID.generate()); Event expected = new Event(); expected.setAutoFields(); TrackerNotificationDataBundle bundle = diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatTest.java index 0ec6641cd76d..f6ee0d6e354c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatTest.java @@ -51,6 +51,7 @@ import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.DataDimensionType; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; @@ -359,57 +360,62 @@ void testPutCollectionUid() { @Test void testExistsTrackedEntity() { - assertFalse(preheat.exists(TrackerType.TRACKED_ENTITY, "uid")); + UID uid = UID.generate(); + assertFalse(preheat.exists(TrackerType.TRACKED_ENTITY, uid)); TrackedEntity te = new TrackedEntity(); - te.setUid("uid"); + te.setUid(uid.getValue()); preheat.putTrackedEntities(List.of(te)); - assertTrue(preheat.exists(TrackerType.TRACKED_ENTITY, "uid")); + assertTrue(preheat.exists(TrackerType.TRACKED_ENTITY, uid)); assertTrue( preheat.exists( org.hisp.dhis.tracker.imports.domain.TrackedEntity.builder() - .trackedEntity("uid") + .trackedEntity(uid.getValue()) .build())); } @Test void testExistsEnrollment() { - assertFalse(preheat.exists(TrackerType.ENROLLMENT, "uid")); + UID uid = UID.generate(); + assertFalse(preheat.exists(TrackerType.ENROLLMENT, uid)); Enrollment enrollment = new Enrollment(); - enrollment.setUid("uid"); + enrollment.setUid(uid.getValue()); preheat.putEnrollments(List.of(enrollment)); - assertTrue(preheat.exists(TrackerType.ENROLLMENT, "uid")); + assertTrue(preheat.exists(TrackerType.ENROLLMENT, uid)); } @Test void testExistsEvent() { - assertFalse(preheat.exists(TrackerType.EVENT, "uid")); + UID uid = UID.generate(); + assertFalse(preheat.exists(TrackerType.EVENT, uid)); Event event = new Event(); - event.setUid("uid"); + event.setUid(uid.getValue()); preheat.putEvents(List.of(event)); - assertTrue(preheat.exists(TrackerType.EVENT, "uid")); + assertTrue(preheat.exists(TrackerType.EVENT, uid)); } @Test void testExistsRelationship() { - assertFalse(preheat.exists(TrackerType.RELATIONSHIP, "uid")); + UID uid = UID.generate(); + assertFalse(preheat.exists(TrackerType.RELATIONSHIP, uid)); org.hisp.dhis.relationship.Relationship relationship = new org.hisp.dhis.relationship.Relationship(); - relationship.setUid("uid"); + relationship.setUid(uid.getValue()); preheat.putRelationship(relationship); - assertTrue(preheat.exists(TrackerType.RELATIONSHIP, "uid")); + assertTrue(preheat.exists(TrackerType.RELATIONSHIP, uid)); } @Test void testExistsFailsOnNullType() { - assertThrows(NullPointerException.class, () -> preheat.exists(null, "uid")); + UID uid = UID.generate(); + assertThrows(NullPointerException.class, () -> preheat.exists(null, uid)); } private Set categoryOptionIds( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java index c82eaa23c82a..99464c99c95e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java @@ -39,6 +39,7 @@ import java.util.stream.Collectors; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.test.TestBase; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.TrackerObjects; @@ -124,7 +125,7 @@ private org.hisp.dhis.user.User map(User assignedUser) { } private Event event(User user) { - return Event.builder().event(CodeGenerator.generateUid()).assignedUser(user).build(); + return Event.builder().event(UID.generate()).assignedUser(user).build(); } private User user() { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessorTest.java index ff04aa98328d..fe215efd9568 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/EventWithoutRegistrationPreProcessorTest.java @@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Collections; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; @@ -60,7 +61,8 @@ void testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration() { event.setProgramStage(MetadataIdentifier.ofUid("programStageUid")); TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build(); Enrollment enrollment = new Enrollment(); - enrollment.setUid("enrollmentUid"); + UID enrollmentUid = UID.generate(); + enrollment.setUid(enrollmentUid.getValue()); Program program = new Program(); program.setUid("programUid"); ProgramStage programStage = new ProgramStage(); @@ -73,7 +75,7 @@ void testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration() { // When preProcessorToTest.process(bundle); // Then - assertEquals("enrollmentUid", bundle.getEvents().get(0).getEnrollment()); + assertEquals(enrollmentUid, bundle.getEvents().get(0).getEnrollment()); } @Test diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessorTest.java index c237e3e5ea19..8d1c70413f84 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/StrategyPreProcessorTest.java @@ -31,6 +31,7 @@ import com.google.common.collect.Lists; import org.hamcrest.Matchers; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.relationship.Relationship; @@ -58,9 +59,9 @@ class StrategyPreProcessorTest extends TestBase { private static final String NEW_ENROLLMENT_UID = "NewEnrollmentUid"; - private static final String EVENT_UID = "EventUid"; + private static final UID EVENT_UID = UID.generate(); - private static final String NEW_EVENT_UID = "NewEventUid"; + private static final UID NEW_EVENT_UID = UID.generate(); private static final String RELATIONSHIP_UID = "RelationshipUid"; @@ -109,7 +110,7 @@ void setUp() { newEnrollment = new org.hisp.dhis.tracker.imports.domain.Enrollment(); newEnrollment.setEnrollment(NEW_ENROLLMENT_UID); dbEvent = new Event(); - dbEvent.setUid(EVENT_UID); + dbEvent.setUid(EVENT_UID.getValue()); event = new org.hisp.dhis.tracker.imports.domain.Event(); event.setEvent(EVENT_UID); newEvent = new org.hisp.dhis.tracker.imports.domain.Event(); @@ -151,10 +152,10 @@ void testStrategyPreprocessForCreateAndUpdate() { bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(NEW_ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.CREATE)); assertThat( - bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID), + bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID.getValue()), Matchers.is(TrackerImportStrategy.UPDATE)); assertThat( - bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID), + bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID.getValue()), Matchers.is(TrackerImportStrategy.CREATE)); assertThat( bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(RELATIONSHIP_UID), @@ -189,10 +190,10 @@ void testStrategyPreprocessForDelete() { bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(NEW_ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.DELETE)); assertThat( - bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID), + bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID.getValue()), Matchers.is(TrackerImportStrategy.DELETE)); assertThat( - bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID), + bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID.getValue()), Matchers.is(TrackerImportStrategy.DELETE)); assertThat( bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(RELATIONSHIP_UID), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java index 19468a6ab289..71e703971996 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/RuleEngineMapperTest.java @@ -39,6 +39,7 @@ import kotlinx.datetime.Instant; import kotlinx.datetime.LocalDate; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.eventdatavalue.EventDataValue; @@ -130,10 +131,16 @@ void shouldMapPayloadEventsToRuleEvents() { assertEquals(2, ruleEvents.size()); assertEvent( eventA, - ruleEvents.stream().filter(e -> e.getEvent().equals(eventA.getUid())).findFirst().get()); + ruleEvents.stream() + .filter(e -> e.getEvent().equals(eventA.getUid().getValue())) + .findFirst() + .get()); assertEvent( eventB, - ruleEvents.stream().filter(e -> e.getEvent().equals(eventB.getUid())).findFirst().get()); + ruleEvents.stream() + .filter(e -> e.getEvent().equals(eventB.getUid().getValue())) + .findFirst() + .get()); } @Test @@ -249,7 +256,7 @@ private void assertEvent(Event event, RuleEvent ruleEvent) { } private void assertEvent(org.hisp.dhis.tracker.imports.domain.Event event, RuleEvent ruleEvent) { - assertEquals(event.getUid(), ruleEvent.getEvent()); + assertEquals(event.getUid().getValue(), ruleEvent.getEvent()); assertEquals(event.getProgramStage().getIdentifier(), ruleEvent.getProgramStage()); assertNotNull(ruleEvent.getProgramStageName()); assertEquals(event.getStatus().name(), ruleEvent.getStatus().name()); @@ -282,7 +289,7 @@ private void assertDataValue(DataValue expectedDataValue, RuleDataValue actualDa private void assertEnrollment( org.hisp.dhis.tracker.imports.domain.Enrollment enrollment, RuleEnrollment ruleEnrollment) { - assertEquals(enrollment.getUid(), ruleEnrollment.getEnrollment()); + assertEquals(enrollment.getUid().getValue(), ruleEnrollment.getEnrollment()); assertNotNull(ruleEnrollment.getProgramName()); assertDates(enrollment.getOccurredAt(), ruleEnrollment.getIncidentDate()); assertDates(enrollment.getEnrolledAt(), ruleEnrollment.getEnrollmentDate()); @@ -364,8 +371,8 @@ private EventDataValue eventDataValue(String dataElementUid, String value) { private org.hisp.dhis.tracker.imports.domain.Event payloadEvent() { return org.hisp.dhis.tracker.imports.domain.Event.builder() - .enrollment(CodeGenerator.generateUid()) - .event(CodeGenerator.generateUid()) + .enrollment(UID.generate()) + .event(UID.generate()) .programStage(MetadataIdentifier.ofUid(programStage.getUid())) .orgUnit(MetadataIdentifier.ofUid(organisationUnit.getUid())) .scheduledAt(YESTERDAY.toInstant()) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutorTest.java index 82dc50cda0c3..7ce02a262fb0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/AssignDataValueExecutorTest.java @@ -71,9 +71,9 @@ class AssignDataValueExecutorTest extends TestBase { private static final UID RULE_UID = UID.of("TvctPPhpD8u"); - private static final String EVENT_ID = "EventId"; + private static final UID EVENT_UID = UID.generate(); - private static final String SECOND_EVENT_ID = "SecondEventId"; + private static final UID SECOND_EVENT_UID = UID.generate(); private static final UID DATA_ELEMENT_UID = UID.of("h4w96yEMlzO"); @@ -168,7 +168,7 @@ void shouldFailWhenAssignedValueIsInvalidOptionAndDataValueIsValidOption() { executor.executeRuleAction(bundle, eventWithOptionDataValue); Optional dataValue = - findDataValueByUid(bundle, EVENT_ID, OPTION_SET_DATA_ELEMENT_UID); + findDataValueByUid(bundle, EVENT_UID, OPTION_SET_DATA_ELEMENT_UID); assertDataValueWasNotAssignedAndErrorIsPresent(VALID_OPTION_VALUE, dataValue, warning); } @@ -192,7 +192,7 @@ void shouldAssignDataValueWhenAssignedValueIsValidOptionAndDataValueIsEmpty() { executor.executeRuleAction(bundle, eventWithOptionDataValue); Optional dataValue = - findDataValueByUid(bundle, EVENT_ID, OPTION_SET_DATA_ELEMENT_UID); + findDataValueByUid(bundle, EVENT_UID, OPTION_SET_DATA_ELEMENT_UID); assertTrue(dataValue.isPresent()); assertEquals(VALID_OPTION_VALUE, dataValue.get().getValue()); @@ -219,7 +219,7 @@ void shouldAssignDataValueWhenAssignedValueIsInvalidOptionAndDataValueIsEmpty() executor.executeRuleAction(bundle, eventWithOptionDataValue); Optional dataValue = - findDataValueByUid(bundle, SECOND_EVENT_ID, OPTION_SET_DATA_ELEMENT_UID); + findDataValueByUid(bundle, SECOND_EVENT_UID, OPTION_SET_DATA_ELEMENT_UID); assertAll( () -> assertTrue(dataValue.isEmpty()), @@ -247,7 +247,7 @@ void shouldAssignNullDataValueWhenAssignedValueIsInvalidOptionAndOverwriteIsTrue executor.executeRuleAction(bundle, eventWithOptionDataValue); Optional dataValue = - findDataValueByUid(bundle, EVENT_ID, OPTION_SET_DATA_ELEMENT_UID); + findDataValueByUid(bundle, EVENT_UID, OPTION_SET_DATA_ELEMENT_UID); assertDataValueWasAssignedAndWarningIsPresent(null, dataValue, warning); } @@ -270,7 +270,7 @@ void shouldAssignDataValueValueForEventsWhenDataValueIsEmpty() { Optional warning = executor.executeRuleAction(bundle, eventWithDataValueNOTSet); - Optional dataValue = findDataValueByUid(bundle, SECOND_EVENT_ID, DATA_ELEMENT_UID); + Optional dataValue = findDataValueByUid(bundle, SECOND_EVENT_UID, DATA_ELEMENT_UID); assertDataValueWasAssignedAndWarningIsPresent(DATAELEMENT_NEW_VALUE, dataValue, warning); } @@ -291,7 +291,7 @@ void shouldNotAssignDataValueValueForEventsWhenDataValueIsAlreadyPresent() { Optional error = executor.executeRuleAction(bundle, eventWithDataValueSet); - Optional dataValue = findDataValueByUid(bundle, EVENT_ID, DATA_ELEMENT_UID); + Optional dataValue = findDataValueByUid(bundle, EVENT_UID, DATA_ELEMENT_UID); assertDataValueWasNotAssignedAndErrorIsPresent(DATAELEMENT_OLD_VALUE, dataValue, error); } @@ -315,7 +315,7 @@ void shouldNotAssignDataValueValueForEventsWhenDataValueIsAlreadyPresentUsingIdS Optional error = executor.executeRuleAction(bundle, eventWithDataValueSet); - Optional dataValue = findDataValueByCode(bundle, EVENT_ID, DATA_ELEMENT_CODE); + Optional dataValue = findDataValueByCode(bundle, EVENT_UID, DATA_ELEMENT_CODE); assertDataValueWasNotAssignedAndErrorIsPresent(DATAELEMENT_OLD_VALUE, dataValue, error); } @@ -337,7 +337,7 @@ void shouldAssignDataValueValueForEventsWhenDataValueIsAlreadyPresentAndHasTheSa Optional warning = executor.executeRuleAction(bundle, eventWithDataValueSetSameValue); - Optional dataValue = findDataValueByUid(bundle, EVENT_ID, DATA_ELEMENT_UID); + Optional dataValue = findDataValueByUid(bundle, EVENT_UID, DATA_ELEMENT_UID); assertDataValueWasAssignedAndWarningIsPresent(DATAELEMENT_NEW_VALUE, dataValue, warning); } @@ -360,13 +360,13 @@ void shouldAssignDataValueValueForEventsWhenDataValueIsAlreadyPresentAndHasTheSa Optional warning = executor.executeRuleAction(bundle, eventWithDataValueSet); - Optional dataValue = findDataValueByUid(bundle, EVENT_ID, DATA_ELEMENT_UID); + Optional dataValue = findDataValueByUid(bundle, EVENT_UID, DATA_ELEMENT_UID); assertDataValueWasAssignedAndWarningIsPresent(DATAELEMENT_NEW_VALUE, dataValue, warning); } private Optional findDataValueByUid( - TrackerBundle bundle, String eventUid, UID dataValueUid) { + TrackerBundle bundle, UID eventUid, UID dataValueUid) { Event event = bundle.findEventByUid(eventUid).get(); return event.getDataValues().stream() .filter(dv -> dv.getDataElement().equals(MetadataIdentifier.ofUid(dataValueUid.getValue()))) @@ -374,7 +374,7 @@ private Optional findDataValueByUid( } private Optional findDataValueByCode( - TrackerBundle bundle, String eventUid, String dataValueCode) { + TrackerBundle bundle, UID eventUid, String dataValueCode) { Event event = bundle.findEventByUid(eventUid).get(); return event.getDataValues().stream() .filter(dv -> dv.getDataElement().equals(MetadataIdentifier.ofCode(dataValueCode))) @@ -404,7 +404,7 @@ private void assertDataValueWasAssignedAndValidationIsPresent( private Event getEventWithDataValueSet() { return Event.builder() - .event(EVENT_ID) + .event(EVENT_UID) .status(EventStatus.ACTIVE) .dataValues(getDataValues()) .build(); @@ -412,7 +412,7 @@ private Event getEventWithDataValueSet() { private Event getEventWithDataValueSet(TrackerIdSchemeParams idSchemes) { return Event.builder() - .event(EVENT_ID) + .event(EVENT_UID) .status(EventStatus.ACTIVE) .dataValues(getDataValues(idSchemes)) .build(); @@ -420,7 +420,7 @@ private Event getEventWithDataValueSet(TrackerIdSchemeParams idSchemes) { private Event getEventWithDataValueSetSameValue() { return Event.builder() - .event(EVENT_ID) + .event(EVENT_UID) .status(EventStatus.ACTIVE) .dataValues(getDataValuesSameValue()) .build(); @@ -428,14 +428,14 @@ private Event getEventWithDataValueSetSameValue() { private Event getEventWithOptionSetDataValueWithValidValue() { return Event.builder() - .event(EVENT_ID) + .event(EVENT_UID) .status(EventStatus.ACTIVE) .dataValues(getOptionSetDataValues()) .build(); } private Event getEventWithDataValueNOTSet() { - return Event.builder().event(SECOND_EVENT_ID).status(EventStatus.COMPLETED).build(); + return Event.builder().event(SECOND_EVENT_UID).status(EventStatus.COMPLETED).build(); } private Set getDataValues(TrackerIdSchemeParams idSchemes) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/RuleEngineErrorExecutorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/RuleEngineErrorExecutorTest.java index f0c972c13eab..1f6f3fe9fa13 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/RuleEngineErrorExecutorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/RuleEngineErrorExecutorTest.java @@ -49,7 +49,7 @@ class RuleEngineErrorExecutorTest extends TestBase { private static final String ERROR_MESSAGE = "Error message"; - private static final String EVENT_ID = "EventUid"; + private static final UID EVENT_UID = UID.generate(); private final RuleEngineErrorExecutor ruleEngineErrorExecutor = new RuleEngineErrorExecutor(RULE_UID, ERROR_MESSAGE); @@ -71,6 +71,6 @@ void shouldReturnAWarningWhenRuleWithSyntaxErrorIsTriggeredOnEvent() { } private Event getEvent() { - return Event.builder().event(EVENT_ID).build(); + return Event.builder().event(EVENT_UID).build(); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/SetMandatoryFieldExecutorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/SetMandatoryFieldExecutorTest.java index 961d69d6cc6d..3388b74dbbb7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/SetMandatoryFieldExecutorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/SetMandatoryFieldExecutorTest.java @@ -67,9 +67,9 @@ @ExtendWith(MockitoExtension.class) class SetMandatoryFieldExecutorTest extends TestBase { - private static final String ACTIVE_EVENT_ID = "EventUid"; + private static final UID ACTIVE_EVENT_UID = UID.generate(); - private static final String COMPLETED_EVENT_ID = "CompletedEventUid"; + private static final UID COMPLETED_EVENT_UID = UID.generate(); private static final UID DATA_ELEMENT_UID = UID.of("h4w96yEMlzO"); @@ -251,25 +251,25 @@ void shouldFailValidationWhenMandatoryFieldIsNotPresentAndDataValuesAreCreated( assertEquals(error(RULE_UID, E1301, dataElement.getUid()), error.get()); } - private org.hisp.dhis.program.Event eventWithMandatoryValue(String uid, EventStatus status) { + private org.hisp.dhis.program.Event eventWithMandatoryValue(UID uid, EventStatus status) { org.hisp.dhis.program.Event event = new org.hisp.dhis.program.Event(); - event.setUid(uid); + event.setUid(uid.getValue()); event.setStatus(status); event.setEventDataValues( Set.of(new EventDataValue(DATA_ELEMENT_UID.getValue(), DATA_ELEMENT_VALUE))); return event; } - private org.hisp.dhis.program.Event event(String uid, EventStatus status) { + private org.hisp.dhis.program.Event event(UID uid, EventStatus status) { org.hisp.dhis.program.Event event = new org.hisp.dhis.program.Event(); - event.setUid(uid); + event.setUid(uid.getValue()); event.setStatus(status); return event; } private Event getEventWithDeleteMandatoryValue() { return Event.builder() - .event(ACTIVE_EVENT_ID) + .event(ACTIVE_EVENT_UID) .status(EventStatus.ACTIVE) .programStage(MetadataIdentifier.ofUid(programStage)) .dataValues(getNullEventDataValues()) @@ -278,7 +278,7 @@ private Event getEventWithDeleteMandatoryValue() { private Event getEventWithMandatoryValueSet(TrackerIdSchemeParams idSchemes) { return Event.builder() - .event(ACTIVE_EVENT_ID) + .event(ACTIVE_EVENT_UID) .status(EventStatus.ACTIVE) .programStage(idSchemes.toMetadataIdentifier(programStage)) .dataValues(getActiveEventDataValues(idSchemes)) @@ -287,7 +287,7 @@ private Event getEventWithMandatoryValueSet(TrackerIdSchemeParams idSchemes) { private Event getEventWithMandatoryValueSet() { return Event.builder() - .event(ACTIVE_EVENT_ID) + .event(ACTIVE_EVENT_UID) .status(EventStatus.ACTIVE) .programStage(MetadataIdentifier.ofUid(programStage)) .dataValues(getActiveEventDataValues()) @@ -296,7 +296,7 @@ private Event getEventWithMandatoryValueSet() { private Event getEventWithMandatoryValueNOTSet() { return Event.builder() - .event(COMPLETED_EVENT_ID) + .event(COMPLETED_EVENT_UID) .status(EventStatus.ACTIVE) .programStage(MetadataIdentifier.ofUid(programStage)) .build(); @@ -304,7 +304,7 @@ private Event getEventWithMandatoryValueNOTSet() { private Event getEventWithMandatoryValueNOTSet(EventStatus status) { return Event.builder() - .event(COMPLETED_EVENT_ID) + .event(COMPLETED_EVENT_UID) .status(status) .programStage(MetadataIdentifier.ofUid(programStage)) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/ValidationExecutorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/ValidationExecutorTest.java index 373a254cc513..69d901af48b4 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/ValidationExecutorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/programrule/executor/event/ValidationExecutorTest.java @@ -72,9 +72,9 @@ class ValidationExecutorTest extends TestBase { private static final String EVALUATED_DATA = "4.0"; - private static final String ACTIVE_EVENT_ID = "EventUid"; + private static final UID ACTIVE_EVENT_UID = UID.generate(); - private static final String COMPLETED_EVENT_ID = "CompletedEventUid"; + private static final UID COMPLETED_EVENT_UID = UID.generate(); private static final String PROGRAM_STAGE_ID = "ProgramStageId"; @@ -209,7 +209,7 @@ private List getEvents() { private Event activeEvent() { return Event.builder() - .event(ACTIVE_EVENT_ID) + .event(ACTIVE_EVENT_UID) .status(EventStatus.ACTIVE) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .build(); @@ -217,7 +217,7 @@ private Event activeEvent() { private Event completedEvent() { return Event.builder() - .event(COMPLETED_EVENT_ID) + .event(COMPLETED_EVENT_UID) .status(EventStatus.COMPLETED) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java index 5f51b81c504e..78e81a96da9a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Set; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.program.EnrollmentStatus; import org.hisp.dhis.program.Program; @@ -204,7 +205,7 @@ void mapEnrollmentWithEvents() { List expected = List.of( Event.builder() - .event(smsEvent.getEvent().getUid()) + .event(UID.of(smsEvent.getEvent().getUid())) .orgUnit(MetadataIdentifier.ofUid(smsEvent.getOrgUnit().getUid())) .programStage(MetadataIdentifier.ofUid(smsEvent.getProgramStage().getUid())) .attributeOptionCombo( @@ -218,7 +219,7 @@ void mapEnrollmentWithEvents() { .value("hello") .storedBy("francis") .build())) - .enrollment(input.getEnrollment().getUid()) + .enrollment(UID.of(input.getEnrollment().getUid())) .build()); assertEquals(expected, actual.getEvents()); } @@ -340,10 +341,10 @@ void mapEventWithMandatoryFields() { Event expected = Event.builder() - .event(input.getEvent().getUid()) + .event(UID.of(input.getEvent().getUid())) .orgUnit(MetadataIdentifier.ofUid(input.getOrgUnit().getUid())) .programStage(MetadataIdentifier.ofUid(input.getProgramStage().getUid())) - .enrollment(input.getEnrollment().getUid()) + .enrollment(UID.of(input.getEnrollment().getUid())) .attributeOptionCombo( MetadataIdentifier.ofUid(input.getAttributeOptionCombo().getUid())) .status(EventStatus.COMPLETED) @@ -374,10 +375,10 @@ void mapEventWithOptionalFields() { Event expected = Event.builder() - .event(input.getEvent().getUid()) + .event(UID.of(input.getEvent().getUid())) .orgUnit(MetadataIdentifier.ofUid(input.getOrgUnit().getUid())) .programStage(MetadataIdentifier.ofUid(input.getProgramStage().getUid())) - .enrollment(input.getEnrollment().getUid()) + .enrollment(UID.of(input.getEnrollment().getUid())) .attributeOptionCombo( MetadataIdentifier.ofUid(input.getAttributeOptionCombo().getUid())) .status(EventStatus.ACTIVE) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/MessageFormatterTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/MessageFormatterTest.java index 77bb39afb9e7..a02b9124c9d4 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/MessageFormatterTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/MessageFormatterTest.java @@ -41,6 +41,7 @@ import org.hisp.dhis.attribute.AttributeValues; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -183,7 +184,8 @@ void formatArgumentsShouldTurnEnrollmentIntoArguments() { @Test void formatArgumentsShouldTurnEventIntoArguments() { List args = - MessageFormatter.formatArguments(idSchemes, Event.builder().event("zwccdzhk5zc").build()); + MessageFormatter.formatArguments( + idSchemes, Event.builder().event(UID.of("zwccdzhk5zc")).build()); assertContainsOnly(List.of("zwccdzhk5zc"), args); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java index ae5cef216dc3..d41df54e3b31 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java @@ -47,6 +47,7 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.test.utils.Assertions; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -482,7 +483,10 @@ Builder enrollment(String uid) { private static Entity enrollment(String uid, Entity parent) { // set child/parent links Enrollment enrollment = - Enrollment.builder().enrollment(uid).trackedEntity(parent.entity.getUid()).build(); + Enrollment.builder() + .enrollment(uid) + .trackedEntity(parent.entity.getUid().getValue()) + .build(); return new Entity<>(enrollment); } @@ -498,13 +502,13 @@ private static Entity enrollment(String uid, Entity p * @return builder */ Builder event(String uid) { - Entity entity = event(uid, currentEnrollment); + Entity entity = event(UID.of(uid), currentEnrollment); this.events.add(entity); current = entity; return this; } - private static Entity event(String uid, Entity parent) { + private static Entity event(UID uid, Entity parent) { // set child/parent links only if the event has a parent. Events in an event program have no // enrollment. // They do have a "fake" enrollment (a default program) but it's not set on the event DTO. @@ -567,7 +571,7 @@ private List toEntitiesInPayload(List> entit private Set invalid(List> entities) { return entities.stream() .filter(e -> !e.valid) - .map(e -> e.entity.getUid()) + .map(e -> e.entity.getStringUid()) .collect(Collectors.toSet()); } @@ -647,7 +651,7 @@ private static void assertContainsOnly( private static List persistableUids( PersistablesFilter.Result persistable, Class type) { - return persistable.get(type).stream().map(TrackerDto::getUid).toList(); + return persistable.get(type).stream().map(TrackerDto::getStringUid).toList(); } private static void assertHasError( @@ -667,7 +671,12 @@ public TrackerType getTrackerType() { } @Override - public String getUid() { + public UID getUid() { + return UID.of(uid); + } + + @Override + public String getStringUid() { return uid; } }; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AllTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AllTest.java index 66c440ca48dd..ba6e5db6e575 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AllTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AllTest.java @@ -38,6 +38,7 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -105,10 +106,12 @@ public boolean needsToRun(TrackerImportStrategy strategy) { @Test void testAllDoesNotCallValidatorIfItShouldNotRunOnGivenStrategyForATrackerDto() { + UID uid = UID.generate(); bundle = TrackerBundle.builder() .importStrategy(CREATE_AND_UPDATE) - .resolvedStrategyMap(new EnumMap<>(Map.of(TrackerType.EVENT, Map.of("event1", UPDATE)))) + .resolvedStrategyMap( + new EnumMap<>(Map.of(TrackerType.EVENT, Map.of(uid.getValue(), UPDATE)))) .build(); Validator validator = @@ -136,7 +139,7 @@ public boolean needsToRun(TrackerImportStrategy strategy) { } }); - validator.validate(reporter, bundle, Event.builder().event("event1").build()); + validator.validate(reporter, bundle, Event.builder().event(uid).build()); assertContainsOnly(List.of("V2"), actualErrorMessages()); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AssertValidations.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AssertValidations.java index 1d72fe230db7..4339cea3f03f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AssertValidations.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/AssertValidations.java @@ -73,7 +73,7 @@ public static void assertHasNoError(Reporter reporter, TrackerDto dto, Validatio } TrackerType type = dto.getTrackerType(); - String uid = dto.getUid(); + String uid = dto.getStringUid(); assertFalse( reporter.getErrors().stream() .anyMatch( @@ -132,7 +132,7 @@ private static void assertHasValidation( TrackerDto dto, ValidationCode code) { TrackerType type = dto.getTrackerType(); - String uid = dto.getUid(); + String uid = dto.getStringUid(); assertFalse( validations.isEmpty(), validationType + " not found since " + validationType + "s is empty"); @@ -155,7 +155,7 @@ private static void assertHasValidation( ValidationCode code, String messageContains) { TrackerType type = dto.getTrackerType(); - String uid = dto.getUid(); + String uid = dto.getStringUid(); assertFalse( validations.isEmpty(), validationType + " not found since " + validationType + "s is empty"); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/SeqTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/SeqTest.java index 94b9e5f41c23..634f8e71a2c0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/SeqTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/SeqTest.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.common.UID; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -182,10 +183,12 @@ public boolean needsToRun(TrackerImportStrategy strategy) { @Test void testSeqDoesNotCallValidatorsIfItShouldNotRunOnGivenStrategyForATrackerDto() { + UID uid = UID.generate(); bundle = TrackerBundle.builder() .importStrategy(CREATE_AND_UPDATE) - .resolvedStrategyMap(new EnumMap<>(Map.of(TrackerType.EVENT, Map.of("event1", UPDATE)))) + .resolvedStrategyMap( + new EnumMap<>(Map.of(TrackerType.EVENT, Map.of(uid.getValue(), UPDATE)))) .build(); Validator validator = @@ -213,7 +216,7 @@ public boolean needsToRun(TrackerImportStrategy strategy) { } }); - validator.validate(reporter, bundle, Event.builder().event("event1").build()); + validator.validate(reporter, bundle, Event.builder().event(uid).build()); assertContainsOnly(List.of("V2"), actualErrorMessages()); } @@ -255,8 +258,13 @@ private static void addError(Reporter reporter, String message) { private static TrackerDto dummyDto() { return new TrackerDto() { @Override - public String getUid() { - return "uid"; + public UID getUid() { + return UID.generate(); + } + + @Override + public String getStringUid() { + return ""; } @Override diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java index 734aa4c167e1..905172f52f69 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java @@ -39,7 +39,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.encryption.EncryptionStatus; import org.hisp.dhis.external.conf.DhisConfigurationProvider; @@ -132,9 +132,10 @@ public void setUp() { when(dhisConfigurationProvider.getEncryptionStatus()) .thenReturn(EncryptionStatus.MISSING_ENCRYPTION_PASSWORD); - String uid = CodeGenerator.generateUid(); + UID uid = UID.generate(); when(enrollment.getUid()).thenReturn(uid); - when(enrollment.getEnrollment()).thenReturn(uid); + when(enrollment.getStringUid()).thenReturn(uid.getValue()); + when(enrollment.getEnrollment()).thenReturn(uid.getValue()); when(enrollment.getTrackerType()).thenCallRealMethod(); enrollment.setTrackedEntity("trackedEntity"); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/ExistingEnrollmentValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/ExistingEnrollmentValidatorTest.java index d59a35776009..dd1a0acc97f9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/ExistingEnrollmentValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/ExistingEnrollmentValidatorTest.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.HashMap; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.EnrollmentStatus; import org.hisp.dhis.program.Program; @@ -75,7 +76,7 @@ class ExistingEnrollmentValidatorTest { private static final String TRACKED_ENTIT_UID = "trackedEntity"; - private static final String ENROLLMENT_UID = "enrollment"; + private static final UID ENROLLMENT_UID = UID.generate(); @BeforeEach public void setUp() { @@ -86,8 +87,9 @@ public void setUp() { when(enrollment.getProgram()).thenReturn(MetadataIdentifier.ofUid(PROGRAM_UID)); when(enrollment.getTrackedEntity()).thenReturn(TRACKED_ENTIT_UID); when(enrollment.getStatus()).thenReturn(EnrollmentStatus.ACTIVE); - when(enrollment.getEnrollment()).thenReturn(ENROLLMENT_UID); + when(enrollment.getEnrollment()).thenReturn(ENROLLMENT_UID.getValue()); when(enrollment.getUid()).thenReturn(ENROLLMENT_UID); + when(enrollment.getStringUid()).thenReturn(ENROLLMENT_UID.getValue()); when(enrollment.getTrackerType()).thenCallRealMethod(); when(preheat.getTrackedEntity(TRACKED_ENTIT_UID)).thenReturn(trackedEntity); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/UpdatableFieldsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/UpdatableFieldsValidatorTest.java index f0bc5d8427ca..aee219ce5ea6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/UpdatableFieldsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/UpdatableFieldsValidatorTest.java @@ -33,6 +33,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.program.Program; @@ -70,7 +71,7 @@ class UpdatableFieldsValidatorTest { private static final String ENROLLMENT_ID = "EnrollmentId"; - private static final String EVENT_ID = "EventId"; + private static final UID EVENT_UID = UID.generate(); private UpdatableFieldsValidator validator; @@ -95,7 +96,7 @@ public void setUp() { when(preheat.getTrackedEntity(TRACKED_ENTITY_ID)).thenReturn(trackedEntity()); when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(getEnrollment()); - when(preheat.getEvent(EVENT_ID)).thenReturn(event()); + when(preheat.getEvent(EVENT_UID)).thenReturn(event()); when(bundle.getPreheat()).thenReturn(preheat); @@ -168,7 +169,7 @@ private Event event() { programStage.setUid(PROGRAM_STAGE_ID); Event event = new Event(); - event.setUid(EVENT_ID); + event.setUid(EVENT_UID.getValue()); event.setEnrollment(getEnrollment()); event.setProgramStage(programStage); return event; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/AssignedUserValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/AssignedUserValidatorTest.java index 3df111d76d0d..c5cf6fa1e91b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/AssignedUserValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/AssignedUserValidatorTest.java @@ -34,7 +34,7 @@ import static org.hisp.dhis.tracker.imports.validation.validator.AssertValidations.assertHasWarning; import com.google.common.collect.Sets; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.test.TestBase; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; @@ -139,7 +139,7 @@ void testAssignedUserIsEmpty() { void testEventWithNotValidUsername() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setAssignedUser(INVALID_USER); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); @@ -154,7 +154,7 @@ void testEventWithNotValidUsername() { void testEventWithUserNotPresentInPreheat() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setAssignedUser(VALID_USER); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); @@ -173,7 +173,7 @@ void testEventWithUserNotPresentInPreheat() { void testEventWithNotEnabledUserAssignment() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setAssignedUser(VALID_USER); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); @@ -191,7 +191,7 @@ void testEventWithNotEnabledUserAssignment() { void testEventWithNullEnabledUserAssignment() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setAssignedUser(VALID_USER); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/CategoryOptValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/CategoryOptValidatorTest.java index e2020b989cfb..d14d56e16805 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/CategoryOptValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/CategoryOptValidatorTest.java @@ -41,7 +41,7 @@ import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.i18n.I18nManager; import org.hisp.dhis.program.Program; @@ -127,7 +127,7 @@ public void setUp() { program.setCategoryCombo(catCombo); event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(program)); event.setOccurredAt(EVENT_INSTANT); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidatorTest.java index e4f30fcf68d6..4dc0a0bdf60f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataRelationsValidatorTest.java @@ -47,6 +47,7 @@ import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.DataDimensionType; +import org.hisp.dhis.common.UID; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Program; @@ -82,7 +83,7 @@ class DataRelationsValidatorTest extends TestBase { private static final String TE_TYPE_ID = "TE_TYPE_ID"; - private static final String ENROLLMENT_ID = "ENROLLMENT_ID"; + private static final UID ENROLLMENT_ID = UID.generate(); private DataRelationsValidator validator; @@ -112,13 +113,14 @@ void eventValidationSucceedsWhenAOCAndCOsAreNotSetAndProgramHasDefaultCC() { .thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID))); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID))) .thenReturn(programStage(PROGRAM_STAGE_ID, program)); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(enrollment(ENROLLMENT_ID, program)); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())) + .thenReturn(enrollment(ENROLLMENT_ID, program)); setUpDefaultCategoryCombo(program); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .program(MetadataIdentifier.ofUid(program)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) @@ -148,7 +150,8 @@ void eventValidationFailsWhenEventAndProgramStageProgramDontMatch() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) + .enrollment(ENROLLMENT_ID) .program(MetadataIdentifier.ofUid(program)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) @@ -175,7 +178,7 @@ void eventValidationFailsWhenProgramIsRegistrationAndEnrollmentIsMissing() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .program(MetadataIdentifier.ofUid(program)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) @@ -197,7 +200,7 @@ void eventValidationFailsWhenEventAndEnrollmentProgramDontMatch() { .thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID))); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID))) .thenReturn(programStage(PROGRAM_STAGE_ID, program)); - when(preheat.getEnrollment(ENROLLMENT_ID)) + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())) .thenReturn( enrollment( ENROLLMENT_ID, programWithRegistration(CodeGenerator.generateUid(), orgUnit))); @@ -206,7 +209,7 @@ void eventValidationFailsWhenEventAndEnrollmentProgramDontMatch() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .program(MetadataIdentifier.ofUid(program)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) @@ -232,13 +235,14 @@ void eventValidationFailsWhenEventAndProgramOrganisationUnitDontMatch() { PROGRAM_UID, Collections.singletonList(anotherOrgUnit.getUid()))); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID))) .thenReturn(programStage(PROGRAM_STAGE_ID, program)); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(enrollment(ENROLLMENT_ID, program)); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())) + .thenReturn(enrollment(ENROLLMENT_ID, program)); setUpDefaultCategoryCombo(program); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .program(MetadataIdentifier.ofUid(program)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) @@ -746,7 +750,7 @@ void eventOfProgramWithRegistrationInEnrollmentWithoutTrackedEntity() { Event event = eventBuilder().enrollment(ENROLLMENT_ID).build(); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(null); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())).thenReturn(null); validator.validate(reporter, bundle, event); @@ -765,13 +769,13 @@ void eventOfProgramWithRegistrationInEnrollmentWithTrackedEntityInBundle() { Event event = eventBuilder().enrollment(ENROLLMENT_ID).build(); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(null); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())).thenReturn(null); org.hisp.dhis.tracker.imports.domain.Enrollment e = new org.hisp.dhis.tracker.imports.domain.Enrollment(); e.setTrackedEntity(CodeGenerator.generateUid()); - when(bundle.findEnrollmentByUid(ENROLLMENT_ID)).thenReturn(Optional.of(e)); + when(bundle.findEnrollmentByUid(ENROLLMENT_ID.getValue())).thenReturn(Optional.of(e)); validator.validate(reporter, bundle, event); @@ -857,23 +861,23 @@ private ProgramStage programStage(String uid, Program program) { return programStage; } - private Enrollment enrollment(String uid, Program program) { + private Enrollment enrollment(UID uid, Program program) { Enrollment enrollment = enrollment(uid); enrollment.setProgram(program); enrollment.setTrackedEntity(new TrackedEntity()); return enrollment; } - private Enrollment enrollment(String uid, TrackedEntity trackedEntity) { + private Enrollment enrollment(UID uid, TrackedEntity trackedEntity) { Enrollment enrollment = new Enrollment(); - enrollment.setUid(uid); + enrollment.setUid(uid.getValue()); enrollment.setTrackedEntity(trackedEntity); return enrollment; } - private Enrollment enrollment(String uid) { + private Enrollment enrollment(UID uid) { Enrollment enrollment = new Enrollment(); - enrollment.setUid(uid); + enrollment.setUid(uid.getValue()); return enrollment; } @@ -884,7 +888,8 @@ private Program setupProgram(OrganisationUnit orgUnit) { .thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID))); when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID))) .thenReturn(programStage(PROGRAM_STAGE_ID, program)); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(enrollment(ENROLLMENT_ID, program)); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())) + .thenReturn(enrollment(ENROLLMENT_ID, program)); return program; } @@ -896,7 +901,7 @@ private Program setupProgram(OrganisationUnit orgUnit, Enrollment enrollment) { when(preheat.getProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID))) .thenReturn(programStage(PROGRAM_STAGE_ID, program)); enrollment.setProgram(program); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(enrollment); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())).thenReturn(enrollment); return program; } @@ -959,7 +964,7 @@ private CategoryOptionCombo firstCategoryOptionCombo(CategoryCombo categoryCombo private Event.EventBuilder eventBuilder() { return Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .program(MetadataIdentifier.ofUid(PROGRAM_UID)) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidatorTest.java index 3d887dea4d06..b2a0e9c99ac6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DataValuesValidatorTest.java @@ -36,7 +36,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.event.EventStatus; @@ -159,7 +159,7 @@ void failValidationWhenDataElementIsInvalid() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(dataValue())) @@ -194,7 +194,7 @@ void shouldFailValidationWhenAMandatoryDataElementIsMissingAndStrategyIsCreate() Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.COMPLETED) .dataValues(Set.of(dataValue())) @@ -245,7 +245,7 @@ void succeedsWhenMandatoryDataElementIsNotPresentButMandatoryValidationIsNotNeed void shouldPassValidationWhenAMandatoryDataElementIsMissingAndDataValueIsAlreadyPresentInDB( EventStatus savedStatus, EventStatus newStatus) { DataElement dataElement = dataElement(); - String eventUid = CodeGenerator.generateUid(); + UID eventUid = UID.generate(); when(preheat.getDataElement(MetadataIdentifier.ofUid(DATA_ELEMENT_UID))) .thenReturn(dataElement); @@ -286,7 +286,7 @@ void shouldPassValidationWhenAMandatoryDataElementIsMissingAndDataValueIsAlready void shouldFailValidationWhenAMandatoryDataElementIsMissingAndDataValuesAreCreated( EventStatus savedStatus, EventStatus newStatus) { DataElement dataElement = dataElement(); - String eventUid = CodeGenerator.generateUid(); + UID eventUid = UID.generate(); when(preheat.getDataElement(MetadataIdentifier.ofUid(DATA_ELEMENT_UID))) .thenReturn(dataElement); @@ -380,7 +380,7 @@ void failValidationWhenDataElementIsNotPresentInProgramStage() { notPresentDataValue.setDataElement(MetadataIdentifier.ofUid("de_not_present_in_program_stage")); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.ACTIVE) .dataValues(Set.of(dataValue(), notPresentDataValue)) @@ -440,7 +440,7 @@ void failValidationWhenFileResourceIsNull() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(validDataValue)) @@ -492,7 +492,7 @@ void failValidationWhenFileResourceValueIsNullAndDataElementIsCompulsory() { validDataValue.setValue(null); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.COMPLETED) .dataValues(Set.of(validDataValue)) @@ -518,7 +518,7 @@ void shouldFailValidationWhenDataElementValueNullAndStrategyCreate() { validDataValue.setValue(null); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.ACTIVE) .dataValues(Set.of(validDataValue)) @@ -532,7 +532,7 @@ void shouldFailValidationWhenDataElementValueNullAndStrategyCreate() { @Test void shouldFailValidationWhenDataElementValueNullAndStrategyUpdate() { DataElement validDataElement = dataElement(); - String eventUid = CodeGenerator.generateUid(); + UID eventUid = UID.generate(); when(preheat.getDataElement(MetadataIdentifier.ofUid(DATA_ELEMENT_UID))) .thenReturn(validDataElement); @@ -572,7 +572,7 @@ void failsOnCompletedEventWithDataElementValueNullAndValidationStrategyOnUpdate( validDataValue.setValue(null); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.COMPLETED) .dataValues(Set.of(validDataValue)) @@ -623,7 +623,7 @@ void failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnCompl validDataValue.setValue(null); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.COMPLETED) .dataValues(Set.of(validDataValue)) @@ -648,7 +648,7 @@ void shouldFailWhenScheduledEventHasDataValueDefined() { validDataValue.setValue("1"); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SCHEDULE) .dataValues(Set.of(validDataValue)) @@ -673,7 +673,7 @@ void shouldFailValidationWhenSkippedEventHasDataValueDefined() { validDataValue.setValue("1"); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(validDataValue)) @@ -698,7 +698,7 @@ void shouldFailValidationWhenOverdueEventHasDataValueDefined() { validDataValue.setValue("1"); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.OVERDUE) .dataValues(Set.of(validDataValue)) @@ -749,7 +749,7 @@ void failValidationWhenFileResourceIsAlreadyAssigned() { when(preheat.get(FileResource.class, validDataValue.getValue())).thenReturn(fileResource); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.ACTIVE) .dataValues(Set.of(validDataValue)) @@ -786,7 +786,7 @@ void validateFileResourceOwner() { when(preheat.get(FileResource.class, validDataValue.getValue())).thenReturn(fileResource); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.ACTIVE) .dataValues(Set.of(validDataValue)) @@ -798,8 +798,9 @@ void validateFileResourceOwner() { assertHasError(reporter, event, ValidationCode.E1009); - event.setEvent("XYZ"); - fileResource.setFileResourceOwner("ABC"); + event.setEvent(UID.generate()); + UID uid = UID.generate(); + fileResource.setFileResourceOwner(uid.getValue()); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.UPDATE); @@ -809,8 +810,8 @@ void validateFileResourceOwner() { assertHasError(reporter, event, ValidationCode.E1009); - event.setEvent("ABC"); - fileResource.setFileResourceOwner("ABC"); + event.setEvent(uid); + fileResource.setFileResourceOwner(uid.getValue()); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.UPDATE); @@ -894,7 +895,7 @@ void failValidationDataElementOptionValueIsInValid() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(validDataValue)) @@ -961,7 +962,7 @@ void failValidationDataElementMultiTextOptionValueIsInValid() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(validDataValue)) @@ -987,7 +988,7 @@ void failValidationWhenOrgUnitValueIsInvalid() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.ACTIVE) .dataValues(Set.of(invalidDataValue)) @@ -1039,7 +1040,7 @@ private void runAndAssertValidationForDataValue(ValueType valueType, String valu validDataValue.setValue(value); Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(idSchemes.toMetadataIdentifier(programStage)) .status(EventStatus.SKIPPED) .dataValues(Set.of(validDataValue)) @@ -1051,10 +1052,9 @@ private void runAndAssertValidationForDataValue(ValueType valueType, String valu assertHasError(reporter, event, ValidationCode.E1302); } - private org.hisp.dhis.program.Event event( - String uid, EventStatus status, Set dataElements) { + private org.hisp.dhis.program.Event event(UID uid, EventStatus status, Set dataElements) { org.hisp.dhis.program.Event event = new org.hisp.dhis.program.Event(); - event.setUid(uid); + event.setUid(uid.getValue()); event.setStatus(status); event.setEventDataValues( dataElements.stream() @@ -1063,9 +1063,9 @@ private org.hisp.dhis.program.Event event( return event; } - private org.hisp.dhis.program.Event event(String uid, EventStatus status) { + private org.hisp.dhis.program.Event event(UID uid, EventStatus status) { org.hisp.dhis.program.Event event = new org.hisp.dhis.program.Event(); - event.setUid(uid); + event.setUid(uid.getValue()); event.setStatus(status); return event; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DateValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DateValidatorTest.java index 52eca791b667..c19ac6febbc3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DateValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/DateValidatorTest.java @@ -40,7 +40,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.period.DailyPeriodType; import org.hisp.dhis.program.Program; @@ -111,7 +111,7 @@ void testEventIsNotValidWhenOccurredDateIsNotPresentAndProgramIsWithoutRegistrat when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITHOUT_REGISTRATION_ID))) .thenReturn(getProgramWithoutRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITHOUT_REGISTRATION_ID)); // when @@ -127,7 +127,7 @@ void testEventIsNotValidWhenOccurredDateIsNotPresentAndEventIsActive() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setStatus(EventStatus.ACTIVE); @@ -144,7 +144,7 @@ void testEventIsNotValidWhenOccurredDateIsNotPresentAndEventIsCompleted() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setStatus(EventStatus.COMPLETED); @@ -161,7 +161,7 @@ void testEventIsNotValidWhenScheduledDateIsNotPresentAndEventIsSchedule() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setOccurredAt(Instant.now()); event.setStatus(EventStatus.SCHEDULE); @@ -179,7 +179,7 @@ void shouldFailWhenCompletedAtIsPresentAndStatusIsNotCompleted() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setOccurredAt(now()); event.setCompletedAt(now()); @@ -196,7 +196,7 @@ void testEventIsNotValidWhenCompletedAtIsTooSoonAndEventIsCompleted() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setOccurredAt(now()); event.setCompletedAt(sevenDaysAgo()); @@ -215,7 +215,7 @@ void testEventIsNotValidWhenOccurredAtAndScheduledAtAreNotPresent() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setOccurredAt(null); event.setScheduledAt(null); @@ -234,7 +234,7 @@ void testEventIsNotValidWhenDateBelongsToExpiredPeriod() { when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID))) .thenReturn(getProgramWithRegistration()); Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgram(MetadataIdentifier.ofUid(PROGRAM_WITH_REGISTRATION_ID)); event.setOccurredAt(sevenDaysAgo()); event.setStatus(EventStatus.ACTIVE); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/ExistenceValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/ExistenceValidatorTest.java index 2b3a195e0fb0..2c4bfd585a5b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/ExistenceValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/ExistenceValidatorTest.java @@ -35,6 +35,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Event; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -52,11 +53,11 @@ */ @ExtendWith(MockitoExtension.class) class ExistenceValidatorTest { - private static final String SOFT_DELETED_EVENT_UID = "SoftDeletedEventId"; + private static final UID SOFT_DELETED_EVENT_UID = UID.generate(); - private static final String EVENT_UID = "EventId"; + private static final UID EVENT_UID = UID.generate(); - private static final String NOT_PRESENT_EVENT_UID = "NotPresentEventId"; + private static final UID NOT_PRESENT_EVENT_UID = UID.generate(); @Mock private TrackerBundle bundle; @@ -150,14 +151,14 @@ void verifyEventValidationFailsWhenIsUpdateAndEventIsNotPresent() { private Event getSoftDeletedEvent() { Event event = new Event(); - event.setUid(SOFT_DELETED_EVENT_UID); + event.setUid(SOFT_DELETED_EVENT_UID.getValue()); event.setDeleted(true); return event; } private Event getEvent() { Event event = new Event(); - event.setUid(EVENT_UID); + event.setUid(EVENT_UID.getValue()); event.setDeleted(false); return event; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/GeoValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/GeoValidatorTest.java index ea1f4f5af93c..ef07e678158e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/GeoValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/GeoValidatorTest.java @@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.organisationunit.FeatureType; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; @@ -116,7 +116,7 @@ void testEventWithNoProgramStageThrowsAnError() { void testProgramStageWithNullFeatureTypeFailsGeometryValidation() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); event.setGeometry(new GeometryFactory().createPoint()); @@ -133,7 +133,7 @@ void testProgramStageWithNullFeatureTypeFailsGeometryValidation() { void testProgramStageWithFeatureTypeNoneFailsGeometryValidation() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); event.setGeometry(new GeometryFactory().createPoint()); @@ -152,7 +152,7 @@ void testProgramStageWithFeatureTypeNoneFailsGeometryValidation() { void testProgramStageWithFeatureTypeDifferentFromGeometryFails() { // given Event event = new Event(); - event.setEvent(CodeGenerator.generateUid()); + event.setEvent(UID.generate()); event.setProgramStage(MetadataIdentifier.ofUid(PROGRAM_STAGE)); event.setGeometry(new GeometryFactory().createPoint()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MandatoryFieldsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MandatoryFieldsValidatorTest.java index 3986b19849ba..df2106abd0e8 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MandatoryFieldsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MandatoryFieldsValidatorTest.java @@ -36,6 +36,7 @@ import static org.mockito.Mockito.when; import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; @@ -87,7 +88,7 @@ public void setUp() { void verifyEventValidationSuccess() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .programStage(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .program(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) @@ -102,7 +103,7 @@ void verifyEventValidationSuccess() { void verifyEventValidationFailsOnMissingProgram() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .programStage(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .program(MetadataIdentifier.EMPTY_UID) @@ -117,7 +118,7 @@ void verifyEventValidationFailsOnMissingProgram() { void verifyEventValidationFailsOnMissingProgramStageReferenceToProgram() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .programStage(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .build(); @@ -136,7 +137,7 @@ void verifyEventValidationFailsOnMissingProgramStageReferenceToProgram() { void verifyEventValidationFailsOnMissingProgramStage() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .programStage(MetadataIdentifier.EMPTY_UID) .program(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) @@ -151,7 +152,7 @@ void verifyEventValidationFailsOnMissingProgramStage() { void verifyEventValidationFailsOnMissingOrgUnit() { Event event = Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .orgUnit(MetadataIdentifier.EMPTY_UID) .programStage(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) .program(MetadataIdentifier.ofUid(CodeGenerator.generateUid())) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MetaValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MetaValidatorTest.java index c5238fda4359..761016a554df 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MetaValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/MetaValidatorTest.java @@ -34,7 +34,7 @@ import static org.hisp.dhis.tracker.imports.validation.validator.AssertValidations.assertHasError; import static org.mockito.Mockito.when; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; @@ -137,7 +137,7 @@ void verifyEventValidationFailsWhenOrgUnitIsNotPresentInDb() { private Event validEvent() { return Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_UID)) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_UID)) .program(MetadataIdentifier.ofUid(PROGRAM_UID)) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidatorTest.java index 6775b9626990..55bd634de406 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/RepeatedEventsValidatorTest.java @@ -35,8 +35,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.when; -import com.google.common.collect.Lists; import java.util.List; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; @@ -71,9 +71,9 @@ class RepeatedEventsValidatorTest extends TestBase { private static final String NOT_REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION = "NOT_REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION"; - private static final String ENROLLMENT_A = "ENROLLMENT_A"; + private static final UID ENROLLMENT_A = UID.generate(); - private static final String ENROLLMENT_B = "ENROLLMENT_B"; + private static final UID ENROLLMENT_B = UID.generate(); private RepeatedEventsValidator validator; @@ -99,7 +99,7 @@ void testSingleEventIsPassingValidation() { when(preheat.getProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithRegistration()); - List events = Lists.newArrayList(notRepeatableEvent("A")); + List events = List.of(notRepeatableEvent()); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); @@ -114,17 +114,18 @@ void testOneEventInNotRepeatableProgramStageAndOneAlreadyOnDBAreNotPassingValida MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithRegistration()); // given - Event event = notRepeatableEvent("A"); + Event event = notRepeatableEvent(); Enrollment enrollment = new Enrollment(); - enrollment.setUid(event.getEnrollment()); + enrollment.setUid(event.getEnrollment().getValue()); // when bundle.setStrategy(event, TrackerImportStrategy.CREATE); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); - when(preheat.hasProgramStageWithEvents(event.getProgramStage(), event.getEnrollment())) + when(preheat.getEnrollment(event.getEnrollment().getValue())).thenReturn(enrollment); + when(preheat.hasProgramStageWithEvents( + event.getProgramStage(), event.getEnrollment().getValue())) .thenReturn(true); - bundle.setEvents(Lists.newArrayList(event)); + bundle.setEvents(List.of(event)); validator.validate(reporter, bundle, bundle.getEvents()); @@ -143,7 +144,7 @@ void testTwoEventInNotRepeatableProgramStageAreNotPassingValidation() { when(preheat.getProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithRegistration()); - List events = Lists.newArrayList(notRepeatableEvent("A"), notRepeatableEvent("B")); + List events = List.of(notRepeatableEvent(), notRepeatableEvent()); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); @@ -173,7 +174,7 @@ void testTwoEventInRepeatableProgramStageArePassingValidation() { when(preheat.getProgramStage( MetadataIdentifier.ofUid(REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(repeatebleProgramStageWithRegistration()); - List events = Lists.newArrayList(repeatableEvent("A"), repeatableEvent("B")); + List events = List.of(repeatableEvent(), repeatableEvent()); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); @@ -187,12 +188,13 @@ void testTwoEventsInNotRepeatableProgramStageWhenOneIsInvalidArePassingValidatio when(preheat.getProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithRegistration()); - Event invalidEvent = notRepeatableEvent("A"); - List events = Lists.newArrayList(invalidEvent, notRepeatableEvent("B")); + Event invalidEvent = notRepeatableEvent(); + List events = List.of(invalidEvent, notRepeatableEvent()); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); reporter.addError( - new Error("", E9999, invalidEvent.getTrackerType(), invalidEvent.getUid(), List.of())); + new Error( + "", E9999, invalidEvent.getTrackerType(), invalidEvent.getUid().getValue(), List.of())); validator.validate(reporter, bundle, bundle.getEvents()); @@ -204,10 +206,10 @@ void testTwoEventsInNotRepeatableProgramStageButInDifferentEnrollmentsArePassing when(preheat.getProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithRegistration()); - Event eventEnrollmentA = notRepeatableEvent("A"); - Event eventEnrollmentB = notRepeatableEvent("B"); + Event eventEnrollmentA = notRepeatableEvent(); + Event eventEnrollmentB = notRepeatableEvent(); eventEnrollmentB.setEnrollment(ENROLLMENT_B); - List events = Lists.newArrayList(eventEnrollmentA, eventEnrollmentB); + List events = List.of(eventEnrollmentA, eventEnrollmentB); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); @@ -221,9 +223,9 @@ void testTwoProgramEventsInSameProgramStageArePassingValidation() { when(preheat.getProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION))) .thenReturn(notRepeatebleProgramStageWithoutRegistration()); - Event eventProgramA = programEvent("A"); - Event eventProgramB = programEvent("B"); - List events = Lists.newArrayList(eventProgramA, eventProgramB); + Event eventProgramA = programEvent(); + Event eventProgramB = programEvent(); + List events = List.of(eventProgramA, eventProgramB); bundle.setEvents(events); events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE)); @@ -265,25 +267,26 @@ private Program programWithoutRegistration() { return program; } - private Event programEvent(String uid) { + private Event programEvent() { Event event = new Event(); - event.setEvent(uid); + event.setEvent(UID.generate()); + event.setEnrollment(ENROLLMENT_B); event.setProgramStage( MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION)); return event; } - private Event notRepeatableEvent(String uid) { + private Event notRepeatableEvent() { Event event = new Event(); - event.setEvent(uid); + event.setEvent(UID.generate()); event.setEnrollment(ENROLLMENT_A); event.setProgramStage(MetadataIdentifier.ofUid(NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION)); return event; } - private Event repeatableEvent(String uid) { + private Event repeatableEvent() { Event event = new Event(); - event.setEvent(uid); + event.setEvent(UID.generate()); event.setEnrollment(ENROLLMENT_A); event.setProgramStage(MetadataIdentifier.ofUid(REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION)); return event; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java index 0e49d0309a3f..fdd7894ff4fc 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/SecurityOwnershipValidatorTest.java @@ -38,8 +38,7 @@ import com.google.common.collect.Sets; import java.util.Collections; import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Enrollment; @@ -147,7 +146,7 @@ private UserDetails changeCompletedEventAuthorisedUser() { @Test void verifyValidationSuccessForEventUsingDeleteStrategy() { - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() .enrollment(enrollmentUid) @@ -163,7 +162,6 @@ void verifyValidationSuccessForEventUsingDeleteStrategy() { preheatEvent.setEnrollment(enrollment); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); UserDetails userDetails = setUpUserWithOrgUnit(); when(aclService.canDataRead(userDetails, program.getTrackedEntityType())).thenReturn(true); @@ -178,7 +176,7 @@ void verifyValidationSuccessForEventUsingDeleteStrategy() { @Test void verifyValidationSuccessForNonTrackerEventUsingCreateStrategy() { program.setProgramType(ProgramType.WITHOUT_REGISTRATION); - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() .enrollment(enrollmentUid) @@ -208,7 +206,7 @@ void verifyValidationSuccessForNonTrackerEventUsingCreateStrategy() { void verifyValidationSuccessForTrackerEventCreation() { org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .enrollment(CodeGenerator.generateUid()) + .enrollment(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) .program(MetadataIdentifier.ofUid(PROGRAM_ID)) @@ -217,7 +215,7 @@ void verifyValidationSuccessForTrackerEventCreation() { when(bundle.getPreheat()).thenReturn(preheat); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(programStage); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(getEnrollment(null)); + when(preheat.getEnrollment(event.getEnrollment().getValue())).thenReturn(getEnrollment(null)); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_ID))).thenReturn(program); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID))) .thenReturn(organisationUnit); @@ -235,7 +233,7 @@ void verifyValidationSuccessForTrackerEventCreation() { void verifyValidationSuccessForTrackerEventUpdate() { org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .enrollment(CodeGenerator.generateUid()) + .enrollment(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) .program(MetadataIdentifier.ofUid(PROGRAM_ID)) @@ -244,7 +242,7 @@ void verifyValidationSuccessForTrackerEventUpdate() { when(bundle.getPreheat()).thenReturn(preheat); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(programStage); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(getEnrollment(null)); + when(preheat.getEnrollment(event.getEnrollment().getValue())).thenReturn(getEnrollment(null)); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_ID))).thenReturn(program); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID))) .thenReturn(organisationUnit); @@ -260,7 +258,7 @@ void verifyValidationSuccessForTrackerEventUpdate() { @Test void verifyValidationSuccessForEventUsingUpdateStrategy() { - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() .enrollment(enrollmentUid) @@ -277,7 +275,6 @@ void verifyValidationSuccessForEventUsingUpdateStrategy() { Event preheatEvent = getEvent(); preheatEvent.setEnrollment(enrollment); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true); when(aclService.canDataRead(user, program)).thenReturn(true); @@ -290,8 +287,8 @@ void verifyValidationSuccessForEventUsingUpdateStrategy() { @Test void verifyValidationSuccessForEventUsingUpdateStrategyOutsideCaptureScopeWithBrokenGlass() { - String enrollmentUid = CodeGenerator.generateUid(); - String eventUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); + UID eventUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() .event(eventUid) @@ -309,7 +306,6 @@ void verifyValidationSuccessForEventUsingUpdateStrategyOutsideCaptureScopeWithBr Event preheatEvent = getEvent(); preheatEvent.setEnrollment(enrollment); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); when(preheat.getProgramOwner()) .thenReturn( Collections.singletonMap( @@ -337,7 +333,7 @@ void verifyValidationSuccessForEventUsingUpdateStrategyOutsideCaptureScopeWithBr @Test void verifyValidationSuccessForEventUsingUpdateStrategyAndUserWithAuthority() { - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() .enrollment(enrollmentUid) @@ -355,7 +351,6 @@ void verifyValidationSuccessForEventUsingUpdateStrategyAndUserWithAuthority() { preheatEvent.setEnrollment(enrollment); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); when(aclService.canDataRead(userDetails, program.getTrackedEntityType())).thenReturn(true); when(aclService.canDataRead(userDetails, program)).thenReturn(true); @@ -370,8 +365,8 @@ void verifyValidationSuccessForEventUsingUpdateStrategyAndUserWithAuthority() { void verifyValidationFailsForTrackerEventCreationAndUserNotInOrgUnitCaptureScope() { org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .event(CodeGenerator.generateUid()) - .enrollment(CodeGenerator.generateUid()) + .event(UID.generate()) + .enrollment(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) .program(MetadataIdentifier.ofUid(PROGRAM_ID)) @@ -380,7 +375,7 @@ void verifyValidationFailsForTrackerEventCreationAndUserNotInOrgUnitCaptureScope when(bundle.getPreheat()).thenReturn(preheat); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(programStage); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(getEnrollment(null)); + when(preheat.getEnrollment(event.getEnrollment().getValue())).thenReturn(getEnrollment(null)); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_ID))).thenReturn(program); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID))) .thenReturn(organisationUnit); @@ -398,8 +393,8 @@ void verifyValidationFailsForTrackerEventCreationAndUserNotInOrgUnitCaptureScope verifyValidationFailsForEventCreationThatIsCreatableInSearchScopeAndUserNotInOrgUnitSearchHierarchy() { org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .event(CodeGenerator.generateUid()) - .enrollment(CodeGenerator.generateUid()) + .event(UID.generate()) + .enrollment(UID.generate()) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) .program(MetadataIdentifier.ofUid(PROGRAM_ID)) @@ -409,7 +404,7 @@ void verifyValidationFailsForTrackerEventCreationAndUserNotInOrgUnitCaptureScope when(bundle.getPreheat()).thenReturn(preheat); when(bundle.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(programStage); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(getEnrollment(null)); + when(preheat.getEnrollment(event.getEnrollment().getValue())).thenReturn(getEnrollment(null)); when(preheat.getProgram(MetadataIdentifier.ofUid(PROGRAM_ID))).thenReturn(program); when(preheat.getOrganisationUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID))) .thenReturn(organisationUnit); @@ -424,10 +419,10 @@ void verifyValidationFailsForTrackerEventCreationAndUserNotInOrgUnitCaptureScope @Test void verifyValidationFailsForEventUsingUpdateStrategyAndUserWithoutAuthority() { - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .enrollment(enrollmentUid) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) @@ -440,7 +435,6 @@ void verifyValidationFailsForEventUsingUpdateStrategyAndUserWithoutAuthority() { Event preheatEvent = getEvent(); preheatEvent.setEnrollment(enrollment); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true); when(aclService.canDataRead(user, program)).thenReturn(true); @@ -453,10 +447,10 @@ void verifyValidationFailsForEventUsingUpdateStrategyAndUserWithoutAuthority() { @Test void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() { - String enrollmentUid = CodeGenerator.generateUid(); + UID enrollmentUid = UID.generate(); org.hisp.dhis.tracker.imports.domain.Event event = org.hisp.dhis.tracker.imports.domain.Event.builder() - .event(CodeGenerator.generateUid()) + .event(UID.generate()) .enrollment(enrollmentUid) .orgUnit(MetadataIdentifier.ofUid(ORG_UNIT_ID)) .programStage(MetadataIdentifier.ofUid(PS_ID)) @@ -473,7 +467,6 @@ void verifySuccessEventValidationWhenEventHasNoOrgUnitAssigned() { preheatEvent.setOrganisationUnit(null); when(preheat.getEvent(event.getEvent())).thenReturn(preheatEvent); - when(preheat.getEnrollment(event.getEnrollment())).thenReturn(enrollment); when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true); when(aclService.canDataRead(user, program)).thenReturn(true); @@ -493,12 +486,12 @@ private TrackedEntity teWithNoEnrollments() { return trackedEntity; } - private Enrollment getEnrollment(String enrollmentUid) { - if (StringUtils.isEmpty(enrollmentUid)) { - enrollmentUid = CodeGenerator.generateUid(); + private Enrollment getEnrollment(UID enrollmentUid) { + if (enrollmentUid == null) { + enrollmentUid = UID.generate(); } Enrollment enrollment = new Enrollment(); - enrollment.setUid(enrollmentUid); + enrollment.setUid(enrollmentUid.getValue()); enrollment.setOrganisationUnit(organisationUnit); enrollment.setTrackedEntity(teWithNoEnrollments()); enrollment.setProgram(program); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/StatusUpdateValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/StatusUpdateValidatorTest.java index d199905c3d75..b098b8565d75 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/StatusUpdateValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/StatusUpdateValidatorTest.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.when; import java.util.stream.Stream; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; @@ -63,7 +64,7 @@ class StatusUpdateValidatorTest { @Mock TrackerPreheat preheat; - private static final String EVENT_UID = "h4w96yEMlzO"; + private static final UID EVENT_UID = UID.generate(); @Mock private TrackerBundle bundle; @@ -84,7 +85,7 @@ public void setUp() { void shouldPassValidationWhenGoingFromStatusToStatus( EventStatus fromStatus, EventStatus toStatus) { org.hisp.dhis.program.Event savedEvent = new org.hisp.dhis.program.Event(); - savedEvent.setUid(EVENT_UID); + savedEvent.setUid(EVENT_UID.getValue()); savedEvent.setStatus(fromStatus); when(preheat.getEvent(EVENT_UID)).thenReturn(savedEvent); @@ -100,7 +101,7 @@ void shouldPassValidationWhenGoingFromStatusToStatus( void shouldFailValidationWhenGoingFromStatusToStatus( EventStatus fromStatus, EventStatus toStatus) { org.hisp.dhis.program.Event savedEvent = new org.hisp.dhis.program.Event(); - savedEvent.setUid(EVENT_UID); + savedEvent.setUid(EVENT_UID.getValue()); savedEvent.setStatus(fromStatus); when(preheat.getEvent(EVENT_UID)).thenReturn(savedEvent); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidatorTest.java deleted file mode 100644 index ee7e1497e255..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidatorTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.validation.validator.event; - -import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty; -import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1048; -import static org.hisp.dhis.tracker.imports.validation.validator.AssertValidations.assertHasError; - -import com.google.common.collect.Lists; -import org.hisp.dhis.common.CodeGenerator; -import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; -import org.hisp.dhis.tracker.imports.domain.Event; -import org.hisp.dhis.tracker.imports.domain.Note; -import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; -import org.hisp.dhis.tracker.imports.validation.Reporter; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * @author Enrico Colasante - */ -class UidValidatorTest { - - private static final String INVALID_UID = "InvalidUID"; - - private UidValidator validator; - - private TrackerBundle bundle; - - private Reporter reporter; - - @BeforeEach - void setUp() { - TrackerPreheat preheat = new TrackerPreheat(); - TrackerIdSchemeParams idSchemes = TrackerIdSchemeParams.builder().build(); - preheat.setIdSchemes(idSchemes); - reporter = new Reporter(idSchemes); - bundle = TrackerBundle.builder().preheat(preheat).build(); - - validator = new UidValidator(); - } - - @Test - void verifyEventValidationSuccess() { - Note note = Note.builder().note(CodeGenerator.generateUid()).build(); - Event event = - Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build(); - - validator.validate(reporter, bundle, event); - - assertIsEmpty(reporter.getErrors()); - } - - @Test - void verifyEventWithInvalidUidFails() { - Event event = Event.builder().event(INVALID_UID).build(); - - validator.validate(reporter, bundle, event); - - assertHasError(reporter, event, E1048); - } - - @Test - void verifyEventWithNoteWithInvalidUidFails() { - Note note = Note.builder().note(INVALID_UID).build(); - Event event = - Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build(); - - validator.validate(reporter, bundle, event); - - assertHasError(reporter, event, E1048); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidatorTest.java index 946c4e9cdb22..f0e411d19f5e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/event/UpdatableFieldsValidatorTest.java @@ -33,6 +33,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.program.Program; @@ -68,9 +69,9 @@ class UpdatableFieldsValidatorTest { private static final String TRACKED_ENTITY_ID = "TrackedEntityId"; - private static final String ENROLLMENT_ID = "EnrollmentId"; + private static final UID ENROLLMENT_ID = UID.generate(); - private static final String EVENT_ID = "EventId"; + private static final UID EVENT_UID = UID.generate(); private UpdatableFieldsValidator validator; @@ -94,8 +95,8 @@ public void setUp() { .thenReturn(TrackerImportStrategy.UPDATE); when(preheat.getTrackedEntity(TRACKED_ENTITY_ID)).thenReturn(trackedEntity()); - when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(getEnrollment()); - when(preheat.getEvent(EVENT_ID)).thenReturn(event()); + when(preheat.getEnrollment(ENROLLMENT_ID.getValue())).thenReturn(getEnrollment()); + when(preheat.getEvent(EVENT_UID)).thenReturn(event()); when(bundle.getPreheat()).thenReturn(preheat); @@ -124,7 +125,7 @@ void verifyEventValidationFailsWhenUpdateProgramStage() { @Test void verifyEventValidationFailsWhenUpdateEnrollment() { org.hisp.dhis.tracker.imports.domain.Event event = validEvent(); - event.setEnrollment("NewEnrollmentId"); + event.setEnrollment(UID.generate()); validator.validate(reporter, bundle, event); @@ -133,7 +134,7 @@ void verifyEventValidationFailsWhenUpdateEnrollment() { private org.hisp.dhis.tracker.imports.domain.Event validEvent() { return org.hisp.dhis.tracker.imports.domain.Event.builder() - .event(EVENT_ID) + .event(EVENT_UID) .programStage(MetadataIdentifier.ofUid(PROGRAM_STAGE_ID)) .enrollment(ENROLLMENT_ID) .build(); @@ -154,7 +155,7 @@ private Enrollment getEnrollment() { program.setUid(PROGRAM_ID); Enrollment enrollment = new Enrollment(); - enrollment.setUid(ENROLLMENT_ID); + enrollment.setUid(ENROLLMENT_ID.getValue()); enrollment.setProgram(program); enrollment.setTrackedEntity(trackedEntity()); return enrollment; @@ -165,7 +166,7 @@ private Event event() { programStage.setUid(PROGRAM_STAGE_ID); Event event = new Event(); - event.setUid(EVENT_ID); + event.setUid(EVENT_UID.getValue()); event.setEnrollment(getEnrollment()); event.setProgramStage(programStage); return event; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/UpdatableFieldsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/UpdatableFieldsValidatorTest.java index 4ebd4b9b04ae..adec8150ecbd 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/UpdatableFieldsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/UpdatableFieldsValidatorTest.java @@ -33,6 +33,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.program.Program; @@ -70,7 +71,7 @@ class UpdatableFieldsValidatorTest { private static final String ENROLLMENT_ID = "EnrollmentId"; - private static final String EVENT_ID = "EventId"; + private static final UID EVENT_UID = UID.generate(); private UpdatableFieldsValidator validator; @@ -95,7 +96,7 @@ public void setUp() { when(preheat.getTrackedEntity(TRACKED_ENTITY_ID)).thenReturn(trackedEntity()); when(preheat.getEnrollment(ENROLLMENT_ID)).thenReturn(getEnrollment()); - when(preheat.getEvent(EVENT_ID)).thenReturn(event()); + when(preheat.getEvent(EVENT_UID)).thenReturn(event()); when(bundle.getPreheat()).thenReturn(preheat); @@ -154,7 +155,7 @@ private Event event() { programStage.setUid(PROGRAM_STAGE_ID); Event event = new Event(); - event.setUid(EVENT_ID); + event.setUid(EVENT_UID.getValue()); event.setEnrollment(getEnrollment()); event.setProgramStage(programStage); return event; diff --git a/dhis-2/dhis-support/dhis-support-test/src/test/java/org/hisp/test/utils/RelationshipUtilsTest.java b/dhis-2/dhis-support/dhis-support-test/src/test/java/org/hisp/test/utils/RelationshipUtilsTest.java index a2eaa33e7d59..1d85670270a3 100644 --- a/dhis-2/dhis-support/dhis-support-test/src/test/java/org/hisp/test/utils/RelationshipUtilsTest.java +++ b/dhis-2/dhis-support/dhis-support-test/src/test/java/org/hisp/test/utils/RelationshipUtilsTest.java @@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import org.hisp.dhis.common.UID; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Event; import org.hisp.dhis.relationship.Relationship; @@ -46,7 +47,7 @@ class RelationshipUtilsTest { private static final String ENROLLMENT_UID = "ENROLLMENT_UID"; - private static final String EVENT_UID = "EVENT_UID"; + private static final UID EVENT_UID = UID.generate(); private static final String RELATIONSHIP_TYPE_UID = "RELATIONSHIP_TYPE_UID"; @@ -67,7 +68,7 @@ void setup() { enrollmentA = new Enrollment(); enrollmentA.setUid(ENROLLMENT_UID); eventA = new Event(); - eventA.setUid(EVENT_UID); + eventA.setUid(EVENT_UID.getValue()); relationshipType = new RelationshipType(); relationshipType.setUid(RELATIONSHIP_TYPE_UID); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java index 15038d64abc3..7a77e454a9f4 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityServiceTest.java @@ -111,7 +111,7 @@ void testDeleteTrackedEntityAndLinkedEnrollmentsAndEvents() throws NotFoundExcep manager.update(trackedEntityA1); TrackedEntity trackedEntityA = manager.get(TrackedEntity.class, trackedEntityA1.getUid()); assertNotNull(trackedEntityA); - trackerObjectDeletionService.deleteTrackedEntities(List.of(trackedEntityA.getUid())); + trackerObjectDeletionService.deleteTrackedEntities(List.of(UID.of(trackedEntityA))); assertNull(manager.get(TrackedEntity.class, trackedEntityA.getUid())); } 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 dc82ee7a0735..8e3dbb5de456 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 @@ -193,7 +193,7 @@ private TrackedEntity createTrackedEntity(TrackedEntityAttribute trackedEntityAt } private void removeTrackedEntity(TrackedEntity trackedEntity) throws NotFoundException { - trackerObjectDeletionService.deleteTrackedEntities(List.of(trackedEntity.getUid())); + trackerObjectDeletionService.deleteTrackedEntities(List.of(UID.of(trackedEntity))); } private Relationship getRelationship(String uid) { diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventChangeLogServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventChangeLogServiceTest.java index 21165176155a..0f5e7e43031a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventChangeLogServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventChangeLogServiceTest.java @@ -117,7 +117,7 @@ void shouldFailWhenEventDoesNotExist() { @Test void shouldFailWhenEventIsSoftDeleted() throws NotFoundException { - trackerObjectDeletionService.deleteEvents(List.of("D9PbzJY8bJM")); + trackerObjectDeletionService.deleteEvents(List.of(UID.of("D9PbzJY8bJM"))); assertThrows( NotFoundException.class, @@ -272,7 +272,7 @@ private void updateDataValue(String event, String dataElementUid, String newValu throws IOException { TrackerObjects trackerObjects = fromJson("tracker/event_and_enrollment.json"); trackerObjects.getEvents().stream() - .filter(e -> e.getEvent().equalsIgnoreCase(event)) + .filter(e -> e.getEvent().getValue().equalsIgnoreCase(event)) .findFirst() .flatMap( e -> 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 ac1115bc31c3..def546289b75 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,7 +37,6 @@ 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; @@ -83,7 +82,7 @@ void shouldCorrectlyPopulateCompletedDataWhenCreatingAnEnrollment(EnrollmentStat assertNoErrors(importReport); Enrollment enrollment = - enrollmentService.getEnrollment(UID.of(trackerObjects.getEnrollments().get(0).getUid())); + enrollmentService.getEnrollment(trackerObjects.getEnrollments().get(0).getUid()); assertEnrollmentCompletedData(enrollment); } @@ -107,7 +106,7 @@ void shouldCorrectlyPopulateCompletedDataWhenUpdatingAnEnrollment( assertNoErrors(importReport); Enrollment enrollment = - enrollmentService.getEnrollment(UID.of(trackerObjects.getEnrollments().get(0).getUid())); + enrollmentService.getEnrollment(trackerObjects.getEnrollments().get(0).getUid()); assertEnrollmentCompletedData(enrollment); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventImportTest.java index 56e9c9d309fc..1d253dce4190 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventImportTest.java @@ -34,7 +34,6 @@ import java.io.IOException; import java.util.stream.Stream; -import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -76,7 +75,7 @@ void shouldPopulateCompletedDataWhenCreatingAnEventWithStatusCompleted() importTracker(params, trackerObjects); - Event event = eventService.getEvent(UID.of(trackerObjects.getEvents().get(0).getUid())); + Event event = eventService.getEvent(trackerObjects.getEvents().get(0).getUid()); assertEquals(importUser.getUsername(), event.getCompletedBy()); assertNotNull(event.getCompletedDate()); @@ -92,7 +91,7 @@ void shouldNotPopulateCompletedDataWhenCreatingAnEventWithNotCompletedStatus(Eve importTracker(params, trackerObjects); - Event event = eventService.getEvent(UID.of(trackerObjects.getEvents().get(0).getUid())); + Event event = eventService.getEvent(trackerObjects.getEvents().get(0).getUid()); assertNull(event.getCompletedBy()); assertNull(event.getCompletedDate()); @@ -111,7 +110,7 @@ void shouldDeleteCompletedDataWhenUpdatingAnEventWithStatusActive() importTracker(params, trackerObjects); - Event event = eventService.getEvent(UID.of(trackerObjects.getEvents().get(0).getUid())); + Event event = eventService.getEvent(trackerObjects.getEvents().get(0).getUid()); assertNull(event.getCompletedBy()); assertNull(event.getCompletedDate()); @@ -131,7 +130,7 @@ void shouldPopulateCompletedDataWhenUpdatingAnEventWithStatusCompleted(EventStat importTracker(params, trackerObjects); - Event event = eventService.getEvent(UID.of(trackerObjects.getEvents().get(0).getUid())); + Event event = eventService.getEvent(trackerObjects.getEvents().get(0).getUid()); assertEquals(importUser.getUsername(), event.getCompletedBy()); assertNotNull(event.getCompletedDate()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java index a158032322ce..1148b07fe2ec 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java @@ -38,6 +38,7 @@ import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.SoftDeletableObject; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dbms.DbmsManager; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Enrollment; @@ -465,7 +466,7 @@ private org.hisp.dhis.tracker.imports.domain.Event importEventProgram() throws I TrackerObjects trackerObjects = fromJson("tracker/single_event.json"); org.hisp.dhis.tracker.imports.domain.Event ev = trackerObjects.getEvents().get(0); ev.setEnrollment(null); - ev.setEvent(CodeGenerator.generateUid()); + ev.setEvent(UID.generate()); // set event program and program stage ev.setProgramStage(MetadataIdentifier.of(TrackerIdScheme.UID, "NpsdDv6kKSe", null)); ev.setProgram(MetadataIdentifier.of(TrackerIdScheme.UID, "BFcipDERJne", null)); @@ -496,19 +497,19 @@ void clearSession() { } Enrollment getEnrollment() { - return getEntityJpql(Enrollment.class.getSimpleName(), enrollment.getUid()); + return getEntityJpql(Enrollment.class.getSimpleName(), enrollment.getStringUid()); } Event getEvent() { - return getEntityJpql(Event.class.getSimpleName(), event.getUid()); + return getEntityJpql(Event.class.getSimpleName(), event.getUid().getValue()); } - Event getEvent(String uid) { - return getEntityJpql(Event.class.getSimpleName(), uid); + Event getEvent(UID uid) { + return getEntityJpql(Event.class.getSimpleName(), uid.getValue()); } TrackedEntity getTrackedEntity() { - return getEntityJpql(TrackedEntity.class.getSimpleName(), trackedEntity.getUid()); + return getEntityJpql(TrackedEntity.class.getSimpleName(), trackedEntity.getStringUid()); } /** diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java index 5c8a07508bcf..49ee861d5b92 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java @@ -263,33 +263,4 @@ void testStatsCountForOneUpdateEventAndOneNewEvent() throws IOException { assertEquals(0, trackerImportEventReport.getStats().getIgnored()); assertEquals(0, trackerImportEventReport.getStats().getDeleted()); } - - @Test - void testStatsCountForOneUpdateEventAndOneNewEventAndOneInvalidEvent() throws IOException { - TrackerObjects trackerObjects = fromJson("tracker/single_te.json"); - TrackerImportParams params = - TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).build(); - trackerImportService.importTracker(params, trackerObjects); - - trackerObjects = fromJson("tracker/single_enrollment.json"); - trackerImportService.importTracker(params, trackerObjects); - - trackerObjects = fromJson("tracker/single_event.json"); - trackerImportService.importTracker(params, trackerObjects); - - trackerObjects = fromJson("tracker/one_update_and_one_new_and_one_invalid_event.json"); - params.setAtomicMode(AtomicMode.OBJECT); - params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - - ImportReport trackerImportEventReport = - trackerImportService.importTracker(params, trackerObjects); - - assertNotNull(trackerImportEventReport); - assertEquals(Status.OK, trackerImportEventReport.getStatus()); - assertEquals(1, trackerImportEventReport.getValidationReport().getErrors().size()); - assertEquals(1, trackerImportEventReport.getStats().getCreated()); - assertEquals(1, trackerImportEventReport.getStats().getUpdated()); - assertEquals(1, trackerImportEventReport.getStats().getIgnored()); - assertEquals(0, trackerImportEventReport.getStats().getDeleted()); - } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java index aa46c5c8564f..4503ff62e63e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java @@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.UID; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.message.MessageConversation; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -188,7 +189,7 @@ void shouldSendTrackerNotificationAtEnrollment() { @Test void shouldSendTrackerNotificationAtEnrollmentCompletionAndThenEventCompletion() { - String eventUid = CodeGenerator.generateUid(); + UID eventUid = UID.generate(); Enrollment enrollment = Enrollment.builder() @@ -205,7 +206,7 @@ void shouldSendTrackerNotificationAtEnrollmentCompletionAndThenEventCompletion() org.hisp.dhis.tracker.imports.domain.Event.builder() .program(MetadataIdentifier.ofUid(programA.getUid())) .orgUnit(MetadataIdentifier.ofUid(orgUnitA.getUid())) - .enrollment(enrollment.getEnrollment()) + .enrollment(enrollment.getUid()) .event(eventUid) .programStage(MetadataIdentifier.ofUid(programStageA.getUid())) .status(EventStatus.ACTIVE) @@ -241,7 +242,7 @@ void shouldSendTrackerNotificationAtEnrollmentCompletionAndThenEventCompletion() org.hisp.dhis.tracker.imports.domain.Event.builder() .program(MetadataIdentifier.ofUid(programA.getUid())) .orgUnit(MetadataIdentifier.ofUid(orgUnitA.getUid())) - .enrollment(enrollment.getEnrollment()) + .enrollment(enrollment.getUid()) .event(eventUid) .programStage(MetadataIdentifier.ofUid(programStageA.getUid())) .status(EventStatus.COMPLETED) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java index 732b0819490f..723b1cfdbb2a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java @@ -38,7 +38,7 @@ import java.io.IOException; import java.util.List; -import org.hisp.dhis.common.CodeGenerator; +import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle; import org.hisp.dhis.eventdatavalue.EventDataValue; @@ -173,10 +173,10 @@ void shouldImportEventAndCorrectlyAssignPreviousEventDataValue( void shouldImportEventAndCorrectlyAssignPreviousEventDataValueConsideringCreateAtWhenOccurredAtIsSame() throws IOException { - String firstEventUid = CodeGenerator.generateUid(); - String secondEventUid = CodeGenerator.generateUid(); - String thirdEventUid = CodeGenerator.generateUid(); - String fourthEventUid = CodeGenerator.generateUid(); + UID firstEventUid = UID.generate(); + UID secondEventUid = UID.generate(); + UID thirdEventUid = UID.generate(); + UID fourthEventUid = UID.generate(); TrackerImportParams params = new TrackerImportParams(); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); @@ -281,7 +281,7 @@ void shouldNotImportWhenDataElementWithDifferentValueIsAssignedByAssignRule() th assertHasOnlyWarnings(importReport, E1308); } - private TrackerObjects getEvent(String eventUid, String occurredDate, String value) + private TrackerObjects getEvent(UID eventUid, String occurredDate, String value) throws IOException { TrackerObjects trackerObjects = fromJson("tracker/programrule/event_without_date.json"); trackerObjects @@ -294,8 +294,8 @@ private TrackerObjects getEvent(String eventUid, String occurredDate, String val return trackerObjects; } - private List getValueForAssignedDataElement(String eventUid) { - return manager.get(Event.class, eventUid).getEventDataValues().stream() + private List getValueForAssignedDataElement(UID eventUid) { + return manager.get(Event.class, eventUid.getValue()).getEventDataValues().stream() .filter(dv -> dv.getDataElement().equals("DATAEL00002")) .map(EventDataValue::getValue) .toList(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java index d3edd1deb3e4..fbdb7c4f80be 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java @@ -38,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import java.io.IOException; +import org.hisp.dhis.common.UID; import org.hisp.dhis.constant.Constant; import org.hisp.dhis.constant.ConstantService; import org.hisp.dhis.dataelement.DataElement; @@ -66,7 +67,7 @@ class ProgramRuleTest extends TrackerTest { private static final String ENROLLMENT_UID = "TvctPPhpD8u"; - private static final String EVENT_UID = "D9PbzJY8bJO"; + private static final UID EVENT_UID = UID.of("D9PbzJY8bJO"); private static final String PROGRAM_EVENT_UID = "PEVENT12345"; @@ -235,7 +236,7 @@ void shouldNotImportEventAndEnrollmentWhenAnErrorIsTriggeredOnEnrollment() throw assertAll( () -> assertHasError(report, E1300, ENROLLMENT_UID), - () -> assertHasError(report, ValidationCode.E5000, EVENT_UID)); + () -> assertHasError(report, ValidationCode.E5000, EVENT_UID.getValue())); } @Test @@ -265,7 +266,7 @@ void shouldNotImportWhenErrorIsTriggeredOnAllEntities() throws IOException { assertAll( () -> assertHasError(report, E1300, ENROLLMENT_UID), - () -> assertHasError(report, E1300, EVENT_UID), + () -> assertHasError(report, E1300, EVENT_UID.getValue()), () -> assertHasError(report, E1300, PROGRAM_EVENT_UID)); } diff --git a/dhis-2/dhis-test-integration/src/test/resources/tracker/one_update_and_one_new_and_one_invalid_event.json b/dhis-2/dhis-test-integration/src/test/resources/tracker/one_update_and_one_new_and_one_invalid_event.json deleted file mode 100644 index 159ff551b9cf..000000000000 --- a/dhis-2/dhis-test-integration/src/test/resources/tracker/one_update_and_one_new_and_one_invalid_event.json +++ /dev/null @@ -1,126 +0,0 @@ -{ - "importMode": "COMMIT", - "idSchemes": { - "dataElementIdScheme": { - "idScheme": "UID" - }, - "orgUnitIdScheme": { - "idScheme": "UID" - }, - "programIdScheme": { - "idScheme": "UID" - }, - "programStageIdScheme": { - "idScheme": "UID" - }, - "idScheme": { - "idScheme": "UID" - }, - "categoryOptionComboIdScheme": { - "idScheme": "UID" - }, - "categoryOptionIdScheme": { - "idScheme": "UID" - } - }, - "importStrategy": "CREATE", - "atomicMode": "ALL", - "flushMode": "AUTO", - "validationMode": "FULL", - "skipPatternValidation": false, - "skipSideEffects": false, - "skipRuleEngine": false, - "trackedEntities": [], - "enrollments": [], - "events": [ - { - "event": "D9PbzJY8bJO", - "status": "COMPLETED", - "program": { - "idScheme": "UID", - "identifier": "BFcipDERJnf" - }, - "programStage": { - "idScheme": "UID", - "identifier": "NpsdDv6kKSO" - }, - "enrollment": "TvctPPhpD8u", - "orgUnit": { - "idScheme": "UID", - "identifier": "h4w96yEMlzO" - }, - "relationships": [], - "occurredAt": "2019-01-28T00:00:00.000", - "scheduledAt": "2019-01-28T12:10:38.100", - "storedBy": "admin", - "deleted": false, - "attributeOptionCombo": { - "idScheme": "UID" - }, - "attributeCategoryOptions": [], - - "dataValues": [], - "notes": [] - }, - { - "event": "NEWEVENT001", - "status": "COMPLETED", - "program": { - "idScheme": "UID", - "identifier": "BFcipDERJnf" - }, - "programStage": { - "idScheme": "UID", - "identifier": "NpsdDv6kKSO" - }, - "enrollment": "TvctPPhpD8u", - "orgUnit": { - "idScheme": "UID", - "identifier": "h4w96yEMlzO" - }, - "relationships": [], - "occurredAt": "2019-01-28T00:00:00.000", - "scheduledAt": "2019-01-28T12:10:38.100", - "storedBy": "admin", - "deleted": false, - "attributeOptionCombo": { - "idScheme": "UID" - }, - "attributeCategoryOptions": [], - - "dataValues": [], - "notes": [] - }, - { - "event": "EVENTUID-TOOLONG", - "status": "COMPLETED", - "program": { - "idScheme": "UID", - "identifier": "BFcipDERJnf" - }, - "programStage": { - "idScheme": "UID", - "identifier": "NpsdDv6kKSO" - }, - "enrollment": "TvctPPhpD8u", - "orgUnit": { - "idScheme": "UID", - "identifier": "h4w96yEMlzO" - }, - "relationships": [], - "occurredAt": "2019-01-28T00:00:00.000", - "scheduledAt": "2019-01-28T12:10:38.100", - "storedBy": "admin", - "deleted": false, - "attributeOptionCombo": { - "idScheme": "UID" - }, - "attributeCategoryOptions": [], - - "dataValues": [], - "notes": [] - } - ], - "relationships": [], - "username": "system-process" -} \ No newline at end of file diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventMapper.java index f840ead21e73..0bb81ccd8639 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventMapper.java @@ -36,6 +36,7 @@ import org.hisp.dhis.webapi.controller.tracker.export.UserMapper; import org.hisp.dhis.webapi.controller.tracker.export.relationship.RelationshipMapper; import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper; +import org.hisp.dhis.webapi.controller.tracker.view.UIDMapper; import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -45,6 +46,7 @@ DataValueMapper.class, CategoryOptionMapper.class, InstantMapper.class, + UIDMapper.class, NoteMapper.class, RelationshipMapper.class, UserMapper.class diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java index 13fe9c3af169..84b726909e45 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java @@ -38,6 +38,7 @@ import org.hisp.dhis.webapi.controller.tracker.export.event.CategoryOptionMapper; import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper; import org.hisp.dhis.webapi.controller.tracker.view.RelationshipItem; +import org.hisp.dhis.webapi.controller.tracker.view.UIDMapper; import org.hisp.dhis.webapi.controller.tracker.view.User; import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper; import org.mapstruct.Mapper; @@ -49,6 +50,7 @@ CategoryOptionMapper.class, DataValueMapper.class, InstantMapper.class, + UIDMapper.class, NoteMapper.class, ProgramOwnerMapper.class, UserMapper.class, diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/EventMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/EventMapper.java index bee2c146262f..0f59ae05212c 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/EventMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/EventMapper.java @@ -30,6 +30,7 @@ import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.webapi.controller.tracker.view.Event; import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper; +import org.hisp.dhis.webapi.controller.tracker.view.UIDMapper; import org.mapstruct.Context; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -40,6 +41,7 @@ NoteMapper.class, DataValueMapper.class, InstantMapper.class, + UIDMapper.class, MetadataIdentifierMapper.class }) interface EventMapper extends DomainMapper { diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/RelationshipMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/RelationshipMapper.java index 5f8263d2b6cf..f7d771d84909 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/RelationshipMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/RelationshipMapper.java @@ -30,11 +30,18 @@ import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper; import org.hisp.dhis.webapi.controller.tracker.view.Relationship; +import org.hisp.dhis.webapi.controller.tracker.view.UIDMapper; import org.mapstruct.Context; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -@Mapper(uses = {RelationshipItemMapper.class, InstantMapper.class, MetadataIdentifierMapper.class}) +@Mapper( + uses = { + RelationshipItemMapper.class, + InstantMapper.class, + UIDMapper.class, + MetadataIdentifierMapper.class + }) interface RelationshipMapper extends DomainMapper { @Mapping( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidator.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/view/UIDMapper.java similarity index 65% rename from dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidator.java rename to dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/view/UIDMapper.java index 42ca17d13b6b..59ed77b1c9be 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/event/UidValidator.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/view/UIDMapper.java @@ -25,24 +25,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.tracker.imports.validation.validator.event; +package org.hisp.dhis.webapi.controller.tracker.view; -import static org.hisp.dhis.tracker.imports.validation.validator.ValidationUtils.checkUidFormat; -import static org.hisp.dhis.tracker.imports.validation.validator.ValidationUtils.validateNotesUid; +import org.hisp.dhis.common.UID; +import org.mapstruct.Mapper; -import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; -import org.hisp.dhis.tracker.imports.domain.Event; -import org.hisp.dhis.tracker.imports.validation.Reporter; -import org.hisp.dhis.tracker.imports.validation.Validator; +@Mapper +public interface UIDMapper { -/** - * @author Morten Svanæs - */ -class UidValidator implements Validator { - @Override - public void validate(Reporter reporter, TrackerBundle bundle, Event event) { - checkUidFormat(event.getEvent(), reporter, event, event, event.getEvent()); - - validateNotesUid(event.getNotes(), reporter, event); + default UID fromString(String stringUid) { + return UID.of(stringUid); } }