diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java index d9bd8ecab83..6e912e995a7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java @@ -53,6 +53,9 @@ import org.hisp.dhis.tracker.acl.TrackerOwnershipManager; import org.hisp.dhis.tracker.export.Page; import org.hisp.dhis.tracker.export.PageParams; +import org.hisp.dhis.tracker.export.event.EventOperationParams; +import org.hisp.dhis.tracker.export.event.EventParams; +import org.hisp.dhis.tracker.export.event.EventService; import org.hisp.dhis.user.UserDetails; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -63,6 +66,8 @@ class DefaultEnrollmentService implements EnrollmentService { private final EnrollmentStore enrollmentStore; + private final EventService eventService; + private final TrackerOwnershipManager trackerOwnershipAccessManager; private final TrackedEntityAttributeService trackedEntityAttributeService; @@ -130,7 +135,9 @@ private Enrollment getEnrollment( result.setDeleted(enrollment.isDeleted()); result.setNotes(enrollment.getNotes()); if (params.isIncludeEvents()) { - result.setEvents(getEvents(user, enrollment, includeDeleted)); + result.setEvents( + getEvents( + enrollment, params.getEnrollmentEventsParams().getEventParams(), includeDeleted)); } if (params.isIncludeRelationships()) { result.setRelationshipItems(getRelationshipItems(user, enrollment, includeDeleted)); @@ -145,8 +152,7 @@ private Enrollment getEnrollment( } @Override - public RelationshipItem getEnrollmentInRelationshipItem( - @Nonnull UID uid, @Nonnull EnrollmentParams params, boolean includeDeleted) + public RelationshipItem getEnrollmentInRelationshipItem(@Nonnull UID uid, boolean includeDeleted) throws NotFoundException { RelationshipItem relationshipItem = new RelationshipItem(); @@ -162,20 +168,29 @@ public RelationshipItem getEnrollmentInRelationshipItem( return null; } - relationshipItem.setEnrollment(getEnrollment(enrollment, params, includeDeleted, currentUser)); + relationshipItem.setEnrollment( + getEnrollment( + enrollment, + EnrollmentParams.FALSE.withIncludeAttributes(true), + includeDeleted, + currentUser)); return relationshipItem; } - private Set getEvents(UserDetails user, Enrollment enrollment, boolean includeDeleted) { - Set events = new HashSet<>(); - - for (Event event : enrollment.getEvents()) { - if ((includeDeleted || !event.isDeleted()) - && trackerAccessManager.canRead(user, event, true).isEmpty()) { - events.add(event); - } + private Set getEvents( + Enrollment enrollment, EventParams eventParams, boolean includeDeleted) { + EventOperationParams eventOperationParams = + EventOperationParams.builder() + .enrollments(Set.of(UID.of(enrollment))) + .eventParams(eventParams) + .includeDeleted(includeDeleted) + .build(); + try { + return Set.copyOf(eventService.getEvents(eventOperationParams)); + } catch (BadRequestException | ForbiddenException e) { + throw new IllegalArgumentException( + "this must be a bug in how the EventOperationParams are built"); } - return events; } private Set getRelationshipItems( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java index b4697b19f43..06051c96f20 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/EnrollmentService.java @@ -45,8 +45,8 @@ public interface EnrollmentService { Enrollment getEnrollment(UID uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException, ForbiddenException; - RelationshipItem getEnrollmentInRelationshipItem( - UID uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException; + RelationshipItem getEnrollmentInRelationshipItem(UID uid, boolean includeDeleted) + throws NotFoundException; /** Get all enrollments matching given params. */ @Nonnull diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventService.java index 441a6b36e13..c20dad793c3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventService.java @@ -238,6 +238,7 @@ private Event getEvent( return event; } + @Nonnull @Override public List getEvents(@Nonnull EventOperationParams operationParams) throws BadRequestException, ForbiddenException { @@ -245,6 +246,7 @@ public List getEvents(@Nonnull EventOperationParams operationParams) return eventStore.getEvents(queryParams); } + @Nonnull @Override public Page getEvents( @Nonnull EventOperationParams operationParams, @Nonnull PageParams pageParams) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java index a4d9f4c5d7a..131700f08e6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java @@ -71,7 +71,8 @@ public class EventOperationParams { private UID orgUnit; - private OrganisationUnitSelectionMode orgUnitMode; + @Builder.Default + private OrganisationUnitSelectionMode orgUnitMode = OrganisationUnitSelectionMode.ACCESSIBLE; private AssignedUserSelectionMode assignedUserMode; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java index 0996d6c512d..ad885c366da 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java @@ -71,7 +71,6 @@ import org.hisp.dhis.tracker.export.FileResourceStream; import org.hisp.dhis.tracker.export.Page; import org.hisp.dhis.tracker.export.PageParams; -import org.hisp.dhis.tracker.export.enrollment.EnrollmentParams; import org.hisp.dhis.tracker.export.enrollment.EnrollmentService; import org.hisp.dhis.tracker.export.event.EventParams; import org.hisp.dhis.tracker.export.event.EventService; @@ -543,9 +542,7 @@ private RelationshipItem getRelationshipItem( } else if (item.getEnrollment() != null) { result = enrollmentService.getEnrollmentInRelationshipItem( - UID.of(item.getEnrollment()), - EnrollmentParams.TRUE.withIncludeRelationships(false), - includeDeleted); + UID.of(item.getEnrollment()), includeDeleted); } else if (item.getEvent() != null) { result = eventService.getEventInRelationshipItem(