From 486ac5200778e7e8d570995d33df991e0aa430b5 Mon Sep 17 00:00:00 2001 From: teleivo Date: Fri, 17 Jan 2025 09:20:47 +0100 Subject: [PATCH] chore: remove unnecessary interface --- .../DefaultTrackedEntityAuditService.java | 3 +-- .../DefaultTrackedEntityService.java | 18 ++++++++++++------ .../{Aggregate.java => AsyncUtils.java} | 10 +++++++--- .../aggregates/EnrollmentAggregate.java | 4 +++- .../aggregates/EventAggregate.java | 4 +++- .../aggregates/TrackedEntityAggregate.java | 3 ++- 6 files changed, 28 insertions(+), 14 deletions(-) rename dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/{Aggregate.java => AsyncUtils.java} (92%) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java index b58afdc44526..4084f3c35ce9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.common.collection.CollectionUtils; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAudit; import org.hisp.dhis.trackedentity.TrackedEntityAuditQueryParams; @@ -81,7 +80,7 @@ public void addTrackedEntityAudit( .map(te -> new TrackedEntityAudit(te.getUid(), username, type)) .toList(); - if (CollectionUtils.isEmpty(audits)) { + if (audits.isEmpty()) { return; } 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 e97f2a253100..0d2d6bcb8825 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 @@ -351,6 +351,7 @@ public List getTrackedEntities( return getTrackedEntities(ids, operationParams, queryParams, user); } + @Override public @Nonnull Page getTrackedEntities( @Nonnull TrackedEntityOperationParams operationParams, @Nonnull PageParams pageParams) @@ -365,12 +366,18 @@ public List getTrackedEntities( } // TODO can I only pass in query params? - private List getTrackedEntities(List ids, TrackedEntityOperationParams operationParams, - TrackedEntityQueryParams queryParams, UserDetails user) throws NotFoundException { + private List getTrackedEntities( + List ids, + TrackedEntityOperationParams operationParams, + TrackedEntityQueryParams queryParams, + UserDetails user) + throws NotFoundException { List trackedEntities = - this.trackedEntityAggregate.find(ids, - operationParams.getTrackedEntityParams(), queryParams, + this.trackedEntityAggregate.find( + ids, + operationParams.getTrackedEntityParams(), + queryParams, queryParams.getOrgUnitMode()); setRelationshipItems( trackedEntities, @@ -388,7 +395,6 @@ private List getTrackedEntities(List ids, TrackedEntityOper return trackedEntities; } - /** * We need to return the full models for relationship items (i.e. trackedEntity, enrollment and * event) in our API. The aggregate stores currently do not support that, so we need to fetch the @@ -571,7 +577,7 @@ private RelationshipItem getTrackedEntityInRelationshipItem(String uid) throws N } private void addSearchAudit(List trackedEntities, UserDetails user) { - trackedEntityAuditService.addTrackedEntityAudit(trackedEntities, user.getUsername(), SEARCH); + trackedEntityAuditService.addTrackedEntityAudit(trackedEntities, user.getUsername(), SEARCH); } @Override diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/Aggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java similarity index 92% rename from dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/Aggregate.java rename to dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java index e8c819d8bfe7..fb3eefbdb919 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/Aggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/AsyncUtils.java @@ -38,7 +38,11 @@ /** * @author Luciano Fiandesio */ -interface Aggregate { +class AsyncUtils { + AsyncUtils() { + throw new IllegalStateException("Utility class"); + } + /** * Executes the Supplier asynchronously using the thread pool from the provided {@see Executor} * @@ -48,7 +52,7 @@ interface Aggregate { * @param executor an Executor instance * @return A CompletableFuture with the result of the Supplier */ - default CompletableFuture> conditionalAsyncFetch( + static CompletableFuture> conditionalAsyncFetch( boolean condition, Supplier> supplier, Executor executor) { return (condition ? supplyAsync(supplier, executor) @@ -61,7 +65,7 @@ default CompletableFuture> conditionalAsyncFetch( * @param supplier The Supplier to execute * @return A CompletableFuture with the result of the Supplier */ - default CompletableFuture> asyncFetch( + static CompletableFuture> asyncFetch( Supplier> supplier, Executor executor) { return supplyAsync(supplier, executor); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java index 1ec4e4c736b9..85f9e882a3b7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EnrollmentAggregate.java @@ -28,6 +28,8 @@ package org.hisp.dhis.tracker.export.trackedentity.aggregates; import static java.util.concurrent.CompletableFuture.allOf; +import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.asyncFetch; +import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.conditionalAsyncFetch; import static org.hisp.dhis.tracker.export.trackedentity.aggregates.ThreadPoolManager.getPool; import com.google.common.collect.Multimap; @@ -51,7 +53,7 @@ */ @Component("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentAggregate") @RequiredArgsConstructor -public class EnrollmentAggregate implements Aggregate { +public class EnrollmentAggregate { @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentStore") @Nonnull private final EnrollmentStore enrollmentStore; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java index ac934a9dc894..623aa262eb98 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/EventAggregate.java @@ -29,6 +29,8 @@ import static java.util.concurrent.CompletableFuture.allOf; import static java.util.concurrent.CompletableFuture.supplyAsync; +import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.asyncFetch; +import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.conditionalAsyncFetch; import static org.hisp.dhis.tracker.export.trackedentity.aggregates.ThreadPoolManager.getPool; import com.google.common.collect.Multimap; @@ -51,7 +53,7 @@ */ @Component("org.hisp.dhis.tracker.trackedentity.aggregates.EventAggregate") @RequiredArgsConstructor -public class EventAggregate implements Aggregate { +public class EventAggregate { @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EventStore") @Nonnull private final EventStore eventStore; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java index fa5694181b25..d8c25e914519 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/TrackedEntityAggregate.java @@ -30,6 +30,7 @@ import static java.util.concurrent.CompletableFuture.allOf; import static java.util.concurrent.CompletableFuture.supplyAsync; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ALL; +import static org.hisp.dhis.tracker.export.trackedentity.aggregates.AsyncUtils.conditionalAsyncFetch; import static org.hisp.dhis.tracker.export.trackedentity.aggregates.ThreadPoolManager.getPool; import com.google.common.collect.Lists; @@ -74,7 +75,7 @@ */ @Component @RequiredArgsConstructor -public class TrackedEntityAggregate implements Aggregate { +public class TrackedEntityAggregate { @Nonnull private final TrackedEntityStore trackedEntityStore; @Qualifier("org.hisp.dhis.tracker.trackedentity.aggregates.EnrollmentAggregate")