From 180976d8995a6fdaa72a30abc8f8afabb0f3a512 Mon Sep 17 00:00:00 2001 From: Enrico Date: Tue, 24 Oct 2023 18:14:28 +0200 Subject: [PATCH 1/5] chore: split fetching all TEs from fetching paginated TEs [TECH-1661] Update dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java chore: split fetching all TEs from fetching paginated TEs [TECH-1661] chore: split fetching all TEs from fetching paginated TEs [TECH-1661] --- .../DefaultTrackedEntityService.java | 43 ++++++--- .../TrackedEntityOperationParamsMapper.java | 4 - .../trackedentity/TrackedEntityService.java | 19 ++-- ...rackedEntityOperationParamsMapperTest.java | 7 -- .../OrderAndPaginationExporterTest.java | 72 ++++++--------- .../TrackedEntityServiceTest.java | 87 +++++++------------ .../export/trackedentity/RequestParams.java | 13 ++- .../TrackedEntitiesExportController.java | 40 ++++++--- .../TrackedEntityRequestParamsMapper.java | 10 --- .../TrackedEntityRequestParamsMapperTest.java | 7 -- 10 files changed, 139 insertions(+), 163 deletions(-) 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 65b7b9a8faa0..8c6e930d9c20 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 @@ -78,6 +78,8 @@ import org.hisp.dhis.trackedentity.TrackerAccessManager; import org.hisp.dhis.trackedentity.TrackerOwnershipManager; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; +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; @@ -306,9 +308,10 @@ private RelationshipItem withNestedEntity( } @Override - public TrackedEntities getTrackedEntities(TrackedEntityOperationParams operationParams) + public List getTrackedEntities(TrackedEntityOperationParams operationParams) throws ForbiddenException, NotFoundException, BadRequestException { TrackedEntityQueryParams queryParams = mapper.map(operationParams); + queryParams.setSkipPaging(true); final List ids = getTrackedEntityIds(queryParams); List trackedEntities = @@ -322,21 +325,41 @@ public TrackedEntities getTrackedEntities(TrackedEntityOperationParams operation addSearchAudit(trackedEntities, queryParams.getUser()); - if (operationParams.isSkipPaging()) { - return TrackedEntities.withoutPagination(trackedEntities); - } + return trackedEntities; + } + + @Override + public Page getTrackedEntities( + TrackedEntityOperationParams operationParams, PageParams pageParams) + throws BadRequestException, ForbiddenException, NotFoundException { + TrackedEntityQueryParams queryParams = mapper.map(operationParams); + queryParams.setPage(pageParams.getPage()); + queryParams.setPageSize(pageParams.getPageSize()); + queryParams.setTotalPages(pageParams.isPageTotal()); + queryParams.setSkipPaging(false); + final List ids = getTrackedEntityIds(queryParams); + + List trackedEntities = + this.trackedEntityAggregate.find( + ids, operationParams.getTrackedEntityParams(), queryParams); + + mapRelationshipItems( + trackedEntities, + operationParams.getTrackedEntityParams(), + operationParams.isIncludeDeleted()); + + addSearchAudit(trackedEntities, queryParams.getUser()); Pager pager; - if (operationParams.isTotalPages()) { + if (pageParams.isPageTotal()) { int count = getTrackedEntityCount(queryParams, true, true); - pager = - new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault()); + pager = new Pager(pageParams.getPage(), count, pageParams.getPageSize()); } else { - pager = handleLastPageFlag(operationParams, trackedEntities); + pager = handleLastPageFlag(queryParams, trackedEntities); } - return TrackedEntities.of(trackedEntities, pager); + return Page.of(trackedEntities, pager); } public List getTrackedEntityIds(TrackedEntityQueryParams params) { @@ -760,7 +783,7 @@ private void addTrackedEntityAudit(TrackedEntity trackedEntity, String user) { * @return the populated SlimPager instance */ private Pager handleLastPageFlag( - TrackedEntityOperationParams params, List trackedEntityList) { + TrackedEntityQueryParams params, List trackedEntityList) { Integer originalPage = defaultIfNull(params.getPage(), FIRST_PAGE); Integer originalPageSize = defaultIfNull(params.getPageSize(), DEFAULT_PAGE_SIZE); boolean isLastPage = false; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapper.java index 89d8571d0321..f7f15b66324e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapper.java @@ -106,10 +106,6 @@ public TrackedEntityQueryParams map(TrackedEntityOperationParams operationParams .setAssignedUserQueryParam(operationParams.getAssignedUserQueryParam()) .setUser(user) .setTrackedEntityUids(operationParams.getTrackedEntityUids()) - .setPage(operationParams.getPage()) - .setPageSize(operationParams.getPageSize()) - .setTotalPages(operationParams.isTotalPages()) - .setSkipPaging(operationParams.isSkipPaging()) .setIncludeDeleted(operationParams.isIncludeDeleted()) .setPotentialDuplicate(operationParams.getPotentialDuplicate()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityService.java index 736bce70bcce..65959cc2d49d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityService.java @@ -27,11 +27,14 @@ */ package org.hisp.dhis.tracker.export.trackedentity; +import java.util.List; import java.util.Set; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.trackedentity.TrackedEntity; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; public interface TrackedEntityService { @@ -46,15 +49,13 @@ TrackedEntity getTrackedEntity( String uid, String programIdentifier, TrackedEntityParams params, boolean includeDeleted) throws NotFoundException, ForbiddenException; - /** - * Fetches {@see TrackedEntity}s based on the specified parameters. - * - * @param operationParams a {@see TrackedEntityOperationParams} instance with the operation - * parameters - * @return {@see TrackedEntity}s - */ - TrackedEntities getTrackedEntities(TrackedEntityOperationParams operationParams) - throws ForbiddenException, NotFoundException, BadRequestException; + /** Get all tracked entities matching given params. */ + List getTrackedEntities(TrackedEntityOperationParams operationParams) + throws BadRequestException, ForbiddenException, NotFoundException; + + /** Get a page of tracked entities matching given params. */ + Page getTrackedEntities(TrackedEntityOperationParams params, PageParams pageParams) + throws BadRequestException, ForbiddenException, NotFoundException; /** * Fields the {@link #getTrackedEntities(TrackedEntityOperationParams)} can order tracked entities diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java index ee3c6e1a119b..5929f9121425 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java @@ -189,19 +189,12 @@ void testMapping() throws BadRequestException, ForbiddenException { .eventStatus(EventStatus.COMPLETED) .eventStartDate(getDate(2019, 7, 7)) .eventEndDate(getDate(2020, 7, 7)) - .page(1) - .pageSize(50) - .totalPages(false) - .skipPaging(false) .includeDeleted(true) .build(); final TrackedEntityQueryParams params = mapper.map(operationParams); assertThat(params.getTrackedEntityType(), is(trackedEntityType)); - assertThat(params.getPageSize(), is(50)); - assertThat(params.getPage(), is(1)); - assertThat(params.isTotalPages(), is(false)); assertThat(params.getProgramStatus(), is(ProgramStatus.ACTIVE)); assertThat(params.getFollowUp(), is(true)); assertThat(params.getLastUpdatedStartDate(), is(operationParams.getLastUpdatedStartDate())); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java index 724235fb1e8e..ae903768560d 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java @@ -75,9 +75,7 @@ import org.hisp.dhis.tracker.export.relationship.RelationshipOperationParams.RelationshipOperationParamsBuilder; import org.hisp.dhis.tracker.export.relationship.RelationshipService; import org.hisp.dhis.tracker.export.relationship.Relationships; -import org.hisp.dhis.tracker.export.trackedentity.TrackedEntities; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityOperationParams; -import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityOperationParams.TrackedEntityOperationParamsBuilder; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityService; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; @@ -138,87 +136,69 @@ void setUp() { @Test void shouldReturnPaginatedTrackedEntitiesGivenNonDefaultPageSize() throws ForbiddenException, BadRequestException, NotFoundException { - TrackedEntityOperationParamsBuilder builder = + TrackedEntityOperationParams params = TrackedEntityOperationParams.builder() .organisationUnits(Set.of(orgUnit.getUid())) .orgUnitMode(DESCENDANTS) .trackedEntityTypeUid(trackedEntityType.getUid()) - .orderBy(UID.of("numericAttr"), SortDirection.ASC); - - TrackedEntityOperationParams params = builder.page(1).pageSize(3).user(importUser).build(); + .user(importUser) + .orderBy(UID.of("numericAttr"), SortDirection.ASC) + .build(); - TrackedEntities firstPage = trackedEntityService.getTrackedEntities(params); + Page firstPage = + trackedEntityService.getTrackedEntities(params, new PageParams(1, 3, false)); assertAll( "first page", - // TODO(tracker): fix in TECH-1601. I assume this was recently introduced (only on master) - // when - // handleLastPageFlag was copied from the event service which works in conjunction with the - // event store - // that fetches pageSize + 1 when totalCount=false. This split of logic between - // service/store is - // error prone and hard to follow. We will fix/refactor it for all entities so this is - // purely a concern - // of the store. - () -> assertSlimPager(1, 3, true, firstPage.getPager()), + () -> assertPager(1, 3, firstPage), () -> assertEquals( - List.of("dUE514NMOlo", "mHWCacsGYYn", "QS6w44flWAf"), - uids(firstPage.getTrackedEntities()))); - - params = builder.page(2).pageSize(3).build(); + List.of("dUE514NMOlo", "mHWCacsGYYn", "QS6w44flWAf"), uids(firstPage.getItems()))); - TrackedEntities secondPage = trackedEntityService.getTrackedEntities(params); + Page secondPage = + trackedEntityService.getTrackedEntities(params, new PageParams(2, 3, false)); assertAll( "second (last) page", - () -> assertSlimPager(2, 3, true, secondPage.getPager()), - () -> - assertEquals( - List.of("QesgJkTyTCk", "guVNoAerxWo"), uids(secondPage.getTrackedEntities()))); - - params = builder.page(3).pageSize(3).build(); + () -> assertPager(2, 3, secondPage), + () -> assertEquals(List.of("QesgJkTyTCk", "guVNoAerxWo"), uids(secondPage.getItems()))); - assertIsEmpty(getTrackedEntities(params)); + assertIsEmpty( + trackedEntityService.getTrackedEntities(params, new PageParams(3, 3, false)).getItems()); } @Test void shouldReturnPaginatedTrackedEntitiesGivenNonDefaultPageSizeAndTotalPages() throws ForbiddenException, BadRequestException, NotFoundException { - TrackedEntityOperationParamsBuilder builder = + TrackedEntityOperationParams params = TrackedEntityOperationParams.builder() .organisationUnits(Set.of(orgUnit.getUid())) .orgUnitMode(DESCENDANTS) .trackedEntityTypeUid(trackedEntityType.getUid()) .user(importUser) - .orderBy(UID.of("numericAttr"), SortDirection.ASC); - - TrackedEntityOperationParams params = builder.page(1).pageSize(3).totalPages(true).build(); + .orderBy(UID.of("numericAttr"), SortDirection.ASC) + .build(); - TrackedEntities firstPage = trackedEntityService.getTrackedEntities(params); + Page firstPage = + trackedEntityService.getTrackedEntities(params, new PageParams(1, 3, true)); assertAll( "first page", () -> assertPager(1, 3, 5, firstPage.getPager()), () -> assertEquals( - List.of("dUE514NMOlo", "mHWCacsGYYn", "QS6w44flWAf"), - uids(firstPage.getTrackedEntities()))); + List.of("dUE514NMOlo", "mHWCacsGYYn", "QS6w44flWAf"), uids(firstPage.getItems()))); - params = builder.page(2).pageSize(3).totalPages(true).build(); - - TrackedEntities secondPage = trackedEntityService.getTrackedEntities(params); + Page secondPage = + trackedEntityService.getTrackedEntities(params, new PageParams(2, 3, true)); assertAll( "second (last) page", () -> assertPager(2, 3, 5, secondPage.getPager()), - () -> - assertEquals( - List.of("QesgJkTyTCk", "guVNoAerxWo"), uids(secondPage.getTrackedEntities()))); - - params = builder.page(3).pageSize(3).totalPages(true).build(); + () -> assertEquals(List.of("QesgJkTyTCk", "guVNoAerxWo"), uids(secondPage.getItems()))); - assertIsEmpty(getTrackedEntities(params)); + assertIsEmpty( + trackedEntityService.getTrackedEntities(params, new PageParams(3, 3, true)).getItems()); } @Test @@ -1317,7 +1297,7 @@ private static void assertPager(int pageNumber, int pageSize, int totalCount, Pa private List getTrackedEntities(TrackedEntityOperationParams params) throws ForbiddenException, BadRequestException, NotFoundException { - return uids(trackedEntityService.getTrackedEntities(params).getTrackedEntities()); + return uids(trackedEntityService.getTrackedEntities(params)); } private List getEnrollments(EnrollmentOperationParams params) 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 5495a16a76db..6f75b5adc36a 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 @@ -431,7 +431,7 @@ void shouldReturnTrackedEntitiesGivenUserHasDataReadAccessToTrackedEntityType() .build(); final List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA, trackedEntityB), trackedEntities); } @@ -452,7 +452,7 @@ void shouldReturnTrackedEntityIncludingAllAttributesEnrollmentsEventsRelationshi .build(); final List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA.getUid()), uids(trackedEntities)); assertContainsOnly(Set.of(enrollmentA.getUid()), uids(trackedEntities.get(0).getEnrollments())); @@ -491,7 +491,7 @@ void shouldReturnTrackedEntityIncludeSpecificProtectedProgram() .build(); final List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); assertContainsOnly( @@ -510,8 +510,7 @@ void shouldTrackedEntityIncludeSpecificOpenProgram() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); assertContainsOnly( @@ -531,8 +530,7 @@ void shouldReturnEmptyCollectionGivenSingleQuoteInAttributeSearchInput() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertIsEmpty(trackedEntities); } @@ -549,8 +547,7 @@ void shouldReturnTrackedEntityIfGivenFilterMatches() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); } @@ -567,8 +564,7 @@ void shouldReturnEmptyCollectionIfGivenFilterDoesNotMatch() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertIsEmpty(trackedEntities); } @@ -585,8 +581,7 @@ void shouldReturnTrackedEntitiesIfTheyHaveGivenAttributeFilteredUsingOnlyUID() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); } @@ -604,8 +599,7 @@ void shouldReturnTrackedEntityWithLastUpdatedParameter() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); @@ -620,7 +614,7 @@ void shouldReturnTrackedEntityWithLastUpdatedParameter() .user(user) .build(); - assertIsEmpty(trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities()); + assertIsEmpty(trackedEntityService.getTrackedEntities(operationParams)); } @Test @@ -637,39 +631,27 @@ void shouldReturnTrackedEntityWithEventFilters() .eventEndDate(Date.from(Instant.now().plus(10, ChronoUnit.DAYS))); final List trackedEntities = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.COMPLETED).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.COMPLETED).build()); assertEquals(4, trackedEntities.size()); // Update status to active final List limitedTrackedEntities = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.ACTIVE).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.ACTIVE).build()); assertIsEmpty(limitedTrackedEntities); // Update status to overdue final List limitedTrackedEntities2 = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.OVERDUE).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.OVERDUE).build()); assertIsEmpty(limitedTrackedEntities2); // Update status to schedule final List limitedTrackedEntities3 = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.OVERDUE).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.OVERDUE).build()); assertIsEmpty(limitedTrackedEntities3); // Update status to schedule final List limitedTrackedEntities4 = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.SCHEDULE).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.SCHEDULE).build()); assertIsEmpty(limitedTrackedEntities4); // Update status to visited final List limitedTrackedEntities5 = - trackedEntityService - .getTrackedEntities(builder.eventStatus(EventStatus.VISITED).build()) - .getTrackedEntities(); + trackedEntityService.getTrackedEntities(builder.eventStatus(EventStatus.VISITED).build()); assertIsEmpty(limitedTrackedEntities5); } @@ -686,8 +668,7 @@ void shouldIncludeDeletedEnrollmentAndEvents() .trackedEntityParams(TrackedEntityParams.TRUE) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); TrackedEntity trackedEntity = trackedEntities.get(0); @@ -708,7 +689,7 @@ void shouldIncludeDeletedEnrollmentAndEvents() enrollmentService.deleteEnrollment(enrollmentA); eventService.deleteEvent(eventA); - trackedEntities = trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); trackedEntity = trackedEntities.get(0); @@ -741,7 +722,7 @@ void shouldIncludeDeletedEnrollmentAndEvents() .includeDeleted(false) .trackedEntityParams(TrackedEntityParams.TRUE) .build(); - trackedEntities = trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); trackedEntity = trackedEntities.get(0); @@ -768,8 +749,7 @@ void shouldReturnTrackedEntityAndEnrollmentsGivenTheyShouldBeIncluded() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA.getUid()), uids(trackedEntities)); assertContainsOnly( @@ -799,8 +779,7 @@ void shouldReturnTrackedEntityWithoutEnrollmentsGivenTheyShouldNotBeIncluded() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); assertIsEmpty(trackedEntities.get(0).getEnrollments()); @@ -821,8 +800,7 @@ void shouldReturnTrackedEntityWithEventsAndNotesGivenTheyShouldBeIncluded() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA), trackedEntities); assertContainsOnly( @@ -854,8 +832,7 @@ void shouldReturnTrackedEntityWithoutEventsGivenTheyShouldNotBeIncluded() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); assertContainsOnly(List.of(trackedEntityA.getUid()), uids(trackedEntities)); assertContainsOnly( @@ -881,8 +858,7 @@ void shouldReturnTrackedEntityMappedCorrectly() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); TrackedEntity trackedEntity = trackedEntities.get(0); assertAll( @@ -916,8 +892,7 @@ void shouldReturnEnrollmentMappedCorrectly() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); List enrollments = new ArrayList<>(trackedEntities.get(0).getEnrollments()); Optional enrollmentOpt = @@ -963,8 +938,7 @@ void shouldReturnEventMappedCorrectly() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); List enrollments = new ArrayList<>(trackedEntities.get(0).getEnrollments()); Optional enrollmentOpt = @@ -1018,8 +992,7 @@ void shouldReturnTrackedEntityWithRelationshipsTei2Tei() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); TrackedEntity trackedEntity = trackedEntities.get(0); Optional relOpt = @@ -1047,8 +1020,7 @@ void returnTrackedEntityRelationshipsWithTei2Enrollment() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); TrackedEntity trackedEntity = trackedEntities.get(0); Optional relOpt = @@ -1076,8 +1048,7 @@ void shouldReturnTrackedEntityRelationshipsWithTei2Event() .user(user) .build(); - List trackedEntities = - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities(); + List trackedEntities = trackedEntityService.getTrackedEntities(operationParams); TrackedEntity trackedEntity = trackedEntities.get(0); Optional relOpt = diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/RequestParams.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/RequestParams.java index 574dc9e54af1..a24a426eb94d 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/RequestParams.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/RequestParams.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller.tracker.export.trackedentity; +import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -45,7 +46,8 @@ import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.program.ProgramStatus; import org.hisp.dhis.trackedentity.TrackedEntityType; -import org.hisp.dhis.webapi.controller.event.webrequest.PagingAndSortingCriteriaAdapter; +import org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria; +import org.hisp.dhis.webapi.controller.tracker.export.PageRequestParams; import org.hisp.dhis.webapi.controller.tracker.view.TrackedEntity; import org.hisp.dhis.webapi.controller.tracker.view.User; @@ -58,9 +60,16 @@ @OpenApi.Property @Data @NoArgsConstructor -class RequestParams extends PagingAndSortingCriteriaAdapter { +class RequestParams implements PageRequestParams { static final String DEFAULT_FIELDS_PARAM = "*,!relationships,!enrollments,!events,!programOwners"; + private Integer page; + private Integer pageSize; + private Boolean totalPages; + private Boolean skipPaging; + + private List order = new ArrayList<>(); + @Deprecated(forRemoval = true, since = "2.41") // Removed field without previous deprecation. // It is still here in order to be validated and warn the client about the removal diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java index e298bcb2ca06..009e8753fb2d 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java @@ -56,7 +56,8 @@ import org.hisp.dhis.fieldfiltering.FieldFilterService; import org.hisp.dhis.fieldfiltering.FieldPath; import org.hisp.dhis.program.Program; -import org.hisp.dhis.tracker.export.trackedentity.TrackedEntities; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityOperationParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityService; @@ -133,21 +134,40 @@ PagingWrapper getTrackedEntities( RequestParams requestParams, @CurrentUser User currentUser) throws BadRequestException, ForbiddenException, NotFoundException { TrackedEntityOperationParams operationParams = paramsMapper.map(requestParams, currentUser); + if (requestParams.isPaged()) { + PageParams pageParams = + new PageParams( + requestParams.getPage(), requestParams.getPageSize(), requestParams.getTotalPages()); - TrackedEntities trackedEntities = trackedEntityService.getTrackedEntities(operationParams); + Page trackedEntityPage = + trackedEntityService.getTrackedEntities(operationParams, pageParams); - PagingWrapper pagingWrapper = new PagingWrapper<>(); + PagingWrapper.Pager.PagerBuilder pagerBuilder = + PagingWrapper.Pager.builder() + .page(trackedEntityPage.getPager().getPage()) + .pageSize(trackedEntityPage.getPager().getPageSize()); + + if (requestParams.isPageTotal()) { + pagerBuilder + .pageCount(trackedEntityPage.getPager().getPageCount()) + .total(trackedEntityPage.getPager().getTotal()); + } - if (requestParams.isPagingRequest()) { - pagingWrapper = - pagingWrapper.withPager( - PagingWrapper.Pager.fromLegacy(requestParams, trackedEntities.getPager())); + PagingWrapper pagingWrapper = new PagingWrapper<>(); + pagingWrapper = pagingWrapper.withPager(pagerBuilder.build()); + List objectNodes = + fieldFilterService.toObjectNodes( + TRACKED_ENTITY_MAPPER.fromCollection(trackedEntityPage.getItems()), + requestParams.getFields()); + return pagingWrapper.withInstances(objectNodes); } + List trackedEntities = + trackedEntityService.getTrackedEntities(operationParams); List objectNodes = fieldFilterService.toObjectNodes( - TRACKED_ENTITY_MAPPER.fromCollection(trackedEntities.getTrackedEntities()), - requestParams.getFields()); + TRACKED_ENTITY_MAPPER.fromCollection(trackedEntities), requestParams.getFields()); + PagingWrapper pagingWrapper = new PagingWrapper<>(); return pagingWrapper.withInstances(objectNodes); } @@ -170,7 +190,7 @@ void getTrackedEntitiesAsCsv( List trackedEntities = TRACKED_ENTITY_MAPPER.fromCollection( - trackedEntityService.getTrackedEntities(operationParams).getTrackedEntities()); + trackedEntityService.getTrackedEntities(operationParams)); OutputStream outputStream = response.getOutputStream(); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapper.java index 679c9ba3e5d0..793ef56dfd00 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapper.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.webapi.controller.tracker.export.trackedentity; -import static org.apache.commons.lang3.BooleanUtils.toBooleanDefaultIfNull; import static org.hisp.dhis.webapi.controller.tracker.export.RequestParamsValidator.parseFilters; import static org.hisp.dhis.webapi.controller.tracker.export.RequestParamsValidator.validateDeprecatedParameter; import static org.hisp.dhis.webapi.controller.tracker.export.RequestParamsValidator.validateDeprecatedUidsParameter; @@ -36,7 +35,6 @@ import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -59,10 +57,6 @@ @Component @RequiredArgsConstructor class TrackedEntityRequestParamsMapper { - - private static final int DEFAULT_PAGE = 1; - private static final int DEFAULT_PAGE_SIZE = 50; - private static final Set ORDERABLE_FIELD_NAMES = TrackedEntityMapper.ORDERABLE_FIELDS.keySet(); @@ -138,10 +132,6 @@ public TrackedEntityOperationParams map( .user(user) .trackedEntityUids(UID.toValueSet(trackedEntities)) .filters(filters) - .page(Objects.requireNonNullElse(requestParams.getPage(), DEFAULT_PAGE)) - .pageSize(Objects.requireNonNullElse(requestParams.getPageSize(), DEFAULT_PAGE_SIZE)) - .totalPages(toBooleanDefaultIfNull(requestParams.isTotalPages(), false)) - .skipPaging(toBooleanDefaultIfNull(requestParams.isSkipPaging(), false)) .includeDeleted(requestParams.isIncludeDeleted()) .potentialDuplicate(requestParams.getPotentialDuplicate()) .trackedEntityParams(fieldsParamMapper.map(fields)); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapperTest.java index e4f4edad6539..e249ecc72d38 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntityRequestParamsMapperTest.java @@ -112,10 +112,6 @@ void testMapping() throws BadRequestException { requestParams.setEventStatus(EventStatus.COMPLETED); requestParams.setEventOccurredAfter(getDate(2019, 7, 7)); requestParams.setEventOccurredBefore(getDate(2020, 7, 7)); - requestParams.setPage(1); - requestParams.setPageSize(50); - requestParams.setTotalPages(false); - requestParams.setSkipPaging(false); requestParams.setIncludeDeleted(true); final TrackedEntityOperationParams params = mapper.map(requestParams, user); @@ -123,9 +119,6 @@ void testMapping() throws BadRequestException { assertThat(params.getProgramUid(), is(PROGRAM_UID)); assertThat(params.getProgramStageUid(), is(PROGRAM_STAGE_UID)); assertThat(params.getTrackedEntityTypeUid(), is(TRACKED_ENTITY_TYPE_UID)); - assertThat(params.getPageSize(), is(50)); - assertThat(params.getPage(), is(1)); - assertThat(params.isTotalPages(), is(false)); assertThat(params.getProgramStatus(), is(ProgramStatus.ACTIVE)); assertThat(params.getFollowUp(), is(true)); assertThat(params.getLastUpdatedStartDate(), is(requestParams.getUpdatedAfter())); From d14fef9d90118ad78f66996b78472aeefb87d505 Mon Sep 17 00:00:00 2001 From: Enrico Date: Wed, 25 Oct 2023 10:55:17 +0200 Subject: [PATCH 2/5] chore: move handling of total count and pagination to store [TECH-1661] --- .../DefaultTrackedEntityService.java | 66 +++-------------- .../HibernateTrackedEntityStore.java | 66 +++++++++++++---- .../TrackedEntityQueryParams.java | 73 ------------------- .../trackedentity/TrackedEntityStore.java | 6 ++ .../TrackedEntitiesExportController.java | 2 + 5 files changed, 70 insertions(+), 143 deletions(-) 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 8c6e930d9c20..b1b05572139a 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 @@ -27,14 +27,10 @@ */ package org.hisp.dhis.tracker.export.trackedentity; -import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; -import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ALL; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CHILDREN; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.DESCENDANTS; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.SELECTED; -import static org.hisp.dhis.common.Pager.DEFAULT_PAGE_SIZE; -import static org.hisp.dhis.common.SlimPager.FIRST_PAGE; import java.util.ArrayList; import java.util.HashSet; @@ -53,8 +49,6 @@ import org.hisp.dhis.common.AuditType; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.IllegalQueryException; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.common.SlimPager; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; @@ -311,7 +305,6 @@ private RelationshipItem withNestedEntity( public List getTrackedEntities(TrackedEntityOperationParams operationParams) throws ForbiddenException, NotFoundException, BadRequestException { TrackedEntityQueryParams queryParams = mapper.map(operationParams); - queryParams.setSkipPaging(true); final List ids = getTrackedEntityIds(queryParams); List trackedEntities = @@ -333,15 +326,11 @@ public Page getTrackedEntities( TrackedEntityOperationParams operationParams, PageParams pageParams) throws BadRequestException, ForbiddenException, NotFoundException { TrackedEntityQueryParams queryParams = mapper.map(operationParams); - queryParams.setPage(pageParams.getPage()); - queryParams.setPageSize(pageParams.getPageSize()); - queryParams.setTotalPages(pageParams.isPageTotal()); - queryParams.setSkipPaging(false); - final List ids = getTrackedEntityIds(queryParams); + final Page ids = getTrackedEntityIds(queryParams, pageParams); List trackedEntities = this.trackedEntityAggregate.find( - ids, operationParams.getTrackedEntityParams(), queryParams); + ids.getItems(), operationParams.getTrackedEntityParams(), queryParams); mapRelationshipItems( trackedEntities, @@ -350,16 +339,7 @@ public Page getTrackedEntities( addSearchAudit(trackedEntities, queryParams.getUser()); - Pager pager; - - if (pageParams.isPageTotal()) { - int count = getTrackedEntityCount(queryParams, true, true); - pager = new Pager(pageParams.getPage(), count, pageParams.getPageSize()); - } else { - pager = handleLastPageFlag(queryParams, trackedEntities); - } - - return Page.of(trackedEntities, pager); + return Page.of(trackedEntities, ids.getPager()); } public List getTrackedEntityIds(TrackedEntityQueryParams params) { @@ -370,6 +350,14 @@ public List getTrackedEntityIds(TrackedEntityQueryParams params) { return trackedEntityStore.getTrackedEntityIds(params); } + public Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams) { + decideAccess(params); + validate(params); + validateSearchScope(params); + + return trackedEntityStore.getTrackedEntityIds(params, pageParams); + } + public void decideAccess(TrackedEntityQueryParams params) { if (params.isOrganisationUnitMode(ALL) && !currentUserService.currentUserIsAuthorized( @@ -769,38 +757,6 @@ private void addTrackedEntityAudit(TrackedEntity trackedEntity, String user) { } } - /** - * This method will apply the logic related to the parameter 'totalPages=false'. This works in - * conjunction with the method: {@link - * TrackedEntityStore#getTrackedEntityIds(TrackedEntityQueryParams)} - * - *

This is needed because we need to query (pageSize + 1) at DB level. The resulting query will - * allow us to evaluate if we are in the last page or not. And this is what his method does, - * returning the respective Pager object. - * - * @param params the request params - * @param trackedEntityList the reference to the list of Tracked Entities - * @return the populated SlimPager instance - */ - private Pager handleLastPageFlag( - TrackedEntityQueryParams params, List trackedEntityList) { - Integer originalPage = defaultIfNull(params.getPage(), FIRST_PAGE); - Integer originalPageSize = defaultIfNull(params.getPageSize(), DEFAULT_PAGE_SIZE); - boolean isLastPage = false; - - if (isNotEmpty(trackedEntityList)) { - isLastPage = trackedEntityList.size() <= originalPageSize; - if (!isLastPage) { - // Get the same number of elements of the pageSize, forcing - // the removal of the last additional element added at querying - // time. - trackedEntityList.retainAll(trackedEntityList.subList(0, originalPageSize)); - } - } - - return new SlimPager(originalPage, originalPageSize, isLastPage); - } - @Override public Set getOrderableFields() { return trackedEntityStore.getOrderableFields(); 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 8a91a35a55f6..964b8cc07056 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 @@ -43,6 +43,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; +import java.util.function.IntSupplier; import java.util.stream.Collectors; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate; @@ -54,6 +55,7 @@ import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.common.Pager; import org.hisp.dhis.common.QueryFilter; import org.hisp.dhis.common.hibernate.SoftDeleteHibernateObjectStore; import org.hisp.dhis.commons.collection.CollectionUtils; @@ -68,6 +70,8 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.export.Order; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.util.DateUtils; import org.springframework.context.ApplicationEventPublisher; @@ -161,7 +165,7 @@ public HibernateTrackedEntityStore( @Override public List getTrackedEntityIds(TrackedEntityQueryParams params) { - String sql = getQuery(params); + String sql = getQuery(params, null); log.debug("Tracked entity query SQL: " + sql); SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); @@ -176,6 +180,36 @@ public List getTrackedEntityIds(TrackedEntityQueryParams params) { return ids; } + @Override + public Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams) { + String sql = getQuery(params, pageParams); + log.debug("Tracked entity query SQL: " + sql); + SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); + + checkMaxTrackedEntityCountReached(params, rowSet); + + List ids = new ArrayList<>(); + + while (rowSet.next()) { + ids.add(rowSet.getLong("trackedentityid")); + } + + IntSupplier teCount = () -> getTrackedEntityCount(params); + return getPage(pageParams, ids, teCount); + } + + private Page getPage(PageParams pageParams, List teIds, IntSupplier enrollmentCount) { + if (pageParams.isPageTotal()) { + Pager pager = + new Pager(pageParams.getPage(), enrollmentCount.getAsInt(), pageParams.getPageSize()); + return Page.of(teIds, pager); + } + + Pager pager = new Pager(pageParams.getPage(), 0, pageParams.getPageSize()); + pager.force(pageParams.getPage(), pageParams.getPageSize()); + return Page.of(teIds, pager); + } + @Override public Set getOrderableFields() { return ORDERABLE_FIELDS.keySet(); @@ -266,11 +300,11 @@ public int getTrackedEntityCountWithMaxTrackedEntityLimit(TrackedEntityQueryPara * @param params params defining the query * @return SQL string */ - private String getQuery(TrackedEntityQueryParams params) { + private String getQuery(TrackedEntityQueryParams params, PageParams pageParams) { StringBuilder stringBuilder = new StringBuilder(getQuerySelect(params)); return stringBuilder .append("FROM ") - .append(getFromSubQuery(params, false)) + .append(getFromSubQuery(params, false, pageParams)) .append(getQueryRelatedTables(params)) .append(getQueryOrderBy(params, false)) .toString(); @@ -287,7 +321,7 @@ private String getCountQuery(TrackedEntityQueryParams params) { return SELECT_COUNT_INSTANCE_FROM + getQuerySelect(params) + "FROM " - + getFromSubQuery(params, true) + + getFromSubQuery(params, true, null) + getQueryRelatedTables(params) + " ) tecount"; } @@ -303,7 +337,7 @@ private String getCountQueryWithMaxTrackedEntityLimit(TrackedEntityQueryParams p return SELECT_COUNT_INSTANCE_FROM + getQuerySelect(params) + "FROM " - + getFromSubQuery(params, true) + + getFromSubQuery(params, true, null) + getQueryRelatedTables(params) + (params.getProgram().getMaxTeiCountToReturn() > 0 ? getLimitClause(params.getProgram().getMaxTeiCountToReturn() + 1) @@ -352,7 +386,8 @@ private String getQuerySelect(TrackedEntityQueryParams params) { * * @return an SQL sub-query */ - private String getFromSubQuery(TrackedEntityQueryParams params, boolean isCountQuery) { + private String getFromSubQuery( + TrackedEntityQueryParams params, boolean isCountQuery, PageParams pageParams) { SqlHelper whereAnd = new SqlHelper(true); StringBuilder fromSubQuery = new StringBuilder() @@ -378,7 +413,7 @@ private String getFromSubQuery(TrackedEntityQueryParams params, boolean isCountQ fromSubQuery .append(getQueryOrderBy(params, true)) // LIMIT, OFFSET - .append(getFromSubQueryLimitAndOffset(params)); + .append(getFromSubQueryLimitAndOffset(params, pageParams)); } return fromSubQuery.append(") TE ").toString(); @@ -980,12 +1015,13 @@ private String getQueryOrderBy(TrackedEntityQueryParams params, boolean innerOrd * * @return a SQL LIMIT and OFFSET clause, or empty string if no LIMIT can be deducted. */ - private String getFromSubQueryLimitAndOffset(TrackedEntityQueryParams params) { + private String getFromSubQueryLimitAndOffset( + TrackedEntityQueryParams params, PageParams pageParams) { StringBuilder limitOffset = new StringBuilder(); int limit = params.getMaxTeLimit(); int teQueryLimit = systemSettingManager.getIntSetting(SettingKey.TRACKED_ENTITY_MAX_LIMIT); - if (limit == 0 && !params.isPaging()) { + if (limit == 0 && pageParams == null) { if (teQueryLimit > 0) { return limitOffset .append(LIMIT) @@ -996,26 +1032,26 @@ private String getFromSubQueryLimitAndOffset(TrackedEntityQueryParams params) { } return limitOffset.toString(); - } else if (limit == 0 && params.isPaging()) { + } else if (limit == 0 && pageParams != null) { return limitOffset .append(LIMIT) .append(SPACE) - .append(params.getPageSizeWithDefault()) + .append(pageParams.getPageSize()) .append(SPACE) .append(OFFSET) .append(SPACE) - .append(params.getOffset()) + .append((pageParams.getPage() - 1) * pageParams.getPageSize()) .append(SPACE) .toString(); - } else if (params.isPaging()) { + } else if (pageParams != null) { return limitOffset .append(LIMIT) .append(SPACE) - .append(Math.min(limit + 1, params.getPageSizeWithDefault())) + .append(Math.min(limit + 1, pageParams.getPageSize())) .append(SPACE) .append(OFFSET) .append(SPACE) - .append(params.getOffset()) + .append((pageParams.getPage() - 1) * pageParams.getPageSize()) .append(SPACE) .toString(); } else { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityQueryParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityQueryParams.java index 6ff1fc60719f..d5ed783e5c1e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityQueryParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityQueryParams.java @@ -61,11 +61,6 @@ @ToString public class TrackedEntityQueryParams { - - public static final int DEFAULT_PAGE = 1; - - public static final int DEFAULT_PAGE_SIZE = 50; - /** * Each attribute will affect the final SQL query. Some attributes are filtered on, while * attributes added via {@link #orderBy(TrackedEntityAttribute, SortDirection)} will be ordered @@ -137,18 +132,6 @@ public class TrackedEntityQueryParams { /** End date for event for the given program. */ private Date eventEndDate; - /** Page number. */ - private Integer page; - - /** Page size. */ - private Integer pageSize; - - /** Indicates whether to include the total number of pages in the paging response. */ - private boolean totalPages; - - /** Indicates whether paging should be skipped. */ - private boolean skipPaging; - /** Indicates if there is a maximum te retrieval limit. 0 no limit. */ private int maxTeLimit; @@ -343,26 +326,6 @@ public boolean hasUniqueFilter() { return false; } - /** Indicates whether paging is enabled. */ - public boolean isPaging() { - return !isSkipPaging(); - } - - /** Returns the page number, falls back to default value of 1 if not specified. */ - public int getPageWithDefault() { - return page != null && page > 0 ? page : DEFAULT_PAGE; - } - - /** Returns the page size, falls back to default value of 50 if not specified. */ - public int getPageSizeWithDefault() { - return pageSize != null && pageSize >= 0 ? pageSize : DEFAULT_PAGE_SIZE; - } - - /** Returns the offset based on the page number and page size. */ - public int getOffset() { - return (getPageWithDefault() - 1) * getPageSizeWithDefault(); - } - /** Returns attributes that are either ordered by or present in any filter. */ public Set getAttributes() { return SetUtils.union(filters.keySet(), getOrderAttributes()); @@ -563,42 +526,6 @@ public TrackedEntityQueryParams setEventEndDate(Date eventEndDate) { return this; } - public Integer getPage() { - return page; - } - - public TrackedEntityQueryParams setPage(Integer page) { - this.page = page; - return this; - } - - public Integer getPageSize() { - return pageSize; - } - - public TrackedEntityQueryParams setPageSize(Integer pageSize) { - this.pageSize = pageSize; - return this; - } - - public boolean isTotalPages() { - return totalPages; - } - - public TrackedEntityQueryParams setTotalPages(boolean totalPages) { - this.totalPages = totalPages; - return this; - } - - public boolean isSkipPaging() { - return skipPaging; - } - - public TrackedEntityQueryParams setSkipPaging(boolean skipPaging) { - this.skipPaging = skipPaging; - return this; - } - public int getMaxTeLimit() { return maxTeLimit; } 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 c762028bc1fb..53249d6d933f 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 @@ -31,12 +31,18 @@ import java.util.Set; import org.hisp.dhis.common.IdentifiableObjectStore; import org.hisp.dhis.trackedentity.TrackedEntity; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; interface TrackedEntityStore extends IdentifiableObjectStore { String ID = TrackedEntityStore.class.getName(); + /** Get all tracked entity ids matching given params. */ List getTrackedEntityIds(TrackedEntityQueryParams params); + /** Get a page of tracked entities matching given params. */ + Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams); + /** * Fields the {@link #getTrackedEntityIds(TrackedEntityQueryParams)})} can order tracked entities * by. Ordering by fields other than these is considered a programmer error. Validation of user diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java index 009e8753fb2d..8d65802c7405 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java @@ -30,6 +30,7 @@ import static org.hisp.dhis.common.OpenApi.Response.Status; import static org.hisp.dhis.webapi.controller.tracker.ControllerSupport.RESOURCE_PATH; import static org.hisp.dhis.webapi.controller.tracker.ControllerSupport.assertUserOrderableFieldsAreSupported; +import static org.hisp.dhis.webapi.controller.tracker.export.RequestParamsValidator.validatePaginationParameters; import static org.hisp.dhis.webapi.controller.tracker.export.trackedentity.RequestParams.DEFAULT_FIELDS_PARAM; import static org.hisp.dhis.webapi.utils.ContextUtils.CONTENT_TYPE_CSV; import static org.hisp.dhis.webapi.utils.ContextUtils.CONTENT_TYPE_CSV_GZIP; @@ -133,6 +134,7 @@ public TrackedEntitiesExportController( PagingWrapper getTrackedEntities( RequestParams requestParams, @CurrentUser User currentUser) throws BadRequestException, ForbiddenException, NotFoundException { + validatePaginationParameters(requestParams); TrackedEntityOperationParams operationParams = paramsMapper.map(requestParams, currentUser); if (requestParams.isPaged()) { PageParams pageParams = From d90067917e7b0949d3f9a4602e7ef1f7d14d446f Mon Sep 17 00:00:00 2001 From: Enrico Date: Wed, 25 Oct 2023 11:47:12 +0200 Subject: [PATCH 3/5] chore: split fetching all relationships from fetching paginated relationships [TECH-1664] --- .../export/enrollment/Enrollments.java | 48 ----------- .../DefaultRelationshipService.java | 39 +++++---- .../RelationshipOperationParams.java | 13 --- .../RelationshipOperationParamsMapper.java | 9 +-- .../relationship/RelationshipQueryParams.java | 9 ++- .../relationship/RelationshipService.java | 10 ++- .../export/trackedentity/TrackedEntities.java | 48 ----------- .../OrderAndPaginationExporterTest.java | 80 ++++++++----------- .../relationship/RelationshipServiceTest.java | 22 ++--- .../RelationshipRequestParamsMapper.java | 7 +- .../RelationshipsExportController.java | 44 +++++++--- .../export/relationship/RequestParams.java | 14 +++- 12 files changed, 125 insertions(+), 218 deletions(-) delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/Enrollments.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntities.java diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/Enrollments.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/Enrollments.java deleted file mode 100644 index c9e636a5f18d..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/Enrollments.java +++ /dev/null @@ -1,48 +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.enrollment; - -import java.util.List; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.program.Enrollment; - -@RequiredArgsConstructor(staticName = "of") -@Getter -@EqualsAndHashCode -public class Enrollments { - - private final List enrollments; - private final Pager pager; - - public static Enrollments withoutPagination(List enrollments) { - return new Enrollments(enrollments, null); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java index 01937ef0929d..58b465a48d37 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/DefaultRelationshipService.java @@ -47,6 +47,8 @@ import org.hisp.dhis.relationship.RelationshipType; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackerAccessManager; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.springframework.stereotype.Service; @@ -66,26 +68,35 @@ public class DefaultRelationshipService implements RelationshipService { private final RelationshipOperationParamsMapper mapper; @Override - public Relationships getRelationships(RelationshipOperationParams params) + public List getRelationships(RelationshipOperationParams params) throws ForbiddenException, NotFoundException { RelationshipQueryParams queryParams = mapper.map(params); + queryParams.setSkipPaging(true); + + return getRelationships(queryParams); + } + + @Override + public Page getRelationships( + RelationshipOperationParams params, PageParams pageParams) + throws ForbiddenException, NotFoundException { + RelationshipQueryParams queryParams = mapper.map(params); + queryParams.setSkipPaging(false); + queryParams.setPage(pageParams.getPage()); + queryParams.setPageSize(pageParams.getPageSize()); + queryParams.setTotalPages(pageParams.isPageTotal()); Pager pager; List relationships = getRelationships(queryParams); - if (queryParams.isSkipPaging()) { - return Relationships.withoutPagination(relationships); - } - - if (queryParams.isTotalPages()) { + if (pageParams.isPageTotal()) { int count = countRelationships(queryParams); - pager = - new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault()); + pager = new Pager(pageParams.getPage(), count, pageParams.getPageSize()); } else { - pager = handleLastPageFlag(params, relationships); + pager = handleLastPageFlag(relationships, pageParams); } - return Relationships.of(relationships, pager); + return Page.of(relationships, pager); } private int countRelationships(RelationshipQueryParams queryParams) { @@ -222,14 +233,12 @@ private RelationshipItem withNestedEntity(RelationshipItem item) { * allow us to evaluate if we are in the last page or not. And this is what his method does, * returning the respective Pager object. * - * @param params the request params * @param relationships the reference to the list of Relationships * @return the populated SlimPager instance */ - private Pager handleLastPageFlag( - RelationshipOperationParams params, List relationships) { - Integer originalPage = defaultIfNull(params.getPage(), FIRST_PAGE); - Integer originalPageSize = defaultIfNull(params.getPageSize(), DEFAULT_PAGE_SIZE); + private Pager handleLastPageFlag(List relationships, PageParams pageParams) { + Integer originalPage = defaultIfNull(pageParams.getPage(), FIRST_PAGE); + Integer originalPageSize = defaultIfNull(pageParams.getPageSize(), DEFAULT_PAGE_SIZE); boolean isLastPage = false; if (isNotEmpty(relationships)) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java index 02435fa4d2a1..f7c8e5e844b5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParams.java @@ -41,23 +41,10 @@ @Builder(toBuilder = true) @AllArgsConstructor(access = AccessLevel.PRIVATE) public class RelationshipOperationParams { - - public static final int DEFAULT_PAGE = 1; - - public static final int DEFAULT_PAGE_SIZE = 50; - private TrackerType type; private String identifier; - private Integer page; - - private Integer pageSize; - - private boolean totalPages; - - private boolean skipPaging; - private List order; public static class RelationshipOperationParamsBuilder { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java index a4df43163d9b..ab5557dd6f7f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipOperationParamsMapper.java @@ -76,14 +76,7 @@ public RelationshipQueryParams map(RelationshipOperationParams params) case RELATIONSHIP -> throw new IllegalArgumentException("Unsupported type"); }; - return RelationshipQueryParams.builder() - .entity(entity) - .page(params.getPage()) - .pageSize(params.getPageSize()) - .totalPages(params.isTotalPages()) - .skipPaging(params.isSkipPaging()) - .order(params.getOrder()) - .build(); + return RelationshipQueryParams.builder().entity(entity).order(params.getOrder()).build(); } private TrackedEntity validateTrackedEntity(User user, String uid) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipQueryParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipQueryParams.java index e15fae9211d9..1d95738b89c5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipQueryParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipQueryParams.java @@ -30,6 +30,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import lombok.Setter; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.tracker.export.Order; @@ -42,13 +43,13 @@ class RelationshipQueryParams { private final IdentifiableObject entity; - private Integer page; + @Setter private Integer page; - private Integer pageSize; + @Setter private Integer pageSize; - private boolean totalPages; + @Setter private boolean totalPages; - private boolean skipPaging; + @Setter private boolean skipPaging; private List order; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java index 680b4b303891..a1a787387482 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/RelationshipService.java @@ -27,14 +27,22 @@ */ package org.hisp.dhis.tracker.export.relationship; +import java.util.List; import java.util.Set; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.relationship.Relationship; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; public interface RelationshipService { - Relationships getRelationships(RelationshipOperationParams params) + /** Get all relationships matching given params. */ + List getRelationships(RelationshipOperationParams params) + throws ForbiddenException, NotFoundException; + + /** Get a page of relationships matching given params. */ + Page getRelationships(RelationshipOperationParams params, PageParams pageParams) throws ForbiddenException, NotFoundException; /** diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntities.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntities.java deleted file mode 100644 index 664dc4029030..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntities.java +++ /dev/null @@ -1,48 +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; - -import java.util.List; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.trackedentity.TrackedEntity; - -@RequiredArgsConstructor(staticName = "of") -@Getter -@EqualsAndHashCode -public class TrackedEntities { - - private final List trackedEntities; - private final Pager pager; - - public static TrackedEntities withoutPagination(List trackedEntities) { - return new TrackedEntities(trackedEntities, null); - } -} diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java index ae903768560d..1854ec2bbefb 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java @@ -35,7 +35,6 @@ import static org.hisp.dhis.utils.Assertions.assertIsEmpty; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; @@ -51,7 +50,6 @@ import org.hisp.dhis.common.Pager; import org.hisp.dhis.common.QueryFilter; import org.hisp.dhis.common.QueryOperator; -import org.hisp.dhis.common.SlimPager; import org.hisp.dhis.common.UID; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; @@ -72,9 +70,7 @@ import org.hisp.dhis.tracker.export.event.EventOperationParams.EventOperationParamsBuilder; import org.hisp.dhis.tracker.export.event.EventService; import org.hisp.dhis.tracker.export.relationship.RelationshipOperationParams; -import org.hisp.dhis.tracker.export.relationship.RelationshipOperationParams.RelationshipOperationParamsBuilder; import org.hisp.dhis.tracker.export.relationship.RelationshipService; -import org.hisp.dhis.tracker.export.relationship.Relationships; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityOperationParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityService; import org.hisp.dhis.tracker.imports.TrackerImportService; @@ -1121,30 +1117,32 @@ void shouldReturnPaginatedRelationshipsGivenNonDefaultPageSize() String expectedOnPage1 = expected.get(0); String expectedOnPage2 = expected.get(1); - RelationshipOperationParamsBuilder builder = - RelationshipOperationParams.builder().type(TrackerType.EVENT).identifier("pTzf9KYMk72"); - - RelationshipOperationParams params = builder.page(1).pageSize(1).build(); + RelationshipOperationParams params = + RelationshipOperationParams.builder() + .type(TrackerType.EVENT) + .identifier("pTzf9KYMk72") + .build(); - Relationships firstPage = relationshipService.getRelationships(params); + Page firstPage = + relationshipService.getRelationships(params, new PageParams(1, 1, false)); assertAll( "first page", - () -> assertSlimPager(1, 1, false, firstPage.getPager()), - () -> assertEquals(List.of(expectedOnPage1), uids(firstPage.getRelationships()))); - - params = builder.page(2).pageSize(1).build(); + () -> assertPager(1, 1, firstPage), + () -> assertEquals(List.of(expectedOnPage1), uids(firstPage))); - Relationships secondPage = relationshipService.getRelationships(params); + Page secondPage = + relationshipService.getRelationships(params, new PageParams(2, 1, false)); assertAll( "second (last) page", - () -> assertSlimPager(2, 1, true, secondPage.getPager()), - () -> assertEquals(List.of(expectedOnPage2), uids(secondPage.getRelationships()))); + () -> assertPager(2, 1, secondPage), + () -> assertEquals(List.of(expectedOnPage2), uids(secondPage))); - params = builder.page(3).pageSize(1).build(); + Page thirdPage = + relationshipService.getRelationships(params, new PageParams(3, 1, false)); - assertIsEmpty(getRelationships(params)); + assertIsEmpty(thirdPage.getItems()); } @Test @@ -1164,30 +1162,32 @@ void shouldReturnPaginatedRelationshipsGivenNonDefaultPageSizeAndTotalPages() String expectedOnPage1 = expected.get(0); String expectedOnPage2 = expected.get(1); - RelationshipOperationParamsBuilder builder = - RelationshipOperationParams.builder().type(TrackerType.EVENT).identifier("pTzf9KYMk72"); - - RelationshipOperationParams params = builder.page(1).pageSize(1).totalPages(true).build(); + RelationshipOperationParams params = + RelationshipOperationParams.builder() + .type(TrackerType.EVENT) + .identifier("pTzf9KYMk72") + .build(); - Relationships firstPage = relationshipService.getRelationships(params); + Page firstPage = + relationshipService.getRelationships(params, new PageParams(1, 1, true)); assertAll( "first page", - () -> assertPager(1, 1, 2, firstPage.getPager()), - () -> assertEquals(List.of(expectedOnPage1), uids(firstPage.getRelationships()))); + () -> assertPager(1, 1, 2, firstPage), + () -> assertEquals(List.of(expectedOnPage1), uids(firstPage))); - params = builder.page(2).pageSize(1).totalPages(true).build(); - - Relationships secondPage = relationshipService.getRelationships(params); + Page secondPage = + relationshipService.getRelationships(params, new PageParams(2, 1, true)); assertAll( "second (last) page", - () -> assertPager(2, 1, 2, secondPage.getPager()), - () -> assertEquals(List.of(expectedOnPage2), uids(secondPage.getRelationships()))); + () -> assertPager(2, 1, 2, secondPage), + () -> assertEquals(List.of(expectedOnPage2), uids(secondPage))); - params = builder.page(3).pageSize(1).totalPages(true).build(); + Page thirdPage = + relationshipService.getRelationships(params, new PageParams(3, 1, true)); - assertIsEmpty(getRelationships(params)); + assertIsEmpty(thirdPage.getItems()); } @Test @@ -1258,20 +1258,6 @@ private T get(Class type, String uid) { return t; } - private static void assertSlimPager(int pageNumber, int pageSize, boolean isLast, Pager pager) { - assertInstanceOf(SlimPager.class, pager, "SlimPager should be returned if totalPages=false"); - SlimPager slimPager = (SlimPager) pager; - assertAll( - "pagination details", - () -> assertEquals(pageNumber, slimPager.getPage(), "number of current page"), - () -> assertEquals(pageSize, slimPager.getPageSize(), "page size"), - () -> - assertEquals( - isLast, - slimPager.isLastPage(), - isLast ? "should be the last page" : "should NOT be the last page")); - } - private static void assertPager(int pageNumber, int pageSize, Page page) { Pager pager = page.getPager(); assertNotNull(pager, "pagintated results should have a pager"); @@ -1317,7 +1303,7 @@ private List getEvents(EventOperationParams params, PageParams pageParam private List getRelationships(RelationshipOperationParams params) throws ForbiddenException, NotFoundException { - return uids(relationshipService.getRelationships(params).getRelationships()); + return uids(relationshipService.getRelationships(params)); } private static List uids(Page events) { diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java index c7878ea472e4..31e7bffabfbd 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/relationship/RelationshipServiceTest.java @@ -233,13 +233,11 @@ void shouldNotReturnRelationshipByTrackedEntityIfUserHasNoAccessToTrackedEntityT RelationshipOperationParams operationParams = RelationshipOperationParams.builder().type(TRACKED_ENTITY).identifier(teA.getUid()).build(); - Relationships relationships = relationshipService.getRelationships(operationParams); + List relationships = relationshipService.getRelationships(operationParams); assertContainsOnly( List.of(accessible.getUid()), - relationships.getRelationships().stream() - .map(Relationship::getUid) - .collect(Collectors.toList())); + relationships.stream().map(Relationship::getUid).collect(Collectors.toList())); } @Test @@ -254,13 +252,11 @@ void shouldNotReturnRelationshipByEnrollmentIfUserHasNoAccessToRelationshipType( .identifier(enrollmentA.getUid()) .build(); - Relationships relationships = relationshipService.getRelationships(operationParams); + List relationships = relationshipService.getRelationships(operationParams); assertContainsOnly( List.of(accessible.getUid()), - relationships.getRelationships().stream() - .map(Relationship::getUid) - .collect(Collectors.toList())); + relationships.stream().map(Relationship::getUid).collect(Collectors.toList())); } @Test @@ -272,13 +268,11 @@ void shouldNotReturnRelationshipByEventIfUserHasNoAccessToProgramStage() RelationshipOperationParams operationParams = RelationshipOperationParams.builder().type(EVENT).identifier(eventA.getUid()).build(); - Relationships relationships = relationshipService.getRelationships(operationParams); + List relationships = relationshipService.getRelationships(operationParams); assertContainsOnly( List.of(accessible.getUid()), - relationships.getRelationships().stream() - .map(Relationship::getUid) - .collect(Collectors.toList())); + relationships.stream().map(Relationship::getUid).collect(Collectors.toList())); } @Test @@ -294,7 +288,7 @@ void shouldOrderRelationshipsByUpdatedAtClientInDescOrder() .orderBy("createdAtClient", SortDirection.DESC) .build(); List relationshipIds = - relationshipService.getRelationships(operationParams).getRelationships().stream() + relationshipService.getRelationships(operationParams).stream() .map(BaseIdentifiableObject::getUid) .collect(Collectors.toList()); @@ -314,7 +308,7 @@ void shouldOrderRelationshipsByUpdatedAtClientInAscOrder() .orderBy("createdAtClient", SortDirection.ASC) .build(); List relationshipIds = - relationshipService.getRelationships(operationParams).getRelationships().stream() + relationshipService.getRelationships(operationParams).stream() .map(BaseIdentifiableObject::getUid) .collect(Collectors.toList()); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java index 20befd0ee4ca..1166ed7dab57 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipRequestParamsMapper.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.webapi.controller.tracker.export.relationship; -import static org.apache.commons.lang3.BooleanUtils.toBooleanDefaultIfNull; import static org.hisp.dhis.tracker.TrackerType.ENROLLMENT; import static org.hisp.dhis.tracker.TrackerType.EVENT; import static org.hisp.dhis.tracker.TrackerType.TRACKED_ENTITY; @@ -90,11 +89,7 @@ public RelationshipOperationParams map(RequestParams requestParams) throws BadRe .identifier( ObjectUtils.firstNonNull( trackedEntity, requestParams.getEnrollment(), requestParams.getEvent()) - .getValue()) - .page(Objects.requireNonNullElse(requestParams.getPage(), DEFAULT_PAGE)) - .pageSize(Objects.requireNonNullElse(requestParams.getPageSize(), DEFAULT_PAGE_SIZE)) - .totalPages(toBooleanDefaultIfNull(requestParams.isTotalPages(), false)) - .skipPaging(toBooleanDefaultIfNull(requestParams.isSkipPaging(), false)); + .getValue()); mapOrderParam(builder, requestParams.getOrder()); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java index adf33d9234d6..29700ea97116 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipsExportController.java @@ -43,9 +43,10 @@ import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.fieldfiltering.FieldFilterService; import org.hisp.dhis.fieldfiltering.FieldPath; +import org.hisp.dhis.tracker.export.Page; +import org.hisp.dhis.tracker.export.PageParams; import org.hisp.dhis.tracker.export.relationship.RelationshipOperationParams; import org.hisp.dhis.tracker.export.relationship.RelationshipService; -import org.hisp.dhis.tracker.export.relationship.Relationships; import org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper; import org.hisp.dhis.webapi.controller.tracker.export.OpenApiExport; import org.hisp.dhis.webapi.controller.tracker.view.Relationship; @@ -96,22 +97,43 @@ public RelationshipsExportController( @GetMapping PagingWrapper getRelationships(RequestParams requestParams) throws NotFoundException, BadRequestException, ForbiddenException { - RelationshipOperationParams operationParams = mapper.map(requestParams); - Relationships relationships = relationshipService.getRelationships(operationParams); - - PagingWrapper pagingWrapper = new PagingWrapper<>(); - if (requestParams.isPagingRequest()) { - pagingWrapper = - pagingWrapper.withPager( - PagingWrapper.Pager.fromLegacy(requestParams, relationships.getPager())); + if (requestParams.isPaged()) { + PageParams pageParams = + new PageParams( + requestParams.getPage(), requestParams.getPageSize(), requestParams.getTotalPages()); + + Page relationshipsPage = + relationshipService.getRelationships(operationParams, pageParams); + + PagingWrapper.Pager.PagerBuilder pagerBuilder = + PagingWrapper.Pager.builder() + .page(relationshipsPage.getPager().getPage()) + .pageSize(relationshipsPage.getPager().getPageSize()); + + if (requestParams.isPageTotal()) { + pagerBuilder + .pageCount(relationshipsPage.getPager().getPageCount()) + .total(relationshipsPage.getPager().getTotal()); + } + + PagingWrapper pagingWrapper = new PagingWrapper<>(); + pagingWrapper = pagingWrapper.withPager(pagerBuilder.build()); + List objectNodes = + fieldFilterService.toObjectNodes( + RELATIONSHIP_MAPPER.fromCollection(relationshipsPage.getItems()), + requestParams.getFields()); + return pagingWrapper.withInstances(objectNodes); } + List relationships = + relationshipService.getRelationships(operationParams); List objectNodes = fieldFilterService.toObjectNodes( - RELATIONSHIP_MAPPER.fromCollection(relationships.getRelationships()), - requestParams.getFields()); + RELATIONSHIP_MAPPER.fromCollection(relationships), requestParams.getFields()); + + PagingWrapper pagingWrapper = new PagingWrapper<>(); return pagingWrapper.withInstances(objectNodes); } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RequestParams.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RequestParams.java index b70f511b26b2..305df4c09851 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RequestParams.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RequestParams.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller.tracker.export.relationship; +import java.util.ArrayList; import java.util.List; import lombok.Data; import lombok.NoArgsConstructor; @@ -34,7 +35,8 @@ import org.hisp.dhis.common.UID; import org.hisp.dhis.fieldfiltering.FieldFilterParser; import org.hisp.dhis.fieldfiltering.FieldPath; -import org.hisp.dhis.webapi.controller.event.webrequest.PagingAndSortingCriteriaAdapter; +import org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria; +import org.hisp.dhis.webapi.controller.tracker.export.PageRequestParams; import org.hisp.dhis.webapi.controller.tracker.view.Enrollment; import org.hisp.dhis.webapi.controller.tracker.view.Event; import org.hisp.dhis.webapi.controller.tracker.view.TrackedEntity; @@ -43,11 +45,17 @@ @OpenApi.Property @Data @NoArgsConstructor -class RequestParams extends PagingAndSortingCriteriaAdapter { - +class RequestParams implements PageRequestParams { static final String DEFAULT_FIELDS_PARAM = "relationship,relationshipType,createdAtClient,from[trackedEntity[trackedEntity],enrollment[enrollment],event[event]],to[trackedEntity[trackedEntity],enrollment[enrollment],event[event]]"; + private Integer page; + private Integer pageSize; + private Boolean totalPages; + private Boolean skipPaging; + + private List order = new ArrayList<>(); + /** * @deprecated use {@link #trackedEntity} instead */ From bac642dc16b44524e6fca853e9fad91ad8a05e4f Mon Sep 17 00:00:00 2001 From: Enrico Date: Thu, 26 Oct 2023 12:01:13 +0200 Subject: [PATCH 4/5] Fix test --- .../export/OrderAndPaginationExporterTest.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java index e619e98d80f5..1854ec2bbefb 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java @@ -1313,18 +1313,4 @@ private static List uids(Page even private static List uids(List identifiableObject) { return identifiableObject.stream().map(BaseIdentifiableObject::getUid).toList(); } - - private static void assertSlimPager(int pageNumber, int pageSize, boolean isLast, Pager pager) { - assertInstanceOf(SlimPager.class, pager, "SlimPager should be returned if totalPages=false"); - SlimPager slimPager = (SlimPager) pager; - assertAll( - "pagination details", - () -> assertEquals(pageNumber, slimPager.getPage(), "number of current page"), - () -> assertEquals(pageSize, slimPager.getPageSize(), "page size"), - () -> - assertEquals( - isLast, - slimPager.isLastPage(), - isLast ? "should be the last page" : "should NOT be the last page")); - } } From 4bb1dff4a809fa0ccda6c9649abfdf0cee97c809 Mon Sep 17 00:00:00 2001 From: Enrico Date: Fri, 27 Oct 2023 09:47:57 +0200 Subject: [PATCH 5/5] Fix code review comments --- .../tracker/export/event/JdbcEventStore.java | 4 -- .../export/relationship/Relationships.java | 48 ------------------- .../HibernateTrackedEntityStore.java | 4 -- 3 files changed, 56 deletions(-) delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/Relationships.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 d67b27d3c8df..b513c8ef8d51 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 @@ -266,8 +266,6 @@ private List fetchEvents(EventQueryParams queryParams, PageParams pagePar sql, mapSqlParameterSource, resultSet -> { - log.debug("Event query SQL: " + sql); - Set notes = new HashSet<>(); while (resultSet.next()) { @@ -543,8 +541,6 @@ private int getEventCount(EventQueryParams params) { sql = sql.replaceFirst("limit \\d+ offset \\d+", ""); - log.debug("Event query count SQL: " + sql); - return jdbcTemplate.queryForObject(sql, mapSqlParameterSource, Integer.class); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/Relationships.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/Relationships.java deleted file mode 100644 index fd469bca5eb2..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/relationship/Relationships.java +++ /dev/null @@ -1,48 +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.relationship; - -import java.util.List; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.relationship.Relationship; - -@RequiredArgsConstructor(staticName = "of") -@Getter -@EqualsAndHashCode -public class Relationships { - - private final List relationships; - private final Pager pager; - - public static Relationships withoutPagination(List relationships) { - return new Relationships(relationships, null); - } -} 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 964b8cc07056..b5bd958725d1 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 @@ -166,7 +166,6 @@ public HibernateTrackedEntityStore( @Override public List getTrackedEntityIds(TrackedEntityQueryParams params) { String sql = getQuery(params, null); - log.debug("Tracked entity query SQL: " + sql); SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); checkMaxTrackedEntityCountReached(params, rowSet); @@ -183,7 +182,6 @@ public List getTrackedEntityIds(TrackedEntityQueryParams params) { @Override public Page getTrackedEntityIds(TrackedEntityQueryParams params, PageParams pageParams) { String sql = getQuery(params, pageParams); - log.debug("Tracked entity query SQL: " + sql); SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); checkMaxTrackedEntityCountReached(params, rowSet); @@ -235,14 +233,12 @@ private void checkMaxTrackedEntityCountReached( @Override public int getTrackedEntityCount(TrackedEntityQueryParams params) { String sql = getCountQuery(params); - log.debug("Tracked entity count SQL: " + sql); return jdbcTemplate.queryForObject(sql, Integer.class); } @Override public int getTrackedEntityCountWithMaxTrackedEntityLimit(TrackedEntityQueryParams params) { String sql = getCountQueryWithMaxTrackedEntityLimit(params); - log.debug("Tracked entity count SQL: " + sql); return jdbcTemplate.queryForObject(sql, Integer.class); }