From c69131d1523c574e84ee3c1e3990a3dd4f492298 Mon Sep 17 00:00:00 2001 From: teleivo Date: Fri, 17 Jan 2025 10:32:24 +0100 Subject: [PATCH] chore: use enrollmentService in te service to get enrollments on /trackedEntities/{uid}?fields=enrollment chore: wire ids and uids through chore: use enrollment service in TE aggregate --- .../tracker/export/event/JdbcEventStore.java | 9 +- .../DefaultTrackedEntityService.java | 48 +++-- .../HibernateTrackedEntityStore.java | 26 +-- ...ect.java => TrackedEntityIdentifiers.java} | 29 +-- .../trackedentity/TrackedEntityStore.java | 5 +- .../trackedentity/aggregates/AsyncUtils.java | 11 -- .../aggregates/EnrollmentAggregate.java | 122 +++++-------- .../aggregates/EnrollmentStore.java | 117 ------------ .../aggregates/EventAggregate.java | 126 ------------- .../trackedentity/aggregates/EventStore.java | 168 ------------------ .../aggregates/TrackedEntityAggregate.java | 11 +- .../aggregates/TrackedEntityStore.java | 4 +- .../mapper/EnrollmentRowCallbackHandler.java | 109 ------------ .../EventDataValueRowCallbackHandler.java | 104 ----------- .../mapper/EventRowCallbackHandler.java | 152 ---------------- .../mapper/NoteRowCallbackHandler.java | 56 ------ .../ProgramAttributeRowCallbackHandler.java | 47 ----- .../aggregates/query/EnrollmentQuery.java | 109 ------------ .../aggregates/query/EventQuery.java | 127 ------------- .../query/ProgramAttributeQuery.java | 80 --------- .../TrackedEntityServiceTest.java | 16 +- 21 files changed, 107 insertions(+), 1369 deletions(-) rename dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/{aggregates/query/Subselect.java => TrackedEntityIdentifiers.java} (75%) delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentStore.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventStore.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventDataValueRowCallbackHandler.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/ProgramAttributeRowCallbackHandler.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EnrollmentQuery.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/ProgramAttributeQuery.java diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java index a5518be292f0..a45b58f4a5d2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java @@ -33,6 +33,7 @@ import static org.hisp.dhis.system.util.SqlUtils.lower; import static org.hisp.dhis.system.util.SqlUtils.quote; import static org.hisp.dhis.system.util.SqlUtils.singleQuote; +import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUserDetails; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -94,6 +95,7 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.TrackerIdScheme; import org.hisp.dhis.tracker.TrackerIdSchemeParam; +import org.hisp.dhis.tracker.acl.TrackerAccessManager; import org.hisp.dhis.tracker.export.Order; import org.hisp.dhis.tracker.export.Page; import org.hisp.dhis.tracker.export.PageParams; @@ -251,6 +253,8 @@ class JdbcEventStore { private final RelationshipStore relationshipStore; + private final TrackerAccessManager trackerAccessManager; + public List getEvents(EventQueryParams queryParams) { return fetchEvents(queryParams, null); } @@ -474,8 +478,11 @@ private List fetchEvents(EventQueryParams queryParams, PageParams pagePar List relationships = relationshipStore.getById(relationshipIds); Multimap map = LinkedListMultimap.create(); - for (Relationship relationship : relationships) { + if (!trackerAccessManager.canRead(getCurrentUserDetails(), relationship).isEmpty()) { + continue; + } + if (relationship.getFrom().getEvent() != null) { map.put(relationship.getFrom().getEvent().getUid(), relationship.getFrom()); } 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 9954a27294b6..6b80701ca314 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 @@ -60,7 +60,6 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwner; import org.hisp.dhis.trackedentity.TrackedEntityType; -import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.trackedentity.TrackedEntityTypeStore; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.tracker.acl.TrackerAccessManager; @@ -68,6 +67,7 @@ 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.EnrollmentOperationParams; import org.hisp.dhis.tracker.export.enrollment.EnrollmentService; import org.hisp.dhis.tracker.export.event.EventParams; import org.hisp.dhis.tracker.export.event.EventService; @@ -86,7 +86,7 @@ class DefaultTrackedEntityService implements TrackedEntityService { private final TrackedEntityAttributeService trackedEntityAttributeService; private final TrackedEntityTypeStore trackedEntityTypeStore; - private final TrackedEntityTypeService trackedEntityTypeService; + private final AclService aclService; private final TrackedEntityAuditService trackedEntityAuditService; @@ -212,7 +212,7 @@ private static TrackedEntityAttribute getAttribute( @Nonnull @Override public TrackedEntity getTrackedEntity(@Nonnull UID uid) - throws NotFoundException, ForbiddenException { + throws NotFoundException, ForbiddenException, BadRequestException { return getTrackedEntity(uid, null, TrackedEntityParams.FALSE); } @@ -222,7 +222,7 @@ public TrackedEntity getTrackedEntity( @Nonnull UID trackedEntityUid, @CheckForNull UID programIdentifier, @Nonnull TrackedEntityParams params) - throws NotFoundException, ForbiddenException { + throws NotFoundException, ForbiddenException, BadRequestException { Program program = null; if (programIdentifier != null) { program = programService.getProgram(programIdentifier.getValue()); @@ -243,7 +243,7 @@ public TrackedEntity getTrackedEntity( */ private TrackedEntity getTrackedEntity( UID uid, Program program, TrackedEntityParams params, UserDetails user) - throws NotFoundException, ForbiddenException { + throws NotFoundException, ForbiddenException, BadRequestException { TrackedEntity trackedEntity = trackedEntityStore.getByUid(uid.getValue()); if (trackedEntity == null) { throw new NotFoundException(TrackedEntity.class, uid); @@ -270,7 +270,10 @@ private TrackedEntity getTrackedEntity( } if (params.isIncludeEnrollments()) { - trackedEntity.setEnrollments(getEnrollments(trackedEntity, user, false, program)); + EnrollmentOperationParams enrollmentOperationParams = + mapToEnrollmentParams(uid, program, params); + List enrollments = enrollmentService.getEnrollments(enrollmentOperationParams); + trackedEntity.setEnrollments(new HashSet<>(enrollments)); } setRelationshipItems(trackedEntity, trackedEntity, params, false); if (params.isIncludeProgramOwners()) { @@ -281,25 +284,13 @@ private TrackedEntity getTrackedEntity( return trackedEntity; } - private Set getEnrollments( - TrackedEntity trackedEntity, UserDetails user, boolean includeDeleted, Program program) { - return trackedEntity.getEnrollments().stream() - .filter(e -> program == null || program.getUid().equals(e.getProgram().getUid())) - .filter(e -> includeDeleted || !e.isDeleted()) - .filter(e -> trackerAccessManager.canRead(user, e, false).isEmpty()) - .map( - e -> { - Set filteredEvents = - e.getEvents().stream() - .filter( - event -> - (includeDeleted || !event.isDeleted()) - && trackerAccessManager.canRead(user, event, false).isEmpty()) - .collect(Collectors.toSet()); - e.setEvents(filteredEvents); - return e; - }) - .collect(Collectors.toSet()); + private EnrollmentOperationParams mapToEnrollmentParams( + UID trackedEntity, Program program, TrackedEntityParams params) { + return EnrollmentOperationParams.builder() + .trackedEntity(trackedEntity) + .program(program) + .enrollmentParams(params.getEnrollmentParams()) + .build(); } private static Set getTrackedEntityProgramOwners( @@ -346,7 +337,7 @@ public List getTrackedEntities( throws ForbiddenException, NotFoundException, BadRequestException { UserDetails user = getCurrentUserDetails(); TrackedEntityQueryParams queryParams = mapper.map(operationParams, user); - final List ids = trackedEntityStore.getTrackedEntityIds(queryParams); + final List ids = trackedEntityStore.getTrackedEntityIds(queryParams); return getTrackedEntities(ids, operationParams, queryParams, user); } @@ -357,7 +348,8 @@ public List getTrackedEntities( throws BadRequestException, ForbiddenException, NotFoundException { UserDetails user = getCurrentUserDetails(); TrackedEntityQueryParams queryParams = mapper.map(operationParams, user); - final Page ids = trackedEntityStore.getTrackedEntityIds(queryParams, pageParams); + final Page ids = + trackedEntityStore.getTrackedEntityIds(queryParams, pageParams); List trackedEntities = getTrackedEntities(ids.getItems(), operationParams, queryParams, user); @@ -365,7 +357,7 @@ public List getTrackedEntities( } private List getTrackedEntities( - List ids, + List ids, TrackedEntityOperationParams operationParams, TrackedEntityQueryParams queryParams, UserDetails user) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java index a98de521046f..5fb09065d40d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java @@ -149,46 +149,46 @@ public HibernateTrackedEntityStore( } @Override - public List getTrackedEntityIds(TrackedEntityQueryParams params) { + public List getTrackedEntityIds(TrackedEntityQueryParams params) { String sql = getQuery(params, null); SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); checkMaxTrackedEntityCountReached(params, rowSet); - List ids = new ArrayList<>(); - + List ids = new ArrayList<>(); while (rowSet.next()) { - ids.add(rowSet.getLong("trackedentityid")); + ids.add( + new TrackedEntityIdentifiers(rowSet.getLong("trackedentityid"), rowSet.getString("uid"))); } - return ids; } @Override - public Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams) { + public Page getTrackedEntityIds( + TrackedEntityQueryParams params, PageParams pageParams) { String sql = getQuery(params, pageParams); SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); checkMaxTrackedEntityCountReached(params, rowSet); - List ids = new ArrayList<>(); - + List ids = new ArrayList<>(); while (rowSet.next()) { - ids.add(rowSet.getLong("trackedentityid")); + ids.add( + new TrackedEntityIdentifiers(rowSet.getLong("trackedentityid"), rowSet.getString("uid"))); } LongSupplier teCount = () -> getTrackedEntityCount(params); return getPage(pageParams, ids, teCount); } - private Page getPage( - PageParams pageParams, List teIds, LongSupplier enrollmentCount) { + private Page getPage( + PageParams pageParams, List ids, LongSupplier enrollmentCount) { if (pageParams.isPageTotal()) { return Page.withTotals( - teIds, pageParams.getPage(), pageParams.getPageSize(), enrollmentCount.getAsLong()); + ids, pageParams.getPage(), pageParams.getPageSize(), enrollmentCount.getAsLong()); } - return Page.withoutTotals(teIds, pageParams.getPage(), pageParams.getPageSize()); + return Page.withoutTotals(ids, pageParams.getPage(), pageParams.getPageSize()); } @Override diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/Subselect.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityIdentifiers.java similarity index 75% rename from dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/Subselect.java rename to dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityIdentifiers.java index 23869e72b52b..008da7ee7b70 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/Subselect.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityIdentifiers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2025, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,28 +25,11 @@ * (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.export.trackedentity.aggregates.query; - -import lombok.AllArgsConstructor; -import lombok.Getter; +package org.hisp.dhis.tracker.export.trackedentity; /** - * @author Luciano Fiandesio + * Temporary solution: pair of primary key and uid needed by the aggregate store. + * + * @deprecated do not use this class! This is a temporary solution that will be removed. */ -@Getter -@AllArgsConstructor -class Subselect implements QueryElement { - private String query; - - private String alias; - - @Override - public String useInSelect() { - return query + " as " + alias; - } - - @Override - public String getResultsetValue() { - return alias; - } -} +public record TrackedEntityIdentifiers(Long id, String uid) {} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityStore.java index ee24a694ca6a..e49c3b8a7a42 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityStore.java @@ -38,10 +38,11 @@ public interface TrackedEntityStore extends IdentifiableObjectStore getTrackedEntityIds(TrackedEntityQueryParams params); + List getTrackedEntityIds(TrackedEntityQueryParams params); /** Get a page of tracked entities matching given params. */ - Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams); + Page getTrackedEntityIds( + TrackedEntityQueryParams params, PageParams pageParams); /** * Fields the {@link #getTrackedEntityIds(TrackedEntityQueryParams)})} can order tracked entities diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java index fb3eefbdb919..155b8ace1d22 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java @@ -58,15 +58,4 @@ static CompletableFuture> conditionalAsyncFetch( ? supplyAsync(supplier, executor) : supplyAsync(ArrayListMultimap::create, executor)); } - - /** - * Executes the Supplier asynchronously using the thread pool from the provided {@see Executor} - * - * @param supplier The Supplier to execute - * @return A CompletableFuture with the result of the Supplier - */ - static CompletableFuture> asyncFetch( - Supplier> supplier, Executor executor) { - return supplyAsync(supplier, executor); - } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java index 6fd4b38a9ba3..f899717af3cc 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java @@ -27,25 +27,19 @@ */ package org.hisp.dhis.tracker.export.trackedentity.aggregates; -import static java.util.concurrent.CompletableFuture.allOf; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.asyncFetch; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.conditionalAsyncFetch; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.ThreadPoolManager.getPool; - +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; -import java.util.concurrent.CompletableFuture; -import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.note.Note; +import org.hisp.dhis.common.UID; +import org.hisp.dhis.feedback.BadRequestException; +import org.hisp.dhis.feedback.ForbiddenException; +import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.relationship.RelationshipItem; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.springframework.beans.factory.annotation.Qualifier; +import org.hisp.dhis.tracker.export.enrollment.EnrollmentOperationParams; +import org.hisp.dhis.tracker.export.enrollment.EnrollmentService; +import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityIdentifiers; +import org.hisp.dhis.user.AuthenticationService; import org.springframework.stereotype.Component; /** @@ -54,13 +48,8 @@ @Component("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentAggregate") @RequiredArgsConstructor class EnrollmentAggregate { - @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentStore") - @Nonnull - private final EnrollmentStore enrollmentStore; - - @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EventAggregate") - @Nonnull - private final EventAggregate eventAggregate; + private final AuthenticationService authenticationService; + private final EnrollmentService enrollmentService; /** * Key: te uid , value Enrollment @@ -69,66 +58,37 @@ class EnrollmentAggregate { * @return a MultiMap where key is a {@see TrackedEntity} uid and the key a List of {@see * Enrollment} objects */ - Multimap findByTrackedEntityIds(List ids, Context ctx) { - Multimap enrollments = - enrollmentStore.getEnrollmentsByTrackedEntityIds(ids, ctx); + Multimap findByTrackedEntityIds( + List ids, Context ctx) { + Multimap result = ArrayListMultimap.create(); - if (enrollments.isEmpty()) { - return enrollments; + try { + authenticationService.obtainAuthentication(ctx.getUserUid()); + ids.forEach( + id -> { + EnrollmentOperationParams params = + EnrollmentOperationParams.builder() + .enrollmentParams(ctx.getParams().getEnrollmentParams()) + .trackedEntity(UID.of(id.uid())) + .build(); + try { + result.putAll(id.uid(), enrollmentService.getEnrollments(params)); + } catch (BadRequestException e) { + throw new IllegalArgumentException( + "this must be a bug in how the EnrollmentOperationParams are built"); + } catch (ForbiddenException e) { + // ForbiddenExceptions are caused when mapping the EnrollmentOperationParams. These + // params should already have been validated as they are coming from the + // TrackedEntityQueryParams. Other reasons the user does not have access to data will + // not be shown as such items are simply not returned in collections. + } + }); + } catch (NotFoundException e) { + throw new IllegalArgumentException( + "this must be called within a context where the user is known to exist"); + } finally { + authenticationService.clearAuthentication(); } - - List enrollmentIds = enrollments.values().stream().map(Enrollment::getId).toList(); - - final CompletableFuture> eventAsync = - conditionalAsyncFetch( - ctx.getParams().getEnrollmentParams().isIncludeEvents(), - () -> eventAggregate.findByEnrollmentIds(enrollmentIds, ctx), - getPool()); - - final CompletableFuture> relationshipAsync = - conditionalAsyncFetch( - ctx.getParams().getEnrollmentParams().isIncludeRelationships(), - () -> enrollmentStore.getRelationships(enrollmentIds, ctx), - getPool()); - - final CompletableFuture> notesAsync = - asyncFetch(() -> enrollmentStore.getNotes(enrollmentIds), getPool()); - - final CompletableFuture> attributesAsync = - conditionalAsyncFetch( - ctx.getParams().getTeEnrollmentParams().isIncludeAttributes(), - () -> enrollmentStore.getAttributes(enrollmentIds, ctx), - getPool()); - - return allOf(eventAsync, notesAsync, relationshipAsync, attributesAsync) - .thenApplyAsync( - fn -> { - Multimap events = eventAsync.join(); - Multimap notes = notesAsync.join(); - Multimap relationships = relationshipAsync.join(); - Multimap attributes = attributesAsync.join(); - - for (Enrollment enrollment : enrollments.values()) { - if (ctx.getParams().getTeEnrollmentParams().isIncludeEvents()) { - enrollment.setEvents(new HashSet<>(events.get(enrollment.getUid()))); - } - if (ctx.getParams().getTeEnrollmentParams().isIncludeRelationships()) { - enrollment.setRelationshipItems( - new HashSet<>(relationships.get(enrollment.getUid()))); - } - if (ctx.getParams().getTeEnrollmentParams().isIncludeAttributes()) { - enrollment - .getTrackedEntity() - .setTrackedEntityAttributeValues( - new LinkedHashSet<>(attributes.get(enrollment.getUid()))); - } - - enrollment.setNotes(new ArrayList<>(notes.get(enrollment.getUid()))); - } - - return enrollments; - }, - getPool()) - .join(); + return result; } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentStore.java deleted file mode 100644 index c4171c88cb3a..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentStore.java +++ /dev/null @@ -1,117 +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.export.trackedentity.aggregates; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import java.util.List; -import org.hisp.dhis.note.Note; -import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.EnrollmentRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.NoteRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.ProgramAttributeRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EnrollmentQuery; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.ProgramAttributeQuery; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Repository; - -/** - * @author Luciano Fiandesio - */ -@Repository("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentStore") -class EnrollmentStore extends AbstractStore { - private static final String GET_ENROLLMENT_SQL_BY_TE = EnrollmentQuery.getQuery(); - - private static final String GET_ATTRIBUTES = ProgramAttributeQuery.getQuery(); - - private static final String GET_NOTES_SQL = - "select en.uid as key, n.uid, n.notetext, " - + "n.creator, n.created " - + "from note n join enrollment_notes enn " - + "on n.noteid = enn.noteid " - + "join enrollment en on enn.enrollmentid = en.enrollmentid " - + "where enn.enrollmentid in (:ids)"; - - private static final String FILTER_OUT_DELETED_ENROLLMENTS = "en.deleted=false"; - - EnrollmentStore(@Qualifier("readOnlyJdbcTemplate") JdbcTemplate jdbcTemplate) { - super(jdbcTemplate); - } - - Multimap getEnrollmentsByTrackedEntityIds(List ids, Context ctx) { - List> teIds = Lists.partition(ids, PARITITION_SIZE); - - Multimap enrollmentMultimap = ArrayListMultimap.create(); - - teIds.forEach( - partition -> - enrollmentMultimap.putAll(getEnrollmentsByTrackedEntityIdsPartitioned(partition, ctx))); - - return enrollmentMultimap; - } - - private Multimap getEnrollmentsByTrackedEntityIdsPartitioned( - List ids, Context ctx) { - EnrollmentRowCallbackHandler handler = new EnrollmentRowCallbackHandler(); - - jdbcTemplate.query( - getQuery( - GET_ENROLLMENT_SQL_BY_TE, - ctx, - " en.programid IN (:programIds)", - FILTER_OUT_DELETED_ENROLLMENTS), - createIdsParam(ids).addValue("programIds", ctx.getPrograms()), - handler); - - return handler.getItems(); - } - - Multimap getNotes(List ids) { - return fetch(GET_NOTES_SQL, new NoteRowCallbackHandler(), ids); - } - - Multimap getAttributes(List ids, Context ctx) { - ProgramAttributeRowCallbackHandler handler = new ProgramAttributeRowCallbackHandler(); - - jdbcTemplate.query( - getQuery( - GET_ATTRIBUTES, ctx, " pa.programid IN (:programIds)", FILTER_OUT_DELETED_ENROLLMENTS), - createIdsParam(ids).addValue("programIds", ctx.getPrograms()), - handler); - - return handler.getItems(); - } - - @Override - String getRelationshipEntityColumn() { - return "enrollmentid"; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java deleted file mode 100644 index 29fcb93fc89d..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java +++ /dev/null @@ -1,126 +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.export.trackedentity.aggregates; - -import static java.util.concurrent.CompletableFuture.allOf; -import static java.util.concurrent.CompletableFuture.supplyAsync; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.asyncFetch; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.conditionalAsyncFetch; -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.ThreadPoolManager.getPool; - -import com.google.common.collect.Multimap; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import javax.annotation.Nonnull; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.eventdatavalue.EventDataValue; -import org.hisp.dhis.note.Note; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.relationship.RelationshipItem; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -/** - * @author Luciano Fiandesio - */ -@Component("org.hisp.dhis.tracker.trackedentity.aggregates.EventAggregate") -@RequiredArgsConstructor -class EventAggregate { - @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EventStore") - @Nonnull - private final EventStore eventStore; - - /** - * Key: enrollment uid -> Value: Event - * - * @param ids a List of {@see Enrollment} Primary Keys - * @param ctx the {@see Context} - * @return a Map where the key is a Enrollment Primary Key, and the value is a List of {@see - * Event} - */ - Multimap findByEnrollmentIds(List ids, Context ctx) { - // Fetch all the Events that are linked to the given Enrollment IDs - - Multimap events = this.eventStore.getEventsByEnrollmentIds(ids, ctx); - - if (events.isEmpty()) { - return events; - } - - List eventIds = events.values().stream().map(Event::getId).toList(); - - /* - * Async fetch Relationships for the given Event ids (only if - * isIncludeRelationships = true) - */ - final CompletableFuture> relationshipAsync = - conditionalAsyncFetch( - ctx.getParams().getEventParams().isIncludeRelationships(), - () -> eventStore.getRelationships(eventIds, ctx), - getPool()); - - /* - * Async fetch Notes for the given Event ids - */ - final CompletableFuture> notesAsync = - asyncFetch(() -> eventStore.getNotes(eventIds), getPool()); - - /* - * Async fetch DataValues for the given Event ids - */ - final CompletableFuture>> dataValuesAsync = - supplyAsync(() -> eventStore.getDataValues(eventIds), getPool()); - - return allOf(dataValuesAsync, notesAsync, relationshipAsync) - .thenApplyAsync( - fn -> { - Map> dataValues = dataValuesAsync.join(); - Multimap notes = notesAsync.join(); - Multimap relationships = relationshipAsync.join(); - - for (Event event : events.values()) { - if (ctx.getParams().getEventParams().isIncludeRelationships()) { - event.setRelationshipItems(new HashSet<>(relationships.get(event.getUid()))); - } - - List dataValuesForEvent = dataValues.get(event.getUid()); - if (dataValuesForEvent != null && !dataValuesForEvent.isEmpty()) { - event.setEventDataValues(new HashSet<>(dataValues.get(event.getUid()))); - } - event.setNotes(new ArrayList<>(notes.get(event.getUid()))); - } - - return events; - }, - getPool()) - .join(); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventStore.java deleted file mode 100644 index 925c3aa14067..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventStore.java +++ /dev/null @@ -1,168 +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.export.trackedentity.aggregates; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.hisp.dhis.eventdatavalue.EventDataValue; -import org.hisp.dhis.note.Note; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.query.JpaQueryUtils; -import org.hisp.dhis.security.acl.AclService; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.EventDataValueRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.EventRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.NoteRowCallbackHandler; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EventQuery; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Repository; - -/** - * @author Luciano Fiandesio - */ -@Repository("org.hisp.dhis.tracker.trackedentity.aggregates.EventStore") -class EventStore extends AbstractStore { - private static final String GET_EVENTS_SQL = EventQuery.getQuery(); - - private static final String GET_DATAVALUES_SQL = - "select ev.uid as key, " - + "ev.eventdatavalues " - + "from event ev " - + "where ev.eventid in (:ids)"; - - private static final String GET_NOTES_SQL = - "select ev.uid as key, n.uid, n.notetext, " - + "n.creator, n.created " - + "from note n " - + "join event_notes evn " - + "on n.noteid = evn.noteid " - + "join event ev on evn.eventid = ev.eventid " - + "where evn.eventid in (:ids)"; - - private static final String ACL_FILTER_SQL = - "CASE WHEN p.type = 'WITH_REGISTRATION' THEN " - + "p.trackedentitytypeid in (:trackedEntityTypeIds) else true END " - + "AND ev.programstageid in (:programStageIds) AND en.programid IN (:programIds)"; - - private static final String ACL_FILTER_SQL_NO_PROGRAM_STAGE = - "CASE WHEN p.type = 'WITH_REGISTRATION' THEN " - + "p.trackedentitytypeid in (:trackedEntityTypeIds) else true END " - + "AND en.programid IN (:programIds)"; - - private static final String FILTER_OUT_DELETED_EVENTS = "ev.deleted=false"; - - EventStore(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate); - } - - String getRelationshipEntityColumn() { - return "eventid"; - } - - public Multimap getEventsByEnrollmentIds(List enrollmentsId, Context ctx) { - List> enrollmentIdsPartitions = Lists.partition(enrollmentsId, PARITITION_SIZE); - - Multimap eventMultimap = ArrayListMultimap.create(); - - enrollmentIdsPartitions.forEach( - partition -> eventMultimap.putAll(getEventsByEnrollmentIdsPartitioned(partition, ctx))); - - return eventMultimap; - } - - private String getAttributeOptionComboClause(Context ctx) { - return " and ev.attributeoptioncomboid not in (" - + "select distinct(cocco.categoryoptioncomboid) " - + "from categoryoptioncombos_categoryoptions as cocco " - + - // Get inaccessible category options - "where cocco.categoryoptionid not in ( " - + "select co.categoryoptionid " - + "from categoryoption co " - + " where " - + JpaQueryUtils.generateSQlQueryForSharingCheck( - "co.sharing", ctx.getUserUid(), ctx.getUserGroups(), AclService.LIKE_READ_DATA) - + ") )"; - } - - private Multimap getEventsByEnrollmentIdsPartitioned( - List enrollmentsId, Context ctx) { - EventRowCallbackHandler handler = new EventRowCallbackHandler(); - - List programStages = ctx.getProgramStages(); - - String aocSql = ctx.isSuperUser() ? "" : getAttributeOptionComboClause(ctx); - - if (programStages.isEmpty()) { - jdbcTemplate.query( - getQuery( - GET_EVENTS_SQL, - ctx, - ACL_FILTER_SQL_NO_PROGRAM_STAGE + aocSql, - FILTER_OUT_DELETED_EVENTS), - createIdsParam(enrollmentsId) - .addValue("trackedEntityTypeIds", ctx.getTrackedEntityTypes()) - .addValue("programIds", ctx.getPrograms()), - handler); - } else { - jdbcTemplate.query( - getQuery(GET_EVENTS_SQL, ctx, ACL_FILTER_SQL + aocSql, FILTER_OUT_DELETED_EVENTS), - createIdsParam(enrollmentsId) - .addValue("trackedEntityTypeIds", ctx.getTrackedEntityTypes()) - .addValue("programStageIds", programStages) - .addValue("programIds", ctx.getPrograms()), - handler); - } - - return handler.getItems(); - } - - Map> getDataValues(List eventIds) { - Map> dataValueListMultimap = new HashMap<>(); - - Lists.partition(eventIds, PARITITION_SIZE) - .forEach(partition -> dataValueListMultimap.putAll(getDataValuesPartitioned(partition))); - - return dataValueListMultimap; - } - - private Map> getDataValuesPartitioned(List eventIds) { - EventDataValueRowCallbackHandler handler = new EventDataValueRowCallbackHandler(); - - jdbcTemplate.query(GET_DATAVALUES_SQL, createIdsParam(eventIds), handler); - - return handler.getItems(); - } - - Multimap getNotes(List eventIds) { - return fetch(GET_NOTES_SQL, new NoteRowCallbackHandler(), eventIds); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java index d8c25e914519..4bd0bce98f0b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java @@ -62,6 +62,7 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwner; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; +import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityIdentifiers; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityQueryParams; import org.hisp.dhis.user.CurrentUserUtil; @@ -111,18 +112,20 @@ protected void init() { /** * Fetches a List of {@see TrackedEntity} based on the list of primary keys and search parameters * - * @param ids a List of {@see TrackedEntity} Primary Keys + * @param identifiers a List of {@see TrackedEntity} primary key and uid tuples * @param params an instance of {@see TrackedEntityParams} * @return a List of {@see TrackedEntity} objects */ public List find( - List ids, + List identifiers, TrackedEntityParams params, TrackedEntityQueryParams queryParams, OrganisationUnitSelectionMode orgUnitMode) { - if (ids.isEmpty()) { + if (identifiers.isEmpty()) { return Collections.emptyList(); } + List ids = identifiers.stream().map(TrackedEntityIdentifiers::id).toList(); + User currentUser = userService.getUserByUsername(CurrentUserUtil.getCurrentUsername()); final Optional user = Optional.ofNullable(currentUser); @@ -184,7 +187,7 @@ public List find( final CompletableFuture> enrollmentsAsync = conditionalAsyncFetch( ctx.getParams().isIncludeEnrollments(), - () -> enrollmentAggregate.findByTrackedEntityIds(ids, ctx), + () -> enrollmentAggregate.findByTrackedEntityIds(identifiers, ctx), getPool()); /* diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityStore.java index 07f2a442b8a8..12445faa877f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityStore.java @@ -163,12 +163,12 @@ Multimap getOwnedTrackedEntities( teds.forEach( partition -> ownedTeisMultiMap.putAll( - getOwnedTeisPartitioned(partition, ctx, skipUserScopeValidation))); + getOwnedTrackedEntitiesPartitioned(partition, ctx, skipUserScopeValidation))); return ownedTeisMultiMap; } - private Multimap getOwnedTeisPartitioned( + private Multimap getOwnedTrackedEntitiesPartitioned( List ids, Context ctx, boolean skipUserScopeValidation) { OwnedTeMapper handler = new OwnedTeMapper(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java deleted file mode 100644 index 205b7725fe12..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java +++ /dev/null @@ -1,109 +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.export.trackedentity.aggregates.mapper; - -import static org.hisp.dhis.tracker.export.trackedentity.aggregates.mapper.JsonbToObjectHelper.setUserInfoSnapshot; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.program.EnrollmentStatus; -import org.hisp.dhis.program.Program; -import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityType; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EnrollmentQuery; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EnrollmentQuery.COLUMNS; - -/** - * @author Luciano Fiandesio - */ -public class EnrollmentRowCallbackHandler extends AbstractMapper { - @Override - Enrollment getItem(ResultSet rs) throws SQLException { - return getEnrollment(rs); - } - - @Override - String getKeyColumn() { - return "te_uid"; - } - - private Enrollment getEnrollment(ResultSet rs) throws SQLException { - Enrollment enrollment = new Enrollment(); - enrollment.setId(rs.getLong(EnrollmentQuery.getColumnName(COLUMNS.ID))); - enrollment.setUid(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.UID))); - - MapperGeoUtils.resolveGeometry(rs.getBytes(EnrollmentQuery.getColumnName(COLUMNS.GEOMETRY))) - .ifPresent(enrollment::setGeometry); - - TrackedEntity trackedEntity = new TrackedEntity(); - trackedEntity.setUid(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.TE_UID))); - TrackedEntityType trackedEntityType = new TrackedEntityType(); - trackedEntityType.setUid(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.TE_TYPE_UID))); - trackedEntity.setTrackedEntityType(trackedEntityType); - enrollment.setTrackedEntity(trackedEntity); - - OrganisationUnit orgUnit = new OrganisationUnit(); - orgUnit.setUid(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.ORGUNIT_UID))); - orgUnit.setName(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.ORGUNIT_NAME))); - enrollment.setOrganisationUnit(orgUnit); - - enrollment.setCreated(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.CREATED))); - enrollment.setCreatedAtClient( - rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.CREATEDCLIENT))); - setUserInfoSnapshot( - rs, EnrollmentQuery.getColumnName(COLUMNS.CREATED_BY), enrollment::setCreatedByUserInfo); - enrollment.setLastUpdated(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.UPDATED))); - enrollment.setLastUpdatedAtClient( - rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.UPDATEDCLIENT))); - setUserInfoSnapshot( - rs, - EnrollmentQuery.getColumnName(COLUMNS.LAST_UPDATED_BY), - enrollment::setLastUpdatedByUserInfo); - - Program program = new Program(); - program.setUid(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.PROGRAM_UID))); - enrollment.setProgram(program); - - final boolean followUp = rs.getBoolean(EnrollmentQuery.getColumnName(COLUMNS.FOLLOWUP)); - enrollment.setFollowup(rs.wasNull() ? null : followUp); - enrollment.setStatus( - EnrollmentStatus.valueOf(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.STATUS)))); - enrollment.setEnrollmentDate( - rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.ENROLLMENTDATE))); - enrollment.setOccurredDate( - rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.OCCURREDDATE))); - enrollment.setCompletedDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED))); - enrollment.setCompletedBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.COMPLETEDBY))); - enrollment.setStoredBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.STOREDBY))); - enrollment.setDeleted(rs.getBoolean(EnrollmentQuery.getColumnName(COLUMNS.DELETED))); - - return enrollment; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventDataValueRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventDataValueRowCallbackHandler.java deleted file mode 100644 index c5801f9b3c9b..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventDataValueRowCallbackHandler.java +++ /dev/null @@ -1,104 +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.export.trackedentity.aggregates.mapper; - -import com.google.gson.Gson; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.hisp.dhis.eventdatavalue.EventDataValue; -import org.hisp.dhis.program.UserInfoSnapshot; -import org.hisp.dhis.util.DateUtils; -import org.postgresql.util.PGobject; -import org.springframework.jdbc.core.RowCallbackHandler; - -/** - * @author Luciano Fiandesio - */ -public class EventDataValueRowCallbackHandler implements RowCallbackHandler { - - private final Map> dataValues; - - private static final Gson gson = new Gson(); - - public EventDataValueRowCallbackHandler() { - this.dataValues = new HashMap<>(); - } - - @Override - public void processRow(ResultSet rs) throws SQLException { - dataValues.put(rs.getString("key"), getDataValue(rs)); - } - - @SuppressWarnings("unchecked") - private List getDataValue(ResultSet rs) throws SQLException { - // TODO not sure this is the most efficient way to handle JSONB -> java - List result = new ArrayList<>(); - - PGobject values = (PGobject) rs.getObject("eventdatavalues"); - Map eventDataValuesJson = gson.fromJson(values.getValue(), Map.class); - - for (Map.Entry entry : eventDataValuesJson.entrySet()) { - Map jsonValues = (Map) entry.getValue(); - - EventDataValue value = new EventDataValue(entry.getKey(), (String) jsonValues.get("value")); - value.setCreated(DateUtils.parseDate((String) jsonValues.get("created"))); - value.setLastUpdated(DateUtils.parseDate((String) jsonValues.get("lastUpdated"))); - value.setStoredBy((String) jsonValues.get("storedBy")); - value.setProvidedElsewhere((Boolean) jsonValues.get("providedElsewhere")); - value.setCreatedByUserInfo( - buildUserInfoSnapshot((Map) jsonValues.get("createdByUserInfo"))); - value.setLastUpdatedByUserInfo( - buildUserInfoSnapshot((Map) jsonValues.get("lastUpdatedByUserInfo"))); - - result.add(value); - } - - return result; - } - - private UserInfoSnapshot buildUserInfoSnapshot(Map createdByUserInfo) { - if (createdByUserInfo == null) { - return null; - } - - UserInfoSnapshot userInfoSnapshot = new UserInfoSnapshot(); - userInfoSnapshot.setUid((String) createdByUserInfo.get("uid")); - userInfoSnapshot.setUsername((String) createdByUserInfo.get("username")); - userInfoSnapshot.setFirstName((String) createdByUserInfo.get("firstName")); - userInfoSnapshot.setSurname((String) createdByUserInfo.get("surname")); - return userInfoSnapshot; - } - - public Map> getItems() { - return this.dataValues; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java deleted file mode 100644 index 586577c3ffaf..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java +++ /dev/null @@ -1,152 +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.export.trackedentity.aggregates.mapper; - -import java.sql.ResultSet; -import java.sql.SQLException; -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.commons.util.TextUtils; -import org.hisp.dhis.event.EventStatus; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.program.EnrollmentStatus; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.program.Program; -import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EventQuery; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.EventQuery.COLUMNS; -import org.hisp.dhis.user.User; - -/** - * @author Luciano Fiandesio - */ -public class EventRowCallbackHandler extends AbstractMapper { - - @Override - Event getItem(ResultSet rs) throws SQLException { - return getEvent(rs); - } - - @Override - String getKeyColumn() { - return "enruid"; - } - - private Event getEvent(ResultSet rs) throws SQLException { - Event event = new Event(); - event.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.UID))); - event.setId(rs.getLong(EventQuery.getColumnName(COLUMNS.ID))); - - event.setStatus(EventStatus.valueOf(rs.getString(EventQuery.getColumnName(COLUMNS.STATUS)))); - event.setOccurredDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.OCCURRED_DATE))); - event.setScheduledDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.SCHEDULED_DATE))); - event.setStoredBy(rs.getString(EventQuery.getColumnName(COLUMNS.STOREDBY))); - event.setCompletedBy(rs.getString(EventQuery.getColumnName(COLUMNS.COMPLETEDBY))); - event.setCompletedDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.COMPLETEDDATE))); - event.setCreated(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.CREATED))); - event.setCreatedAtClient(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.CREATEDCLIENT))); - JsonbToObjectHelper.setUserInfoSnapshot( - rs, EventQuery.getColumnName(COLUMNS.CREATED_BY), event::setCreatedByUserInfo); - event.setLastUpdated(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.UPDATED))); - event.setLastUpdatedAtClient(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.UPDATEDCLIENT))); - JsonbToObjectHelper.setUserInfoSnapshot( - rs, EventQuery.getColumnName(COLUMNS.LAST_UPDATED_BY), event::setLastUpdatedByUserInfo); - MapperGeoUtils.resolveGeometry(rs.getBytes(EventQuery.getColumnName(COLUMNS.GEOMETRY))) - .ifPresent(event::setGeometry); - event.setDeleted(rs.getBoolean(EventQuery.getColumnName(COLUMNS.DELETED))); - - OrganisationUnit orgUnit = new OrganisationUnit(); - orgUnit.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.ORGUNIT_UID))); - orgUnit.setName(rs.getString(EventQuery.getColumnName(COLUMNS.ORGUNIT_NAME))); - event.setOrganisationUnit(orgUnit); - - Enrollment enrollment = new Enrollment(); - enrollment.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.ENROLLMENT_UID))); - Program program = new Program(); - program.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.PROGRAM_UID))); - enrollment.setProgram(program); - final boolean followUp = rs.getBoolean(EventQuery.getColumnName(COLUMNS.ENROLLMENT_FOLLOWUP)); - enrollment.setFollowup(rs.wasNull() ? null : followUp); - enrollment.setStatus( - EnrollmentStatus.valueOf( - rs.getString(EventQuery.getColumnName(COLUMNS.ENROLLMENT_STATUS)))); - TrackedEntity trackedEntity = new TrackedEntity(); - trackedEntity.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.TE_UID))); - enrollment.setTrackedEntity(trackedEntity); - event.setEnrollment(enrollment); - - ProgramStage programStage = new ProgramStage(); - programStage.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.PROGRAM_STAGE_UID))); - event.setProgramStage(programStage); - - CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo(); - categoryOptionCombo.setUid(rs.getString(EventQuery.getColumnName(COLUMNS.COC_UID))); - Set categoryOptions = - TextUtils.splitToSet( - rs.getString(EventQuery.getColumnName(COLUMNS.CAT_OPTIONS)), TextUtils.SEMICOLON) - .stream() - .map( - o -> { - CategoryOption co = new CategoryOption(); - co.setUid(o); - return co; - }) - .collect(Collectors.toSet()); - categoryOptionCombo.setCategoryOptions(categoryOptions); - event.setAttributeOptionCombo(categoryOptionCombo); - - String assignedUserUid = rs.getString(EventQuery.getColumnName(COLUMNS.ASSIGNED_USER)); - String assignedUserUsername = - rs.getString(EventQuery.getColumnName(COLUMNS.ASSIGNED_USER_USERNAME)); - String assignedUserFirstName = - rs.getString(EventQuery.getColumnName(COLUMNS.ASSIGNED_USER_FIRST_NAME)); - String assignedUserSurname = - rs.getString(EventQuery.getColumnName(COLUMNS.ASSIGNED_USER_SURNAME)); - if (StringUtils.isNotEmpty(assignedUserUid) - || StringUtils.isNotEmpty(assignedUserUsername) - || StringUtils.isNotEmpty(assignedUserFirstName) - || StringUtils.isNotEmpty(assignedUserSurname)) { - User assignedUser = new User(); - assignedUser.setUid(assignedUserUid); - assignedUser.setUsername(assignedUserUsername); - assignedUser.setFirstName(assignedUserFirstName); - assignedUser.setSurname(assignedUserSurname); - if (assignedUser.getFirstName() != null && assignedUser.getSurname() != null) { - assignedUser.setName(assignedUser.getFirstName() + " " + assignedUser.getSurname()); - } - event.setAssignedUser(assignedUser); - } - - return event; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java deleted file mode 100644 index 0526b7105945..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java +++ /dev/null @@ -1,56 +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.export.trackedentity.aggregates.mapper; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.hisp.dhis.note.Note; - -/** - * @author Luciano Fiandesio - */ -public class NoteRowCallbackHandler extends AbstractMapper { - @Override - Note getItem(ResultSet rs) throws SQLException { - return getNote(rs); - } - - @Override - String getKeyColumn() { - return "key"; - } - - private Note getNote(ResultSet rs) throws SQLException { - Note note = new Note(); - note.setUid(rs.getString("uid")); - note.setNoteText(rs.getString("notetext")); - note.setCreator(rs.getString("creator")); - note.setCreated(rs.getTimestamp("created")); - return note; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/ProgramAttributeRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/ProgramAttributeRowCallbackHandler.java deleted file mode 100644 index 62b02c49e4c8..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/ProgramAttributeRowCallbackHandler.java +++ /dev/null @@ -1,47 +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.export.trackedentity.aggregates.mapper; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.ProgramAttributeQuery; -import org.hisp.dhis.tracker.export.trackedentity.aggregates.query.ProgramAttributeQuery.COLUMNS; - -public class ProgramAttributeRowCallbackHandler extends AbstractMapper - implements AttributeMapper { - @Override - TrackedEntityAttributeValue getItem(ResultSet rs) throws SQLException { - return getAttribute(rs); - } - - @Override - String getKeyColumn() { - return ProgramAttributeQuery.getColumnName(COLUMNS.PI_UID); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EnrollmentQuery.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EnrollmentQuery.java deleted file mode 100644 index 9384db933f90..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EnrollmentQuery.java +++ /dev/null @@ -1,109 +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.export.trackedentity.aggregates.query; - -import com.google.common.collect.ImmutableMap; -import java.util.Map; - -/** - * @author Luciano Fiandesio - */ -public class EnrollmentQuery { - public enum COLUMNS { - TE_UID, - ID, - UID, - CREATED, - CREATEDCLIENT, - CREATED_BY, - UPDATED, - UPDATEDCLIENT, - LAST_UPDATED_BY, - STATUS, - GEOMETRY, - ENROLLMENTDATE, - OCCURREDDATE, - FOLLOWUP, - COMPLETED, - COMPLETEDBY, - STOREDBY, - DELETED, - PROGRAM_UID, - PROGRAM_FEATURE_TYPE, - TE_TYPE_UID, - ORGUNIT_UID, - ORGUNIT_NAME - } - - public static final Map columnMap = - ImmutableMap.builder() - .put(COLUMNS.TE_UID, new TableColumn("te", "uid", "te_uid")) - .put(COLUMNS.GEOMETRY, new Function("ST_AsBinary", "en", "geometry", "geometry")) - .put(COLUMNS.ID, new TableColumn("en", "enrollmentid")) - .put(COLUMNS.UID, new TableColumn("en", "uid")) - .put(COLUMNS.CREATED, new TableColumn("en", "created")) - .put(COLUMNS.CREATEDCLIENT, new TableColumn("en", "createdatclient")) - .put(COLUMNS.CREATED_BY, new TableColumn("en", "createdbyuserinfo")) - .put(COLUMNS.UPDATED, new TableColumn("en", "lastupdated")) - .put(COLUMNS.UPDATEDCLIENT, new TableColumn("en", "lastupdatedatclient")) - .put(COLUMNS.LAST_UPDATED_BY, new TableColumn("en", "lastupdatedbyuserinfo")) - .put(COLUMNS.STATUS, new TableColumn("en", "status")) - .put(COLUMNS.ENROLLMENTDATE, new TableColumn("en", "enrollmentdate")) - .put(COLUMNS.OCCURREDDATE, new TableColumn("en", "occurreddate")) - .put(COLUMNS.FOLLOWUP, new TableColumn("en", "followup")) - .put(COLUMNS.COMPLETED, new TableColumn("en", "completeddate")) - .put(COLUMNS.COMPLETEDBY, new TableColumn("en", "completedby")) - .put(COLUMNS.STOREDBY, new TableColumn("en", "storedby")) - .put(COLUMNS.DELETED, new TableColumn("en", "deleted")) - .put(COLUMNS.PROGRAM_UID, new TableColumn("p", "uid", "program_uid")) - .put( - COLUMNS.PROGRAM_FEATURE_TYPE, - new TableColumn("p", "featuretype", "program_feature_type")) - .put(COLUMNS.TE_TYPE_UID, new TableColumn("tet", "uid", "type_uid")) - .put(COLUMNS.ORGUNIT_UID, new TableColumn("o", "uid", "ou_uid")) - .put(COLUMNS.ORGUNIT_NAME, new TableColumn("o", "name", "ou_name")) - .build(); - - public static String getQuery() { - return getSelect() - + "from enrollment en " - + "join program p on en.programid = p.programid " - + "join trackedentity te on en.trackedentityid = te.trackedentityid " - + "join trackedentitytype tet on te.trackedentitytypeid = tet.trackedentitytypeid " - + "join organisationunit o on en.organisationunitid = o.organisationunitid " - + "where en.trackedentityid in (:ids) "; - } - - private static String getSelect() { - return QueryUtils.getSelect(columnMap.values()); - } - - public static String getColumnName(COLUMNS columns) { - return columnMap.get(columns).getResultsetValue(); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java deleted file mode 100644 index b750f77aec85..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java +++ /dev/null @@ -1,127 +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.export.trackedentity.aggregates.query; - -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; - -import com.google.common.collect.ImmutableList; -import java.util.Arrays; -import java.util.Collection; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * @author Luciano Fiandesio - */ -public class EventQuery { - @RequiredArgsConstructor - public enum COLUMNS { - ID(new TableColumn("ev", "eventid")), - UID(new TableColumn("ev", "uid")), - STATUS(new TableColumn("ev", "status")), - OCCURRED_DATE(new TableColumn("ev", "occurreddate")), - SCHEDULED_DATE(new TableColumn("ev", "scheduleddate")), - STOREDBY(new TableColumn("ev", "storedby")), - COMPLETEDBY(new TableColumn("ev", "completedby")), - COMPLETEDDATE(new TableColumn("ev", "completeddate")), - CREATED_BY(new TableColumn("ev", "createdbyuserinfo")), - CREATED(new TableColumn("ev", "created")), - CREATEDCLIENT(new TableColumn("ev", "createdatclient")), - UPDATED(new TableColumn("ev", "lastupdated")), - UPDATEDCLIENT(new TableColumn("ev", "lastupdatedatclient")), - LAST_UPDATED_BY(new TableColumn("ev", "lastupdatedbyuserinfo")), - DELETED(new TableColumn("ev", "deleted")), - GEOMETRY(new Function("ST_AsBinary", "ev", "geometry", "geometry")), - TE_UID(new TableColumn("te", "uid", "te_uid")), - ENROLLMENT_UID(new TableColumn("en", "uid", "enruid")), - ENROLLMENT_FOLLOWUP(new TableColumn("en", "followup", "enrfollowup")), - ENROLLMENT_STATUS(new TableColumn("en", "status", "enrstatus")), - PROGRAM_UID(new TableColumn("p", "uid", "prguid")), - PROGRAM_STAGE_UID(new TableColumn("ps", "uid", "prgstguid")), - ORGUNIT_UID(new TableColumn("o", "uid", "ou_uid")), - ORGUNIT_NAME(new TableColumn("o", "name", "ou_name")), - COC_UID(new TableColumn("coc", "uid", "cocuid")), - CAT_OPTIONS( - new Subselect( - "( " - + "SELECT string_agg(opt.uid::text, ';') " - + "FROM categoryoption opt " - + "join categoryoptioncombos_categoryoptions ccc " - + "on opt.categoryoptionid = ccc.categoryoptionid " - + "WHERE coc.categoryoptioncomboid = ccc.categoryoptioncomboid )", - "catoptions")), - ASSIGNED_USER(new TableColumn("ui", "uid", "userid")), - ASSIGNED_USER_FIRST_NAME(new TableColumn("ui", "firstname")), - ASSIGNED_USER_SURNAME(new TableColumn("ui", "surname")), - ASSIGNED_USER_USERNAME(new TableColumn("ui", "username")); - - @Getter private final QueryElement queryElement; - - public String getColumnName() { - if (queryElement instanceof TableColumn tableColumn) { - return tableColumn.getColumn(); - } - if (queryElement instanceof Function function) { - return function.getColumn(); - } - throw new IllegalArgumentException( - "getColumnName can only be invoked on TableColumn or Function"); - } - } - - private static final Collection QUERY_ELEMENTS; - - static { - QUERY_ELEMENTS = - Arrays.stream(COLUMNS.values()) - .map(COLUMNS::getQueryElement) - .collect(collectingAndThen(toList(), ImmutableList::copyOf)); - } - - public static String getQuery() { - return getSelect() - + "from event ev " - + "join enrollment en on ev.enrollmentid = en.enrollmentid " - + "join trackedentity te on en.trackedentityid = te.trackedentityid " - + "join program p on en.programid = p.programid " - + "join programstage ps on ev.programstageid = ps.programstageid " - + "join organisationunit o on ev.organisationunitid = o.organisationunitid " - + "join categoryoptioncombo coc on ev.attributeoptioncomboid = coc.categoryoptioncomboid " - + "left join userinfo ui on ev.assigneduserid = ui.userinfoid " - + "where en.enrollmentid in (:ids)"; - } - - private static String getSelect() { - return QueryUtils.getSelect(QUERY_ELEMENTS); - } - - public static String getColumnName(COLUMNS columns) { - return columns.getQueryElement().getResultsetValue(); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/ProgramAttributeQuery.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/ProgramAttributeQuery.java deleted file mode 100644 index a98091354474..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/ProgramAttributeQuery.java +++ /dev/null @@ -1,80 +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.export.trackedentity.aggregates.query; - -import com.google.common.collect.ImmutableMap; -import java.util.Map; - -public class ProgramAttributeQuery { - public enum COLUMNS { - PI_UID, - PI_ID, - CREATED, - UPDATED, - VALUE, - STOREDBY, - ATTR_UID, - ATTR_NAME, - ATTR_VALUE_TYPE, - ATTR_CODE, - ATTR_SKIP_SYNC - } - - public static final Map columnMap = - ImmutableMap.builder() - .put(COLUMNS.PI_UID, new TableColumn("en", "uid", "pi_uid")) - .put(COLUMNS.PI_ID, new TableColumn("en", "enrollmentid", "id")) - .put(COLUMNS.CREATED, new TableColumn("teav", "created")) - .put(COLUMNS.UPDATED, new TableColumn("teav", "lastupdated")) - .put(COLUMNS.STOREDBY, new TableColumn("teav", "storedby")) - .put(COLUMNS.VALUE, new TableColumn("teav", "value")) - .put(COLUMNS.ATTR_UID, new TableColumn("t", "uid", "att_uid")) - .put(COLUMNS.ATTR_VALUE_TYPE, new TableColumn("t", "valuetype", "att_val_type")) - .put(COLUMNS.ATTR_CODE, new TableColumn("t", "code", "att_code")) - .put(COLUMNS.ATTR_NAME, new TableColumn("t", "name", "att_name")) - .put(COLUMNS.ATTR_SKIP_SYNC, new TableColumn("t", "skipsynchronization", "att_skip_sync")) - .build(); - - public static String getQuery() { - return getSelect() - + "from trackedentityattributevalue teav " - + "join program_attributes pa on teav.trackedentityattributeid = pa.trackedentityattributeid " - + "join trackedentityattribute t on t.trackedentityattributeid = pa.trackedentityattributeid " - + "join trackedentity te on te.trackedentityid = teav.trackedentityid " - + "join enrollment en on en.programid = pa.programid and en.trackedentityid = te.trackedentityid " - + "where en.enrollmentid IN (:ids)"; - } - - private static String getSelect() { - return QueryUtils.getSelect(columnMap.values()); - } - - public static String getColumnName(COLUMNS columns) { - return columnMap.get(columns).getResultsetValue(); - } -} diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java index c02670ca455e..d8e03286548c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java @@ -74,6 +74,7 @@ import org.hisp.dhis.common.QueryFilter; import org.hisp.dhis.common.QueryOperator; import org.hisp.dhis.common.UID; +import org.hisp.dhis.common.UidObject; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.event.EventStatus; import org.hisp.dhis.feedback.BadRequestException; @@ -1301,18 +1302,18 @@ void shouldReturnTrackedEntityWithEventsAndNotesGivenTheyShouldBeIncluded() List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); - assertContainsOnly(List.of(trackedEntityA), trackedEntities); + assertContainsOnly(List.of(trackedEntityA), trackedEntities, UidObject::getUid); assertContainsOnly( - Set.of(enrollmentA.getUid(), enrollmentB.getUid()), - uids(trackedEntities.get(0).getEnrollments())); - // ensure that EventAggregate is called and attaches the events with notes + Set.of(enrollmentA, enrollmentB), + trackedEntities.get(0).getEnrollments(), + UidObject::getUid); List enrollments = new ArrayList<>(trackedEntities.get(0).getEnrollments()); Optional enrollmentA = enrollments.stream() .filter(enrollment -> enrollment.getUid().equals(this.enrollmentA.getUid())) .findFirst(); Set events = enrollmentA.get().getEvents(); - assertContainsOnly(Set.of(eventA), events); + assertContainsOnly(Set.of(eventA), events, UidObject::getUid); assertNotes(eventA.getNotes(), events.stream().findFirst().get().getNotes()); } @@ -1429,10 +1430,7 @@ void shouldReturnEnrollmentMappedCorrectly() assertAll( () -> assertEquals(enrollmentA.getId(), enrollment.getId()), () -> assertEquals(trackedEntityA.getUid(), enrollment.getTrackedEntity().getUid()), - () -> - assertEquals( - trackedEntityA.getTrackedEntityType().getUid(), - enrollment.getTrackedEntity().getTrackedEntityType().getUid()), + () -> assertEquals(trackedEntityA.getUid(), enrollment.getTrackedEntity().getUid()), () -> assertEquals(orgUnitA.getUid(), enrollment.getOrganisationUnit().getUid()), () -> assertEquals(orgUnitA.getName(), enrollment.getOrganisationUnit().getName()), () -> assertEquals(programA.getUid(), enrollment.getProgram().getUid()),