From 520136b45feb1f4725ab016f3c4ffe4021f33bc4 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Tue, 14 Nov 2023 16:36:58 +0100 Subject: [PATCH 1/3] chore: Make async tracker importer use scheduler (#15684) * "chore: Make async tracker importer use scheduler" This reverts commit bc2befccc341638152bea5a7bbd0da12b87dddbb. * fix: wait until file resource content is available (#15686) * fix: wait until file resource content is available * fix: detect null content for file resources * fix: wait for file content to become available --------- Co-authored-by: Jan Bernitt --- .../fileresource/FileResourceService.java | 22 +- .../FileResourceStorageStatus.java | 1 - .../org/hisp/dhis/scheduling/JobType.java | 3 +- .../DefaultFileResourceService.java | 44 +++- .../JCloudsFileResourceContentStore.java | 1 + .../HibernateJobConfigurationStore.java | 3 + .../dhis-service-tracker/pom.xml | 8 - .../imports/DefaultTrackerImportService.java | 225 ++++-------------- .../dhis/tracker/imports/ParamsConverter.java | 15 +- .../tracker/imports/TrackerIdSchemeParam.java | 3 +- .../imports/TrackerIdSchemeParams.java | 3 +- .../imports/TrackerIdentifierCollector.java | 11 +- .../tracker/imports/TrackerImportParams.java | 60 +---- .../tracker/imports/TrackerImportService.java | 22 +- .../bundle/DefaultTrackerBundleService.java | 10 +- .../imports/bundle/TrackerBundleService.java | 4 +- .../tracker/imports/domain/Attribute.java | 3 +- .../tracker/imports/domain/Coordinate.java | 3 +- .../tracker/imports/domain/DataValue.java | 3 +- .../tracker/imports/domain/Enrollment.java | 3 +- .../dhis/tracker/imports/domain/Event.java | 3 +- .../imports/domain/MetadataIdentifier.java | 3 +- .../dhis/tracker/imports/domain/Note.java | 3 +- .../tracker/imports/domain/Relationship.java | 3 +- .../imports/domain/RelationshipItem.java | 3 +- .../tracker/imports/domain/TrackedEntity.java | 3 +- .../imports/domain/TrackerObjects.java} | 43 ++-- .../dhis/tracker/imports/domain/User.java | 3 +- .../imports/job/TrackerImportThread.java | 62 ----- .../tracker/imports/job/TrackerMessage.java | 62 ----- .../imports/job/TrackerMessageManager.java | 89 ------- .../preheat/DefaultTrackerPreheatService.java | 13 +- .../preheat/TrackerPreheatService.java | 7 +- .../supplier/AbstractPreheatSupplier.java | 8 +- .../preheat/supplier/ClassBasedSupplier.java | 8 +- .../preheat/supplier/DefaultsSupplier.java | 4 +- .../DuplicateRelationshipSupplier.java | 6 +- .../preheat/supplier/EnrollmentSupplier.java | 4 +- ...nrollmentsWithAtLeastOneEventSupplier.java | 4 +- .../EventCategoryOptionComboSupplier.java | 6 +- .../EventProgramStageMapSupplier.java | 10 +- .../supplier/FileResourceSupplier.java | 13 +- .../supplier/OrgUnitValueTypeSupplier.java | 10 +- .../preheat/supplier/PeriodTypeSupplier.java | 4 +- .../preheat/supplier/PreheatSupplier.java | 5 +- .../supplier/ProgramOrgUnitsSupplier.java | 4 +- .../supplier/ProgramOwnerSupplier.java | 8 +- .../TrackedEntityEnrollmentSupplier.java | 8 +- .../supplier/UniqueAttributesSupplier.java | 23 +- .../preheat/supplier/UserSupplier.java | 8 +- .../supplier/UsernameValueTypeSupplier.java | 8 +- .../strategy/AbstractSchemaStrategy.java | 6 +- .../strategy/ClassBasedSupplierStrategy.java | 3 +- .../supplier/strategy/EnrollmentStrategy.java | 4 +- .../supplier/strategy/EventStrategy.java | 4 +- .../supplier/strategy/NoteStrategy.java | 4 +- .../strategy/RelationshipStrategy.java | 4 +- .../strategy/TrackerEntityStrategy.java | 4 +- .../tracker/imports/report/ImportReport.java | 15 +- .../tracker/imports/report/TimingsStats.java | 153 ------------ .../TrackerIdentifierCollectorTest.java | 46 ++-- .../bundle/TrackerImporterServiceTest.java | 40 ++-- .../DefaultTrackerPreheatServiceTest.java | 16 +- .../supplier/ClassBasedSupplierTest.java | 10 +- .../DuplicateRelationshipSupplierTest.java | 8 +- .../supplier/EnrollmentSupplierTest.java | 6 +- .../EventCategoryOptionComboSupplierTest.java | 48 ++-- .../supplier/FileResourceSupplierTest.java | 29 +-- .../OrgUnitValueTypeSupplierTest.java | 29 +-- .../supplier/PeriodTypeSupplierTest.java | 4 +- .../supplier/UniqueAttributeSupplierTest.java | 26 +- .../preheat/supplier/UserSupplierTest.java | 6 +- .../strategy/TrackerEntityStrategyTest.java | 8 +- .../imports/report/ImportReportTest.java | 4 +- .../report/TrackerBundleImportReportTest.java | 64 +---- .../tracker/TrackerImportExportActions.java | 8 + .../tracker/AclEventExporterTest.java | 5 +- .../org/hisp/dhis/tracker/TrackerTest.java | 24 +- .../OrderAndPaginationExporterTest.java | 5 +- .../export/event/AclEventExporterTest.java | 5 +- .../export/event/EventExporterTest.java | 5 +- .../imports/AtomicModeIntegrationTest.java | 16 +- .../imports/TrackerImportParamsSerdeTest.java | 16 +- .../imports/bundle/EventDataValueTest.java | 37 ++- .../imports/bundle/LastUpdateImportTest.java | 33 ++- .../tracker/imports/bundle/OwnershipTest.java | 116 ++++----- .../bundle/RelationshipImportTest.java | 25 +- .../ReportSummaryDeleteIntegrationTest.java | 39 +-- .../bundle/ReportSummaryIntegrationTest.java | 141 ++++++----- .../bundle/TrackedEntityAttributeTest.java | 13 +- .../TrackedEntityAttributeValueAuditTest.java | 15 +- .../TrackedEntityDataValueAuditTest.java | 8 +- ...dEntityProgramAttributeEncryptionTest.java | 2 + ...ntityProgramAttributeFileResourceTest.java | 2 + .../TrackedEntityProgramAttributeTest.java | 34 +-- .../bundle/TrackerBundleServiceTest.java | 9 +- .../bundle/TrackerEventBundleServiceTest.java | 16 +- .../TrackerProgramRuleBundleServiceTest.java | 9 +- .../TrackerSideEffectHandlerServiceTest.java | 2 + .../TrackerPreheatIdentifiersTest.java | 76 +++--- .../TrackerPreheatServiceIntegrationTest.java | 23 +- .../preheat/TrackerPreheatServiceTest.java | 46 ++-- .../ProgramRuleAssignActionTest.java | 22 +- .../imports/programrule/ProgramRuleTest.java | 87 ++++--- .../EnrollmentAttrValidationTest.java | 64 +++-- .../EnrollmentImportValidationTest.java | 82 ++++--- ...nrollmentSecurityImportValidationTest.java | 39 +-- .../validation/EventImportValidationTest.java | 90 ++++--- .../EventSecurityImportValidationTest.java | 24 +- .../TeTaEncryptionValidationTest.java | 26 +- .../validation/TeTaValidationTest.java | 40 ++-- .../TrackedEntityImportValidationTest.java | 103 ++++---- .../imports/TrackerImportControllerTest.java | 4 +- dhis-2/dhis-web-api/pom.xml | 4 - .../TrackedEntityInstanceController.java | 3 +- .../metadata/MetadataImportJob.java | 2 +- .../controller/tracker/imports/Body.java | 3 +- .../tracker/imports/TrackerAsyncImporter.java | 64 ----- .../imports/TrackerImportController.java | 108 ++++++--- .../tracker/imports/TrackerImportJob.java | 102 ++++++++ .../imports/TrackerImportParamsMapper.java | 32 +-- .../TrackerJobWebMessageResponse.java | 7 +- .../imports/TrackerImportControllerTest.java | 57 +++-- .../TrackerImportParamsMapperTest.java | 42 ++-- .../imports/TrackerImporterImplTest.java | 98 -------- 125 files changed, 1406 insertions(+), 1853 deletions(-) rename dhis-2/{dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerSyncImporter.java => dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerObjects.java} (63%) delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerImportThread.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessage.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessageManager.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/TimingsStats.java delete mode 100644 dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerAsyncImporter.java create mode 100644 dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportJob.java rename dhis-2/{dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job => dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports}/TrackerJobWebMessageResponse.java (92%) delete mode 100644 dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImporterImplTest.java diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceService.java index bedcd14e40a0..92e43b63b40c 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceService.java @@ -32,18 +32,33 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +import java.time.Duration; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import org.hisp.dhis.feedback.ConflictException; +import org.hisp.dhis.feedback.NotFoundException; /** * @author Halvdan Hoem Grelland */ public interface FileResourceService { + + @CheckForNull FileResource getFileResource(String uid); + /** + * Get the {@link FileResource} with the given ID + * + * @param uid the resource to fetch + * @return the file resource + * @throws NotFoundException when no such file resource exits + */ + @Nonnull + FileResource getExistingFileResource(String uid) throws NotFoundException; + /** * Lookup a {@link FileResource} by uid and {@link FileResourceDomain}. * @@ -83,7 +98,12 @@ public interface FileResourceService { void deleteFileResource(FileResource fileResource); - InputStream getFileResourceContent(FileResource fileResource); + @Nonnull + InputStream getFileResourceContent(FileResource fileResource) throws ConflictException; + + @Nonnull + InputStream getFileResourceContent(FileResource fileResource, Duration timeout) + throws ConflictException; /** Copy fileResource content to outputStream and Return File content length */ void copyFileResourceContent(FileResource fileResource, OutputStream outputStream) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStorageStatus.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStorageStatus.java index 517550c01ec3..c2c77dad7aa4 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStorageStatus.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResourceStorageStatus.java @@ -33,6 +33,5 @@ public enum FileResourceStorageStatus { NONE, // No content stored PENDING, // In transit to store, not available - FAILED, // Storing the resource failed STORED // Is available from store } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/JobType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/JobType.java index 7357c130c46c..7b51389db2d9 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/JobType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/JobType.java @@ -206,6 +206,7 @@ public boolean isUsingNotifications() { || this == DATAVALUE_IMPORT || this == COMPLETE_DATA_SET_REGISTRATION_IMPORT || this == METADATA_IMPORT + || this == TRACKER_IMPORT_JOB || this == GEOJSON_IMPORT; } @@ -231,7 +232,7 @@ public boolean isUsingErrorNotification() { * the ready jobs per type is attempted to start in a single loop cycle */ public boolean isUsingContinuousExecution() { - return this == METADATA_IMPORT; + return this == METADATA_IMPORT || this == TRACKER_IMPORT_JOB; } public boolean hasJobParameters() { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java index 708222a7eccf..96c46639bcdc 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java @@ -27,6 +27,10 @@ */ package org.hisp.dhis.fileresource; +import static java.lang.System.currentTimeMillis; +import static java.time.Duration.ofMillis; +import static java.time.Duration.ofSeconds; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -43,7 +47,9 @@ import lombok.RequiredArgsConstructor; import org.hibernate.SessionFactory; import org.hisp.dhis.common.IllegalQueryException; +import org.hisp.dhis.feedback.ConflictException; import org.hisp.dhis.feedback.ErrorCode; +import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.fileresource.events.BinaryFileSavedEvent; import org.hisp.dhis.fileresource.events.FileDeletedEvent; import org.hisp.dhis.fileresource.events.FileSavedEvent; @@ -86,6 +92,15 @@ public class DefaultFileResourceService implements FileResourceService { // FileResourceService implementation // ------------------------------------------------------------------------- + @Nonnull + @Override + @Transactional(readOnly = true) + public FileResource getExistingFileResource(String uid) throws NotFoundException { + FileResource fr = fileResourceStore.getByUid(uid); + if (fr == null) throw new NotFoundException(FileResource.class, uid); + return fr; + } + @Override @Transactional(readOnly = true) public FileResource getFileResource(String uid) { @@ -228,26 +243,43 @@ public void deleteFileResource(FileResource fileResource) { } @Override - @Transactional(readOnly = true) - public InputStream getFileResourceContent(FileResource fileResource) { - return fileResourceContentStore.getFileResourceContent(fileResource.getStorageKey()); + @Nonnull + public InputStream getFileResourceContent(FileResource fileResource) throws ConflictException { + return getFileResourceContent(fileResource, ofSeconds(10)); + } + + @Nonnull + @Override + public InputStream getFileResourceContent(FileResource fileResource, java.time.Duration timeout) + throws ConflictException { + String key = fileResource.getStorageKey(); + InputStream content = fileResourceContentStore.getFileResourceContent(key); + long since = currentTimeMillis(); + while (content == null && !timeout.minus(ofMillis(currentTimeMillis() - since)).isNegative()) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + content = fileResourceContentStore.getFileResourceContent(key); + } + if (content == null) + throw new ConflictException("File resource exists but content input stream was null"); + return content; } @Override - @Transactional(readOnly = true) public long getFileResourceContentLength(FileResource fileResource) { return fileResourceContentStore.getFileResourceContentLength(fileResource.getStorageKey()); } @Override - @Transactional(readOnly = true) public void copyFileResourceContent(FileResource fileResource, OutputStream outputStream) throws IOException, NoSuchElementException { fileResourceContentStore.copyContent(fileResource.getStorageKey(), outputStream); } @Override - @Transactional(readOnly = true) public byte[] copyFileResourceContent(FileResource fileResource) throws IOException, NoSuchElementException { return fileResourceContentStore.copyContent(fileResource.getStorageKey()); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java index 63c6e70f4702..0c9ada0ea604 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java @@ -194,6 +194,7 @@ public InputStream getFileResourceContent(String key) { final Blob blob = getBlob(key); if (blob == null) { + return null; } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/HibernateJobConfigurationStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/HibernateJobConfigurationStore.java index be63df14bf74..44653469e464 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/HibernateJobConfigurationStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/HibernateJobConfigurationStore.java @@ -29,6 +29,7 @@ import static java.lang.Math.max; import static java.util.stream.Collectors.toSet; +import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; import java.util.List; import java.util.Set; @@ -45,6 +46,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; /** * @author Jan Bernitt @@ -242,6 +244,7 @@ public Stream getDueJobConfigurations(boolean includeWaiting) } @Override + @Transactional(propagation = REQUIRES_NEW) public boolean tryExecuteNow(@Nonnull String jobId) { // language=SQL String sql = diff --git a/dhis-2/dhis-services/dhis-service-tracker/pom.xml b/dhis-2/dhis-services/dhis-service-tracker/pom.xml index 393e2d329c1a..542a8b642f0d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/pom.xml +++ b/dhis-2/dhis-services/dhis-service-tracker/pom.xml @@ -65,10 +65,6 @@ org.hisp.dhis.rules rule-engine - - org.springframework - spring-core - org.springframework spring-jdbc @@ -89,10 +85,6 @@ org.springframework spring-beans - - org.springframework.security - spring-security-core - org.projectlombok lombok diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/DefaultTrackerImportService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/DefaultTrackerImportService.java index ccf754014a01..b203d58bbc68 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/DefaultTrackerImportService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/DefaultTrackerImportService.java @@ -27,35 +27,25 @@ */ package org.hisp.dhis.tracker.imports; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.COMMIT_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PREHEAT_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PREPROCESS_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PROGRAMRULE_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.TOTAL_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.VALIDATE_PROGRAMRULE_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.VALIDATION_OPS; - import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.hisp.dhis.system.notification.NotificationLevel; -import org.hisp.dhis.system.notification.Notifier; +import org.hisp.dhis.scheduling.JobProgress; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.bundle.TrackerBundleService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.job.TrackerSideEffectDataBundle; import org.hisp.dhis.tracker.imports.preprocess.TrackerPreprocessService; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.PersistenceReport; import org.hisp.dhis.tracker.imports.report.Status; -import org.hisp.dhis.tracker.imports.report.TimingsStats; import org.hisp.dhis.tracker.imports.report.TrackerTypeReport; import org.hisp.dhis.tracker.imports.report.ValidationReport; import org.hisp.dhis.tracker.imports.validation.ValidationResult; @@ -78,144 +68,78 @@ public class DefaultTrackerImportService implements TrackerImportService { @Nonnull private final TrackerUserService trackerUserService; - @Nonnull private final Notifier notifier; - + /* Import is not meant to be annotated with @Transactional. + * PreHeat and Commit phases are separated transactions, other + * phases do not need to be in a transaction. */ @Override - public ImportReport importTracker(TrackerImportParams params) { + public ImportReport importTracker( + TrackerImportParams params, TrackerObjects trackerObjects, JobProgress jobProgress) { User user = trackerUserService.getUser(params.getUserId()); - params.setUser(user); - - TimingsStats opsTimer = new TimingsStats(); - - startImport(params); - - try { - TrackerBundle trackerBundle = preHeat(params, opsTimer); - - Map bundleSize = calculatePayloadSize(trackerBundle); - - preProcess(opsTimer, trackerBundle); - - ValidationReport validationReport = validate(params, opsTimer, trackerBundle); - if (exitOnError(validationReport, params)) { - return buildReportAndNotify(params, validationReport, opsTimer, bundleSize); - } + jobProgress.startingStage("Running PreHeat"); + TrackerBundle trackerBundle = + jobProgress.runStage(() -> trackerBundleService.create(params, trackerObjects, user)); - PersistenceReport persistenceReport = commit(params, opsTimer, trackerBundle); + jobProgress.startingStage("Calculating Payload Size"); + Map bundleSize = + jobProgress.runStage(() -> calculatePayloadSize(trackerBundle)); - postCommit(trackerBundle); + jobProgress.startingStage("Running PreProcess"); + jobProgress.runStage(() -> trackerPreprocessService.preprocess(trackerBundle)); - ImportReport importReport = - ImportReport.withImportCompleted( - Status.OK, persistenceReport, validationReport, opsTimer.stopTimer(), bundleSize); + jobProgress.startingStage("Running Validation"); + ValidationResult validationResult = jobProgress.runStage(() -> validateBundle(trackerBundle)); - endImport(params, importReport); + ValidationReport validationReport = ValidationReport.fromResult(validationResult); - return importReport; - } catch (Exception e) { - log.error("Exception thrown during import.", e); - - ImportReport report = - ImportReport.withError( - "Exception:" + e.getMessage(), ValidationReport.emptyReport(), opsTimer.stopTimer()); - - endImportWithError(params, report, e); - - return report; + if (!trackerBundle.isSkipRuleEngine() && !params.getImportStrategy().isDelete()) { + jobProgress.startingStage("Running Rule Engine"); + jobProgress.runStage(() -> trackerBundleService.runRuleEngine(trackerBundle)); + + jobProgress.startingStage("Running Rule Engine Validation"); + ValidationResult result = + jobProgress.runStage(() -> validationService.validateRuleEngine(trackerBundle)); + trackerBundle.setTrackedEntities(result.getTrackedEntities()); + trackerBundle.setEnrollments(result.getEnrollments()); + trackerBundle.setEvents(result.getEvents()); + trackerBundle.setRelationships(result.getRelationships()); + + validationReport = ValidationReport.merge(validationResult, result); } - } - - private TrackerBundle preHeat(TrackerImportParams params, TimingsStats opsTimer) { - TrackerBundle trackerBundle = opsTimer.exec(PREHEAT_OPS, () -> preheatBundle(params)); - - notifyOps(params, PREHEAT_OPS, opsTimer); - return trackerBundle; - } - - private void preProcess(TimingsStats opsTimer, TrackerBundle trackerBundle) { - opsTimer.execVoid(PREPROCESS_OPS, () -> preProcessBundle(trackerBundle)); - } - - private ValidationReport validate( - TrackerImportParams params, TimingsStats opsTimer, TrackerBundle trackerBundle) { - ValidationResult validationResult = - opsTimer.exec(VALIDATION_OPS, () -> validateBundle(params, trackerBundle, opsTimer)); + if (exitOnError(validationReport, params)) { + return ImportReport.withValidationErrors( + validationReport, bundleSize.values().stream().mapToInt(Integer::intValue).sum()); + } - if (!trackerBundle.isSkipRuleEngine() && !params.getImportStrategy().isDelete()) { - ValidationResult ruleEnginevalidationResult = execRuleEngine(params, opsTimer, trackerBundle); + jobProgress.startingStage("Commit Transaction"); + PersistenceReport persistenceReport = jobProgress.runStage(() -> commit(params, trackerBundle)); - return ValidationReport.merge(validationResult, ruleEnginevalidationResult); - } + jobProgress.startingStage("PostCommit"); + jobProgress.runStage(() -> trackerBundleService.postCommit(trackerBundle)); - return ValidationReport.fromResult(validationResult); + return ImportReport.withImportCompleted( + Status.OK, persistenceReport, validationReport, bundleSize); } - private PersistenceReport commit( - TrackerImportParams params, TimingsStats opsTimer, TrackerBundle trackerBundle) { - PersistenceReport persistenceReport; + private PersistenceReport commit(TrackerImportParams params, TrackerBundle trackerBundle) { if (TrackerImportStrategy.DELETE == params.getImportStrategy()) { - persistenceReport = opsTimer.exec(COMMIT_OPS, () -> deleteBundle(trackerBundle)); + return deleteBundle(trackerBundle); } else { - persistenceReport = opsTimer.exec(COMMIT_OPS, () -> commitBundle(trackerBundle)); + return commitBundle(trackerBundle); } - - notifyOps(params, COMMIT_OPS, opsTimer); - return persistenceReport; - } - - private void postCommit(TrackerBundle trackerBundle) { - trackerBundleService.postCommit(trackerBundle); } - protected ValidationResult validateBundle( - TrackerImportParams params, TrackerBundle bundle, TimingsStats opsTimer) { + protected ValidationResult validateBundle(TrackerBundle bundle) { ValidationResult result = validationService.validate(bundle); bundle.setTrackedEntities(result.getTrackedEntities()); bundle.setEnrollments(result.getEnrollments()); bundle.setEvents(result.getEvents()); bundle.setRelationships(result.getRelationships()); - notifyOps(params, VALIDATION_OPS, opsTimer); - - return result; - } - - private ValidationResult execRuleEngine( - TrackerImportParams params, TimingsStats opsTimer, TrackerBundle bundle) { - opsTimer.execVoid(PROGRAMRULE_OPS, () -> trackerBundleService.runRuleEngine(bundle)); - - notifyOps(params, PROGRAMRULE_OPS, opsTimer); - - ValidationResult result = - opsTimer.exec(VALIDATE_PROGRAMRULE_OPS, () -> validationService.validateRuleEngine(bundle)); - bundle.setTrackedEntities(result.getTrackedEntities()); - bundle.setEnrollments(result.getEnrollments()); - bundle.setEvents(result.getEvents()); - bundle.setRelationships(result.getRelationships()); - - notifyOps(params, VALIDATE_PROGRAMRULE_OPS, opsTimer); - return result; } - private ImportReport buildReportAndNotify( - TrackerImportParams params, - ValidationReport validationReport, - TimingsStats opsTimer, - Map bundleSize) { - ImportReport importReport = - ImportReport.withValidationErrors( - validationReport, - opsTimer.stopTimer(), - bundleSize.values().stream().mapToInt(Integer::intValue).sum()); - - endImport(params, importReport); - - return importReport; - } - private boolean exitOnError(ValidationReport validationReport, TrackerImportParams params) { return validationReport.hasErrors() && params.getAtomicMode() == AtomicMode.ALL; } @@ -228,14 +152,6 @@ private Map calculatePayloadSize(TrackerBundle bundle) { TrackerType.RELATIONSHIP, bundle.getRelationships().size()); } - protected TrackerBundle preheatBundle(TrackerImportParams params) { - return trackerBundleService.create(params); - } - - protected void preProcessBundle(TrackerBundle bundle) { - trackerPreprocessService.preprocess(bundle); - } - protected PersistenceReport commitBundle(TrackerBundle trackerBundle) { PersistenceReport persistenceReport = trackerBundleService.commit(trackerBundle); @@ -244,7 +160,7 @@ protected PersistenceReport commitBundle(TrackerBundle trackerBundle) { Stream.of(TrackerType.ENROLLMENT, TrackerType.EVENT) .map(trackerType -> safelyGetSideEffectsDataBundles(persistenceReport, trackerType)) .flatMap(Collection::stream) - .collect(Collectors.toList()); + .toList(); trackerBundleService.handleTrackerSideEffects(sideEffectDataBundles); } @@ -265,48 +181,6 @@ protected PersistenceReport deleteBundle(TrackerBundle trackerBundle) { return trackerBundleService.delete(trackerBundle); } - private void startImport(TrackerImportParams params) { - if (null != params.getJobConfiguration()) { - notifier.notify(params.getJobConfiguration(), params.userStartInfo() + " Import:Start"); - } - } - - private void notifyOps(TrackerImportParams params, String validationOps, TimingsStats opsTimer) { - if (null != params.getJobConfiguration()) { - notifier.update( - params.getJobConfiguration(), - NotificationLevel.DEBUG, - params - + validationOps - + " completed in " - + opsTimer.get(validationOps) - + " Import:" - + validationOps); - } - } - - private void endImport(TrackerImportParams params, ImportReport importReport) { - if (null != params.getJobConfiguration()) { - notifier.update( - params.getJobConfiguration(), - params + " finished in " + importReport.getTimingsStats().get(TOTAL_OPS) + " Import:Done", - true); - - notifier.addJobSummary(params.getJobConfiguration(), importReport, ImportReport.class); - } - } - - private void endImportWithError( - TrackerImportParams params, ImportReport importReport, Exception e) { - notifier.update( - params.getJobConfiguration(), - NotificationLevel.ERROR, - params + " failed with exception: " + e.getMessage() + " Import:Error", - true); - - notifier.addJobSummary(params.getJobConfiguration(), importReport, ImportReport.class); - } - /** * Clone the TrackerImportReport and filters out validation data based on the provided {@link * PersistenceReport}. @@ -328,11 +202,10 @@ public ImportReport buildImportReport( if (originalValidationReport != null) { validationReport.addErrors(originalValidationReport.getErrors()); } - if (originalValidationReport != null && TrackerBundleReportMode.WARNINGS == reportMode) { - validationReport.addWarnings(originalValidationReport.getWarnings()); - } else if (originalValidationReport != null && TrackerBundleReportMode.FULL == reportMode) { + if (originalValidationReport != null + && (TrackerBundleReportMode.WARNINGS == reportMode + || TrackerBundleReportMode.FULL == reportMode)) { validationReport.addWarnings(originalValidationReport.getWarnings()); - importReportBuilder.timingsStats(originalImportReport.getTimingsStats()); } importReportBuilder.validationReport(validationReport); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/ParamsConverter.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/ParamsConverter.java index 927c04736253..3aaafa746dd5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/ParamsConverter.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/ParamsConverter.java @@ -28,12 +28,15 @@ package org.hisp.dhis.tracker.imports; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; +import org.hisp.dhis.user.User; /** * @author Luciano Fiandesio */ public class ParamsConverter { - public static TrackerBundle convert(TrackerImportParams params) { + public static TrackerBundle convert( + TrackerImportParams params, TrackerObjects trackerObjects, User user) { return TrackerBundle.builder() .importMode(params.getImportMode()) .importStrategy(params.getImportStrategy()) @@ -42,11 +45,11 @@ public static TrackerBundle convert(TrackerImportParams params) { .skipRuleEngine(params.isSkipRuleEngine()) .flushMode(params.getFlushMode()) .validationMode(params.getValidationMode()) - .trackedEntities(params.getTrackedEntities()) - .enrollments(params.getEnrollments()) - .events(params.getEvents()) - .relationships(params.getRelationships()) - .user(params.getUser()) + .trackedEntities(trackerObjects.getTrackedEntities()) + .enrollments(trackerObjects.getEnrollments()) + .events(trackerObjects.getEvents()) + .relationships(trackerObjects.getRelationships()) + .user(user) .build(); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParam.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParam.java index cde712ce7863..161bc0bc8905 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParam.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParam.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.Serializable; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -50,7 +51,7 @@ // which is invalid. Drop @OpenApi.Property annotation after implementing support for the unpacking // of query param classes in OpenApiGenerator @OpenApi.Property(value = TrackerIdScheme.class) -public class TrackerIdSchemeParam { +public class TrackerIdSchemeParam implements Serializable { public static final TrackerIdSchemeParam UID = TrackerIdSchemeParam.of(TrackerIdScheme.UID, null); public static final TrackerIdSchemeParam CODE = diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParams.java index 83760db26294..a2fb0826b1e5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdSchemeParams.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -50,7 +51,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class TrackerIdSchemeParams { +public class TrackerIdSchemeParams implements Serializable { /** Specific identifier to match data elements on. */ @JsonProperty @Builder.Default private TrackerIdSchemeParam dataElementIdScheme = TrackerIdSchemeParam.UID; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java index d64c2653dc04..7467d89bb261 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java @@ -53,6 +53,7 @@ import org.hisp.dhis.tracker.imports.domain.Note; import org.hisp.dhis.tracker.imports.domain.Relationship; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.springframework.stereotype.Component; /** @@ -70,12 +71,12 @@ public class TrackerIdentifierCollector { private final ProgramRuleService programRuleService; - public Map, Set> collect(TrackerImportParams params) { + public Map, Set> collect(TrackerObjects trackerObjects) { final Map, Set> identifiers = new HashMap<>(); - collectTrackedEntities(identifiers, params.getTrackedEntities()); - collectEnrollments(identifiers, params.getEnrollments()); - collectEvents(identifiers, params.getEvents()); - collectRelationships(identifiers, params.getRelationships()); + collectTrackedEntities(identifiers, trackerObjects.getTrackedEntities()); + collectEnrollments(identifiers, trackerObjects.getEnrollments()); + collectEvents(identifiers, trackerObjects.getEvents()); + collectRelationships(identifiers, trackerObjects.getRelationships()); collectProgramRulesFields(identifiers); return identifiers; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportParams.java index df96cda1f128..6b5fc80f54fe 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportParams.java @@ -28,21 +28,12 @@ package org.hisp.dhis.tracker.imports; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.hisp.dhis.scheduling.JobConfiguration; -import org.hisp.dhis.scheduling.JobType; +import org.hisp.dhis.scheduling.JobParameters; import org.hisp.dhis.tracker.imports.bundle.TrackerBundleMode; -import org.hisp.dhis.tracker.imports.domain.Enrollment; -import org.hisp.dhis.tracker.imports.domain.Event; -import org.hisp.dhis.tracker.imports.domain.Relationship; -import org.hisp.dhis.tracker.imports.domain.TrackedEntity; -import org.hisp.dhis.user.User; /** * @author Morten Olav Hansen @@ -51,13 +42,10 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class TrackerImportParams { +public class TrackerImportParams implements JobParameters { /** User uid to use for import job. */ @JsonProperty private String userId; - /** User to use for import job. */ - private User user; - /** Should import be imported or just validated. */ @JsonProperty @Builder.Default private final TrackerBundleMode importMode = TrackerBundleMode.COMMIT; @@ -91,50 +79,6 @@ public class TrackerImportParams { /** Name of file that was used for import (if available). */ @JsonProperty @Builder.Default private final String filename = null; - /** Job configuration */ - private JobConfiguration jobConfiguration; - @JsonProperty @Builder.Default private TrackerBundleReportMode reportMode = TrackerBundleReportMode.ERRORS; - - /** Tracked entities to import. */ - @JsonProperty @Builder.Default - private final List trackedEntities = new ArrayList<>(); - - /** Enrollments to import. */ - @JsonProperty @Builder.Default private final List enrollments = new ArrayList<>(); - - /** Events to import. */ - @JsonProperty @Builder.Default private final List events = new ArrayList<>(); - - /** Relationships to import. */ - @JsonProperty @Builder.Default private final List relationships = new ArrayList<>(); - - public TrackerImportParams setUser(User user) { - this.user = user; - - if (user != null) { - this.userId = user.getUid(); - } - - return this; - } - - @JsonProperty - public String getUsername() { - return User.username(user); - } - - @Override - public String toString() { - return Optional.ofNullable(this.getJobConfiguration()) - .map( - jobConfiguration -> - JobType.TRACKER_IMPORT_JOB + " ( " + jobConfiguration.getUid() + " )") - .orElse(JobType.TRACKER_IMPORT_JOB.toString()); - } - - public String userStartInfo() { - return this + " started by " + this.getUsername() + " ( " + this.userId + " )"; - } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportService.java index 23d3222af8cc..caa72a9b64f8 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerImportService.java @@ -27,6 +27,9 @@ */ package org.hisp.dhis.tracker.imports; +import org.hisp.dhis.scheduling.JobProgress; +import org.hisp.dhis.scheduling.NoopJobProgress; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; /** @@ -37,10 +40,25 @@ public interface TrackerImportService { * Import object using provided params. Takes the objects through all phases of the importer from * preheating to validation, and then finished with a commit (unless its validate only) * - * @param params Parameters for import, including objects + * @param params Parameters for import + * @param trackerObjects the objects to import * @return Report giving status of import (and any errors) */ - ImportReport importTracker(TrackerImportParams params); + default ImportReport importTracker(TrackerImportParams params, TrackerObjects trackerObjects) { + return importTracker(params, trackerObjects, NoopJobProgress.INSTANCE); + } + + /** + * Import object using provided params. Takes the objects through all phases of the importer from + * preheating to validation, and then finished with a commit (unless its validate only) + * + * @param params Parameters for import + * @param trackerObjects the objects to import + * @param jobProgress to track import progress + * @return Report giving status of import (and any errors) + */ + ImportReport importTracker( + TrackerImportParams params, TrackerObjects trackerObjects, JobProgress jobProgress); /** * Build the report based on the mode selected by the client. diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/DefaultTrackerBundleService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/DefaultTrackerBundleService.java index 0374ea7aa1b7..a8699eadad70 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/DefaultTrackerBundleService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/DefaultTrackerBundleService.java @@ -41,6 +41,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.bundle.persister.CommitService; import org.hisp.dhis.tracker.imports.bundle.persister.TrackerObjectDeletionService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.job.TrackerSideEffectDataBundle; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheatService; @@ -48,6 +49,7 @@ import org.hisp.dhis.tracker.imports.report.PersistenceReport; import org.hisp.dhis.tracker.imports.report.TrackerTypeReport; import org.hisp.dhis.tracker.imports.sideeffect.SideEffectHandlerService; +import org.hisp.dhis.user.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -78,9 +80,11 @@ public void setSideEffectHandlers(List sideEffectHandl } @Override - public TrackerBundle create(TrackerImportParams params) { - TrackerBundle trackerBundle = ParamsConverter.convert(params); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + public TrackerBundle create( + TrackerImportParams params, TrackerObjects trackerObjects, User user) { + TrackerBundle trackerBundle = ParamsConverter.convert(params, trackerObjects, user); + TrackerPreheat preheat = + trackerPreheatService.preheat(trackerObjects, params.getIdSchemes(), user); trackerBundle.setPreheat(preheat); return trackerBundle; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleService.java index af8e46e72472..cdb50aee5cda 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleService.java @@ -29,8 +29,10 @@ import java.util.List; import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.job.TrackerSideEffectDataBundle; import org.hisp.dhis.tracker.imports.report.PersistenceReport; +import org.hisp.dhis.user.User; /** * @author Morten Olav Hansen @@ -42,7 +44,7 @@ public interface TrackerBundleService { * @param params Params object for this bundle. * @return Configured TrackerBundle instance(s) (if bundle splitting is enabled) */ - TrackerBundle create(TrackerImportParams params); + TrackerBundle create(TrackerImportParams params, TrackerObjects trackerObjects, User user); /** * Call rule engine for tracker bundle. diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java index be0ccf18d421..37134c2f6bff 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; @@ -42,7 +43,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Attribute { +public class Attribute implements Serializable { @JsonProperty private MetadataIdentifier attribute; @JsonProperty private String code; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Coordinate.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Coordinate.java index 567290315e17..b00612269568 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Coordinate.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Coordinate.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -41,7 +42,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Coordinate { +public class Coordinate implements Serializable { @JsonProperty private Double latitude; @JsonProperty private Double longitude; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java index fd1e6689c491..d0b0a7de9f93 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; @@ -41,7 +42,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class DataValue { +public class DataValue implements Serializable { @JsonProperty private Instant createdAt; @JsonProperty private Instant updatedAt; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java index d5ec22ed7d47..0e702d9bbf81 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -45,7 +46,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Enrollment implements TrackerDto { +public class Enrollment implements TrackerDto, Serializable { @JsonProperty private String enrollment; @JsonProperty private Instant createdAt; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java index 4b30f68fb4c1..5298abab4e03 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import java.util.ArrayList; import java.util.HashSet; @@ -49,7 +50,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Event implements TrackerDto { +public class Event implements TrackerDto, Serializable { @JsonProperty private String event; @JsonProperty @Builder.Default private EventStatus status = EventStatus.ACTIVE; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/MetadataIdentifier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/MetadataIdentifier.java index 3b28029e61b4..3ad1b265787b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/MetadataIdentifier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/MetadataIdentifier.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.util.Objects; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -57,7 +58,7 @@ */ @Value @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class MetadataIdentifier { +public class MetadataIdentifier implements Serializable { public static final MetadataIdentifier EMPTY_UID = MetadataIdentifier.ofUid((String) null); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java index cec45da897d7..5401ed822ccc 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; @@ -44,7 +45,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Note { +public class Note implements Serializable { @JsonProperty private String note; @JsonProperty private Instant storedAt; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java index 5219571ab623..83beb87b27a5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; @@ -42,7 +43,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class Relationship implements TrackerDto { +public class Relationship implements TrackerDto, Serializable { @JsonProperty private String relationship; @JsonProperty private String relationshipName; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/RelationshipItem.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/RelationshipItem.java index 12e022a460ae..cc80e0be0337 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/RelationshipItem.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/RelationshipItem.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -40,7 +41,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class RelationshipItem { +public class RelationshipItem implements Serializable { @JsonProperty private String trackedEntity; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java index 7aee6fba58e9..29eaf07e3f9d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.domain; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -45,7 +46,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class TrackedEntity implements TrackerDto { +public class TrackedEntity implements TrackerDto, Serializable { @JsonProperty private String trackedEntity; @JsonProperty private MetadataIdentifier trackedEntityType; diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerSyncImporter.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerObjects.java similarity index 63% rename from dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerSyncImporter.java rename to dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerObjects.java index c48ae7a81316..02a8a89dba76 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerSyncImporter.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackerObjects.java @@ -25,27 +25,30 @@ * (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.webapi.controller.tracker.imports; +package org.hisp.dhis.tracker.imports.domain; -import javax.annotation.Nonnull; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.tracker.imports.TrackerImportParams; -import org.hisp.dhis.tracker.imports.TrackerImportService; -import org.hisp.dhis.tracker.imports.report.ImportReport; -import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; -/** - * @author Luca Cambi - */ -@Component -@RequiredArgsConstructor -public class TrackerSyncImporter { - - @Nonnull private final TrackerImportService trackerImportService; - - public ImportReport importTracker(TrackerImportParams params) { - ImportReport importReport = trackerImportService.importTracker(params); +@Getter +@ToString +@EqualsAndHashCode +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TrackerObjects implements Serializable { + @JsonProperty @Builder.Default + private final List trackedEntities = new ArrayList<>(); - return trackerImportService.buildImportReport(importReport, params.getReportMode()); - } + @JsonProperty @Builder.Default private final List enrollments = new ArrayList<>(); + @JsonProperty @Builder.Default private final List events = new ArrayList<>(); + @JsonProperty @Builder.Default private final List relationships = new ArrayList<>(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java index d30e8891540e..0509c17bad16 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java @@ -30,6 +30,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -42,7 +43,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class User { +public class User implements Serializable { @JsonProperty private String uid; @JsonProperty private String username; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerImportThread.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerImportThread.java deleted file mode 100644 index cb2796a2cb23..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerImportThread.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.job; - -import org.hisp.dhis.security.SecurityContextRunnable; -import org.hisp.dhis.tracker.imports.TrackerImportParams; -import org.hisp.dhis.tracker.imports.TrackerImportService; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -/** - * @author Morten Olav Hansen - */ -@Component -@Scope(BeanDefinition.SCOPE_PROTOTYPE) -public class TrackerImportThread extends SecurityContextRunnable { - private final TrackerImportService trackerImportService; - - private TrackerImportParams trackerImportParams; - - public TrackerImportThread(TrackerImportService trackerImportService) { - this.trackerImportService = trackerImportService; - } - - @Override - public void call() { - Assert.notNull(trackerImportParams, "Field trackerImportParams can not be null. "); - - trackerImportService.importTracker(trackerImportParams); // discard returned report - } - - public void setTrackerImportParams(TrackerImportParams trackerImportParams) { - this.trackerImportParams = trackerImportParams; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessage.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessage.java deleted file mode 100644 index ab8bcb5ceaab..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessage.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.job; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import lombok.Builder; -import lombok.Value; -import org.hisp.dhis.artemis.MessageType; -import org.hisp.dhis.artemis.SerializableMessage; -import org.hisp.dhis.tracker.imports.TrackerImportParams; - -/** - * Used by Apache Artemis to pass tracker import jobs from the /api/tracker endpoint to the tracker - * import services. - * - * @author Morten Olav Hansen - */ -@Value -@Builder(builderClassName = "TrackerMessageBuilder") -@JsonDeserialize(builder = TrackerMessage.TrackerMessageBuilder.class) -public class TrackerMessage implements SerializableMessage { - @JsonProperty private final String uid; - - @JsonProperty private final String authentication; - - @JsonProperty private final TrackerImportParams trackerImportParams; - - @Override - public MessageType getMessageType() { - return MessageType.TRACKER_JOB; - } - - @JsonPOJOBuilder(withPrefix = "") - public static final class TrackerMessageBuilder {} -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessageManager.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessageManager.java deleted file mode 100644 index ef8d8abfbef7..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerMessageManager.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.job; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import javax.jms.JMSException; -import javax.jms.TextMessage; -import org.hisp.dhis.artemis.Topics; -import org.hisp.dhis.common.AsyncTaskExecutor; -import org.hisp.dhis.scheduling.JobConfiguration; -import org.hisp.dhis.scheduling.JobType; -import org.hisp.dhis.security.AuthenticationSerializer; -import org.hisp.dhis.tracker.imports.TrackerImportParams; -import org.springframework.beans.factory.ObjectFactory; -import org.springframework.jms.annotation.JmsListener; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; - -/** - * @author Morten Olav Hansen - */ -@Component -public class TrackerMessageManager { - private final ObjectMapper objectMapper; - - private final AsyncTaskExecutor taskExecutor; - - private final ObjectFactory trackerImportThreadFactory; - - public TrackerMessageManager( - ObjectMapper objectMapper, - AsyncTaskExecutor taskExecutor, - ObjectFactory trackerImportThreadFactory) { - this.objectMapper = objectMapper; - this.taskExecutor = taskExecutor; - this.trackerImportThreadFactory = trackerImportThreadFactory; - } - - @JmsListener( - destination = Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, - containerFactory = "jmsQueueListenerContainerFactory") - public void consume(TextMessage message) throws JMSException, JsonProcessingException { - String payload = message.getText(); - - TrackerMessage trackerMessage = objectMapper.readValue(payload, TrackerMessage.class); - TrackerImportParams trackerImportParams = trackerMessage.getTrackerImportParams(); - - JobConfiguration jobConfiguration = - new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, trackerImportParams.getUserId()); - - jobConfiguration.setUid(trackerMessage.getUid()); - trackerImportParams.setJobConfiguration(jobConfiguration); - - TrackerImportThread trackerImportThread = trackerImportThreadFactory.getObject(); - trackerImportThread.setTrackerImportParams(trackerImportParams); - - SecurityContextHolder.getContext() - .setAuthentication( - AuthenticationSerializer.deserialize(trackerMessage.getAuthentication())); - - taskExecutor.executeTask(trackerImportThread); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatService.java index 3051680314c2..c2de4078f69d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatService.java @@ -36,8 +36,10 @@ import lombok.extern.slf4j.Slf4j; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.preheat.PreheatException; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.supplier.PreheatSupplier; +import org.hisp.dhis.user.User; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; @@ -70,17 +72,18 @@ public void setApplicationContext(ApplicationContext applicationContext) throws @Override @Transactional(readOnly = true) - public TrackerPreheat preheat(TrackerImportParams params) { + public TrackerPreheat preheat( + TrackerObjects trackerObjects, TrackerIdSchemeParams idSchemeParams, User user) { TrackerPreheat preheat = new TrackerPreheat(); - preheat.setIdSchemes(params.getIdSchemes()); - preheat.setUser(params.getUser()); + preheat.setIdSchemes(idSchemeParams); + preheat.setUser(user); checkNotNull(preheat.getUser(), "TrackerPreheat is missing the user object."); for (String supplier : preheatSuppliers) { final String beanName = Introspector.decapitalize(supplier); try { - ctx.getBean(beanName, PreheatSupplier.class).add(params, preheat); + ctx.getBean(beanName, PreheatSupplier.class).add(trackerObjects, preheat); } catch (BeansException beanException) { processException( "Unable to find a preheat supplier with name " diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatService.java index 83425bab3a07..05b97823a1ca 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatService.java @@ -27,7 +27,9 @@ */ package org.hisp.dhis.tracker.imports.preheat; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; +import org.hisp.dhis.user.User; /** * @author Morten Olav Hansen @@ -39,5 +41,6 @@ public interface TrackerPreheatService { * * @param params Params for preheating */ - TrackerPreheat preheat(TrackerImportParams params); + TrackerPreheat preheat( + TrackerObjects trackerObjects, TrackerIdSchemeParams idSchemeParams, User user); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/AbstractPreheatSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/AbstractPreheatSupplier.java index 0b344e8e4d82..8a7d1958a208 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/AbstractPreheatSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/AbstractPreheatSupplier.java @@ -33,7 +33,7 @@ import org.apache.commons.lang3.time.StopWatch; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.hibernate.HibernateProxyUtils; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.cache.PreheatCacheService; @@ -50,7 +50,7 @@ public abstract class AbstractPreheatSupplier implements PreheatSupplier { private final long CACHE_CAPACITY = 1000; @Override - public void add(TrackerImportParams params, TrackerPreheat preheat) { + public void add(TrackerObjects trackerObjects, TrackerPreheat preheat) { StopWatch watch = null; if (log.isDebugEnabled()) { log.debug("Executing preheat supplier: {}", this.getClass().getName()); @@ -58,7 +58,7 @@ public void add(TrackerImportParams params, TrackerPreheat preheat) { watch.start(); } - preheatAdd(params, preheat); + preheatAdd(trackerObjects, preheat); if (log.isDebugEnabled()) { if (watch != null && watch.isStarted()) { @@ -72,7 +72,7 @@ public void add(TrackerImportParams params, TrackerPreheat preheat) { } /** Template method: executes preheat logic from the subclass */ - public abstract void preheatAdd(TrackerImportParams params, TrackerPreheat preheat); + public abstract void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat); protected void addToCache(PreheatCacheService cache, List objects) { objects.forEach( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplier.java index 831441c6dc90..93c256b92412 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplier.java @@ -35,7 +35,7 @@ import java.util.Set; import lombok.RequiredArgsConstructor; import org.hisp.dhis.tracker.imports.TrackerIdentifierCollector; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.supplier.strategy.ClassBasedSupplierStrategy; import org.hisp.dhis.tracker.imports.preheat.supplier.strategy.GenericStrategy; @@ -67,13 +67,13 @@ public class ClassBasedSupplier extends AbstractPreheatSupplier implements Appli private final Map classStrategies; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { /* * Collects all references from the payload and create a Map where key * is the reference type (e.g. Enrollment) and the value is a Set of * identifiers (e.g. a list of all Enrollment UIDs found in the payload) */ - Map, Set> identifierMap = identifierCollector.collect(params); + Map, Set> identifierMap = identifierCollector.collect(trackerObjects); identifierMap.forEach( (key, identifiers) -> { @@ -90,7 +90,7 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { } else { context .getBean(Introspector.decapitalize(bean), ClassBasedSupplierStrategy.class) - .add(params, splitList, preheat); + .add(splitList, preheat); } }); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DefaultsSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DefaultsSupplier.java index bf12d2c46db3..7db809ab2c3c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DefaultsSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DefaultsSupplier.java @@ -36,7 +36,7 @@ import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.cache.PreheatCacheService; import org.hisp.dhis.tracker.imports.preheat.mappers.CategoryComboMapper; @@ -59,7 +59,7 @@ public class DefaultsSupplier extends AbstractPreheatSupplier { @Nonnull private final PreheatCacheService cache; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { // not using manager.getDefaults() as the collections of the entities // are still hibernate proxies // this leads to lazy init exceptions with - no session. reason is the diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplier.java index a91c405021ba..89ec6171e11c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplier.java @@ -34,8 +34,8 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.relationship.RelationshipStore; import org.hisp.dhis.relationship.RelationshipType; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Relationship; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.RelationshipMapper; import org.hisp.dhis.tracker.imports.util.RelationshipKeySupport; @@ -47,9 +47,9 @@ public class DuplicateRelationshipSupplier extends AbstractPreheatSupplier { @Nonnull private final RelationshipStore relationshipStore; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List relationships = - retrieveRelationshipKeys(params.getRelationships(), preheat); + retrieveRelationshipKeys(trackerObjects.getRelationships(), preheat); relationships.stream() .map(RelationshipMapper.INSTANCE::map) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplier.java index f8c9338257d0..e26b40d99e51 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplier.java @@ -36,7 +36,7 @@ import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStore; import org.hisp.dhis.program.ProgramType; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.EnrollmentMapper; import org.springframework.stereotype.Component; @@ -52,7 +52,7 @@ public class EnrollmentSupplier extends AbstractPreheatSupplier { @Nonnull private final ProgramStore programStore; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List programsWithoutRegistration = preheat.getAll(Program.class).stream() .filter(program -> program.getProgramType().equals(ProgramType.WITHOUT_REGISTRATION)) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentsWithAtLeastOneEventSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentsWithAtLeastOneEventSupplier.java index 4a0190c49171..f3981a09d4d5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentsWithAtLeastOneEventSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentsWithAtLeastOneEventSupplier.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -64,7 +64,7 @@ protected EnrollmentsWithAtLeastOneEventSupplier(JdbcTemplate jdbcTemplate) { } @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { final Map enrollments = preheat.getEnrollments(); List programStageIds = enrollments.values().stream().map(IdentifiableObject::getId).collect(Collectors.toList()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplier.java index 2409d9c2a61d..8d3ce4dd9221 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplier.java @@ -40,9 +40,9 @@ import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.CategoryOptionComboMapper; import org.springframework.stereotype.Component; @@ -63,10 +63,10 @@ public class EventCategoryOptionComboSupplier extends AbstractPreheatSupplier { @Nonnull private final CategoryService categoryService; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List>> events = - params.getEvents().stream() + trackerObjects.getEvents().stream() .filter( e -> e.getAttributeOptionCombo().isBlank() diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java index bdf845453377..fa1a2128754d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventProgramStageMapSupplier.java @@ -31,8 +31,8 @@ import java.util.Objects; import java.util.stream.Collectors; import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; @@ -72,13 +72,13 @@ protected EventProgramStageMapSupplier(JdbcTemplate jdbcTemplate) { } @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { - if (params.getEvents().isEmpty()) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { + if (trackerObjects.getEvents().isEmpty()) { return; } List notRepeatableProgramStageUids = - params.getEvents().stream() + trackerObjects.getEvents().stream() .map(Event::getProgramStage) .filter(Objects::nonNull) .map(preheat::getProgramStage) @@ -90,7 +90,7 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { .collect(Collectors.toList()); List enrollmentUids = - params.getEvents().stream() + trackerObjects.getEvents().stream() .map(Event::getEnrollment) .filter(Objects::nonNull) .distinct() diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplier.java index 6a0cc39b88cd..186716c87d47 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplier.java @@ -39,10 +39,10 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.DataValue; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.springframework.stereotype.Component; @@ -55,9 +55,8 @@ public class FileResourceSupplier extends AbstractPreheatSupplier { @Nonnull private final FileResourceService fileResourceService; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { - TrackerIdSchemeParams idSchemes = params.getIdSchemes(); - + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { + TrackerIdSchemeParams idSchemes = preheat.getIdSchemes(); List fileResourceAttributes = preheat.getAll(TrackedEntityAttribute.class).stream() .filter(at -> at.getValueType().isFile()) @@ -71,15 +70,15 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { .collect(Collectors.toList()); List fileResourceIds = new ArrayList<>(); - params + trackerObjects .getTrackedEntities() .forEach( te -> collectResourceIds(fileResourceAttributes, fileResourceIds, te.getAttributes())); - params + trackerObjects .getEnrollments() .forEach( en -> collectResourceIds(fileResourceAttributes, fileResourceIds, en.getAttributes())); - params + trackerObjects .getEvents() .forEach( en -> diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplier.java index ef817a04a2da..9918e4f6bdf6 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplier.java @@ -41,10 +41,10 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.DataValue; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.springframework.stereotype.Component; @@ -57,7 +57,7 @@ public class OrgUnitValueTypeSupplier extends AbstractPreheatSupplier { @Nonnull private final IdentifiableObjectManager manager; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { TrackerIdSchemeParams idSchemes = preheat.getIdSchemes(); List orgUnitAttributes = @@ -73,13 +73,13 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { .collect(Collectors.toList()); List orgUnitIds = new ArrayList<>(); - params + trackerObjects .getTrackedEntities() .forEach(te -> collectResourceIds(orgUnitAttributes, orgUnitIds, te.getAttributes())); - params + trackerObjects .getEnrollments() .forEach(en -> collectResourceIds(orgUnitAttributes, orgUnitIds, en.getAttributes())); - params + trackerObjects .getEvents() .forEach(ev -> collectResourceIds(orgUnitDataElements, orgUnitIds, ev.getDataValues())); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplier.java index a9d832164f76..94ae63808d93 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplier.java @@ -35,7 +35,7 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodStore; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.cache.PreheatCacheService; import org.springframework.stereotype.Component; @@ -51,7 +51,7 @@ public class PeriodTypeSupplier extends AbstractPreheatSupplier { @Nonnull private final PreheatCacheService cache; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { if (cache.hasKey(Period.class.getName())) { preheat.put(TrackerIdSchemeParam.UID, cache.getAll(Period.class.getName())); } else { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PreheatSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PreheatSupplier.java index f57986b87bad..231addb5deb3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PreheatSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/PreheatSupplier.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.imports.preheat.supplier; import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; /** @@ -39,8 +40,8 @@ public interface PreheatSupplier { /** * Adds data to the {@link TrackerPreheat} using the supplied {@link TrackerImportParams} * - * @param params {@link TrackerImportParams} + * @param trackerObjects {@link TrackerObjects} * @param preheat {@link TrackerPreheat} */ - void add(TrackerImportParams params, TrackerPreheat preheat); + void add(TrackerObjects trackerObjects, TrackerPreheat preheat); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOrgUnitsSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOrgUnitsSupplier.java index e44c6459bf5b..ee4b26b85a5b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOrgUnitsSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOrgUnitsSupplier.java @@ -31,7 +31,7 @@ import java.util.stream.Collectors; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -55,7 +55,7 @@ protected ProgramOrgUnitsSupplier(JdbcTemplate jdbcTemplate) { } @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { // fetch all existing Org Units from payload final List orgUnitIds = preheat.getAll(OrganisationUnit.class).stream() diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java index 7dcd04847c3f..87c909951e01 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/ProgramOwnerSupplier.java @@ -38,8 +38,8 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerOrgUnit; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.OrganisationUnitMapper; import org.springframework.stereotype.Component; @@ -53,18 +53,18 @@ public class ProgramOwnerSupplier extends AbstractPreheatSupplier { @Nonnull private final TrackedEntityProgramOwnerStore trackedEntityProgramOwnerStore; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { final Map preheatedTrackedEntities = preheat.getTrackedEntities(); final Map preheatedEnrollments = preheat.getEnrollments(); Set teIds = new HashSet<>(); - for (org.hisp.dhis.tracker.imports.domain.Enrollment en : params.getEnrollments()) { + for (org.hisp.dhis.tracker.imports.domain.Enrollment en : trackerObjects.getEnrollments()) { TrackedEntity te = preheatedTrackedEntities.get(en.getTrackedEntity()); if (te != null) { teIds.add(te.getId()); } } - for (Event ev : params.getEvents()) { + for (Event ev : trackerObjects.getEvents()) { Enrollment enrollment = preheatedEnrollments.get(ev.getEnrollment()); if (enrollment != null && enrollment.getTrackedEntity() != null) { teIds.add(enrollment.getTrackedEntity().getId()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/TrackedEntityEnrollmentSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/TrackedEntityEnrollmentSupplier.java index 3b075fed7f1e..9072523a59e1 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/TrackedEntityEnrollmentSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/TrackedEntityEnrollmentSupplier.java @@ -37,7 +37,7 @@ import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStatus; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.util.Constant; import org.springframework.jdbc.core.JdbcTemplate; @@ -97,9 +97,9 @@ protected TrackedEntityEnrollmentSupplier(JdbcTemplate jdbcTemplate) { } @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List trackedEntityList = - params.getEnrollments().stream() + trackerObjects.getEnrollments().stream() .map(org.hisp.dhis.tracker.imports.domain.Enrollment::getTrackedEntity) .collect(Collectors.toList()); @@ -115,7 +115,7 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { Map> trackedEntityToEnrollmentMap = new HashMap<>(); - if (params.getEnrollments().isEmpty()) return; + if (trackerObjects.getEnrollments().isEmpty()) return; for (List trackedEntityListSubList : trackedEntities) { queryTeiAndAddToMap(trackedEntityToEnrollmentMap, trackedEntityListSubList, programList); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java index 598a38bc0d74..353bb1888b91 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributesSupplier.java @@ -52,9 +52,9 @@ import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.UniqueAttributeValue; import org.springframework.stereotype.Component; @@ -74,20 +74,20 @@ public class UniqueAttributesSupplier extends AbstractPreheatSupplier { @Nonnull private final TrackedEntityAttributeValueService trackedEntityAttributeValueService; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List uniqueTrackedEntityAttributes = trackedEntityAttributeService.getAllUniqueTrackedEntityAttributes(); Map> allUniqueAttributesByTrackedEntity = - getAllAttributesByTrackedEntity(params, preheat, uniqueTrackedEntityAttributes); + getAllAttributesByTrackedEntity(trackerObjects, preheat, uniqueTrackedEntityAttributes); List uniqueAttributeValuesFromPayload = getDuplicatedUniqueValuesInPayload(allUniqueAttributesByTrackedEntity); List uniqueAttributeValuesFromDB = getAlreadyPresentInDbUniqueValues( - params.getIdSchemes(), + preheat.getIdSchemes(), allUniqueAttributesByTrackedEntity, uniqueTrackedEntityAttributes); @@ -102,11 +102,11 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { private Map> getAllAttributesByTrackedEntity( - TrackerImportParams params, + TrackerObjects trackerObjects, TrackerPreheat preheat, List uniqueTrackedEntityAttributes) { Map> teUniqueAttributes = - params.getTrackedEntities().stream() + trackerObjects.getTrackedEntities().stream() .collect( toMap( Function.identity(), @@ -115,9 +115,10 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { Map> enrollmentUniqueAttributes = - params.getEnrollments().stream() + trackerObjects.getEnrollments().stream() .collect( - groupingBy(e -> getEntityForEnrollment(params, preheat, e.getTrackedEntity()))) + groupingBy( + e -> getEntityForEnrollment(trackerObjects, preheat, e.getTrackedEntity()))) .entrySet() .stream() .collect( @@ -136,12 +137,12 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { } private org.hisp.dhis.tracker.imports.domain.TrackedEntity getEntityForEnrollment( - TrackerImportParams params, TrackerPreheat preheat, String teUid) { + TrackerObjects trackerObjects, TrackerPreheat preheat, String teUid) { TrackedEntity trackedEntity = preheat.getTrackedEntity(teUid); // Get te from Preheat Optional optionalTe = - params.getTrackedEntities().stream() + trackerObjects.getTrackedEntities().stream() .filter(te -> Objects.equals(te.getTrackedEntity(), teUid)) .findAny(); if (optionalTe.isPresent()) { @@ -152,7 +153,7 @@ private org.hisp.dhis.tracker.imports.domain.TrackedEntity getEntityForEnrollmen new org.hisp.dhis.tracker.imports.domain.TrackedEntity(); te.setTrackedEntity(teUid); te.setOrgUnit( - params.getIdSchemes().toMetadataIdentifier(trackedEntity.getOrganisationUnit())); + preheat.getIdSchemes().toMetadataIdentifier(trackedEntity.getOrganisationUnit())); return te; } else // TE is not present. but we do not fail here. // A validation error will be thrown in validation phase diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplier.java index 0f119ea5a100..ff98ac18a259 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplier.java @@ -37,8 +37,8 @@ import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.domain.User; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.UserMapper; @@ -56,9 +56,9 @@ public class UserSupplier extends AbstractPreheatSupplier { @Nonnull private final UserService userService; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { Set userUids = - params.getEvents().stream() + trackerObjects.getEvents().stream() .filter(Objects::nonNull) .map(Event::getAssignedUser) .filter(Objects::nonNull) @@ -67,7 +67,7 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { .collect(Collectors.toSet()); Set usernames = - params.getEvents().stream() + trackerObjects.getEvents().stream() .filter(Objects::nonNull) .map(Event::getAssignedUser) .filter(Objects::nonNull) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UsernameValueTypeSupplier.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UsernameValueTypeSupplier.java index 0702e56f7c44..a2523c34631c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UsernameValueTypeSupplier.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/UsernameValueTypeSupplier.java @@ -37,9 +37,9 @@ import org.hisp.dhis.common.ValueType; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.UserMapper; import org.hisp.dhis.user.User; @@ -56,7 +56,7 @@ public class UsernameValueTypeSupplier extends AbstractPreheatSupplier { @Nonnull private final UserService userService; @Override - public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { + public void preheatAdd(TrackerObjects trackerObjects, TrackerPreheat preheat) { List attributes = preheat.getAll(TrackedEntityAttribute.class); TrackerIdSchemeParams idSchemes = preheat.getIdSchemes(); @@ -68,10 +68,10 @@ public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) { List usernames = new ArrayList<>(); - params + trackerObjects .getTrackedEntities() .forEach(te -> collectResourceIds(usernameAttributes, usernames, te.getAttributes())); - params + trackerObjects .getEnrollments() .forEach(en -> collectResourceIds(usernameAttributes, usernames, en.getAttributes())); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/AbstractSchemaStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/AbstractSchemaStrategy.java index da4e957a096e..b33812b83b40 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/AbstractSchemaStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/AbstractSchemaStrategy.java @@ -44,7 +44,6 @@ import org.hisp.dhis.schema.SchemaService; import org.hisp.dhis.tracker.imports.TrackerIdScheme; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.cache.PreheatCacheService; import org.hisp.dhis.tracker.imports.preheat.mappers.CopyMapper; @@ -79,9 +78,8 @@ protected AbstractSchemaStrategy( } @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { - TrackerIdSchemeParam idSchemeParam = params.getIdSchemes().getByClass(getSchemaClass()); + public void add(List> splitList, TrackerPreheat preheat) { + TrackerIdSchemeParam idSchemeParam = preheat.getIdSchemes().getByClass(getSchemaClass()); Schema schema = schemaService.getDynamicSchema(getSchemaClass()); queryForIdentifiableObjects(preheat, schema, idSchemeParam, splitList, mapper()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/ClassBasedSupplierStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/ClassBasedSupplierStrategy.java index 3bdff20cc475..9b6811151a03 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/ClassBasedSupplierStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/ClassBasedSupplierStrategy.java @@ -28,12 +28,11 @@ package org.hisp.dhis.tracker.imports.preheat.supplier.strategy; import java.util.List; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; /** * @author Luciano Fiandesio */ public interface ClassBasedSupplierStrategy { - void add(TrackerImportParams params, List> splitList, TrackerPreheat preheat); + void add(List> splitList, TrackerPreheat preheat); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EnrollmentStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EnrollmentStrategy.java index 2875cba5ee7d..03e8ea052440 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EnrollmentStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EnrollmentStrategy.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.program.EnrollmentStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.EnrollmentMapper; import org.hisp.dhis.tracker.imports.preheat.supplier.DetachUtils; @@ -50,8 +49,7 @@ public class EnrollmentStrategy implements ClassBasedSupplierStrategy { @Nonnull private final EnrollmentStore enrollmentStore; @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { + public void add(List> splitList, TrackerPreheat preheat) { for (List ids : splitList) { List enrollments = enrollmentStore.getIncludingDeleted(ids); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EventStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EventStrategy.java index 5148447256d4..aceb75b5833d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EventStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/EventStrategy.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.program.Event; import org.hisp.dhis.program.EventStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.EventMapper; import org.hisp.dhis.tracker.imports.preheat.supplier.DetachUtils; @@ -48,8 +47,7 @@ public class EventStrategy implements ClassBasedSupplierStrategy { @Nonnull private final EventStore eventStore; @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { + public void add(List> splitList, TrackerPreheat preheat) { for (List ids : splitList) { List events = eventStore.getIncludingDeleted(ids); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/NoteStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/NoteStrategy.java index f0d7f3d971db..0b6fdcd25595 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/NoteStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/NoteStrategy.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.note.Note; import org.hisp.dhis.note.NoteStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.NoteMapper; import org.hisp.dhis.tracker.imports.preheat.supplier.DetachUtils; @@ -48,8 +47,7 @@ public class NoteStrategy implements ClassBasedSupplierStrategy { @Nonnull private final NoteStore noteStore; @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { + public void add(List> splitList, TrackerPreheat preheat) { splitList.forEach( ids -> preheat.putNotes( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/RelationshipStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/RelationshipStrategy.java index 20902c26b09f..b44a38149515 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/RelationshipStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/RelationshipStrategy.java @@ -33,7 +33,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.relationship.RelationshipStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Relationship; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.RelationshipMapper; @@ -50,8 +49,7 @@ public class RelationshipStrategy implements ClassBasedSupplierStrategy { @Nonnull private final RelationshipStore relationshipStore; @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { + public void add(List> splitList, TrackerPreheat preheat) { List relationships = retrieveRelationships(splitList); preheat.putRelationships( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategy.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategy.java index 27f29f913215..182f8645c2cc 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategy.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategy.java @@ -32,7 +32,6 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.mappers.TrackedEntityMapper; import org.hisp.dhis.tracker.imports.preheat.supplier.DetachUtils; @@ -50,8 +49,7 @@ public class TrackerEntityStrategy implements ClassBasedSupplierStrategy { @Nonnull private TrackedEntityStore trackedEntityStore; @Override - public void add( - TrackerImportParams params, List> splitList, TrackerPreheat preheat) { + public void add(List> splitList, TrackerPreheat preheat) { for (List ids : splitList) { // Fetch all Tracked Entity present in the payload List trackedEntities = trackedEntityStore.getIncludingDeleted(ids); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/ImportReport.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/ImportReport.java index d9545c36e13a..15670984a5de 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/ImportReport.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/ImportReport.java @@ -75,9 +75,6 @@ public class ImportReport { */ @JsonProperty Stats stats; - /** A report object containing the elapsed time for each Import stage */ - @JsonProperty TimingsStats timingsStats; - /** A report containing the outcome of the commit stage (e.g. how many entities were persisted) */ @JsonProperty("bundleReport") PersistenceReport persistenceReport; @@ -96,15 +93,13 @@ public class ImportReport { * therefore all bundle objects were ignored. * * @param validationReport The validation report - * @param timingsStats The timing stats * @param bundleSize The sum of all bundle objects */ public static ImportReport withValidationErrors( - ValidationReport validationReport, TimingsStats timingsStats, int bundleSize) { + ValidationReport validationReport, int bundleSize) { return builder() .status(Status.ERROR) .validationReport(validationReport) - .timingsStats(timingsStats) .stats(Stats.builder().ignored(bundleSize).build()) .build(); } @@ -119,15 +114,12 @@ public static ImportReport withValidationErrors( * * @param message The error message * @param validationReport The validation report if available - * @param timingsStats The timing stats if available */ - public static ImportReport withError( - String message, ValidationReport validationReport, TimingsStats timingsStats) { + public static ImportReport withError(String message, ValidationReport validationReport) { // TODO shall we calculate stats in this case? return builder() .status(Status.ERROR) .validationReport(validationReport) - .timingsStats(timingsStats) .message(message) .build(); } @@ -142,7 +134,6 @@ public static ImportReport withError( * @param persistenceReport The report containing how many bundle objects were successfully * persisted * @param validationReport The validation report if available - * @param timingsStats The timing stats if available * @param bundleSize a map containing the size of each entity type in the Bundle - before the * validation */ @@ -150,7 +141,6 @@ public static ImportReport withImportCompleted( Status status, PersistenceReport persistenceReport, ValidationReport validationReport, - TimingsStats timingsStats, Map bundleSize) { Stats stats = Stats.builder().build(); Stats brs = persistenceReport.getStats(); @@ -159,7 +149,6 @@ public static ImportReport withImportCompleted( return builder() .status(status) .validationReport(validationReport) - .timingsStats(timingsStats) .persistenceReport(processBundleReport(persistenceReport, bundleSize)) .stats(stats) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/TimingsStats.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/TimingsStats.java deleted file mode 100644 index 594ac149f333..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/report/TimingsStats.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.report; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Supplier; -import lombok.Data; -import org.hisp.dhis.commons.timer.SystemTimer; -import org.hisp.dhis.commons.timer.Timer; - -/** - * This report keeps track of the elapsed time for each stage of the validation process. - * - * @author Luciano Fiandesio - */ -@Data -public class TimingsStats { - public static final String PREHEAT_OPS = "preheat"; - - public static final String PREPROCESS_OPS = "preprocess"; - - public static final String COMMIT_OPS = "commit"; - - public static final String VALIDATION_OPS = "validation"; - - public static final String PROGRAMRULE_OPS = "programrule"; - - public static final String VALIDATE_PROGRAMRULE_OPS = "programruleValidation"; - - public static final String TOTAL_OPS = "totalImport"; - - public static final String PREPARE_REQUEST_OPS = "prepareRequest"; - - public static final String TOTAL_REQUEST_OPS = "totalRequest"; - - @JsonProperty private Map timers = new LinkedHashMap<>(); - - private static final String DEFAULT_VALUE = "0.0 sec."; - - public String getPrepareRequest() { - return timers.getOrDefault(PREPARE_REQUEST_OPS, DEFAULT_VALUE); - } - - public String getValidation() { - return timers.getOrDefault(VALIDATION_OPS, DEFAULT_VALUE); - } - - public String getCommit() { - return timers.getOrDefault(COMMIT_OPS, DEFAULT_VALUE); - } - - public String getPreheat() { - return timers.getOrDefault(PREHEAT_OPS, DEFAULT_VALUE); - } - - public String getProgramRule() { - return timers.getOrDefault(PROGRAMRULE_OPS, DEFAULT_VALUE); - } - - public String getTotalImport() { - return timers.getOrDefault(TOTAL_OPS, DEFAULT_VALUE); - } - - public String getTotalRequest() { - - return timers.getOrDefault(TOTAL_REQUEST_OPS, DEFAULT_VALUE); - } - - @JsonIgnore private Timer totalTimer; - - public TimingsStats() { - totalTimer = new SystemTimer().start(); - } - - public void set(String timedOperation, String elapsed) { - this.timers.put(timedOperation, elapsed); - } - - /** - * Executes the given Supplier and measure the elapsed time. - * - * @param timedOperation the operation name to place in the timers map - * @param supplier ths Supplier to execute - * @return the result of the Supplier invocation - */ - public T exec(String timedOperation, Supplier supplier) { - Timer timer = new SystemTimer().start(); - - T result = supplier.get(); - - timer.stop(); - - this.set(timedOperation, timer.toString()); - - return result; - } - - /** - * Executes the given operation. - * - * @param timedOperation the operation name to place in the timers map - * @param runnable the operation to execute - */ - public void execVoid(String timedOperation, Runnable runnable) { - Timer timer = new SystemTimer().start(); - - runnable.run(); - - timer.stop(); - - this.set(timedOperation, timer.toString()); - } - - public TimingsStats stopTimer() { - if (totalTimer != null) { - totalTimer.stop(); - this.timers.put(TOTAL_OPS, totalTimer.toString()); - } - return this; - } - - public String get(String validationOps) { - return this.timers.getOrDefault(validationOps, DEFAULT_VALUE); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java index 89a605f721e1..8fe3e1309cb0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/TrackerIdentifierCollectorTest.java @@ -65,6 +65,7 @@ import org.hisp.dhis.tracker.imports.domain.Relationship; import org.hisp.dhis.tracker.imports.domain.RelationshipItem; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -81,13 +82,6 @@ void setUp() { @Test void collectTrackedEntities() { - - TrackerIdSchemeParams idSchemes = - TrackerIdSchemeParams.builder() - .idScheme(TrackerIdSchemeParam.ofAttribute("NTVsGflP5Ix")) - .orgUnitIdScheme(TrackerIdSchemeParam.NAME) - .build(); - TrackedEntity trackedEntity = TrackedEntity.builder() .trackedEntity(uid()) @@ -96,10 +90,10 @@ void collectTrackedEntities() { .attributes(teAttributes("VohJnvWfvyo", "qv9xOw8fBzy")) .build(); - TrackerImportParams params = - params(idSchemes).trackedEntities(singletonList(trackedEntity)).build(); + TrackerObjects trackerObjects = + TrackerObjects.builder().trackedEntities(singletonList(trackedEntity)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertContainsOnly(Set.of(trackedEntity.getTrackedEntity()), ids.get(TrackedEntity.class)); @@ -110,13 +104,6 @@ void collectTrackedEntities() { @Test void collectEnrollments() { - - TrackerIdSchemeParams idSchemes = - TrackerIdSchemeParams.builder() - .orgUnitIdScheme(TrackerIdSchemeParam.NAME) - .programIdScheme(TrackerIdSchemeParam.ofAttribute("NTVsGflP5Ix")) - .build(); - Enrollment enrollment = Enrollment.builder() .enrollment(uid()) @@ -126,9 +113,10 @@ void collectEnrollments() { .attributes(teAttributes("VohJnvWfvyo", "qv9xOw8fBzy")) .build(); - TrackerImportParams params = params(idSchemes).enrollments(singletonList(enrollment)).build(); + TrackerObjects trackerObjects = + TrackerObjects.builder().enrollments(singletonList(enrollment)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertContainsOnly(Set.of(enrollment.getUid()), ids.get(Enrollment.class)); @@ -162,9 +150,9 @@ void collectEvents() { .notes(List.of(Note.builder().note("i1vviSlidJE").value("nice day!").build())) .build(); - TrackerImportParams params = params(idSchemes).events(singletonList(event)).build(); + TrackerObjects trackerObjects = TrackerObjects.builder().events(singletonList(event)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertContainsOnly(Set.of(event.getUid()), ids.get(Event.class)); @@ -182,10 +170,9 @@ void collectEvents() { void collectEventsSkipsNotesWithoutAnId() { Event event = Event.builder().notes(List.of(Note.builder().value("nice day!").build())).build(); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()).events(singletonList(event)).build(); + TrackerObjects trackerObjects = TrackerObjects.builder().events(singletonList(event)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertNull(ids.get(org.hisp.dhis.note.Note.class)); @@ -196,10 +183,9 @@ void collectEventsSkipsNotesWithoutAValue() { Event event = Event.builder().notes(List.of(Note.builder().note("i1vviSlidJE").build())).build(); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()).events(singletonList(event)).build(); + TrackerObjects trackerObjects = TrackerObjects.builder().events(singletonList(event)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertNull(ids.get(org.hisp.dhis.note.Note.class)); @@ -222,10 +208,10 @@ void collectRelationships() { .to(RelationshipItem.builder().event(uid()).build()) .build(); - TrackerImportParams params = - params(idSchemes).relationships(singletonList(relationship)).build(); + TrackerObjects trackerObjects = + TrackerObjects.builder().relationships(singletonList(relationship)).build(); - Map, Set> ids = collector.collect(params); + Map, Set> ids = collector.collect(trackerObjects); assertNotNull(ids); assertContainsOnly(Set.of(relationship.getRelationship()), ids.get(Relationship.class)); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java index d1b6c5948c67..dc32d1c6c9f0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerImporterServiceTest.java @@ -39,12 +39,14 @@ import java.util.List; import java.util.stream.Collectors; import org.hisp.dhis.random.BeanRandomizer; +import org.hisp.dhis.scheduling.NoopJobProgress; import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.tracker.imports.DefaultTrackerImportService; import org.hisp.dhis.tracker.imports.ParamsConverter; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerUserService; import org.hisp.dhis.tracker.imports.domain.Event; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preprocess.TrackerPreprocessService; import org.hisp.dhis.tracker.imports.report.PersistenceReport; import org.hisp.dhis.tracker.imports.validation.ValidationResult; @@ -78,27 +80,26 @@ class TrackerImporterServiceTest { private TrackerImportParams params = null; + private TrackerObjects trackerObjects; + private final BeanRandomizer rnd = BeanRandomizer.create(); @BeforeEach public void setUp() { subject = new DefaultTrackerImportService( - trackerBundleService, - validationService, - trackerPreprocessService, - trackerUserService, - notifier); + trackerBundleService, validationService, trackerPreprocessService, trackerUserService); final List events = rnd.objects(Event.class, 3).collect(Collectors.toList()); - params = - TrackerImportParams.builder() + params = TrackerImportParams.builder().userId("123").build(); + + trackerObjects = + TrackerObjects.builder() .events(events) .enrollments(new ArrayList<>()) .relationships(new ArrayList<>()) .trackedEntities(new ArrayList<>()) - .userId("123") .build(); PersistenceReport persistenceReport = PersistenceReport.emptyReport(); @@ -110,25 +111,26 @@ public void setUp() { when(validationService.validateRuleEngine(any(TrackerBundle.class))) .thenReturn(validationResult); when(trackerPreprocessService.preprocess(any(TrackerBundle.class))) - .thenReturn(ParamsConverter.convert(params)); + .thenReturn(ParamsConverter.convert(params, trackerObjects, new User())); } @Test void testSkipSideEffect() { TrackerImportParams parameters = - TrackerImportParams.builder() - .events(params.getEvents()) + TrackerImportParams.builder().skipSideEffects(true).userId("123").build(); + + TrackerObjects objects = + TrackerObjects.builder() + .events(trackerObjects.getEvents()) .enrollments(new ArrayList<>()) .relationships(new ArrayList<>()) .trackedEntities(new ArrayList<>()) - .skipSideEffects(true) - .userId("123") .build(); - when(trackerBundleService.create(any(TrackerImportParams.class))) - .thenReturn(ParamsConverter.convert(parameters)); + when(trackerBundleService.create(any(TrackerImportParams.class), any(), any())) + .thenReturn(ParamsConverter.convert(parameters, objects, new User())); - subject.importTracker(parameters); + subject.importTracker(parameters, trackerObjects, NoopJobProgress.INSTANCE); verify(trackerBundleService, times(0)).handleTrackerSideEffects(anyList()); } @@ -138,10 +140,10 @@ void testWithSideEffects() { doAnswer(invocationOnMock -> null) .when(trackerBundleService) .handleTrackerSideEffects(anyList()); - when(trackerBundleService.create(any(TrackerImportParams.class))) - .thenReturn(ParamsConverter.convert(params)); + when(trackerBundleService.create(any(TrackerImportParams.class), any(), any())) + .thenReturn(ParamsConverter.convert(params, trackerObjects, new User())); - subject.importTracker(params); + subject.importTracker(params, trackerObjects, NoopJobProgress.INSTANCE); verify(trackerBundleService, times(1)).handleTrackerSideEffects(anyList()); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatServiceTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatServiceTest.java index 7b317272e009..84455dbeba55 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/DefaultTrackerPreheatServiceTest.java @@ -37,8 +37,9 @@ import java.util.Collections; import java.util.List; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.supplier.ClassBasedSupplier; import org.hisp.dhis.tracker.imports.preheat.supplier.PreheatSupplier; import org.hisp.dhis.user.User; @@ -72,12 +73,13 @@ class DefaultTrackerPreheatServiceTest { private DefaultTrackerPreheatService preheatService; - private final TrackerImportParams preheatParams = - TrackerImportParams.builder() - .user(getUser()) + private final TrackerObjects preheatParams = + TrackerObjects.builder() .trackedEntities(Collections.singletonList(new TrackedEntity())) .build(); + private final TrackerIdSchemeParams idSchemeParams = TrackerIdSchemeParams.builder().build(); + @BeforeEach public void setUp() { preheatService = @@ -95,7 +97,7 @@ void shouldGetFromContextAndAdd() { doCallRealMethod().when(classBasedSupplier).add(any(), any()); - preheatService.preheat(preheatParams); + preheatService.preheat(preheatParams, idSchemeParams, getUser()); verify(applicationContext).getBean(bean.getValue(), preheatSupplierClassCaptor.getValue()); verify(classBasedSupplier).add(any(), any()); @@ -107,7 +109,7 @@ void shouldDoNothingWhenSupplierBeanNotFound() { when(applicationContext.getBean(bean.capture(), preheatSupplierClassCaptor.capture())) .thenThrow(new BeanCreationException("e")); - preheatService.preheat(preheatParams); + preheatService.preheat(preheatParams, idSchemeParams, getUser()); verify(applicationContext).getBean(bean.getValue(), preheatSupplierClassCaptor.getValue()); verify(classBasedSupplier, times(0)).add(any(), any()); @@ -120,7 +122,7 @@ void shouldDoNothingWhenAddException() { .thenReturn(classBasedSupplier); doThrow(new RuntimeException("e")).when(classBasedSupplier).add(any(), any()); - preheatService.preheat(preheatParams); + preheatService.preheat(preheatParams, idSchemeParams, getUser()); verify(applicationContext).getBean(bean.getValue(), preheatSupplierClassCaptor.getValue()); verify(classBasedSupplier).add(any(), any()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplierTest.java index 3f0afe9218d1..e1b10b5a4f5f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/ClassBasedSupplierTest.java @@ -36,8 +36,8 @@ import java.util.HashMap; import java.util.HashSet; import org.hisp.dhis.tracker.imports.TrackerIdentifierCollector; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.supplier.strategy.ClassBasedSupplierStrategy; import org.hisp.dhis.tracker.imports.preheat.supplier.strategy.GenericStrategy; @@ -63,7 +63,7 @@ class ClassBasedSupplierTest { @Mock private GenericStrategy genericStrategy; - @Mock private TrackerImportParams trackerImportParams; + @Mock private TrackerObjects trackerObjects; @Mock private TrackerEntityStrategy trackerEntityStrategy; @@ -74,7 +74,7 @@ public void setUp() { classBasedSupplier = new ClassBasedSupplier(identifierCollector, strategiesMap); classBasedSupplier.setApplicationContext(applicationContext); - when(identifierCollector.collect(trackerImportParams)) + when(identifierCollector.collect(trackerObjects)) .thenReturn( new HashMap<>() { { @@ -91,7 +91,7 @@ void verifyGenericStrategy() { when(applicationContext.getBean(Constant.GENERIC_STRATEGY_BEAN, GenericStrategy.class)) .thenReturn(genericStrategy); - classBasedSupplier.preheatAdd(trackerImportParams, new TrackerPreheat()); + classBasedSupplier.preheatAdd(trackerObjects, new TrackerPreheat()); verify(applicationContext).getBean(Constant.GENERIC_STRATEGY_BEAN, GenericStrategy.class); } @@ -102,7 +102,7 @@ void verifyClassBasedSupplierStrategy() { when(applicationContext.getBean(anyString(), eq(ClassBasedSupplierStrategy.class))) .thenReturn(trackerEntityStrategy); - classBasedSupplier.preheatAdd(trackerImportParams, new TrackerPreheat()); + classBasedSupplier.preheatAdd(trackerObjects, new TrackerPreheat()); verify(applicationContext).getBean("classbasedstrategy", ClassBasedSupplierStrategy.class); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java index f9fada079f06..6f2e07b02199 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/DuplicateRelationshipSupplierTest.java @@ -39,9 +39,9 @@ import org.hisp.dhis.relationship.RelationshipType; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; import org.hisp.dhis.tracker.imports.domain.RelationshipItem; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -148,12 +148,12 @@ void verifySupplier() { when(relationshipStore.getByUid(List.of(REL_A_UID, REL_B_UID))) .thenReturn(List.of(relationshipA(), relationshipB())); - TrackerImportParams trackerImportParams = - TrackerImportParams.builder() + TrackerObjects trackerObjects = + TrackerObjects.builder() .relationships(List.of(relationshipA, relationshipB, relationshipC)) .build(); - supplier.preheatAdd(trackerImportParams, preheat); + supplier.preheatAdd(trackerObjects, preheat); assertTrue(preheat.isDuplicate(relationshipA)); assertFalse(preheat.isDuplicate(invertTeToTeRelationship(relationshipA))); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplierTest.java index b04efa42457a..e10fbf54cbd2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EnrollmentSupplierTest.java @@ -43,7 +43,7 @@ import org.hisp.dhis.program.ProgramStore; import org.hisp.dhis.random.BeanRandomizer; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -73,7 +73,7 @@ class EnrollmentSupplierTest extends DhisConvenienceTest { private Program programWithoutRegistration; - private TrackerImportParams params; + private TrackerObjects params; private final BeanRandomizer rnd = BeanRandomizer.create(); @@ -100,7 +100,7 @@ public void setUp() { when(enrollmentStore.getByPrograms(Lists.newArrayList(programWithoutRegistration))) .thenReturn(enrollments); - params = TrackerImportParams.builder().build(); + params = TrackerObjects.builder().build(); preheat = new TrackerPreheat(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplierTest.java index 2274ae89f00e..a251928a66b0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/EventCategoryOptionComboSupplierTest.java @@ -52,9 +52,9 @@ import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -97,10 +97,10 @@ void shouldPreheatEventAOCIfNotProvided() { .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); when(preheat.getProgram(event.getProgram())).thenReturn(program); + when(preheat.getIdSchemes()).thenReturn(identifierParams); options.forEach( o -> when(preheat.getCategoryOption(identifierParams.toMetadataIdentifier(o))) @@ -142,9 +142,9 @@ void shouldPreheatEventAOCIfNotProvidedAndEventHasProgramStageButNoProgram() { .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(stage); options.forEach( o -> @@ -183,9 +183,9 @@ void shouldPreheatEventAOCIfNotProvidedOnlyIfNotAlreadyFetched() { .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event, event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); options.forEach( o -> @@ -228,9 +228,9 @@ void shouldPreheatEventAOCEvenIfNotFound() { .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event, event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); options.forEach( o -> @@ -271,9 +271,9 @@ void shouldNotPreheatEventAOCIfNotProvidedAndCONotFound() { .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); when(categoryService.getCategoryOptionCombo(categoryCombo, aoc.getCategoryOptions())) .thenReturn(aoc); @@ -304,8 +304,9 @@ void shouldNotPreheatEventAOCIfEventHasNoProgram() { .programStage(MetadataIdentifier.EMPTY_UID) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + + when(preheat.getIdSchemes()).thenReturn(identifierParams); supplier.preheatAdd(params, preheat); @@ -335,8 +336,9 @@ void shouldNotPreheatEventAOCIfEventHasNoProgramAndNoProgramStage() { .programStage(MetadataIdentifier.EMPTY_UID) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + + when(preheat.getIdSchemes()).thenReturn(identifierParams); options.forEach( o -> @@ -374,9 +376,9 @@ void shouldNotPreheatEventAOCIfEventHasNoProgramAndItsProgramStageHasNoProgram() .attributeCategoryOptions(categoryOptionIds(identifierParams, options)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgramStage(event.getProgramStage())).thenReturn(stage); options.forEach( o -> @@ -412,9 +414,9 @@ void shouldNotPreheatEventAOCIfAOCAndCOsAreProvided() { .attributeOptionCombo(identifierParams.toMetadataIdentifier(aoc)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); supplier.preheatAdd(params, preheat); @@ -443,9 +445,9 @@ void shouldNotPreheatEventAOCIfAOCIsProvided() { .attributeOptionCombo(identifierParams.toMetadataIdentifier(aoc)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); supplier.preheatAdd(params, preheat); @@ -474,9 +476,9 @@ void shouldNotPreheatEventAOCIfNoCategoryOptionsProvided() { .attributeOptionCombo(identifierParams.toMetadataIdentifier((CategoryOptionCombo) null)) .build(); List events = List.of(event); - TrackerImportParams params = - TrackerImportParams.builder().idSchemes(identifierParams).events(events).build(); + TrackerObjects params = TrackerObjects.builder().events(events).build(); + when(preheat.getIdSchemes()).thenReturn(identifierParams); when(preheat.getProgram(event.getProgram())).thenReturn(program); supplier.preheatAdd(params, preheat); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java index d5a67a2cb66e..e34306bd2eeb 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java @@ -43,14 +43,13 @@ import org.hisp.dhis.fileresource.FileResourceService; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.DataValue; import org.hisp.dhis.tracker.imports.domain.Enrollment; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -86,8 +85,8 @@ void testSupplierAddsFileResourcesReferencedByTeAttributes() { when(fileResourceService.getFileResources(List.of("kKacJUdANDC"))) .thenReturn(List.of(fileResource)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .trackedEntities( List.of( trackedEntity(numericAttribute(), fileAttribute("hQKI6KcEu5t", "kKacJUdANDC")))) @@ -102,8 +101,8 @@ void testSupplierAddsFileResourcesReferencedByTeAttributes() { void testSupplierDoesNotAddFileResourceIfTeAttributeValueIsEmpty() { preheat.put(TrackerIdSchemeParam.UID, List.of(teaFileResource("hQKI6KcEu5t"))); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .trackedEntities(List.of(trackedEntity(fileAttribute("hQKI6KcEu5t", "")))) .build(); @@ -122,8 +121,8 @@ void testSupplierAddsFileResourcesReferencedByEnrollmentAttributes() { when(fileResourceService.getFileResources(List.of("kKacJUdANDC"))) .thenReturn(List.of(fileResource)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .enrollments( List.of( enrollment(numericAttribute(), fileAttribute("hQKI6KcEu5t", "kKacJUdANDC")))) @@ -144,8 +143,8 @@ void testSupplierAddsFileResourcesReferencedByEventDataElement() { when(fileResourceService.getFileResources(List.of("kKacJUdANDC"))) .thenReturn(List.of(fileResource)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .events( List.of(event(dataValue("numeric", "2"), dataValue("hQKI6KcEu5t", "kKacJUdANDC")))) .build(); @@ -159,10 +158,8 @@ void testSupplierAddsFileResourcesReferencedByEventDataElement() { void testSupplierDoesNotAddFileResourceIfEventDataValueValueIsEmpty() { preheat.put(TrackerIdSchemeParam.UID, List.of(fileDataElement("hQKI6KcEu5t"))); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) - .events(List.of(event(dataValue("hQKI6KcEu5t", "")))) - .build(); + TrackerObjects params = + TrackerObjects.builder().events(List.of(event(dataValue("hQKI6KcEu5t", "")))).build(); supplier.preheatAdd(params, preheat); @@ -189,10 +186,6 @@ private FileResource fileResource(String uid) { return fileResource; } - private TrackerImportParams.TrackerImportParamsBuilder params(TrackerIdSchemeParams idSchemes) { - return TrackerImportParams.builder().idSchemes(idSchemes); - } - private Attribute numericAttribute() { return Attribute.builder() .attribute(MetadataIdentifier.ofUid("numeric")) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java index d887a5538c29..9326f0ea7e24 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java @@ -43,14 +43,13 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.DataValue; import org.hisp.dhis.tracker.imports.domain.Enrollment; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -82,8 +81,8 @@ void testSupplierAddsOrgUnitReferencedByTeAttributes() { when(manager.getByUid(OrganisationUnit.class, List.of("kKacJUdANDC"))) .thenReturn(List.of(orgUnit)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .trackedEntities( List.of( trackedEntity( @@ -99,8 +98,8 @@ void testSupplierAddsOrgUnitReferencedByTeAttributes() { void testSupplierDoesNotAddOrgUnitIfTeAttributeValueIsEmpty() { preheat.put(TrackerIdSchemeParam.UID, List.of(teaOrgUnit("hQKI6KcEu5t"))); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .trackedEntities(List.of(trackedEntity(orgUnitAttribute("hQKI6KcEu5t", "")))) .build(); @@ -118,8 +117,8 @@ void testSupplierAddsOrgUnitReferencedByEnrollmentAttributes() { when(manager.getByUid(OrganisationUnit.class, List.of("kKacJUdANDC"))) .thenReturn(List.of(orgUnit)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .enrollments( List.of( enrollment(numericAttribute(), orgUnitAttribute("hQKI6KcEu5t", "kKacJUdANDC")))) @@ -140,8 +139,8 @@ void testSupplierAddsOrgUnitReferencedByEventDataElement() { when(manager.getByUid(OrganisationUnit.class, List.of("kKacJUdANDC"))) .thenReturn(List.of(orgUnit)); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) + TrackerObjects params = + TrackerObjects.builder() .events( List.of(event(dataValue("numeric", "2"), dataValue("hQKI6KcEu5t", "kKacJUdANDC")))) .build(); @@ -155,10 +154,8 @@ void testSupplierAddsOrgUnitReferencedByEventDataElement() { void testSupplierDoesNotAddOrgUnitIfEventDataValueValueIsEmpty() { preheat.put(TrackerIdSchemeParam.UID, List.of(orgUnitDataElement("hQKI6KcEu5t"))); - TrackerImportParams params = - params(TrackerIdSchemeParams.builder().build()) - .events(List.of(event(dataValue("hQKI6KcEu5t", "")))) - .build(); + TrackerObjects params = + TrackerObjects.builder().events(List.of(event(dataValue("hQKI6KcEu5t", "")))).build(); supplier.preheatAdd(params, preheat); @@ -185,10 +182,6 @@ private OrganisationUnit orgUnit(String uid) { return orgUnit; } - private TrackerImportParams.TrackerImportParamsBuilder params(TrackerIdSchemeParams idSchemes) { - return TrackerImportParams.builder().idSchemes(idSchemes); - } - private Attribute numericAttribute() { return Attribute.builder() .attribute(MetadataIdentifier.ofUid("numeric")) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplierTest.java index c2a6cde37893..c9c06a56d47e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/PeriodTypeSupplierTest.java @@ -36,7 +36,7 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodStore; import org.hisp.dhis.random.BeanRandomizer; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.cache.DefaultPreheatCacheService; import org.hisp.dhis.tracker.imports.preheat.cache.PreheatCacheService; @@ -70,7 +70,7 @@ void verifySupplier() { final List periods = rnd.objects(Period.class, 20).collect(Collectors.toList()); when(periodStore.getAll()).thenReturn(periods); - final TrackerImportParams params = TrackerImportParams.builder().build(); + final TrackerObjects params = TrackerObjects.builder().build(); TrackerPreheat preheat = new TrackerPreheat(); this.supplier.preheatAdd(params, preheat); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java index 99c86ac1f564..078b526715ac 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UniqueAttributeSupplierTest.java @@ -49,8 +49,8 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -77,7 +77,7 @@ class UniqueAttributeSupplierTest extends DhisConvenienceTest { @Mock private TrackedEntityAttributeValueService trackedEntityAttributeValueService; - private TrackerImportParams params; + private TrackerObjects params; private TrackerPreheat preheat; @@ -91,7 +91,7 @@ class UniqueAttributeSupplierTest extends DhisConvenienceTest { @BeforeEach public void setUp() { - params = TrackerImportParams.builder().build(); + params = TrackerObjects.builder().build(); preheat = new TrackerPreheat(); uniqueAttribute = createTrackedEntityAttribute('A', ValueType.TEXT); OrganisationUnit orgUnit = createOrganisationUnit('A'); @@ -121,8 +121,8 @@ void verifySupplierWhenNoUniqueAttributeIsPresentInTheSystem() { void verifySupplierWhenTeAndEnrollmentHaveTheSameUniqueAttribute() { when(trackedEntityAttributeService.getAllUniqueTrackedEntityAttributes()) .thenReturn(Collections.singletonList(uniqueAttribute)); - TrackerImportParams importParams = - TrackerImportParams.builder() + TrackerObjects importParams = + TrackerObjects.builder() .trackedEntities(Collections.singletonList(trackedEntity())) .enrollments(Collections.singletonList(enrollment(TE_UID))) .build(); @@ -136,8 +136,8 @@ void verifySupplierWhenTeAndEnrollmentHaveTheSameUniqueAttribute() { void verifySupplierWhenTwoTesHaveAttributeWithSameUniqueValue() { when(trackedEntityAttributeService.getAllUniqueTrackedEntityAttributes()) .thenReturn(Collections.singletonList(uniqueAttribute)); - TrackerImportParams importParams = - TrackerImportParams.builder().trackedEntities(sameUniqueAttributeTrackedEntities()).build(); + TrackerObjects importParams = + TrackerObjects.builder().trackedEntities(sameUniqueAttributeTrackedEntities()).build(); this.supplier.preheatAdd(importParams, preheat); @@ -148,8 +148,8 @@ void verifySupplierWhenTwoTesHaveAttributeWithSameUniqueValue() { void verifySupplierWhenTeAndEnrollmentFromAnotherTeHaveAttributeWithSameUniqueValue() { when(trackedEntityAttributeService.getAllUniqueTrackedEntityAttributes()) .thenReturn(Collections.singletonList(uniqueAttribute)); - TrackerImportParams importParams = - TrackerImportParams.builder() + TrackerObjects importParams = + TrackerObjects.builder() .trackedEntities(Collections.singletonList(trackedEntity())) .enrollments(Collections.singletonList(enrollment(ANOTHER_TE_UID))) .build(); @@ -169,8 +169,8 @@ void verifySupplierWhenTeinPayloadAndDBHaveTheSameUniqueAttribute() { when(trackedEntityAttributeValueService.getUniqueAttributeByValues( trackedEntityAttributeListMap)) .thenReturn(attributeValues); - TrackerImportParams importParams = - TrackerImportParams.builder() + TrackerObjects importParams = + TrackerObjects.builder() .trackedEntities(Collections.singletonList(trackedEntity())) .build(); @@ -189,8 +189,8 @@ void verifySupplierWhenTeinPayloadAndAnotherTeInDBHaveTheSameUniqueAttribute() { when(trackedEntityAttributeValueService.getUniqueAttributeByValues( trackedEntityAttributeListMap)) .thenReturn(attributeValues); - TrackerImportParams importParams = - TrackerImportParams.builder() + TrackerObjects importParams = + TrackerObjects.builder() .trackedEntities(Collections.singletonList(anotherTrackedEntity())) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java index 40539cd8d544..96c9f3b8ab90 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java @@ -41,8 +41,8 @@ import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.random.BeanRandomizer; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Event; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.domain.User; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.user.UserService; @@ -97,7 +97,7 @@ void verifyUserSupplierByUid() { when(manager.getByUid(eq(org.hisp.dhis.user.User.class), argThat(t -> t.containsAll(userIds)))) .thenReturn(users); - final TrackerImportParams params = TrackerImportParams.builder().events(events).build(); + final TrackerObjects params = TrackerObjects.builder().events(events).build(); TrackerPreheat preheat = new TrackerPreheat(); this.supplier.preheatAdd(params, preheat); @@ -117,7 +117,7 @@ void verifyUserSupplierByUsername() { when(userService.getUsersByUsernames(argThat(t -> t.containsAll(usernames)))).thenReturn(users); - final TrackerImportParams params = TrackerImportParams.builder().events(events).build(); + final TrackerObjects params = TrackerObjects.builder().events(events).build(); TrackerPreheat preheat = new TrackerPreheat(); this.supplier.preheatAdd(params, preheat); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategyTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategyTest.java index c312d29bdfd7..679a55664aa9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategyTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/strategy/TrackerEntityStrategyTest.java @@ -33,7 +33,6 @@ import java.util.List; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityStore; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -55,11 +54,6 @@ class TrackerEntityStrategyTest { @Test void verifyStrategyAddRightTeToPreheat() { - final List trackedEntities = - trackedEntities(); - final TrackerImportParams params = - TrackerImportParams.builder().trackedEntities(trackedEntities).build(); - final List uids = List.of("TEIA", "TEIB"); List> splitUids = new ArrayList<>(); @@ -71,7 +65,7 @@ void verifyStrategyAddRightTeToPreheat() { teB.setUid("TEIB"); List dbTrackedEntities = List.of(teA, teB); when(trackedEntityStore.getIncludingDeleted(uids)).thenReturn(dbTrackedEntities); - strategy.add(params, splitUids, preheat); + strategy.add(splitUids, preheat); Mockito.verify(trackedEntityStore).getIncludingDeleted(uids); Mockito.verify(preheat).putTrackedEntities(dbTrackedEntities); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/ImportReportTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/ImportReportTest.java index ef6e59e58bef..7d031bb72fe9 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/ImportReportTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/ImportReportTest.java @@ -57,8 +57,6 @@ void testImportCalculatesIgnoredValues() { // Create validation report with 3 objects ValidationReport validationReport = ValidationReport.emptyReport(); validationReport.addErrors(rnd.objects(Error.class, 3).collect(Collectors.toList())); - // Create empty Timing Stats report - TimingsStats timingsStats = new TimingsStats(); // Create payload map Map originalPayload = new HashMap<>(); originalPayload.put(TrackerType.TRACKED_ENTITY, 10); @@ -66,7 +64,7 @@ void testImportCalculatesIgnoredValues() { // Method under test ImportReport rep = ImportReport.withImportCompleted( - Status.OK, persistenceReport, validationReport, timingsStats, originalPayload); + Status.OK, persistenceReport, validationReport, originalPayload); assertThat(rep.getStats().getCreated(), is(8)); assertThat(rep.getStats().getUpdated(), is(6)); assertThat(rep.getStats().getIgnored(), is(3)); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/TrackerBundleImportReportTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/TrackerBundleImportReportTest.java index 9fac55491548..0ecabc5ed491 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/TrackerBundleImportReportTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/report/TrackerBundleImportReportTest.java @@ -28,17 +28,9 @@ package org.hisp.dhis.tracker.imports.report; import static org.hisp.dhis.tracker.TrackerType.TRACKED_ENTITY; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.COMMIT_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PREHEAT_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PREPARE_REQUEST_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.PROGRAMRULE_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.TOTAL_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.TOTAL_REQUEST_OPS; -import static org.hisp.dhis.tracker.imports.report.TimingsStats.VALIDATION_OPS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import com.fasterxml.jackson.core.JsonProcessingException; @@ -92,7 +84,6 @@ void testImportReportErrors() { assertNotNull(report.getValidationReport()); assertTrue(report.getValidationReport().hasErrors()); assertFalse(report.getValidationReport().hasWarnings()); - assertNull(report.getTimingsStats()); } @Test @@ -106,7 +97,6 @@ void testImportReportWarnings() { assertNotNull(report.getValidationReport()); assertTrue(report.getValidationReport().hasErrors()); assertTrue(report.getValidationReport().hasWarnings()); - assertNull(report.getTimingsStats()); } @Test @@ -119,12 +109,6 @@ void testImportReportFull() { assertNotNull(report.getValidationReport()); assertTrue(report.getValidationReport().hasErrors()); assertTrue(report.getValidationReport().hasWarnings()); - assertNotNull(report.getTimingsStats()); - assertEquals("1 sec.", report.getTimingsStats().getProgramRule()); - assertEquals("2 sec.", report.getTimingsStats().getCommit()); - assertEquals("3 sec.", report.getTimingsStats().getPreheat()); - assertEquals("4 sec.", report.getTimingsStats().getValidation()); - assertEquals("10 sec.", report.getTimingsStats().getTotalImport()); } @Test @@ -141,15 +125,7 @@ void testSerializingAndDeserializingImportReport() throws JsonProcessingExceptio typeReport.getStats().setDeleted(3); typeReportMap.put(TRACKED_ENTITY, typeReport); PersistenceReport persistenceReport = new PersistenceReport(typeReportMap); - // Build TimingsStats - TimingsStats timingsStats = new TimingsStats(); - timingsStats.set(COMMIT_OPS, "0.1 sec."); - timingsStats.set(PREHEAT_OPS, "0.2 sec."); - timingsStats.set(PROGRAMRULE_OPS, "0.3 sec."); - timingsStats.set(TOTAL_OPS, "0.4 sec."); - timingsStats.set(VALIDATION_OPS, "4 sec."); - timingsStats.set(PREPARE_REQUEST_OPS, "0.5 sec."); - timingsStats.set(TOTAL_REQUEST_OPS, "0.6 sec."); + // Build ValidationReport ValidationReport tvr = ValidationReport.emptyReport(); @@ -171,8 +147,7 @@ void testSerializingAndDeserializingImportReport() throws JsonProcessingExceptio final Map bundleSize = new HashMap<>(); bundleSize.put(TRACKED_ENTITY, 1); ImportReport toSerializeReport = - ImportReport.withImportCompleted( - Status.ERROR, persistenceReport, tvr, timingsStats, bundleSize); + ImportReport.withImportCompleted(Status.ERROR, persistenceReport, tvr, bundleSize); // Serialize TrackerImportReport into String String jsonString = jsonMapper.writeValueAsString(toSerializeReport); // Deserialize the String back into TrackerImportReport @@ -244,28 +219,7 @@ void testSerializingAndDeserializingImportReport() throws JsonProcessingExceptio assertEquals( toSerializeReport.getValidationReport().getWarnings().get(0).getTrackerType(), deserializedReport.getValidationReport().getWarnings().get(0).getTrackerType()); - // Verify TimingsStats - assertEquals( - toSerializeReport.getTimingsStats().getCommit(), - deserializedReport.getTimingsStats().getCommit()); - assertEquals( - toSerializeReport.getTimingsStats().getPreheat(), - deserializedReport.getTimingsStats().getPreheat()); - assertEquals( - toSerializeReport.getTimingsStats().getPrepareRequest(), - deserializedReport.getTimingsStats().getPrepareRequest()); - assertEquals( - toSerializeReport.getTimingsStats().getProgramRule(), - deserializedReport.getTimingsStats().getProgramRule()); - assertEquals( - toSerializeReport.getTimingsStats().getTotalImport(), - deserializedReport.getTimingsStats().getTotalImport()); - assertEquals( - toSerializeReport.getTimingsStats().getTotalRequest(), - deserializedReport.getTimingsStats().getTotalRequest()); - assertEquals( - toSerializeReport.getTimingsStats().getValidation(), - deserializedReport.getTimingsStats().getValidation()); + assertEquals(toSerializeReport.getStats(), deserializedReport.getStats()); } @@ -281,17 +235,7 @@ private ImportReport createImportReport() { final Map bundleSize = new HashMap<>(); bundleSize.put(TRACKED_ENTITY, 1); return ImportReport.withImportCompleted( - Status.OK, createBundleReport(), createValidationReport(), createTimingStats(), bundleSize); - } - - private TimingsStats createTimingStats() { - TimingsStats timingsStats = new TimingsStats(); - timingsStats.set(PROGRAMRULE_OPS, "1 sec."); - timingsStats.set(COMMIT_OPS, "2 sec."); - timingsStats.set(PREHEAT_OPS, "3 sec."); - timingsStats.set(VALIDATION_OPS, "4 sec."); - timingsStats.set(TOTAL_OPS, "10 sec."); - return timingsStats; + Status.OK, createBundleReport(), createValidationReport(), bundleSize); } private ValidationReport createValidationReport() { diff --git a/dhis-2/dhis-test-e2e/src/main/java/org/hisp/dhis/actions/tracker/TrackerImportExportActions.java b/dhis-2/dhis-test-e2e/src/main/java/org/hisp/dhis/actions/tracker/TrackerImportExportActions.java index 94e394d1fa67..47cfb12c81ed 100644 --- a/dhis-2/dhis-test-e2e/src/main/java/org/hisp/dhis/actions/tracker/TrackerImportExportActions.java +++ b/dhis-2/dhis-test-e2e/src/main/java/org/hisp/dhis/actions/tracker/TrackerImportExportActions.java @@ -92,6 +92,10 @@ public TrackerApiResponse postAndGetJobReport( return getJobReportByImportResponse(response); } + public ApiResponse checkJobReport(String jobId, String reportMode) { + return this.get(String.format("/jobs/%s/report?reportMode=%s", jobId, reportMode)); + } + public TrackerApiResponse getJobReport(String jobId, String reportMode) { ApiResponse response = this.get(String.format("/jobs/%s/report?reportMode=%s", jobId, reportMode)); @@ -189,6 +193,10 @@ private TrackerApiResponse getJobReportByImportResponse(ApiResponse response) { this.waitUntilJobIsCompleted(jobId); + Callable jobIsCompleted = () -> this.checkJobReport(jobId, "FULL").statusCode(); + + with().atMost(21, TimeUnit.SECONDS).await().until(() -> jobIsCompleted.call() == 200); + return this.getJobReport(jobId, "FULL"); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/AclEventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/AclEventExporterTest.java index 7d9e651125c2..f4cc60be6c72 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/AclEventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/AclEventExporterTest.java @@ -53,6 +53,7 @@ import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; import org.junit.jupiter.api.BeforeEach; @@ -75,9 +76,9 @@ class AclEventExporterTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); User userA = userService.getUser("M5zQapPyTZI"); + TrackerImportParams params = TrackerImportParams.builder().userId(userA.getUid()).build(); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/event_and_enrollment.json", userA.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/event_and_enrollment.json"))); orgUnit = get(OrganisationUnit.class, "h4w96yEMlzO"); ProgramStage programStage = get(ProgramStage.class, "NpsdDv6kKSO"); program = programStage.getProgram(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/TrackerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/TrackerTest.java index 2e12ed6d11e1..fe5f8e89b73b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/TrackerTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/TrackerTest.java @@ -44,7 +44,7 @@ import org.hisp.dhis.render.RenderFormat; import org.hisp.dhis.render.RenderService; import org.hisp.dhis.test.integration.SingleSetupIntegrationTestBase; -import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; @@ -107,26 +107,8 @@ protected ObjectBundle setUpMetadata(String path, User user) throws IOException return bundle; } - protected TrackerImportParams fromJson(String path) throws IOException { - TrackerImportParams trackerImportParams = _fromJson(path); - trackerImportParams.setUser(currentUserService.getCurrentUser()); - return trackerImportParams; - } - - protected TrackerImportParams fromJson(String path, String userUid) throws IOException { - TrackerImportParams trackerImportParams = _fromJson(path); - trackerImportParams.setUserId(userUid); - return trackerImportParams; - } - - protected TrackerImportParams fromJson(String path, User user) throws IOException { - TrackerImportParams trackerImportParams = _fromJson(path); - trackerImportParams.setUser(user); - return trackerImportParams; - } - - private TrackerImportParams _fromJson(String path) throws IOException { + protected TrackerObjects fromJson(String path) throws IOException { return renderService.fromJson( - new ClassPathResource(path).getInputStream(), TrackerImportParams.class); + new ClassPathResource(path).getInputStream(), TrackerObjects.class); } } 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 28c706005044..6a6c1fcbf173 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 @@ -74,6 +74,7 @@ import org.hisp.dhis.tracker.export.relationship.RelationshipService; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityOperationParams; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityService; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; import org.hisp.dhis.webapi.controller.event.mapper.SortDirection; @@ -110,9 +111,9 @@ class OrderAndPaginationExporterTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); importUser = userService.getUser("M5zQapPyTZI"); + TrackerImportParams params = TrackerImportParams.builder().userId(importUser.getUid()).build(); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/event_and_enrollment.json", importUser.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/event_and_enrollment.json"))); orgUnit = get(OrganisationUnit.class, "h4w96yEMlzO"); programStage = get(ProgramStage.class, "NpsdDv6kKSO"); trackedEntityType = get(TrackedEntityType.class, "ja8NY4PW7Xm"); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java index c2bd259a0c20..edfe77fef37e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java @@ -59,6 +59,7 @@ import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; import org.junit.jupiter.api.BeforeEach; @@ -84,9 +85,9 @@ class AclEventExporterTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); User userA = userService.getUser("M5zQapPyTZI"); + TrackerImportParams params = TrackerImportParams.builder().userId(userA.getUid()).build(); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/event_and_enrollment.json", userA.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/event_and_enrollment.json"))); orgUnit = get(OrganisationUnit.class, "h4w96yEMlzO"); ProgramStage programStage = get(ProgramStage.class, "NpsdDv6kKSO"); program = programStage.getProgram(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java index 33ebe1e366ef..e99448529462 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java @@ -72,6 +72,7 @@ import org.hisp.dhis.relationship.RelationshipItem; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; import org.hisp.dhis.util.DateUtils; @@ -108,9 +109,9 @@ class EventExporterTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); importUser = userService.getUser("M5zQapPyTZI"); + TrackerImportParams params = TrackerImportParams.builder().userId(importUser.getUid()).build(); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/event_and_enrollment.json", importUser.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/event_and_enrollment.json"))); orgUnit = get(OrganisationUnit.class, "h4w96yEMlzO"); programStage = get(ProgramStage.class, "NpsdDv6kKSO"); program = programStage.getProgram(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/AtomicModeIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/AtomicModeIntegrationTest.java index da06b0dad95d..9f6ea3eff68c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/AtomicModeIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/AtomicModeIntegrationTest.java @@ -34,6 +34,7 @@ import java.io.IOException; import org.hisp.dhis.trackedentity.TrackedEntityService; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.Status; import org.junit.jupiter.api.Test; @@ -52,10 +53,12 @@ public void initTest() throws IOException { @Test void testImportSuccessWithAtomicModeObjectIfThereIsAnErrorInOneTEI() throws IOException { - TrackerImportParams params = fromJson("tracker/one_valid_tei_and_one_invalid.json"); - params.setAtomicMode(AtomicMode.OBJECT); + TrackerObjects trackerObjects = fromJson("tracker/one_valid_tei_and_one_invalid.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).build(); - ImportReport trackerImportTeiReport = trackerImportService.importTracker(params); + ImportReport trackerImportTeiReport = + trackerImportService.importTracker(params, trackerObjects); assertNotNull(trackerImportTeiReport); assertEquals(Status.OK, trackerImportTeiReport.getStatus()); @@ -66,10 +69,11 @@ void testImportSuccessWithAtomicModeObjectIfThereIsAnErrorInOneTEI() throws IOEx @Test void testImportFailWithAtomicModeAllIfThereIsAnErrorInOneTEI() throws IOException { - TrackerImportParams params = fromJson("tracker/one_valid_tei_and_one_invalid.json"); - params.setAtomicMode(AtomicMode.ALL); + TrackerObjects trackerObjects = fromJson("tracker/one_valid_tei_and_one_invalid.json"); + TrackerImportParams params = TrackerImportParams.builder().atomicMode(AtomicMode.ALL).build(); - ImportReport trackerImportTeiReport = trackerImportService.importTracker(params); + ImportReport trackerImportTeiReport = + trackerImportService.importTracker(params, trackerObjects); assertNotNull(trackerImportTeiReport); assertEquals(Status.ERROR, trackerImportTeiReport.getStatus()); assertEquals(1, trackerImportTeiReport.getValidationReport().getErrors().size()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/TrackerImportParamsSerdeTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/TrackerImportParamsSerdeTest.java index 21edc0b6da59..0ae89946dddc 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/TrackerImportParamsSerdeTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/TrackerImportParamsSerdeTest.java @@ -28,7 +28,6 @@ package org.hisp.dhis.tracker.imports; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; @@ -83,12 +82,7 @@ void testJsonSerialization() throws Exception { + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":false," + "\"skipSideEffects\":false," - + "\"skipRuleEngine\":true," - + "\"trackedEntities\":[]," - + "\"enrollments\":[]," - + "\"events\":[]," - + "\"relationships\":[]," - + "\"username\":\"system-process\"}", + + "\"skipRuleEngine\":true}", json, JSONCompareMode.LENIENT); } @@ -111,12 +105,7 @@ void testJsonDeserialization() throws IOException { + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":true," + "\"skipSideEffects\":true," - + "\"skipRuleEngine\":true," - + "\"trackedEntities\":[]," - + "\"enrollments\":[]," - + "\"events\":[]," - + "\"relationships\":[]," - + "\"username\":\"system-process\"}"; + + "\"skipRuleEngine\":true}"; final TrackerImportParams trackerImportParams = renderService.fromJson(json, TrackerImportParams.class); @@ -129,7 +118,6 @@ void testJsonDeserialization() throws IOException { assertThat(trackerImportParams.isSkipPatternValidation(), is(true)); assertThat(trackerImportParams.isSkipSideEffects(), is(true)); assertThat(trackerImportParams.isSkipRuleEngine(), is(true)); - assertThat(trackerImportParams.getUser(), is(nullValue())); TrackerIdSchemeParams idSchemes = trackerImportParams.getIdSchemes(); assertThat(idSchemes.getIdScheme(), is(TrackerIdSchemeParam.CODE)); assertThat(idSchemes.getProgramIdScheme().getIdScheme(), is(TrackerIdScheme.ATTRIBUTE)); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventDataValueTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventDataValueTest.java index bd652e88b4df..8b5ef6f4e2f1 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventDataValueTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/EventDataValueTest.java @@ -45,6 +45,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.user.User; import org.junit.jupiter.api.Test; @@ -66,12 +67,11 @@ protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); final User userA = userService.getUser("M5zQapPyTZI"); injectSecurityContext(userA); - - TrackerImportParams teiParams = fromJson("tracker/single_tei.json", userA.getUid()); - assertNoErrors(trackerImportService.importTracker(teiParams)); - TrackerImportParams enrollmentParams = - fromJson("tracker/single_enrollment.json", userA.getUid()); - assertNoErrors(trackerImportService.importTracker(enrollmentParams)); + TrackerImportParams params = TrackerImportParams.builder().userId(userA.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + assertNoErrors(trackerImportService.importTracker(params, trackerObjects)); + TrackerObjects enTrackerObjects = fromJson("tracker/single_enrollment.json"); + assertNoErrors(trackerImportService.importTracker(params, enTrackerObjects)); manager.flush(); } @@ -79,7 +79,7 @@ protected void initTest() throws IOException { void successWhenEventHasNoProgramAndHasProgramStage() throws IOException { ImportReport importReport = trackerImportService.importTracker( - fromJson("tracker/validations/events-with_no_program.json")); + new TrackerImportParams(), fromJson("tracker/validations/events-with_no_program.json")); assertNoErrors(importReport); } @@ -87,7 +87,8 @@ void successWhenEventHasNoProgramAndHasProgramStage() throws IOException { @Test void testEventDataValue() throws IOException { ImportReport importReport = - trackerImportService.importTracker(fromJson("tracker/event_with_data_values.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/event_with_data_values.json")); assertNoErrors(importReport); List events = manager.getAll(Event.class); @@ -99,8 +100,9 @@ void testEventDataValue() throws IOException { @Test void testEventDataValueUpdate() throws IOException { - ImportReport importReport = - trackerImportService.importTracker(fromJson("tracker/event_with_data_values.json")); + TrackerObjects trackerObjects = fromJson("tracker/event_with_data_values.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List events = manager.getAll(Event.class); @@ -109,17 +111,10 @@ void testEventDataValueUpdate() throws IOException { Set eventDataValues = event.getEventDataValues(); assertEquals(4, eventDataValues.size()); // update - TrackerImportParams trackerImportParams = - fromJson("tracker/event_with_updated_data_values.json"); - // make sure that the uid property is populated as well - otherwise - // update will - // not work - trackerImportParams - .getEvents() - .get(0) - .setEvent(trackerImportParams.getEvents().get(0).getEvent()); - trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - importReport = trackerImportService.importTracker(trackerImportParams); + + TrackerObjects updatedTrackerObjects = fromJson("tracker/event_with_updated_data_values.json"); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + importReport = trackerImportService.importTracker(params, updatedTrackerObjects); assertNoErrors(importReport); List updatedEvents = manager.getAll(Event.class); assertEquals(1, updatedEvents.size()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java index af021c5f645b..e04fe595b412 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java @@ -44,6 +44,7 @@ import org.hisp.dhis.tracker.imports.domain.Enrollment; import org.hisp.dhis.tracker.imports.domain.EnrollmentStatus; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -61,16 +62,19 @@ class LastUpdateImportTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); injectAdminUser(); - TrackerImportParams trackerImportParams = fromJson("tracker/single_tei.json"); - assertNoErrors(trackerImportService.importTracker(trackerImportParams)); - trackedEntity = trackerImportParams.getTrackedEntities().get(0); - assertNoErrors(trackerImportService.importTracker(fromJson("tracker/single_enrollment.json"))); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + assertNoErrors(trackerImportService.importTracker(new TrackerImportParams(), trackerObjects)); + trackedEntity = trackerObjects.getTrackedEntities().get(0); + assertNoErrors( + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/single_enrollment.json"))); manager.flush(); } @Test void shouldUpdateTeiIfTeiIsUpdated() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams trackerImportParams = new TrackerImportParams(); trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE); Attribute attribute = Attribute.builder() @@ -80,7 +84,7 @@ void shouldUpdateTeiIfTeiIsUpdated() throws IOException { trackedEntity.setAttributes(Collections.singletonList(attribute)); Date lastUpdateBefore = trackedEntityService.getTrackedEntity(trackedEntity.getTrackedEntity()).getLastUpdated(); - assertNoErrors(trackerImportService.importTracker(trackerImportParams)); + assertNoErrors(trackerImportService.importTracker(trackerImportParams, trackerObjects)); assertTrue( manager .get(TrackedEntity.class, trackedEntity.getTrackedEntity()) @@ -91,14 +95,15 @@ void shouldUpdateTeiIfTeiIsUpdated() throws IOException { @Test void shouldUpdateTeiIfEventIsUpdated() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json"); + TrackerObjects trackerObjects = fromJson("tracker/event_with_data_values.json"); + TrackerImportParams trackerImportParams = new TrackerImportParams(); Date lastUpdateBefore = trackedEntityService.getTrackedEntity(trackedEntity.getTrackedEntity()).getLastUpdated(); - assertNoErrors(trackerImportService.importTracker(trackerImportParams)); + assertNoErrors(trackerImportService.importTracker(trackerImportParams, trackerObjects)); - trackerImportParams = fromJson("tracker/event_with_updated_data_values.json"); + trackerObjects = fromJson("tracker/event_with_updated_data_values.json"); trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE); - assertNoErrors(trackerImportService.importTracker(trackerImportParams)); + assertNoErrors(trackerImportService.importTracker(trackerImportParams, trackerObjects)); manager.clear(); assertTrue( manager @@ -110,13 +115,15 @@ void shouldUpdateTeiIfEventIsUpdated() throws IOException { @Test void shouldUpdateTeiIfEnrollmentIsUpdated() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/single_enrollment.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_enrollment.json"); + TrackerImportParams trackerImportParams = new TrackerImportParams(); Date lastUpdateBefore = trackedEntityService.getTrackedEntity(trackedEntity.getTrackedEntity()).getLastUpdated(); - Enrollment enrollment = trackerImportParams.getEnrollments().get(0); + Enrollment enrollment = trackerObjects.getEnrollments().get(0); enrollment.setStatus(EnrollmentStatus.COMPLETED); trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(trackerImportParams, trackerObjects); assertNoErrors(importReport); manager.clear(); assertTrue( diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java index 9c2517c0ad18..017ca502bac7 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java @@ -52,6 +52,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; import org.hisp.dhis.tracker.imports.domain.EnrollmentStatus; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.validation.ValidationCode; import org.hisp.dhis.user.User; @@ -80,18 +81,16 @@ protected void initTest() throws IOException { injectSecurityContext(superUser); nonSuperUser = userService.getUser("Tu9fv8ezgHl"); + TrackerImportParams params = TrackerImportParams.builder().userId(superUser.getUid()).build(); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/ownership_tei.json", superUser.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/ownership_tei.json"))); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/ownership_enrollment.json", superUser.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/ownership_enrollment.json"))); } @Test void testProgramOwnerWhenEnrolled() throws IOException { - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -104,15 +103,11 @@ void testProgramOwnerWhenEnrolled() throws IOException { assertNotNull(tepo.getTrackedEntity()); assertNotNull(tepo.getProgram()); assertNotNull(tepo.getOrganisationUnit()); - assertTrue(enrollmentParams.getEnrollments().get(0).getProgram().isEqualTo(tepo.getProgram())); + assertTrue(trackerObjects.getEnrollments().get(0).getProgram().isEqualTo(tepo.getProgram())); assertTrue( - enrollmentParams - .getEnrollments() - .get(0) - .getOrgUnit() - .isEqualTo(tepo.getOrganisationUnit())); + trackerObjects.getEnrollments().get(0).getOrgUnit().isEqualTo(tepo.getOrganisationUnit())); assertEquals( - enrollmentParams.getEnrollments().get(0).getTrackedEntity(), + trackerObjects.getEnrollments().get(0).getTrackedEntity(), tepo.getTrackedEntity().getUid()); } @@ -120,14 +115,13 @@ void testProgramOwnerWhenEnrolled() throws IOException { void testClientDatesForTeiEnrollmentEvent() throws IOException { User nonSuperUser = userService.getUser(this.nonSuperUser.getUid()); injectSecurityContext(nonSuperUser); - - TrackerImportParams trackerImportParams = - fromJson("tracker/ownership_event.json", nonSuperUser); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_event.json"); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); manager.flush(); - TrackerImportParams teParams = fromJson("tracker/ownership_tei.json", nonSuperUser); - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser); + TrackerObjects teTrackerObjects = fromJson("tracker/ownership_tei.json"); + TrackerObjects enTrackerObjects = fromJson("tracker/ownership_enrollment.json"); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -136,10 +130,10 @@ void testClientDatesForTeiEnrollmentEvent() throws IOException { assertNotNull(te.getCreatedAtClient()); assertNotNull(te.getLastUpdatedAtClient()); assertEquals( - DateUtils.fromInstant(teParams.getTrackedEntities().get(0).getCreatedAtClient()), + DateUtils.fromInstant(teTrackerObjects.getTrackedEntities().get(0).getCreatedAtClient()), te.getCreatedAtClient()); assertEquals( - DateUtils.fromInstant(teParams.getTrackedEntities().get(0).getUpdatedAtClient()), + DateUtils.fromInstant(teTrackerObjects.getTrackedEntities().get(0).getUpdatedAtClient()), te.getLastUpdatedAtClient()); Set enrollments = te.getEnrollments(); assertEquals(1, enrollments.size()); @@ -147,10 +141,10 @@ void testClientDatesForTeiEnrollmentEvent() throws IOException { assertNotNull(enrollment.getCreatedAtClient()); assertNotNull(enrollment.getLastUpdatedAtClient()); assertEquals( - DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getCreatedAtClient()), + DateUtils.fromInstant(enTrackerObjects.getEnrollments().get(0).getCreatedAtClient()), enrollment.getCreatedAtClient()); assertEquals( - DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getUpdatedAtClient()), + DateUtils.fromInstant(enTrackerObjects.getEnrollments().get(0).getUpdatedAtClient()), enrollment.getLastUpdatedAtClient()); Set events = enrollment.getEvents(); assertEquals(1, events.size()); @@ -158,34 +152,35 @@ void testClientDatesForTeiEnrollmentEvent() throws IOException { assertNotNull(event.getCreatedAtClient()); assertNotNull(event.getLastUpdatedAtClient()); assertEquals( - DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getCreatedAtClient()), + DateUtils.fromInstant(trackerObjects.getEvents().get(0).getCreatedAtClient()), event.getCreatedAtClient()); assertEquals( - DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getUpdatedAtClient()), + DateUtils.fromInstant(trackerObjects.getEvents().get(0).getUpdatedAtClient()), event.getLastUpdatedAtClient()); } @Test void testUpdateEnrollment() throws IOException { - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); List enrollments = manager.getAll(Enrollment.class); assertEquals(2, enrollments.size()); Enrollment enrollment = enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get(); - compareEnrollmentBasicProperties(enrollment, enrollmentParams.getEnrollments().get(0)); + compareEnrollmentBasicProperties(enrollment, trackerObjects.getEnrollments().get(0)); assertNull(enrollment.getCompletedBy()); assertNull(enrollment.getCompletedDate()); org.hisp.dhis.tracker.imports.domain.Enrollment updatedEnrollment = - enrollmentParams.getEnrollments().get(0); + trackerObjects.getEnrollments().get(0); updatedEnrollment.setStatus(EnrollmentStatus.COMPLETED); updatedEnrollment.setCreatedAtClient(Instant.now()); updatedEnrollment.setUpdatedAtClient(Instant.now()); updatedEnrollment.setEnrolledAt(Instant.now()); updatedEnrollment.setOccurredAt(Instant.now()); - enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); manager.flush(); assertNoErrors(updatedReport); assertEquals(1, updatedReport.getStats().getUpdated()); @@ -199,13 +194,14 @@ void testUpdateEnrollment() throws IOException { @Test void testDeleteEnrollment() throws IOException { - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); List enrollments = manager.getAll(Enrollment.class); assertEquals(2, enrollments.size()); enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get(); - enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.DELETE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(updatedReport); assertEquals(1, updatedReport.getStats().getDeleted()); enrollments = manager.getAll(Enrollment.class); @@ -215,19 +211,20 @@ void testDeleteEnrollment() throws IOException { @Test void testCreateEnrollmentAfterDeleteEnrollment() throws IOException { injectSecurityContext(userService.getUser(nonSuperUser.getUid())); - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); List enrollments = manager.getAll(Enrollment.class); assertEquals(2, enrollments.size()); - enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.DELETE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(updatedReport); assertEquals(1, updatedReport.getStats().getDeleted()); enrollments = manager.getAll(Enrollment.class); assertEquals(1, enrollments.size()); - enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE); - enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid()); - updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.CREATE); + trackerObjects.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid()); + updatedReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(updatedReport); assertEquals(1, updatedReport.getStats().getCreated()); enrollments = manager.getAll(Enrollment.class); @@ -237,21 +234,22 @@ void testCreateEnrollmentAfterDeleteEnrollment() throws IOException { @Test void testCreateEnrollmentWithoutOwnership() throws IOException { injectSecurityContext(userService.getUser(nonSuperUser.getUid())); - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); List enrollments = manager.getAll(Enrollment.class); assertEquals(2, enrollments.size()); - enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.DELETE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(updatedReport); assertEquals(1, updatedReport.getStats().getDeleted()); TrackedEntity te = manager.get(TrackedEntity.class, "IOR1AXXl24H"); OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP"); Program pgm = manager.get(Program.class, "BFcipDERJnf"); trackerOwnershipManager.transferOwnership(te, pgm, ou, true, false); - enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE); - enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid()); - updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.CREATE); + trackerObjects.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid()); + updatedReport = trackerImportService.importTracker(params, trackerObjects); assertEquals(1, updatedReport.getStats().getIgnored()); assertHasError(updatedReport, ValidationCode.E1102); } @@ -262,11 +260,12 @@ void testDeleteEnrollmentWithoutOwnership() throws IOException { TrackedEntity te = manager.get(TrackedEntity.class, "IOR1AXXl24H"); OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP"); Program pgm = manager.get(Program.class, "BFcipDERJnf"); - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); trackerOwnershipManager.transferOwnership(te, pgm, ou, true, false); - enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + params.setImportStrategy(TrackerImportStrategy.DELETE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); assertEquals(1, updatedReport.getStats().getIgnored()); assertHasError(updatedReport, ValidationCode.E1102); } @@ -278,10 +277,11 @@ void testUpdateEnrollmentWithoutOwnership() throws IOException { OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP"); Program pgm = manager.get(Program.class, "BFcipDERJnf"); trackerOwnershipManager.transferOwnership(te, pgm, ou, true, false); - TrackerImportParams enrollmentParams = - fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid()); - enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport updatedReport = trackerImportService.importTracker(enrollmentParams); + TrackerImportParams params = + TrackerImportParams.builder().userId(nonSuperUser.getUid()).build(); + TrackerObjects trackerObjects = fromJson("tracker/ownership_enrollment.json"); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + ImportReport updatedReport = trackerImportService.importTracker(params, trackerObjects); assertEquals(1, updatedReport.getStats().getIgnored()); assertHasError(updatedReport, ValidationCode.E1102); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/RelationshipImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/RelationshipImportTest.java index fb8daad5335f..c617089cb10c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/RelationshipImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/RelationshipImportTest.java @@ -37,6 +37,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.Status; import org.hisp.dhis.user.User; @@ -58,31 +59,33 @@ class RelationshipImportTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); userA = userService.getUser("M5zQapPyTZI"); + TrackerImportParams params = TrackerImportParams.builder().userId(userA.getUid()).build(); + assertNoErrors(trackerImportService.importTracker(params, fromJson("tracker/single_tei.json"))); assertNoErrors( - trackerImportService.importTracker(fromJson("tracker/single_tei.json", userA.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/single_enrollment.json"))); assertNoErrors( - trackerImportService.importTracker( - fromJson("tracker/single_enrollment.json", userA.getUid()))); - assertNoErrors( - trackerImportService.importTracker(fromJson("tracker/single_event.json", userA.getUid()))); + trackerImportService.importTracker(params, fromJson("tracker/single_event.json"))); manager.flush(); } @Test void successImportingRelationships() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/relationships.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/relationships.json")); assertThat(importReport.getStatus(), is(Status.OK)); assertThat(importReport.getStats().getCreated(), is(2)); } @Test void successUpdateRelationships() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/relationships.json"); - trackerImportService.importTracker(trackerImportParams); - trackerImportParams = fromJson("tracker/relationshipToUpdate.json"); + TrackerImportParams trackerImportParams = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/relationships.json"); + trackerImportService.importTracker(trackerImportParams, trackerObjects); + trackerObjects = fromJson("tracker/relationshipToUpdate.json"); trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(trackerImportParams, trackerObjects); assertThat(importReport.getStatus(), is(Status.OK)); assertThat(importReport.getStats().getCreated(), is(0)); assertThat(importReport.getStats().getIgnored(), is(1)); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryDeleteIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryDeleteIntegrationTest.java index ed4ca445cb27..b3e5a208b125 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryDeleteIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryDeleteIntegrationTest.java @@ -41,6 +41,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.PersistenceReport; import org.hisp.dhis.tracker.imports.validation.ValidationCode; @@ -58,12 +59,13 @@ class ReportSummaryDeleteIntegrationTest extends TrackerTest { protected void initTest() throws IOException { setUpMetadata("tracker/tracker_basic_metadata.json"); injectAdminUser(); - TrackerImportParams params = fromJson("tracker/tracker_basic_data_before_deletion.json"); - assertEquals(13, params.getTrackedEntities().size()); - assertEquals(2, params.getEnrollments().size()); - assertEquals(2, params.getEvents().size()); + TrackerObjects trackerObjects = fromJson("tracker/tracker_basic_data_before_deletion.json"); + assertEquals(13, trackerObjects.getTrackedEntities().size()); + assertEquals(2, trackerObjects.getEnrollments().size()); + assertEquals(2, trackerObjects.getEvents().size()); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); PersistenceReport persistenceReport = importReport.getPersistenceReport(); assertImportedObjects(13, persistenceReport, TrackerType.TRACKED_ENTITY); @@ -77,11 +79,12 @@ protected void initTest() throws IOException { @Test void testTrackedEntityDeletion() throws IOException { - TrackerImportParams params = fromJson("tracker/tracked_entity_basic_data_for_deletion.json"); + TrackerObjects trackerObjects = fromJson("tracker/tracked_entity_basic_data_for_deletion.json"); + TrackerImportParams params = new TrackerImportParams(); params.setImportStrategy(TrackerImportStrategy.DELETE); - assertEquals(9, params.getTrackedEntities().size()); + assertEquals(9, trackerObjects.getTrackedEntities().size()); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertDeletedObjects(9, importReport.getPersistenceReport(), TrackerType.TRACKED_ENTITY); // remaining @@ -93,10 +96,11 @@ void testTrackedEntityDeletion() throws IOException { void testEnrollmentDeletion() throws IOException { dbmsManager.clearSession(); assertEquals(2, manager.getAll(Event.class).size()); - TrackerImportParams params = fromJson("tracker/enrollment_basic_data_for_deletion.json"); + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/enrollment_basic_data_for_deletion.json"); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertDeletedObjects(1, importReport.getPersistenceReport(), TrackerType.ENROLLMENT); @@ -108,10 +112,11 @@ void testEnrollmentDeletion() throws IOException { @Test void testEventDeletion() throws IOException { - TrackerImportParams params = fromJson("tracker/event_basic_data_for_deletion.json"); + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/event_basic_data_for_deletion.json"); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertDeletedObjects(1, importReport.getPersistenceReport(), TrackerType.EVENT); @@ -121,21 +126,23 @@ void testEventDeletion() throws IOException { @Test void testNonExistentEnrollment() throws IOException { - TrackerImportParams params = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/non_existent_enrollment_basic_data_for_deletion.json"); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasError(importReport, ValidationCode.E1081); } @Test void testDeleteMultipleEntities() throws IOException { - TrackerImportParams params = fromJson("tracker/tracker_data_for_deletion.json"); + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/tracker_data_for_deletion.json"); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertDeletedObjects(1, importReport.getPersistenceReport(), TrackerType.ENROLLMENT); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java index 3f2221e5af24..c0c7e4575eb4 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/ReportSummaryIntegrationTest.java @@ -37,6 +37,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.Status; import org.hisp.dhis.user.User; @@ -59,11 +60,12 @@ protected void initTest() throws IOException { @Test void testStatsCountForOneCreatedTEI() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); - params.setUserId(userA.getUid()); - params.setAtomicMode(AtomicMode.OBJECT); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); - ImportReport trackerImportTeiReport = trackerImportService.importTracker(params); + ImportReport trackerImportTeiReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportTeiReport); assertEquals(1, trackerImportTeiReport.getStats().getCreated()); @@ -74,16 +76,19 @@ void testStatsCountForOneCreatedTEI() throws IOException { @Test void testStatsCountForOneCreatedAndOneUpdatedTEI() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_tei_and_one_new_tei.json"); + trackerObjects = fromJson("tracker/one_update_tei_and_one_new_tei.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportTeiReport = trackerImportService.importTracker(params); + ImportReport trackerImportTeiReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportTeiReport); assertEquals(1, trackerImportTeiReport.getStats().getCreated()); @@ -94,17 +99,20 @@ void testStatsCountForOneCreatedAndOneUpdatedTEI() throws IOException { @Test void testStatsCountForOneCreatedAndOneUpdatedTEIAndOneInvalidTEI() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_tei_and_one_new_tei_and_one_invalid_tei.json"); + trackerObjects = fromJson("tracker/one_update_tei_and_one_new_tei_and_one_invalid_tei.json"); params.setUserId(userA.getUid()); params.setAtomicMode(AtomicMode.OBJECT); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportTeiReport = trackerImportService.importTracker(params); + ImportReport trackerImportTeiReport = + trackerImportService.importTracker(params, trackerObjects); assertNotNull(trackerImportTeiReport); assertEquals(Status.OK, trackerImportTeiReport.getStatus()); @@ -117,16 +125,19 @@ void testStatsCountForOneCreatedAndOneUpdatedTEIAndOneInvalidTEI() throws IOExce @Test void testStatsCountForOneCreatedEnrollment() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params); + ImportReport trackerImportEnrollmentReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEnrollmentReport); assertEquals(1, trackerImportEnrollmentReport.getStats().getCreated()); @@ -137,16 +148,19 @@ void testStatsCountForOneCreatedEnrollment() throws IOException { @Test void testStatsCountForOneCreatedEnrollmentAndUpdateSameEnrollment() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params); + ImportReport trackerImportEnrollmentReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEnrollmentReport); assertEquals(1, trackerImportEnrollmentReport.getStats().getCreated()); @@ -154,11 +168,11 @@ void testStatsCountForOneCreatedEnrollmentAndUpdateSameEnrollment() throws IOExc assertEquals(0, trackerImportEnrollmentReport.getStats().getIgnored()); assertEquals(0, trackerImportEnrollmentReport.getStats().getDeleted()); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - trackerImportEnrollmentReport = trackerImportService.importTracker(params); + trackerImportEnrollmentReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEnrollmentReport); assertEquals(0, trackerImportEnrollmentReport.getStats().getCreated()); @@ -169,21 +183,24 @@ void testStatsCountForOneCreatedEnrollmentAndUpdateSameEnrollment() throws IOExc @Test void testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollment() throws IOException { - TrackerImportParams params = fromJson("tracker/one_update_tei_and_one_new_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/one_update_tei_and_one_new_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_enrollment_and_one_new_enrollment.json"); + trackerObjects = fromJson("tracker/one_update_enrollment_and_one_new_enrollment.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params); + ImportReport trackerImportEnrollmentReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEnrollmentReport); assertEquals(1, trackerImportEnrollmentReport.getStats().getCreated()); @@ -195,23 +212,26 @@ void testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollment() throws IOExce @Test void testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollmentAndOneInvalidEnrollment() throws IOException { - TrackerImportParams params = fromJson("tracker/three_teis.json"); + TrackerObjects trackerObjects = fromJson("tracker/three_teis.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_and_one_new_and_one_invalid_enrollment.json"); + trackerObjects = fromJson("tracker/one_update_and_one_new_and_one_invalid_enrollment.json"); params.setUserId(userA.getUid()); params.setAtomicMode(AtomicMode.OBJECT); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(params); + ImportReport trackerImportEnrollmentReport = + trackerImportService.importTracker(params, trackerObjects); assertNotNull(trackerImportEnrollmentReport); assertEquals(Status.OK, trackerImportEnrollmentReport.getStatus()); @@ -224,20 +244,23 @@ void testStatsCountForOneUpdateEnrollmentAndOneCreatedEnrollmentAndOneInvalidEnr @Test void testStatsCountForOneCreatedEvent() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_event.json"); + trackerObjects = fromJson("tracker/single_event.json"); params.setUserId(userA.getUid()); - ImportReport trackerImportEventReport = trackerImportService.importTracker(params); + ImportReport trackerImportEventReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEventReport); assertEquals(1, trackerImportEventReport.getStats().getCreated()); @@ -248,26 +271,29 @@ void testStatsCountForOneCreatedEvent() throws IOException { @Test void testStatsCountForOneUpdateEventAndOneNewEvent() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_event.json"); + trackerObjects = fromJson("tracker/single_event.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_event_and_one_new_event.json"); + trackerObjects = fromJson("tracker/one_update_event_and_one_new_event.json"); params.setUserId(userA.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEventReport = trackerImportService.importTracker(params); + ImportReport trackerImportEventReport = + trackerImportService.importTracker(params, trackerObjects); assertNoErrors(trackerImportEventReport); assertEquals(1, trackerImportEventReport.getStats().getCreated()); @@ -278,27 +304,30 @@ void testStatsCountForOneUpdateEventAndOneNewEvent() throws IOException { @Test void testStatsCountForOneUpdateEventAndOneNewEventAndOneInvalidEvent() throws IOException { - TrackerImportParams params = fromJson("tracker/single_tei.json"); + TrackerObjects trackerObjects = fromJson("tracker/single_tei.json"); + TrackerImportParams params = + TrackerImportParams.builder().atomicMode(AtomicMode.OBJECT).userId(userA.getUid()).build(); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_enrollment.json"); + trackerObjects = fromJson("tracker/single_enrollment.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/single_event.json"); + trackerObjects = fromJson("tracker/single_event.json"); params.setUserId(userA.getUid()); - trackerImportService.importTracker(params); + trackerImportService.importTracker(params, trackerObjects); - params = fromJson("tracker/one_update_and_one_new_and_one_invalid_event.json"); + trackerObjects = fromJson("tracker/one_update_and_one_new_and_one_invalid_event.json"); params.setUserId(userA.getUid()); params.setAtomicMode(AtomicMode.OBJECT); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport trackerImportEventReport = trackerImportService.importTracker(params); + ImportReport trackerImportEventReport = + trackerImportService.importTracker(params, trackerObjects); assertNotNull(trackerImportEventReport); assertEquals(Status.OK, trackerImportEventReport.getStatus()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeTest.java index b5d2f85398d7..b5c6e904bbf9 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeTest.java @@ -41,8 +41,10 @@ import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheatService; import org.hisp.dhis.tracker.imports.report.ImportReport; @@ -70,8 +72,10 @@ protected void initTest() throws IOException { @Test void testTrackedAttributePreheater() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/te_with_tea_data.json"); - TrackerPreheat preheat = trackerPreheatService.preheat(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/te_with_tea_data.json"); + TrackerPreheat preheat = + trackerPreheatService.preheat( + trackerObjects, new TrackerIdSchemeParams(), userService.getUser(ADMIN_USER_UID)); assertNotNull(preheat.get(OrganisationUnit.class, "cNEZTkdAvmg")); assertNotNull(preheat.get(TrackedEntityType.class, "KrYIdvLxkMb")); assertNotNull(preheat.get(TrackedEntityAttribute.class, "sYn3tkL3XKa")); @@ -81,8 +85,9 @@ void testTrackedAttributePreheater() throws IOException { @Test void testTrackedAttributeValueBundleImporter() throws IOException { - ImportReport importReport = - trackerImportService.importTracker(fromJson("tracker/te_with_tea_data.json")); + TrackerObjects trackerObjects = fromJson("tracker/te_with_tea_data.json"); + TrackerImportParams params = TrackerImportParams.builder().build(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java index bbc7722dc71a..dd59653ea493 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java @@ -46,6 +46,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -71,7 +72,8 @@ protected void initTest() throws IOException { @Test void testTrackedEntityAttributeValueAuditCreate() throws IOException { assertNoErrors( - trackerImportService.importTracker(fromJson("tracker/te_program_with_tea_data.json"))); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/te_program_with_tea_data.json"))); List trackedEntities = manager.getAll(TrackedEntity.class); assertEquals(1, trackedEntities.size()); @@ -95,9 +97,10 @@ void testTrackedEntityAttributeValueAuditCreate() throws IOException { @Test void testTrackedEntityAttributeValueAuditDelete() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json"); + TrackerObjects trackerObjects = fromJson("tracker/te_program_with_tea_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List attributeValues1 = trackedEntityAttributeValueService.getTrackedEntityAttributeValues( @@ -106,9 +109,9 @@ void testTrackedEntityAttributeValueAuditDelete() throws IOException { attributeValues1.stream() .map(TrackedEntityAttributeValue::getAttribute) .collect(Collectors.toList()); - trackerImportParams = fromJson("tracker/te_program_with_tea_null_data.json"); - trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/te_program_with_tea_null_data.json"); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); List attributeValueAudits = diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java index fd8935c6ea60..a90f2ee01e9a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java @@ -43,6 +43,7 @@ import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -77,15 +78,16 @@ protected void initTest() throws IOException { @Test void testTrackedEntityDataValueAuditCreate() throws IOException { + TrackerImportParams params = new TrackerImportParams(); assertNoErrors( trackerImportService.importTracker( - fromJson("tracker/event_and_enrollment_with_data_values.json"))); + params, fromJson("tracker/event_and_enrollment_with_data_values.json"))); assertNoErrors( trackerImportService.importTracker( - fromJson("tracker/event_with_data_values_for_update_audit.json"))); + params, fromJson("tracker/event_with_data_values_for_update_audit.json"))); assertNoErrors( trackerImportService.importTracker( - fromJson("tracker/event_with_data_values_for_delete_audit.json"))); + params, fromJson("tracker/event_with_data_values_for_delete_audit.json"))); dataElement = manager.search(DataElement.class, DE); event = manager.search(Event.class, PSI); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeEncryptionTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeEncryptionTest.java index 875ff64b62b5..3c3c8dee2e8e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeEncryptionTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeEncryptionTest.java @@ -38,6 +38,7 @@ import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; @@ -68,6 +69,7 @@ protected void initTest() throws IOException { void testTrackedEntityProgramAttributeEncryptedValue() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/te_program_with_tea_encryption_data.json")); assertNoErrors(importReport); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeFileResourceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeFileResourceTest.java index 825b17d073e2..5338a1ddaee6 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeFileResourceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeFileResourceTest.java @@ -43,6 +43,7 @@ import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; @@ -82,6 +83,7 @@ void testTrackedEntityProgramAttributeFileResourceValue() throws IOException { assertFalse(fileResource.isAssigned()); ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/te_program_with_tea_fileresource_data.json")); assertNoErrors(importReport); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeTest.java index 1bd7a6209887..2a0d63d8c3d4 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityProgramAttributeTest.java @@ -40,6 +40,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -63,8 +64,9 @@ protected void initTest() throws IOException { @Test void testTrackedEntityProgramAttributeValue() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/te_program_with_tea_data.json"); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -77,8 +79,9 @@ void testTrackedEntityProgramAttributeValue() throws IOException { @Test void testTrackedEntityProgramAttributeValueUpdate() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/te_program_with_tea_data.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -89,9 +92,9 @@ void testTrackedEntityProgramAttributeValueUpdate() throws IOException { assertEquals(5, attributeValues.size()); manager.clear(); // update - trackerImportParams = fromJson("tracker/te_program_with_tea_update_data.json"); - trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/te_program_with_tea_update_data.json"); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); trackedEntities = manager.getAll(TrackedEntity.class); @@ -104,8 +107,9 @@ void testTrackedEntityProgramAttributeValueUpdate() throws IOException { @Test void testTrackedEntityProgramAttributeValueUpdateAndDelete() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/te_program_with_tea_data.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -116,9 +120,9 @@ void testTrackedEntityProgramAttributeValueUpdateAndDelete() throws IOException assertEquals(5, attributeValues.size()); manager.clear(); // update - trackerImportParams = fromJson("tracker/te_program_with_tea_update_data.json"); - trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/te_program_with_tea_update_data.json"); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); trackedEntities = manager.getAll(TrackedEntity.class); @@ -129,9 +133,9 @@ void testTrackedEntityProgramAttributeValueUpdateAndDelete() throws IOException assertEquals(5, attributeValues.size()); manager.clear(); // delete - trackerImportParams = fromJson("tracker/te_program_with_tea_delete_data.json"); - trackerImportParams.setImportStrategy(TrackerImportStrategy.DELETE); - importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/te_program_with_tea_delete_data.json"); + params.setImportStrategy(TrackerImportStrategy.DELETE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); trackedEntities = manager.getAll(TrackedEntity.class); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleServiceTest.java index 3519956be68b..85f96e5a0bce 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerBundleServiceTest.java @@ -39,6 +39,7 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -67,9 +68,11 @@ void testVerifyMetadata() { @Test void testTrackedEntityImport() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/trackedentity_basic_data.json"); - assertEquals(13, trackerImportParams.getTrackedEntities().size()); - TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/trackedentity_basic_data.json"); + assertEquals(13, trackerObjects.getTrackedEntities().size()); + TrackerBundle trackerBundle = + trackerBundleService.create( + new TrackerImportParams(), trackerObjects, userService.getUser(ADMIN_USER_UID)); trackerBundleService.commit(trackerBundle); List trackedEntities = manager.getAll(TrackedEntity.class); assertEquals(13, trackedEntities.size()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerEventBundleServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerEventBundleServiceTest.java index b67f6fcc79fd..36acc0dc557c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerEventBundleServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerEventBundleServiceTest.java @@ -38,6 +38,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -58,9 +59,10 @@ protected void initTest() throws IOException { @Test void testCreateSingleEventData() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/event_events_and_enrollment.json"); - assertEquals(8, trackerImportParams.getEvents().size()); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/event_events_and_enrollment.json"); + assertEquals(8, trackerObjects.getEvents().size()); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); List events = eventStore.getAll(); @@ -69,13 +71,15 @@ void testCreateSingleEventData() throws IOException { @Test void testUpdateSingleEventData() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/event_events_and_enrollment.json"); + TrackerObjects trackerObjects = fromJson("tracker/event_events_and_enrollment.json"); + TrackerImportParams trackerImportParams = new TrackerImportParams(); trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(trackerImportParams, trackerObjects); assertNoErrors(importReport); assertEquals(8, eventStore.getAll().size()); - importReport = trackerImportService.importTracker(trackerImportParams); + importReport = trackerImportService.importTracker(trackerImportParams, trackerObjects); assertNoErrors(importReport); assertEquals(8, eventStore.getAll().size()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerProgramRuleBundleServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerProgramRuleBundleServiceTest.java index 17ecd943bbc5..f548deddc7e6 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerProgramRuleBundleServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerProgramRuleBundleServiceTest.java @@ -40,6 +40,7 @@ import org.hisp.dhis.programrule.ProgramRuleService; import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -70,9 +71,11 @@ protected void initTest() throws IOException { @Test void testRunRuleEngineForEventOnBundleCreate() throws IOException { - TrackerImportParams trackerImportParams = fromJson("tracker/event_events_and_enrollment.json"); - assertEquals(8, trackerImportParams.getEvents().size()); - TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams); + TrackerObjects trackerObjects = fromJson("tracker/event_events_and_enrollment.json"); + assertEquals(8, trackerObjects.getEvents().size()); + TrackerBundle trackerBundle = + trackerBundleService.create( + new TrackerImportParams(), trackerObjects, userService.getUser(ADMIN_USER_UID)); trackerBundle = trackerBundleService.runRuleEngine(trackerBundle); assertEquals(trackerBundle.getEvents().size(), trackerBundle.getEventRuleEffects().size()); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerSideEffectHandlerServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerSideEffectHandlerServiceTest.java index 91bf43adb2f4..373b53f17c34 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerSideEffectHandlerServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerSideEffectHandlerServiceTest.java @@ -36,6 +36,7 @@ import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.program.notification.ProgramNotificationInstance; import org.hisp.dhis.tracker.TrackerTest; +import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Disabled; @@ -61,6 +62,7 @@ protected void initTest() throws IOException { void testRuleEngineSideEffectHandlerService() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/enrollment_data_with_program_rule_side_effects.json")); assertNoErrors(importReport); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatIdentifiersTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatIdentifiersTest.java index c77a08a2de31..2d6d3a54558a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatIdentifiersTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatIdentifiersTest.java @@ -30,7 +30,6 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.hisp.dhis.tracker.imports.TrackerIdSchemeParams.builder; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -54,10 +53,11 @@ import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.DataValue; import org.hisp.dhis.tracker.imports.domain.Event; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; +import org.hisp.dhis.user.User; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -69,9 +69,12 @@ class TrackerPreheatIdentifiersTest extends TrackerTest { @Autowired private IdentifiableObjectManager manager; + private User user; + @Override protected void initTest() throws IOException { setUpMetadata("tracker/identifier_metadata.json"); + user = currentUserService.getCurrentUser(); } @Test @@ -81,9 +84,10 @@ void testOrgUnitIdentifiers() { String id = pair.getLeft(); TrackerIdSchemeParam param = pair.getRight(); Event event = Event.builder().orgUnit(param.toMetadataIdentifier(id)).build(); - TrackerImportParams params = buildParams(event, builder().orgUnitIdScheme(param).build()); + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(event)).build(); + TrackerIdSchemeParams params = TrackerIdSchemeParams.builder().orgUnitIdScheme(param).build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatedObjectExists(preheat, OrganisationUnit.class, param, id); } @@ -96,10 +100,11 @@ void testProgramStageIdentifiers() { String id = pair.getLeft(); TrackerIdSchemeParam param = pair.getRight(); Event event = Event.builder().programStage(param.toMetadataIdentifier(id)).build(); - TrackerImportParams params = - buildParams(event, builder().programStageIdScheme(param).build()); + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(event)).build(); + TrackerIdSchemeParams params = + TrackerIdSchemeParams.builder().programStageIdScheme(param).build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatedObjectExists(preheat, ProgramStage.class, param, id); } @@ -118,9 +123,11 @@ void testDataElementIdentifiers() { .programStage(MetadataIdentifier.ofUid("NpsdDv6kKSO")) .dataValues(Collections.singleton(dv1)) .build(); - TrackerImportParams params = buildParams(event, builder().dataElementIdScheme(param).build()); + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(event)).build(); + TrackerIdSchemeParams params = + TrackerIdSchemeParams.builder().dataElementIdScheme(param).build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatedObjectExists(preheat, DataElement.class, param, id); } @@ -134,10 +141,11 @@ void testCategoryOptionIdentifiers() { TrackerIdSchemeParam param = pair.getRight(); Event event = Event.builder().attributeCategoryOptions(Set.of(param.toMetadataIdentifier(id))).build(); - TrackerImportParams params = - buildParams(event, builder().categoryOptionIdScheme(param).build()); + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(event)).build(); + TrackerIdSchemeParams params = + TrackerIdSchemeParams.builder().categoryOptionIdScheme(param).build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatedObjectExists(preheat, CategoryOption.class, param, id); } @@ -150,10 +158,11 @@ void testCategoryOptionComboIdentifiers() { String id = pair.getLeft(); TrackerIdSchemeParam param = pair.getRight(); Event event = Event.builder().attributeOptionCombo(param.toMetadataIdentifier(id)).build(); - TrackerImportParams params = - buildParams(event, builder().categoryOptionComboIdScheme(param).build()); + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(event)).build(); + TrackerIdSchemeParams params = + TrackerIdSchemeParams.builder().categoryOptionComboIdScheme(param).build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatedObjectExists(preheat, CategoryOptionCombo.class, param, id); } @@ -162,10 +171,10 @@ void testCategoryOptionComboIdentifiers() { @Test void testDefaultsWithIdSchemeUID() { - TrackerImportParams params = - TrackerImportParams.builder().user(currentUserService.getCurrentUser()).build(); + TrackerObjects trackerObjects = TrackerObjects.builder().build(); + TrackerIdSchemeParams params = TrackerIdSchemeParams.builder().build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatHasDefault(preheat, Category.class); assertPreheatHasDefault(preheat, CategoryCombo.class); @@ -175,20 +184,15 @@ void testDefaultsWithIdSchemeUID() { @Test void testDefaultsWithIdSchemesOtherThanUID() { + TrackerObjects trackerObjects = TrackerObjects.builder().events(List.of(new Event())).build(); + TrackerIdSchemeParams params = + TrackerIdSchemeParams.builder() + .idScheme(TrackerIdSchemeParam.NAME) + .categoryOptionIdScheme(TrackerIdSchemeParam.ofAttribute(CodeGenerator.generateUid())) + .categoryOptionComboIdScheme(TrackerIdSchemeParam.CODE) + .build(); - Event event = new Event(); - - TrackerImportParams params = - buildParams( - event, - builder() - .idScheme(TrackerIdSchemeParam.NAME) - .categoryOptionIdScheme( - TrackerIdSchemeParam.ofAttribute(CodeGenerator.generateUid())) - .categoryOptionComboIdScheme(TrackerIdSchemeParam.CODE) - .build()); - - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = trackerPreheatService.preheat(trackerObjects, params, user); assertPreheatHasDefault(preheat, Category.class); assertPreheatHasDefault(preheat, CategoryCombo.class); @@ -196,16 +200,6 @@ void testDefaultsWithIdSchemesOtherThanUID() { assertPreheatHasDefault(preheat, CategoryOptionCombo.class); } - private TrackerImportParams buildParams(Event event, TrackerIdSchemeParams idParams) { - TrackerImportParams params = - TrackerImportParams.builder() - .events(Collections.singletonList(event)) - .user(currentUserService.getCurrentUser()) - .idSchemes(idParams) - .build(); - return params; - } - private List> buildDataSet( String uid, String code, String name) { List> data = new ArrayList<>(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceIntegrationTest.java index 5f3f45d3f588..78ba1fa1b5c6 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceIntegrationTest.java @@ -45,10 +45,10 @@ import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.Enrollment; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; import org.junit.jupiter.api.Test; @@ -120,20 +120,21 @@ void testPreheatWithDifferentIdSchemes() { .trackedEntity("TE123456789") .build(); - TrackerImportParams params = - TrackerImportParams.builder() - .user(currentUser) + TrackerObjects trackerObjects = + TrackerObjects.builder() .trackedEntities(Lists.newArrayList(teA)) .enrollments(Lists.newArrayList(enrollmentA)) - .idSchemes( - TrackerIdSchemeParams.builder() - .idScheme(TrackerIdSchemeParam.UID) - .orgUnitIdScheme(TrackerIdSchemeParam.CODE) - .programIdScheme(TrackerIdSchemeParam.ofAttribute(ATTRIBUTE_UID)) - .build()) .build(); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerIdSchemeParams idSchemeParams = + TrackerIdSchemeParams.builder() + .idScheme(TrackerIdSchemeParam.UID) + .orgUnitIdScheme(TrackerIdSchemeParam.CODE) + .programIdScheme(TrackerIdSchemeParam.ofAttribute(ATTRIBUTE_UID)) + .build(); + + TrackerPreheat preheat = + trackerPreheatService.preheat(trackerObjects, idSchemeParams, currentUser); assertNotNull(preheat); // asserting on specific fields instead of plain assertEquals since diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceTest.java index 4cfaa53f987a..b17a4517f57b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/preheat/TrackerPreheatServiceTest.java @@ -42,12 +42,11 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.tracker.TrackerTest; -import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerIdentifierCollector; -import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; import org.hisp.dhis.tracker.imports.domain.TrackedEntity; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -65,11 +64,11 @@ protected void initTest() {} @Test void testCollectIdentifiersEvents() throws IOException { - TrackerImportParams params = fromJson("tracker/event_events.json"); - assertTrue(params.getTrackedEntities().isEmpty()); - assertTrue(params.getEnrollments().isEmpty()); - assertFalse(params.getEvents().isEmpty()); - Map, Set> collectedMap = identifierCollector.collect(params); + TrackerObjects trackerObjects = fromJson("tracker/event_events.json"); + assertTrue(trackerObjects.getTrackedEntities().isEmpty()); + assertTrue(trackerObjects.getEnrollments().isEmpty()); + assertFalse(trackerObjects.getEvents().isEmpty()); + Map, Set> collectedMap = identifierCollector.collect(trackerObjects); assertTrue(collectedMap.containsKey(DataElement.class)); assertTrue(collectedMap.containsKey(ProgramStage.class)); assertTrue(collectedMap.containsKey(OrganisationUnit.class)); @@ -103,12 +102,8 @@ void testCollectIdentifiersEvents() throws IOException { @Test void testCollectIdentifiersAttributeValues() { - TrackerImportParams params = - TrackerImportParams.builder() - .idSchemes( - TrackerIdSchemeParams.builder() - .idScheme(TrackerIdSchemeParam.ofAttribute("ATTR1234567")) - .build()) + TrackerObjects trackerObjects = + TrackerObjects.builder() .trackedEntities( Lists.newArrayList( TrackedEntity.builder() @@ -116,10 +111,10 @@ void testCollectIdentifiersAttributeValues() { .orgUnit(MetadataIdentifier.ofCode("OU123456789")) .build())) .build(); - assertFalse(params.getTrackedEntities().isEmpty()); - assertTrue(params.getEnrollments().isEmpty()); - assertTrue(params.getEvents().isEmpty()); - Map, Set> collectedMap = identifierCollector.collect(params); + assertFalse(trackerObjects.getTrackedEntities().isEmpty()); + assertTrue(trackerObjects.getEnrollments().isEmpty()); + assertTrue(trackerObjects.getEvents().isEmpty()); + Map, Set> collectedMap = identifierCollector.collect(trackerObjects); assertTrue(collectedMap.containsKey(TrackedEntity.class)); Set trackedEntities = collectedMap.get(TrackedEntity.class); assertTrue(collectedMap.containsKey(OrganisationUnit.class)); @@ -132,21 +127,20 @@ void testCollectIdentifiersAttributeValues() { @Test void testPreheatValidation() throws IOException { - TrackerImportParams params = fromJson("tracker/event_events.json"); - assertTrue(params.getTrackedEntities().isEmpty()); - assertTrue(params.getEnrollments().isEmpty()); - assertFalse(params.getEvents().isEmpty()); + TrackerObjects trackerObjects = fromJson("tracker/event_events.json"); + assertTrue(trackerObjects.getTrackedEntities().isEmpty()); + assertTrue(trackerObjects.getEnrollments().isEmpty()); + assertFalse(trackerObjects.getEvents().isEmpty()); } @Test void testPreheatEvents() throws IOException { setUpMetadata("tracker/event_metadata.json"); - TrackerImportParams params = fromJson("tracker/event_events.json"); - assertTrue(params.getTrackedEntities().isEmpty()); - assertTrue(params.getEnrollments().isEmpty()); - assertFalse(params.getEvents().isEmpty()); + TrackerObjects trackerObjects = fromJson("tracker/event_events.json"); - TrackerPreheat preheat = trackerPreheatService.preheat(params); + TrackerPreheat preheat = + trackerPreheatService.preheat( + trackerObjects, new TrackerIdSchemeParams(), userService.getUser(ADMIN_USER_UID)); assertNotNull(preheat); assertFalse(preheat.getAll(DataElement.class).isEmpty()); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java index e33d41b7760a..3d27f7cd4b68 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleAssignActionTest.java @@ -52,6 +52,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -86,28 +87,31 @@ public void initTest() throws IOException { assignProgramRule(); trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment_completed_event.json")); } @Test void shouldImportWithWarningWhenDataElementWithSameValueIsAssignedByAssignRule() throws IOException { - TrackerImportParams params = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/programrule/event_update_datavalue_same_value.json"); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyWarnings(importReport, E1308); } @Test void shouldNotImportWhenDataElementWithDifferentValueIsAssignedByAssignRule() throws IOException { - TrackerImportParams params = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/programrule/event_update_datavalue_different_value.json"); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, E1307); } @@ -117,11 +121,12 @@ void shouldNotImportWhenDataElementWithDifferentValueIsAssignedByAssignRule() th shouldImportWithWarningWhenDataElementWithDifferentValueIsAssignedByAssignRuleAndOverwriteKeyIsTrue() throws IOException { systemSettingManager.saveSystemSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE, true); - TrackerImportParams params = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/programrule/event_update_datavalue_different_value.json"); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyWarnings(importReport, E1308); } @@ -131,11 +136,12 @@ void shouldNotImportWhenDataElementWithDifferentValueIsAssignedByAssignRule() th shouldImportWithWarningWhenDataElementWithDifferentAndEmptyValueIsAssignedByAssignRuleAndOverwriteKeyIsTrue() throws IOException { systemSettingManager.saveSystemSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE, true); - TrackerImportParams params = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/programrule/event_update_datavalue_empty_value.json"); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyWarnings(importReport, E1308); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java index 484ca72cfc65..44e00dbd3e3a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/programrule/ProgramRuleTest.java @@ -55,6 +55,7 @@ import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.validation.ValidationCode; import org.junit.jupiter.api.Test; @@ -111,7 +112,8 @@ public void initTest() throws IOException { @Test void shouldImportEnrollmentWithNoWarningsWhenThereAreNoProgramRules() throws IOException { ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/tei_enrollment.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment.json")); assertNoErrorsAndNoWarnings(report); } @@ -120,7 +122,8 @@ void shouldImportEnrollmentWithNoWarningsWhenThereAreNoProgramRules() throws IOE void shouldImportEnrollmentWithWarningsWhenAWarningIsTriggered() throws IOException { alwaysTrueWarningProgramRule(); ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/tei_enrollment.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment.json")); assertHasOnlyWarnings(report, E1300); } @@ -129,7 +132,8 @@ void shouldImportEnrollmentWithWarningsWhenAWarningIsTriggered() throws IOExcept void shouldNotImportEnrollmentWhenAnErrorIsTriggered() throws IOException { alwaysTrueErrorProgramRule(); ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/tei_enrollment.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment.json")); assertHasOnlyErrors(report, E1300); } @@ -138,7 +142,8 @@ void shouldNotImportEnrollmentWhenAnErrorIsTriggered() throws IOException { void shouldImportProgramEventWithWarningsWhenAWarningIsTriggered() throws IOException { alwaysTrueWarningProgramEventProgramRule(); ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/program_event.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/program_event.json")); assertHasOnlyWarnings(report, E1300); } @@ -148,7 +153,8 @@ void shouldNotImportProgramEventWhenAnErrorIsTriggeredBasedOnConditionEvaluating throws IOException { conditionWithConstantEvaluatesToTrue(); ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/program_event.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/program_event.json")); assertHasOnlyErrors(report, E1300); } @@ -157,7 +163,8 @@ void shouldNotImportProgramEventWhenAnErrorIsTriggeredBasedOnConditionEvaluating void shouldNotImportProgramEventWhenAnErrorIsTriggered() throws IOException { alwaysTrueErrorProgramEventProgramRule(); ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/program_event.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/program_event.json")); assertHasOnlyErrors(report, E1300); } @@ -166,6 +173,7 @@ void shouldNotImportProgramEventWhenAnErrorIsTriggered() throws IOException { void shouldImportEventWithNoWarningsWhenThereAreNoProgramRules() throws IOException { ImportReport report = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment_completed_event.json")); assertNoErrorsAndNoWarnings(report); @@ -174,11 +182,14 @@ void shouldImportEventWithNoWarningsWhenThereAreNoProgramRules() throws IOExcept @Test void shouldImportEventWithWarningsWhenAWarningIsTriggered() throws IOException { ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/tei_enrollment.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment.json")); assertNoErrors(report); alwaysTrueWarningProgramRule(); - report = trackerImportService.importTracker(fromJson("tracker/programrule/event.json")); + report = + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/event.json")); assertHasOnlyWarnings(report, E1300); } @@ -186,11 +197,14 @@ void shouldImportEventWithWarningsWhenAWarningIsTriggered() throws IOException { @Test void shouldNotImportEventWhenAnErrorIsTriggered() throws IOException { ImportReport report = - trackerImportService.importTracker(fromJson("tracker/programrule/tei_enrollment.json")); + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment.json")); assertNoErrors(report); alwaysTrueErrorProgramRule(); - report = trackerImportService.importTracker(fromJson("tracker/programrule/event.json")); + report = + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/event.json")); assertHasOnlyErrors(report, E1300); } @@ -201,6 +215,7 @@ void shouldNotValidateEventAndValidateEnrollmentWhenAnErrorIsTriggeredOnEvent() onCompleteErrorProgramRule(); ImportReport report = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment_completed_event.json")); assertHasOnlyErrors(report, E1300); @@ -211,6 +226,7 @@ void shouldNotImportEventAndEnrollmentWhenAnErrorIsTriggeredOnEnrollment() throw onCompleteErrorProgramRule(); ImportReport report = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_completed_enrollment_event.json")); assertAll( @@ -222,11 +238,14 @@ void shouldNotImportEventAndEnrollmentWhenAnErrorIsTriggeredOnEnrollment() throw void shouldImportEventWhenAnErrorIsTriggeredOnEnrollmentAlreadyPresentInDB() throws IOException { ImportReport report = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_completed_enrollment.json")); assertNoErrorsAndNoWarnings(report); onCompleteErrorProgramRule(); - report = trackerImportService.importTracker(fromJson("tracker/programrule/event.json")); + report = + trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/event.json")); assertNoErrorsAndNoWarnings(report); } @@ -237,6 +256,7 @@ void shouldNotImportWhenErrorIsTriggeredOnAllEntities() throws IOException { alwaysTrueErrorProgramEventProgramRule(); ImportReport report = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/programrule/tei_enrollment_event_programevent.json")); assertAll( @@ -248,9 +268,10 @@ void shouldNotImportWhenErrorIsTriggeredOnAllEntities() throws IOException { @Test void shouldImportWithWarningWhenARuleWithASyntaxErrorIsTriggered() throws IOException { syntaxErrorRule(); - TrackerImportParams params = fromJson("tracker/programrule/tei_enrollment.json"); + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_enrollment.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyWarnings(importReport, E1300); } @@ -259,10 +280,11 @@ void shouldImportWithWarningWhenARuleWithASyntaxErrorIsTriggered() throws IOExce void shouldImportWithWarningWhenAWarningIsTriggeredOnEventInSameProgramStage() throws IOException { programStageWarningRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_enrollment_completed_event.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyWarnings(importReport, E1300); } @@ -271,11 +293,12 @@ void shouldImportWithWarningWhenAWarningIsTriggeredOnEventInSameProgramStage() void shouldImportWithNoWarningsWhenAWarningIsTriggeredOnEventInDifferentProgramStage() throws IOException { programStageWarningRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson( "tracker/programrule/tei_enrollment_completed_event_from_another_program_stage.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrorsAndNoWarnings(importReport); } @@ -284,10 +307,11 @@ void shouldImportWithNoWarningsWhenAWarningIsTriggeredOnEventInDifferentProgramS void shouldImportWithNoWarningsWhenAWarningIsTriggeredOnActiveEventInOnCompleteProgramStage() throws IOException { programStage2WarningRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_enrollment_event_from_another_program_stage.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrorsAndNoWarnings(importReport); } @@ -296,11 +320,12 @@ void shouldImportWithNoWarningsWhenAWarningIsTriggeredOnActiveEventInOnCompleteP void shouldImportWithWarningsWhenAWarningIsTriggeredOnCompletedEventInOnCompleteProgramStage() throws IOException { programStage2WarningRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson( "tracker/programrule/tei_enrollment_completed_event_from_another_program_stage.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyWarnings(importReport, E1300); } @@ -309,11 +334,12 @@ void shouldImportWithWarningsWhenAWarningIsTriggeredOnCompletedEventInOnComplete void shouldImportWithNoWarningsWhenAWarningIsTriggeredWithADataElementFromADifferentProgramStage() throws IOException { programStage2WrongDataElementWarningRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson( "tracker/programrule/tei_enrollment_completed_event_from_another_program_stage.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrorsAndNoWarnings(importReport); } @@ -321,10 +347,11 @@ void shouldImportWithNoWarningsWhenAWarningIsTriggeredWithADataElementFromADiffe @Test void shouldNotImportWithWhenDataElementHasValue() throws IOException { showErrorWhenVariableHasValueRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_completed_enrollment_event.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, E1300); } @@ -332,10 +359,11 @@ void shouldNotImportWithWhenDataElementHasValue() throws IOException { @Test void shouldImportWithNoWarningsWhenDataElementHasNoValue() throws IOException { showErrorWhenVariableHasValueRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_enrollment_event_with_no_data_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrorsAndNoWarnings(importReport); } @@ -343,10 +371,11 @@ void shouldImportWithNoWarningsWhenDataElementHasNoValue() throws IOException { @Test void shouldImportWithNoWarningsWhenDataElementHasNullValue() throws IOException { showErrorWhenVariableHasValueRule(); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/programrule/tei_enrollment_event_with_null_data_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrorsAndNoWarnings(importReport); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentAttrValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentAttrValidationTest.java index c724d547332e..56fa2c88b94b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentAttrValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentAttrValidationTest.java @@ -36,6 +36,7 @@ import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -54,119 +55,130 @@ protected void initTest() throws IOException { injectAdminUser(); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_te-data_2.json"))); manager.flush(); } @Test void failValidationWhenTrackedEntityAttributeHasWrongOptionValue() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_with_invalid_option_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1125); } @Test void successValidationWhenTrackedEntityAttributeHasValidOptionValue() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_with_valid_option_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @Test void testAttributesMissingUid() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-missing-uuid.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1075); } @Test void testAttributesMissingValues() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-missing-value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1076); } @Test void testAttributesMissingTeA() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-non-existing.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1006); } @Test void testAttributesMissingMandatory() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-missing-mandatory.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1018); } @Test void testAttributesUniquenessInSameTei() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_unique_attr_same_tei.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @Test void testAttributesUniquenessAlreadyInDB() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_te_te-data_3.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_te-data_3.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); manager.flush(); manager.clear(); - params = fromJson("tracker/validations/enrollments_te_unique_attr_same_tei.json"); + trackerObjects = fromJson("tracker/validations/enrollments_te_unique_attr_same_tei.json"); - importReport = trackerImportService.importTracker(params); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); manager.flush(); manager.clear(); - params = fromJson("tracker/validations/enrollments_te_unique_attr_in_db.json"); + trackerObjects = fromJson("tracker/validations/enrollments_te_unique_attr_in_db.json"); - importReport = trackerImportService.importTracker(params); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1064); } @Test void testAttributesUniquenessInDifferentTeis() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_te_te-data_3.json"); - assertNoErrors(trackerImportService.importTracker(params)); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_te-data_3.json"); + assertNoErrors(trackerImportService.importTracker(new TrackerImportParams(), trackerObjects)); manager.flush(); manager.clear(); - params = fromJson("tracker/validations/enrollments_te_unique_attr.json"); + trackerObjects = fromJson("tracker/validations/enrollments_te_unique_attr.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasErrors(importReport, 2, ValidationCode.E1064); } @Test void testAttributesOnlyProgramAttrAllowed() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-only-program-attr.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1019); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentImportValidationTest.java index e66a95192ca9..9feb1f5ff0ad 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentImportValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentImportValidationTest.java @@ -40,9 +40,11 @@ import org.hisp.dhis.program.EnrollmentService; import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.TrackerType; +import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheatService; import org.hisp.dhis.tracker.imports.report.ImportReport; @@ -68,28 +70,33 @@ protected void initTest() throws IOException { injectAdminUser(); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_te-data.json"))); manager.flush(); } @Test void testEnrollmentValidationOkAll() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @Test void testPreheatOwnershipForSubsequentEnrollment() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); - TrackerImportParams secondParams = + TrackerObjects secondTrackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); - TrackerPreheat preheat = trackerPreheatService.preheat(secondParams); - secondParams + TrackerPreheat preheat = + trackerPreheatService.preheat( + secondTrackerObjects, new TrackerIdSchemeParams(), userService.getUser(ADMIN_USER_UID)); + secondTrackerObjects .getEnrollments() .forEach( e -> { @@ -113,31 +120,34 @@ void testDisplayIncidentDateTrueButDateValueIsInvalid() { @Test void testNoWriteAccessToOrg() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); User user = userService.getUser(USER_2); - params.setUser(user); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasErrors(importReport, 4, ValidationCode.E1000); } @Test void testOnlyProgramAttributesAllowedOnEnrollments() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_error_non_program_attr.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasErrors(importReport, 3, ValidationCode.E1019); } @Test void testAttributesOk() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_te_attr-data.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); assertEquals( @@ -153,45 +163,49 @@ void testAttributesOk() throws IOException { @Test void testDeleteCascadeEnrollments() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_te_attr-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_attr-data.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); manager.flush(); importEvents(); manager.flush(); - params = fromJson("tracker/validations/enrollments_te_attr-data.json"); + trackerObjects = fromJson("tracker/validations/enrollments_te_attr-data.json"); User user2 = userService.getUser(USER_4); - params.setUser(user2); + params.setUserId(user2.getUid()); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport trackerImportDeleteReport = trackerImportService.importTracker(params); + ImportReport trackerImportDeleteReport = + trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(trackerImportDeleteReport, ValidationCode.E1103, ValidationCode.E1091); } protected void importEvents() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/events-with-registration.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/events-with-registration.json"); + TrackerImportParams params = new TrackerImportParams(); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @Test void testActiveEnrollmentAlreadyExists() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_double-tei-enrollment_part1.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); - TrackerImportParams trackerImportParams1 = + TrackerObjects trackerObjects2 = fromJson("tracker/validations/enrollments_double-tei-enrollment_part2.json"); - importReport = trackerImportService.importTracker(trackerImportParams1); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects2); ValidationReport validationResult = importReport.getValidationReport(); @@ -200,19 +214,21 @@ void testActiveEnrollmentAlreadyExists() throws IOException { @Test void testEnrollmentDeleteOk() throws IOException { - TrackerImportParams paramsCreate = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); - ImportReport importReport = trackerImportService.importTracker(paramsCreate); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); manager.flush(); manager.clear(); - TrackerImportParams paramsDelete = + TrackerObjects deleteTrackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data-delete.json"); - paramsDelete.setImportStrategy(TrackerImportStrategy.DELETE); + params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReportDelete = trackerImportService.importTracker(paramsDelete); + ImportReport importReportDelete = + trackerImportService.importTracker(params, deleteTrackerObjects); assertNoErrors(importReportDelete); assertEquals(1, importReportDelete.getStats().getDeleted()); @@ -221,9 +237,11 @@ void testEnrollmentDeleteOk() throws IOException { /** Notes with no value are ignored */ @Test void testBadEnrollmentNoteNoValue() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_bad-note-no-value.json"); + TrackerObjects trackerObjects = + fromJson("tracker/validations/enrollments_bad-note-no-value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java index 650514afb414..3e5218410c38 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EnrollmentSecurityImportValidationTest.java @@ -53,6 +53,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; @@ -163,19 +164,21 @@ protected void initTest() throws IOException { injectAdminUser(); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_te-data.json"))); } @Test void testNoWriteAccessToOrg() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); User user = userService.getUser(USER_2); injectSecurityContext(user); - params.setUser(user); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasErrors(importReport, 4, ValidationCode.E1000); } @@ -193,11 +196,12 @@ void testUserNoAccessToTrackedEntity() throws IOException { createUserWithAuth("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA)); userService.addUser(user); injectSecurityContext(user); - TrackerImportParams params = fromJson("tracker/validations/enrollments_no-access-tei.json"); - params.setUser(user); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_no-access-tei.json"); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1104); } @@ -219,11 +223,13 @@ void testUserNoWriteAccessToProgram() throws IOException { createUserWithAuth("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA)); userService.addUser(user); injectSecurityContext(user); - TrackerImportParams params = fromJson("tracker/validations/enrollments_no-access-program.json"); - params.setUser(user); + TrackerObjects trackerObjects = + fromJson("tracker/validations/enrollments_no-access-program.json"); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1091); } @@ -241,11 +247,13 @@ void testUserHasWriteAccessToProgram() throws IOException { createUserWithAuth("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA)); userService.addUser(user); injectSecurityContext(user); - TrackerImportParams params = fromJson("tracker/validations/enrollments_no-access-program.json"); - params.setUser(user); + TrackerObjects trackerObjects = + fromJson("tracker/validations/enrollments_no-access-program.json"); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @@ -262,12 +270,13 @@ void testUserHasNoAccessToProgramTeiType() throws IOException { User user = createUserWithAuth("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA)); injectSecurityContext(user); - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_program-teitype-missmatch.json"); - params.setUser(user); + TrackerImportParams params = new TrackerImportParams(); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1104); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventImportValidationTest.java index 6faf730c1010..97701106ae92 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventImportValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventImportValidationTest.java @@ -59,6 +59,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.TrackerTypeReport; import org.hisp.dhis.user.User; @@ -85,9 +86,11 @@ protected void initTest() throws IOException { injectAdminUser(); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_te-data.json"))); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_enrollments-data.json"))); } @@ -95,6 +98,7 @@ protected void initTest() throws IOException { void testInvalidEnrollmentPreventsValidEventFromBeingCreated() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/invalid_enrollment_with_valid_event.json")); assertHasOnlyErrors(importReport, ValidationCode.E1070, ValidationCode.E5000); @@ -104,6 +108,7 @@ void testInvalidEnrollmentPreventsValidEventFromBeingCreated() throws IOExceptio void failValidationWhenTrackedEntityAttributeHasWrongOptionValue() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-with_invalid_option_value.json")); assertHasOnlyErrors(importReport, ValidationCode.E1125); @@ -113,6 +118,7 @@ void failValidationWhenTrackedEntityAttributeHasWrongOptionValue() throws IOExce void successWhenTrackedEntityAttributeHasValidOptionValue() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-with_valid_option_value.json")); assertNoErrors(importReport); @@ -122,6 +128,7 @@ void successWhenTrackedEntityAttributeHasValidOptionValue() throws IOException { void testEventValidationOkAll() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-with-registration.json")); assertNoErrors(importReport); @@ -131,6 +138,7 @@ void testEventValidationOkAll() throws IOException { void testEventValidationOkWithoutAttributeOptionCombo() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-without-attribute-option-combo.json")); assertNoErrors(importReport); @@ -138,24 +146,24 @@ void testEventValidationOkWithoutAttributeOptionCombo() throws IOException { @Test void testTrackerAndProgramEventUpdateSuccess() throws IOException { - TrackerImportParams trackerBundleParams = - fromJson("tracker/validations/program_and_tracker_events.json"); - assertNoErrors(trackerImportService.importTracker(trackerBundleParams)); + TrackerObjects trackerObjects = fromJson("tracker/validations/program_and_tracker_events.json"); + TrackerImportParams params = new TrackerImportParams(); + assertNoErrors(trackerImportService.importTracker(params, trackerObjects)); - trackerBundleParams.setImportStrategy(UPDATE); - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + params.setImportStrategy(UPDATE); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @Test void testCantWriteAccessCatCombo() throws IOException { - TrackerImportParams trackerImportParams = - fromJson("tracker/validations/events-cat-write-access.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/events-cat-write-access.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_6); - trackerImportParams.setUser(user); + params.setUserId(user.getUid()); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors( importReport, @@ -167,44 +175,45 @@ void testCantWriteAccessCatCombo() throws IOException { @Test void testNoWriteAccessToOrg() throws IOException { - TrackerImportParams trackerBundleParams = - fromJson("tracker/validations/events-with-registration.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/events-with-registration.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_2); - trackerBundleParams.setUser(user); - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + params.setUserId(user.getUid()); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1000); } @Test void testNonRepeatableProgramStage() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/events_non-repeatable-programstage_part1.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); - trackerImportParams = - fromJson("tracker/validations/events_non-repeatable-programstage_part2.json"); + trackerObjects = fromJson("tracker/validations/events_non-repeatable-programstage_part2.json"); - importReport = trackerImportService.importTracker(trackerImportParams); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1039); } @Test void shouldSuccessfullyImportRepeatedEventsInEventProgram() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/program_events_non-repeatable-programstage_part1.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); - trackerImportParams = + trackerObjects = fromJson("tracker/validations/program_events_non-repeatable-programstage_part2.json"); - importReport = trackerImportService.importTracker(trackerImportParams); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @@ -219,6 +228,7 @@ void testWrongScheduledDateString() { void testEventProgramHasNonDefaultCategoryCombo() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_non-default-combo.json")); assertHasOnlyErrors(importReport, ValidationCode.E1055); @@ -228,6 +238,7 @@ void testEventProgramHasNonDefaultCategoryCombo() throws IOException { void testCategoryOptionComboNotFound() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_cant-find-cat-opt-combo.json")); assertHasOnlyErrors(importReport, ValidationCode.E1115); @@ -237,6 +248,7 @@ void testCategoryOptionComboNotFound() throws IOException { void testCategoryOptionComboNotFoundGivenSubsetOfCategoryOptions() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_cant-find-aoc-with-subset-of-cos.json")); assertHasOnlyErrors(importReport, ValidationCode.E1117); @@ -246,6 +258,7 @@ void testCategoryOptionComboNotFoundGivenSubsetOfCategoryOptions() throws IOExce void testCOFoundButAOCNotFound() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_cant-find-aoc-but-co-exists.json")); assertHasOnlyErrors(importReport, ValidationCode.E1115); @@ -255,6 +268,7 @@ void testCOFoundButAOCNotFound() throws IOException { void testCategoryOptionsNotFound() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_cant-find-cat-option.json")); assertHasOnlyErrors(importReport, ValidationCode.E1116); @@ -264,6 +278,7 @@ void testCategoryOptionsNotFound() throws IOException { void testAttributeCategoryOptionNotInProgramCC() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-aoc-not-in-program-cc.json")); assertHasOnlyErrors(importReport, ValidationCode.E1054); @@ -273,6 +288,7 @@ void testAttributeCategoryOptionNotInProgramCC() throws IOException { void testAttributeCategoryOptionAndCODoNotMatch() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events-aoc-and-co-dont-match.json")); assertHasOnlyErrors(importReport, ValidationCode.E1117); @@ -283,6 +299,7 @@ void testAttributeCategoryOptionCannotBeFoundForEventProgramCCAndGivenCategoryOp throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson( "tracker/validations/events_cant-find-cat-option-combo-for-given-cc-and-co.json")); @@ -293,6 +310,7 @@ void testAttributeCategoryOptionCannotBeFoundForEventProgramCCAndGivenCategoryOp void testWrongDatesInCatCombo() throws IOException { ImportReport importReport = trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/events_combo-date-wrong.json")); assertHasOnlyErrors(importReport, ValidationCode.E1056, ValidationCode.E1057); @@ -362,41 +380,43 @@ private void testDeletedEventFails(TrackerImportStrategy importStrategy) { assertNotNull(event); // When -> Soft-delete the event programStageServiceInstance.deleteEvent(event); - TrackerImportParams trackerBundleParams = - fromJson("tracker/validations/events-with-notes-data.json"); - trackerBundleParams.setImportStrategy(importStrategy); + TrackerObjects trackerObjects = fromJson("tracker/validations/events-with-notes-data.json"); + TrackerImportParams params = new TrackerImportParams(); + params.setImportStrategy(importStrategy); // When - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1082); } @Test void testEventDeleteOk() throws IOException { - TrackerImportParams trackerBundleParams = - fromJson("tracker/validations/events-with-registration.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/events-with-registration.json"); + TrackerImportParams params = new TrackerImportParams(); - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); manager.flush(); manager.clear(); - TrackerImportParams paramsDelete = fromJson("tracker/validations/event-data-delete.json"); - paramsDelete.setImportStrategy(DELETE); + TrackerObjects deleteTrackerObjects = fromJson("tracker/validations/event-data-delete.json"); + params.setImportStrategy(DELETE); - ImportReport importReportDelete = trackerImportService.importTracker(paramsDelete); + ImportReport importReportDelete = + trackerImportService.importTracker(params, deleteTrackerObjects); assertNoErrors(importReportDelete); assertEquals(1, importReportDelete.getStats().getDeleted()); } private ImportReport createEvent(String jsonPayload) throws IOException { // Given - TrackerImportParams trackerBundleParams = fromJson(jsonPayload); - trackerBundleParams.setImportStrategy(CREATE_AND_UPDATE); + TrackerObjects trackerObjects = fromJson(jsonPayload); + TrackerImportParams params = new TrackerImportParams(); + params.setImportStrategy(CREATE_AND_UPDATE); // When - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); // Then assertNoErrors(importReport); return importReport; diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java index f870d492eb17..250bf1a50eb4 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/EventSecurityImportValidationTest.java @@ -63,6 +63,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; @@ -127,9 +128,11 @@ protected void initTest() throws IOException { injectAdminUser(); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_te-data.json"))); assertNoErrors( trackerImportService.importTracker( + new TrackerImportParams(), fromJson("tracker/validations/enrollments_te_enrollments-data.json"))); manager.flush(); } @@ -217,14 +220,14 @@ private void setupMetadata() { @Test void testNoWriteAccessToProgramStage() throws IOException { setupMetadata(); - TrackerImportParams trackerBundleParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/events_error-no-programStage-access.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_3); - trackerBundleParams.setUser(user); + params.setUserId(user.getUid()); user.addOrganisationUnit(organisationUnitA); manager.update(user); - trackerBundleParams.setUser(user); - ImportReport importReport = trackerImportService.importTracker(trackerBundleParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1095, ValidationCode.E1096); } @@ -232,16 +235,15 @@ void testNoWriteAccessToProgramStage() throws IOException { @Test void testNoUncompleteEventAuth() throws IOException { setupMetadata(); - TrackerImportParams params = fromJson("tracker/validations/events_error-no-uncomplete.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/events_error-no-uncomplete.json"); + TrackerImportParams params = new TrackerImportParams(); params.setImportStrategy(TrackerImportStrategy.CREATE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); // Change just inserted Event to status COMPLETED... Event zwwuwNp6gVd = programStageServiceInstance.getEvent("ZwwuwNp6gVd"); zwwuwNp6gVd.setStatus(EventStatus.COMPLETED); manager.update(zwwuwNp6gVd); - TrackerImportParams trackerBundleParams = - fromJson("tracker/validations/events_error-no-uncomplete.json"); programA.setPublicAccess(AccessStringHelper.FULL); manager.update(programA); programStageA.setPublicAccess(AccessStringHelper.FULL); @@ -253,9 +255,9 @@ void testNoUncompleteEventAuth() throws IOException { manager.update(user); manager.flush(); manager.clear(); - trackerBundleParams.setUserId(user.getUid()); - trackerBundleParams.setImportStrategy(TrackerImportStrategy.UPDATE); - importReport = trackerImportService.importTracker(trackerBundleParams); + params.setUserId(user.getUid()); + params.setImportStrategy(TrackerImportStrategy.UPDATE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1083); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaEncryptionValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaEncryptionValidationTest.java index f8bc741c6541..dcf6a55beaba 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaEncryptionValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaEncryptionValidationTest.java @@ -35,6 +35,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -50,32 +51,33 @@ protected void initTest() throws IOException { @Test void testUniqueFailInOrgUnit() throws IOException { - TrackerImportParams trackerImportParams = + TrackerImportParams params = new TrackerImportParams(); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_unique_data_in_country.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); - trackerImportParams = + trackerObjects = fromJson("tracker/validations/te-program_with_tea_unique_data_in_country.json"); - trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); - importReport = trackerImportService.importTracker(trackerImportParams); + params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); - trackerImportParams = - fromJson("tracker/validations/te-program_with_tea_unique_data_in_region.json"); - importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/validations/te-program_with_tea_unique_data_in_region.json"); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @Test void testUniqueFail() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_unique_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); - trackerImportParams = fromJson("tracker/validations/te-program_with_tea_unique_data2.json"); + trackerObjects = fromJson("tracker/validations/te-program_with_tea_unique_data2.json"); - importReport = trackerImportService.importTracker(trackerImportParams); + importReport = trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1064); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaValidationTest.java index ca60d780448d..f13c725ba1a7 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TeTaValidationTest.java @@ -45,6 +45,7 @@ import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -80,9 +81,9 @@ void testTrackedEntityProgramAttributeFileResourceValue() throws IOException { File file = File.createTempFile("file-resource", "test"); fileResourceService.saveFileResource(fileResource, file); assertFalse(fileResource.isAssigned()); - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_fileresource_data.json"); - trackerImportService.importTracker(trackerImportParams); + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); List trackedEntities = manager.getAll(TrackedEntity.class); assertEquals(1, trackedEntities.size()); TrackedEntity trackedEntity = trackedEntities.get(0); @@ -106,9 +107,9 @@ void testFileAlreadyAssign() throws IOException { File file = File.createTempFile("file-resource", "test"); fileResourceService.saveFileResource(fileResource, file); assertFalse(fileResource.isAssigned()); - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_fileresource_data.json"); - trackerImportService.importTracker(trackerImportParams); + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); List trackedEntities = manager.getAll(TrackedEntity.class); assertEquals(1, trackedEntities.size()); TrackedEntity trackedEntity = trackedEntities.get(0); @@ -117,17 +118,18 @@ void testFileAlreadyAssign() throws IOException { assertEquals(1, attributeValues.size()); fileResource = fileResourceService.getFileResource(fileResource.getUid()); assertTrue(fileResource.isAssigned()); - trackerImportParams = - fromJson("tracker/validations/te-program_with_tea_fileresource_data2.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + trackerObjects = fromJson("tracker/validations/te-program_with_tea_fileresource_data2.json"); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1009); } @Test void testNoFileRef() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_fileresource_data.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1084); List trackedEntities = manager.getAll(TrackedEntity.class); @@ -136,40 +138,44 @@ void testNoFileRef() throws IOException { @Test void testTeaMaxTextValueLength() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_too_long_text_value.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1077); } @Test void testTeaInvalidFormat() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_invalid_format_value.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1085); } @Test void testTeaInvalidImage() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_invalid_image_value.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1085, ValidationCode.E1007); } @Test void testTeaIsNull() throws IOException { - TrackerImportParams trackerImportParams = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-program_with_tea_invalid_value_isnull.json"); - ImportReport importReport = trackerImportService.importTracker(trackerImportParams); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1076); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TrackedEntityImportValidationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TrackedEntityImportValidationTest.java index a32b48287d1c..d5f62d263553 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TrackedEntityImportValidationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/validation/TrackedEntityImportValidationTest.java @@ -45,6 +45,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.tracker.imports.TrackerImportStrategy; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.user.User; import org.junit.jupiter.api.Test; @@ -66,47 +67,53 @@ protected void initTest() throws IOException { @Test void failValidationWhenTrackedEntityAttributeHasWrongOptionValue() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-with_invalid_option_value.json"); + TrackerObjects trackerObjects = + fromJson("tracker/validations/te-with_invalid_option_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1125); } @Test void successValidationWhenTrackedEntityAttributeHasValidOptionValue() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-with_valid_option_value.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-with_valid_option_value.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @Test void failValidationWhenTrackedEntityAttributesHaveSameUniqueValues() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-with_unique_attributes.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-with_unique_attributes.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertHasErrors(importReport, 2, ValidationCode.E1064); } @Test void testTeValidationOkAll() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_with_different_ou.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } @Test void testNoCreateTeiAccessOutsideCaptureScopeOu() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_with_different_ou.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_7); - params.setUser(user); + params.setUserId(user.getUid()); params.setAtomicMode(AtomicMode.OBJECT); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1000); assertEquals(2, importReport.getStats().getCreated()); assertEquals(1, importReport.getStats().getIgnored()); @@ -114,8 +121,9 @@ void testNoCreateTeiAccessOutsideCaptureScopeOu() throws IOException { @Test void testUpdateAccessInSearchScopeOu() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_with_different_ou.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertEquals(3, importReport.getStats().getCreated()); // For some reason teiSearchOrgunits is not created properly from @@ -125,29 +133,30 @@ void testUpdateAccessInSearchScopeOu() throws IOException { user.setTeiSearchOrganisationUnits(new HashSet<>(user.getDataViewOrganisationUnits())); userService.updateUser(user); dbmsManager.clearSession(); - params = fromJson("tracker/validations/te-data_with_different_ou.json"); + trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); user = userService.getUser(USER_8); - params.setUser(user); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); params.setAtomicMode(AtomicMode.OBJECT); - importReport = trackerImportService.importTracker(params); + importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertEquals(3, importReport.getStats().getUpdated()); } @Test void testNoUpdateAccessOutsideSearchScopeOu() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_with_different_ou.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); assertEquals(3, importReport.getStats().getCreated()); dbmsManager.clearSession(); - params = fromJson("tracker/validations/te-data_with_different_ou.json"); + trackerObjects = fromJson("tracker/validations/te-data_with_different_ou.json"); User user = userService.getUser(USER_7); - params.setUser(user); + params.setUserId(user.getUid()); params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE); params.setAtomicMode(AtomicMode.OBJECT); - importReport = trackerImportService.importTracker(params); + importReport = trackerImportService.importTracker(params, trackerObjects); assertHasOnlyErrors(importReport, ValidationCode.E1003); assertEquals(2, importReport.getStats().getUpdated()); assertEquals(1, importReport.getStats().getIgnored()); @@ -155,81 +164,89 @@ void testNoUpdateAccessOutsideSearchScopeOu() throws IOException { @Test void testNoWriteAccessInAcl() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_ok.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_ok.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_1); - params.setUser(user); + params.setUserId(user.getUid()); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasErrors(importReport, 13, ValidationCode.E1001); } @Test void testWriteAccessInAclViaUserGroup() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_ok.json"); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_ok.json"); + TrackerImportParams params = new TrackerImportParams(); User user = userService.getUser(USER_3); params.setUserId(user.getUid()); - params.setUser(user); + params.setUserId(user.getUid()); user.setPassword("user4password"); injectSecurityContext(user); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @Test void testGeoOk() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data_error_geo-ok.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_error_geo-ok.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); } @Test void testTeAttrNonExistentAttr() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data_error_attr-non-existing.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasErrors(importReport, 2, ValidationCode.E1006); } @Test void testDeleteCascadeEnrollments() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/enrollments_te_te-data.json"); - assertNoErrors(trackerImportService.importTracker(params)); + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_te-data.json"); + TrackerImportParams params = new TrackerImportParams(); + assertNoErrors(trackerImportService.importTracker(params, trackerObjects)); importEnrollments(); manager.flush(); manager.clear(); - params = fromJson("tracker/validations/enrollments_te_te-data.json"); + trackerObjects = fromJson("tracker/validations/enrollments_te_te-data.json"); User user2 = userService.getUser(USER_4); - params.setUser(user2); + params.setUserId(user2.getUid()); params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertHasErrors(importReport, 2, ValidationCode.E1100); } @Test void testTeDeleteOk() throws IOException { - TrackerImportParams params = fromJson("tracker/validations/te-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + TrackerObjects trackerObjects = fromJson("tracker/validations/te-data.json"); + TrackerImportParams params = new TrackerImportParams(); + ImportReport importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); manager.flush(); manager.clear(); - TrackerImportParams paramsDelete = fromJson("tracker/validations/te-data-delete.json"); - paramsDelete.setImportStrategy(TrackerImportStrategy.DELETE); + TrackerObjects deleteTrackerObjects = fromJson("tracker/validations/te-data-delete.json"); + params.setImportStrategy(TrackerImportStrategy.DELETE); - ImportReport importReportDelete = trackerImportService.importTracker(paramsDelete); + ImportReport importReportDelete = + trackerImportService.importTracker(params, deleteTrackerObjects); assertNoErrors(importReportDelete); assertEquals(1, importReportDelete.getStats().getDeleted()); } protected void importEnrollments() throws IOException { - TrackerImportParams params = + TrackerObjects trackerObjects = fromJson("tracker/validations/enrollments_te_enrollments-data.json"); - ImportReport importReport = trackerImportService.importTracker(params); + ImportReport importReport = + trackerImportService.importTracker(new TrackerImportParams(), trackerObjects); assertNoErrors(importReport); } } diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java index d0a0837fe6bf..62d15b1863a8 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java @@ -28,7 +28,7 @@ package org.hisp.dhis.webapi.controller.tracker.imports; import org.hisp.dhis.web.HttpStatus; -import org.hisp.dhis.webapi.DhisControllerConvenienceTest; +import org.hisp.dhis.webapi.DhisControllerIntegrationTest; import org.junit.jupiter.api.Test; /** @@ -37,7 +37,7 @@ * * @author Jan Bernitt */ -class TrackerImportControllerTest extends DhisControllerConvenienceTest { +class TrackerImportControllerTest extends DhisControllerIntegrationTest { @Test void shouldSucceedWhenAllValidParametersArePassed() { assertWebMessage( diff --git a/dhis-2/dhis-web-api/pom.xml b/dhis-2/dhis-web-api/pom.xml index 6a0c8894417b..10823ccd10f0 100644 --- a/dhis-2/dhis-web-api/pom.xml +++ b/dhis-2/dhis-web-api/pom.xml @@ -214,10 +214,6 @@ org.hisp.dhis.rules rule-engine - - org.hisp.dhis - dhis-support-artemis - org.hisp.dhis dhis-service-acl diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/deprecated/tracker/TrackedEntityInstanceController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/deprecated/tracker/TrackedEntityInstanceController.java index 50f0b1fc0542..11a5d4704f32 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/deprecated/tracker/TrackedEntityInstanceController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/deprecated/tracker/TrackedEntityInstanceController.java @@ -73,6 +73,7 @@ import org.hisp.dhis.dxf2.webmessage.WebMessage; import org.hisp.dhis.dxf2.webmessage.WebMessageException; import org.hisp.dhis.feedback.BadRequestException; +import org.hisp.dhis.feedback.ConflictException; import org.hisp.dhis.fieldfilter.FieldFilterParams; import org.hisp.dhis.fieldfilter.FieldFilterService; import org.hisp.dhis.fileresource.FileResource; @@ -205,7 +206,7 @@ public void getAttributeImage( @RequestParam(required = false) Integer height, @RequestParam(required = false) ImageFileDimension dimension, HttpServletResponse response) - throws WebMessageException { + throws WebMessageException, ConflictException { User user = currentUserService.getCurrentUser(); TrackedEntity trackedEntity = instanceService.getTrackedEntity(teiId); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportJob.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportJob.java index 20c76b3ae303..1aaa4126861f 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportJob.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportJob.java @@ -82,7 +82,7 @@ public void execute(JobConfiguration config, JobProgress progress) { MetadataImportParams params = (MetadataImportParams) config.getJobParameters(); progress.startingStage("Loading file resource"); FileResource data = - progress.runStage(() -> fileResourceService.getFileResource(config.getUid())); + progress.runStage(() -> fileResourceService.getExistingFileResource(config.getUid())); progress.startingStage("Loading file content"); try (InputStream input = progress.runStage(() -> fileResourceService.getFileResourceContent(data))) { diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/Body.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/Body.java index 6ab8f2d79861..b60d474a7065 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/Body.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/Body.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import lombok.AllArgsConstructor; @@ -54,7 +55,7 @@ @NoArgsConstructor @AllArgsConstructor @JsonDeserialize(converter = BodyConverter.class) -class Body { +class Body implements Serializable { /** Tracked entities to import. */ @JsonProperty @Builder.Default private final List trackedEntities = new ArrayList<>(); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerAsyncImporter.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerAsyncImporter.java deleted file mode 100644 index 50ecec4368ad..000000000000 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerAsyncImporter.java +++ /dev/null @@ -1,64 +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.webapi.controller.tracker.imports; - -import javax.annotation.Nonnull; -import lombok.RequiredArgsConstructor; -import org.hisp.dhis.artemis.MessageManager; -import org.hisp.dhis.artemis.Topics; -import org.hisp.dhis.security.AuthenticationSerializer; -import org.hisp.dhis.tracker.imports.TrackerImportParams; -import org.hisp.dhis.tracker.imports.job.TrackerMessage; -import org.hisp.dhis.tracker.imports.report.ImportReport; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; - -/** - * @author Luca Cambi - */ -@Component -@RequiredArgsConstructor -public class TrackerAsyncImporter { - @Nonnull private final MessageManager messageManager; - - public ImportReport importTracker( - TrackerImportParams params, Authentication authentication, String uid) { - TrackerMessage trackerMessage = - TrackerMessage.builder() - .trackerImportParams(params) - .authentication(AuthenticationSerializer.serialize(authentication)) - .uid(uid) - .build(); - - messageManager.sendQueue(Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, trackerMessage); - - return null; // empty report is not - // returned - // in async creation - } -} diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportController.java index 2610b91c51ac..e882355a4df9 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportController.java @@ -32,28 +32,33 @@ import static org.hisp.dhis.webapi.utils.ContextUtils.setNoStore; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.ObjectOutputStream; import java.util.Deque; import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.DhisApiVersion; import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.commons.util.StreamUtils; import org.hisp.dhis.dxf2.webmessage.WebMessage; +import org.hisp.dhis.feedback.ConflictException; import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.scheduling.JobConfiguration; +import org.hisp.dhis.scheduling.JobConfigurationService; +import org.hisp.dhis.scheduling.JobSchedulerService; import org.hisp.dhis.scheduling.JobType; import org.hisp.dhis.system.notification.Notification; import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.tracker.imports.TrackerBundleReportMode; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; -import org.hisp.dhis.tracker.imports.job.TrackerJobWebMessageResponse; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.Status; import org.hisp.dhis.user.CurrentUser; @@ -65,7 +70,7 @@ import org.locationtech.jts.io.ParseException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.util.MimeType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -87,33 +92,60 @@ public class TrackerImportController { static final String TRACKER_JOB_ADDED = "Tracker job added"; - private final TrackerSyncImporter syncImporter; - - private final TrackerAsyncImporter asyncImporter; - private final TrackerImportService trackerImportService; private final CsvService csvEventService; private final Notifier notifier; + private final JobSchedulerService jobSchedulerService; + + private final JobConfigurationService jobConfigurationService; + @PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) @ResponseBody public WebMessage asyncPostJsonTracker( HttpServletRequest request, RequestParams requestParams, @CurrentUser User currentUser, - @RequestBody Body body) { - String jobId = CodeGenerator.generateUid(); + @RequestBody Body body) + throws ConflictException, NotFoundException, IOException { TrackerImportParams trackerImportParams = - TrackerImportParamsMapper.trackerImportParams( - true, jobId, currentUser.getUid(), requestParams, body); + TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), requestParams); + TrackerObjects trackerObjects = + TrackerImportParamsMapper.trackerObjects(body, trackerImportParams.getIdSchemes()); + + return startAsyncTracker( + trackerImportParams, + MimeType.valueOf("application/json"), + trackerObjects, + currentUser, + request); + } - asyncImporter.importTracker( - trackerImportParams, SecurityContextHolder.getContext().getAuthentication(), jobId); + private WebMessage startAsyncTracker( + TrackerImportParams params, + MimeType contentType, + TrackerObjects trackerObjects, + User user, + HttpServletRequest request) + throws IOException, ConflictException, NotFoundException { + JobConfiguration config = new JobConfiguration(JobType.TRACKER_IMPORT_JOB); + config.setExecutedBy(user.getUid()); + config.setJobParameters(params); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); - String location = ContextUtils.getRootPath(request) + "/tracker/jobs/" + jobId; + oos.writeObject(trackerObjects); + + oos.flush(); + oos.close(); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + + jobSchedulerService.executeNow(jobConfigurationService.create(config, contentType, is)); + String jobId = config.getUid(); + String location = ContextUtils.getRootPath(request) + "/tracker/jobs/" + jobId; return ok(TRACKER_JOB_ADDED) .setLocation("/tracker/jobs/" + jobId) .setResponse(TrackerJobWebMessageResponse.builder().id(jobId).location(location).build()); @@ -125,12 +157,13 @@ public WebMessage asyncPostJsonTracker( params = {"async=false"}) public ResponseEntity syncPostJsonTracker( RequestParams requestParams, @CurrentUser User currentUser, @RequestBody Body body) { - String jobId = CodeGenerator.generateUid(); - TrackerImportParams trackerImportParams = - TrackerImportParamsMapper.trackerImportParams( - false, jobId, currentUser.getUid(), requestParams, body); - - ImportReport importReport = syncImporter.importTracker(trackerImportParams); + TrackerImportParams params = + TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), requestParams); + TrackerObjects trackerObjects = + TrackerImportParamsMapper.trackerObjects(body, params.getIdSchemes()); + ImportReport importReport = + trackerImportService.buildImportReport( + trackerImportService.importTracker(params, trackerObjects), params.getReportMode()); ResponseEntity.BodyBuilder builder = importReport.getStatus() == Status.ERROR @@ -150,26 +183,25 @@ public WebMessage asyncPostCsvTracker( RequestParams importRequest, @CurrentUser User currentUser, @RequestParam(required = false, defaultValue = "true") boolean skipFirst) - throws IOException, ParseException { + throws IOException, ParseException, ConflictException, NotFoundException { InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()); List events = csvEventService.read(inputStream, skipFirst); Body body = Body.builder().events(events).build(); - String jobId = CodeGenerator.generateUid(); TrackerImportParams trackerImportParams = - TrackerImportParamsMapper.trackerImportParams( - true, jobId, currentUser.getUid(), importRequest, body); + TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), importRequest); - asyncImporter.importTracker( - trackerImportParams, SecurityContextHolder.getContext().getAuthentication(), jobId); - - String location = ContextUtils.getRootPath(request) + "/tracker/jobs/" + jobId; + TrackerObjects trackerObjects = + TrackerImportParamsMapper.trackerObjects(body, trackerImportParams.getIdSchemes()); - return ok(TRACKER_JOB_ADDED) - .setLocation("/tracker/jobs/" + jobId) - .setResponse(TrackerJobWebMessageResponse.builder().id(jobId).location(location).build()); + return startAsyncTracker( + trackerImportParams, + MimeType.valueOf("application/csv"), + trackerObjects, + currentUser, + request); } @PostMapping( @@ -189,12 +221,14 @@ public ResponseEntity syncPostCsvTracker( List events = csvEventService.read(inputStream, skipFirst); Body body = Body.builder().events(events).build(); - String jobId = CodeGenerator.generateUid(); TrackerImportParams trackerImportParams = - TrackerImportParamsMapper.trackerImportParams( - false, jobId, currentUser.getUid(), importRequest, body); - - ImportReport importReport = syncImporter.importTracker(trackerImportParams); + TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), importRequest); + TrackerObjects trackerObjects = + TrackerImportParamsMapper.trackerObjects(body, trackerImportParams.getIdSchemes()); + ImportReport importReport = + trackerImportService.buildImportReport( + trackerImportService.importTracker(trackerImportParams, trackerObjects), + trackerImportParams.getReportMode()); ResponseEntity.BodyBuilder builder = importReport.getStatus() == Status.ERROR @@ -221,6 +255,6 @@ public ImportReport getJobReport( return Optional.ofNullable(notifier.getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid)) .map(report -> trackerImportService.buildImportReport((ImportReport) report, reportMode)) - .orElseThrow(() -> new NotFoundException(JobConfiguration.class, uid)); + .orElseThrow(() -> new NotFoundException("Summary for job " + uid + " does not exist")); } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportJob.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportJob.java new file mode 100644 index 000000000000..d144c60e0970 --- /dev/null +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportJob.java @@ -0,0 +1,102 @@ +/* + * 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.webapi.controller.tracker.imports; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.util.function.Consumer; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.hisp.dhis.fileresource.FileResource; +import org.hisp.dhis.fileresource.FileResourceService; +import org.hisp.dhis.scheduling.Job; +import org.hisp.dhis.scheduling.JobConfiguration; +import org.hisp.dhis.scheduling.JobProgress; +import org.hisp.dhis.scheduling.JobType; +import org.hisp.dhis.system.notification.Notifier; +import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.TrackerImportService; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; +import org.hisp.dhis.tracker.imports.report.ImportReport; +import org.hisp.dhis.tracker.imports.report.Stats; +import org.hisp.dhis.tracker.imports.report.Status; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class TrackerImportJob implements Job { + private final TrackerImportService trackerImportService; + private final FileResourceService fileResourceService; + private final Notifier notifier; + + @Override + public JobType getJobType() { + return JobType.TRACKER_IMPORT_JOB; + } + + @Override + public void execute(JobConfiguration config, JobProgress progress) { + progress.startingProcess("Tracker import started"); + TrackerImportParams params = (TrackerImportParams) config.getJobParameters(); + progress.startingStage("Loading file resource"); + FileResource data = + progress.runStage(() -> fileResourceService.getExistingFileResource(config.getUid())); + progress.startingStage("Loading file content"); + try (InputStream input = + progress.runStage(() -> fileResourceService.getFileResourceContent(data))) { + ImportReport report = + trackerImportService.importTracker(params, toTrackerObjects(input), progress); + if (report == null) { + progress.failedProcess("Import failed, no summary available"); + return; + } + notifier.addJobSummary(config, report, ImportReport.class); + Stats stats = report.getStats(); + Consumer endProcess = + report.getStatus() == Status.ERROR ? progress::failedProcess : progress::completedProcess; + endProcess.accept( + "Import complete with status %s, %d created, %d updated, %d deleted, %d ignored" + .formatted( + report.getStatus(), + stats.getCreated(), + stats.getUpdated(), + stats.getDeleted(), + stats.getIgnored())); + } catch (Exception ex) { + progress.failedProcess(ex); + } + } + + private TrackerObjects toTrackerObjects(InputStream input) + throws IOException, ClassNotFoundException { + ObjectInputStream ois = new ObjectInputStream(input); + return (TrackerObjects) ois.readObject(); + } +} diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapper.java index 5eb64ff0609d..e1de076a1d4b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapper.java @@ -27,11 +27,10 @@ */ package org.hisp.dhis.webapi.controller.tracker.imports; -import org.hisp.dhis.scheduling.JobConfiguration; -import org.hisp.dhis.scheduling.JobType; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.TrackerImportParams; +import org.hisp.dhis.tracker.imports.domain.TrackerObjects; import org.mapstruct.factory.Mappers; public class TrackerImportParamsMapper { @@ -46,10 +45,19 @@ public class TrackerImportParamsMapper { private static final RelationshipMapper RELATIONSHIP_MAPPER = Mappers.getMapper(RelationshipMapper.class); + public static TrackerObjects trackerObjects(Body body, TrackerIdSchemeParams idSchemeParams) { + return TrackerObjects.builder() + .trackedEntities( + TRACKED_ENTITY_MAPPER.fromCollection(body.getTrackedEntities(), idSchemeParams)) + .enrollments(ENROLLMENT_MAPPER.fromCollection(body.getEnrollments(), idSchemeParams)) + .events(EVENT_MAPPER.fromCollection(body.getEvents(), idSchemeParams)) + .relationships(RELATIONSHIP_MAPPER.fromCollection(body.getRelationships(), idSchemeParams)) + .build(); + } + private TrackerImportParamsMapper() {} - public static TrackerImportParams trackerImportParams( - boolean isAsync, String jobId, String userId, RequestParams request, Body params) { + public static TrackerImportParams trackerImportParams(String userId, RequestParams request) { TrackerIdSchemeParam defaultIdSchemeParam = request.getIdScheme(); TrackerIdSchemeParams idSchemeParams = TrackerIdSchemeParams.builder() @@ -77,21 +85,7 @@ public static TrackerImportParams trackerImportParams( .skipSideEffects(request.isSkipSideEffects()) .skipRuleEngine(request.isSkipRuleEngine()) .reportMode(request.getReportMode()) - .userId(userId) - .trackedEntities( - TRACKED_ENTITY_MAPPER.fromCollection(params.getTrackedEntities(), idSchemeParams)) - .enrollments(ENROLLMENT_MAPPER.fromCollection(params.getEnrollments(), idSchemeParams)) - .events(EVENT_MAPPER.fromCollection(params.getEvents(), idSchemeParams)) - .relationships( - RELATIONSHIP_MAPPER.fromCollection(params.getRelationships(), idSchemeParams)); - - if (!isAsync) { - JobConfiguration jobConfiguration = - new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, userId); - jobConfiguration.setUid(jobId); - paramsBuilder.jobConfiguration(jobConfiguration); - } - + .userId(userId); return paramsBuilder.build(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerJobWebMessageResponse.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java similarity index 92% rename from dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerJobWebMessageResponse.java rename to dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java index 630f30f46e4a..3251757dc7ba 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/job/TrackerJobWebMessageResponse.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,16 +25,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.tracker.imports.job; +package org.hisp.dhis.webapi.controller.tracker.imports; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; import org.hisp.dhis.webmessage.WebMessageResponse; -/** - * @author Morten Olav Hansen - */ @Data @Builder public class TrackerJobWebMessageResponse implements WebMessageResponse { diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java index acb52aa69679..67610dbe6e05 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportControllerTest.java @@ -29,6 +29,7 @@ import static java.util.Collections.singletonList; import static org.hamcrest.Matchers.hasSize; +import static org.hisp.dhis.scheduling.JobType.TRACKER_IMPORT_JOB; import static org.hisp.dhis.webapi.controller.tracker.imports.TrackerImportController.TRACKER_JOB_ADDED; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -50,7 +51,8 @@ import org.hisp.dhis.feedback.NotFoundException; import org.hisp.dhis.render.DefaultRenderService; import org.hisp.dhis.render.RenderService; -import org.hisp.dhis.scheduling.JobType; +import org.hisp.dhis.scheduling.JobConfigurationService; +import org.hisp.dhis.scheduling.JobSchedulerService; import org.hisp.dhis.schema.SchemaService; import org.hisp.dhis.system.notification.Notification; import org.hisp.dhis.system.notification.Notifier; @@ -58,7 +60,6 @@ import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.PersistenceReport; import org.hisp.dhis.tracker.imports.report.Status; -import org.hisp.dhis.tracker.imports.report.TimingsStats; import org.hisp.dhis.tracker.imports.report.ValidationReport; import org.hisp.dhis.webapi.controller.CrudControllerAdvice; import org.hisp.dhis.webapi.controller.tracker.ControllerSupport; @@ -85,14 +86,14 @@ class TrackerImportControllerTest { @Mock private DefaultTrackerImportService trackerImportService; - @Mock private TrackerSyncImporter syncImporter; - - @Mock private TrackerAsyncImporter asyncImporter; - @Mock private CsvService csvEventService; @Mock private Notifier notifier; + @Mock private JobSchedulerService jobSchedulerService; + + @Mock private JobConfigurationService jobConfigurationService; + private RenderService renderService; @BeforeEach @@ -106,7 +107,11 @@ public void setUp() { // Controller under test final TrackerImportController controller = new TrackerImportController( - syncImporter, asyncImporter, trackerImportService, csvEventService, notifier); + trackerImportService, + csvEventService, + notifier, + jobSchedulerService, + jobConfigurationService); mockMvc = MockMvcBuilders.standaloneSetup(controller) @@ -140,19 +145,17 @@ void verifyAsyncForCsv() throws Exception { .andExpect(content().contentType("application/json")); verify(csvEventService).read(any(), eq(true)); - verify(asyncImporter).importTracker(any(), any(), any()); } @Test void verifySyncResponseShouldBeOkWhenImportReportStatusIsOk() throws Exception { // When - when(syncImporter.importTracker(any())) + when(trackerImportService.buildImportReport(any(), any())) .thenReturn( ImportReport.withImportCompleted( Status.OK, PersistenceReport.emptyReport(), ValidationReport.emptyReport(), - new TimingsStats(), new HashMap<>())); // Then @@ -170,7 +173,7 @@ void verifySyncResponseShouldBeOkWhenImportReportStatusIsOk() throws Exception { .getResponse() .getContentAsString(); - verify(syncImporter).importTracker(any()); + verify(trackerImportService).importTracker(any(), any()); try { renderService.fromJson(contentAsString, ImportReport.class); @@ -182,13 +185,12 @@ void verifySyncResponseShouldBeOkWhenImportReportStatusIsOk() throws Exception { @Test void verifySyncResponseForCsvShouldBeOkWhenImportReportStatusIsOk() throws Exception { // When - when(syncImporter.importTracker(any())) + when(trackerImportService.buildImportReport(any(), any())) .thenReturn( ImportReport.withImportCompleted( Status.OK, PersistenceReport.emptyReport(), ValidationReport.emptyReport(), - new TimingsStats(), new HashMap<>())); // Then @@ -206,7 +208,7 @@ void verifySyncResponseForCsvShouldBeOkWhenImportReportStatusIsOk() throws Excep .getContentAsString(); verify(csvEventService).read(any(), eq(true)); - verify(syncImporter).importTracker(any()); + verify(trackerImportService).importTracker(any(), any()); try { renderService.fromJson(contentAsString, ImportReport.class); @@ -219,10 +221,8 @@ void verifySyncResponseForCsvShouldBeOkWhenImportReportStatusIsOk() throws Excep void verifySyncResponseShouldBeConflictWhenImportReportStatusIsError() throws Exception { String errorMessage = "errorMessage"; // When - when(syncImporter.importTracker(any())) - .thenReturn( - ImportReport.withError( - "errorMessage", ValidationReport.emptyReport(), new TimingsStats())); + when(trackerImportService.buildImportReport(any(), any())) + .thenReturn(ImportReport.withError(errorMessage, ValidationReport.emptyReport())); // Then String contentAsString = @@ -239,7 +239,7 @@ void verifySyncResponseShouldBeConflictWhenImportReportStatusIsError() throws Ex .getResponse() .getContentAsString(); - verify(syncImporter).importTracker(any()); + verify(trackerImportService).importTracker(any(), any()); try { renderService.fromJson(contentAsString, ImportReport.class); @@ -252,10 +252,8 @@ void verifySyncResponseShouldBeConflictWhenImportReportStatusIsError() throws Ex void verifySyncResponseForCsvShouldBeConflictWhenImportReportStatusIsError() throws Exception { String errorMessage = "errorMessage"; // When - when(syncImporter.importTracker(any())) - .thenReturn( - ImportReport.withError( - "errorMessage", ValidationReport.emptyReport(), new TimingsStats())); + when(trackerImportService.buildImportReport(any(), any())) + .thenReturn(ImportReport.withError(errorMessage, ValidationReport.emptyReport())); // Then String contentAsString = @@ -272,7 +270,7 @@ void verifySyncResponseForCsvShouldBeConflictWhenImportReportStatusIsError() thr .getContentAsString(); verify(csvEventService).read(any(), eq(true)); - verify(syncImporter).importTracker(any()); + verify(trackerImportService).importTracker(any(), any()); try { renderService.fromJson(contentAsString, ImportReport.class); @@ -285,7 +283,7 @@ void verifySyncResponseForCsvShouldBeConflictWhenImportReportStatusIsError() thr void verifyShouldFindJob() throws Exception { String uid = CodeGenerator.generateUid(); // When - when(notifier.getNotificationsByJobId(JobType.TRACKER_IMPORT_JOB, uid)) + when(notifier.getNotificationsByJobId(TRACKER_IMPORT_JOB, uid)) .thenReturn(new LinkedList<>(singletonList(new Notification()))); // Then @@ -305,7 +303,7 @@ void verifyShouldFindJob() throws Exception { .getResponse() .getContentAsString(); - verify(notifier).getNotificationsByJobId(JobType.TRACKER_IMPORT_JOB, uid); + verify(notifier).getNotificationsByJobId(TRACKER_IMPORT_JOB, uid); } @Test @@ -317,11 +315,10 @@ void verifyShouldFindJobReport() throws Exception { Status.OK, PersistenceReport.emptyReport(), ValidationReport.emptyReport(), - new TimingsStats(), new HashMap<>()); // When - when(notifier.getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid)).thenReturn(importReport); + when(notifier.getJobSummaryByJobId(TRACKER_IMPORT_JOB, uid)).thenReturn(importReport); when(trackerImportService.buildImportReport(any(), any())).thenReturn(importReport); @@ -340,7 +337,7 @@ void verifyShouldFindJobReport() throws Exception { .getResponse() .getContentAsString(); - verify(notifier).getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid); + verify(notifier).getJobSummaryByJobId(TRACKER_IMPORT_JOB, uid); verify(trackerImportService).buildImportReport(any(), any()); try { @@ -355,7 +352,7 @@ void verifyShouldThrowWhenJobReportNotFound() throws Exception { String uid = CodeGenerator.generateUid(); // When - when(notifier.getJobSummaryByJobId(JobType.TRACKER_IMPORT_JOB, uid)).thenReturn(null); + when(notifier.getJobSummaryByJobId(TRACKER_IMPORT_JOB, uid)).thenReturn(null); // Then mockMvc diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapperTest.java index 63e8c827f19e..8cb802fe993d 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImportParamsMapperTest.java @@ -63,8 +63,7 @@ void testValidationMode() { e -> { RequestParams requestParams = RequestParams.builder().validationMode(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat(params.getValidationMode(), is(e)); }); } @@ -76,8 +75,7 @@ void testImportMode() { e -> { RequestParams requestParams = RequestParams.builder().importMode(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat(params.getImportMode(), is(e)); }); } @@ -89,8 +87,7 @@ void testAtomicMode() { e -> { RequestParams requestParams = RequestParams.builder().atomicMode(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat(params.getAtomicMode(), is(e)); }); } @@ -102,8 +99,7 @@ void testFlushMode() { e -> { RequestParams requestParams = RequestParams.builder().flushMode(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat(params.getFlushMode(), is(e)); }); } @@ -115,8 +111,7 @@ void testImportStrategy() { e -> { RequestParams requestParams = RequestParams.builder().importStrategy(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat(params.getImportStrategy(), is(e)); }); } @@ -126,8 +121,7 @@ void testIdSchemeUsingIdSchemeName() { RequestParams requestParams = RequestParams.builder().idScheme(TrackerIdSchemeParam.NAME).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); TrackerIdSchemeParam expected = TrackerIdSchemeParam.NAME; assertEquals(expected, params.getIdSchemes().getIdScheme()); @@ -144,8 +138,7 @@ void testIdSchemeUsingIdSchemeAttribute() { RequestParams requestParams = RequestParams.builder().idScheme(TrackerIdSchemeParam.ofAttribute("WSiOAALYocA")).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); TrackerIdSchemeParam expected = TrackerIdSchemeParam.ofAttribute("WSiOAALYocA"); assertEquals(expected, params.getIdSchemes().getIdScheme()); @@ -164,8 +157,7 @@ void testOrgUnitIdentifier() { e -> { RequestParams requestParams = RequestParams.builder().orgUnitIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getOrgUnitIdScheme().getIdScheme(), is(e.getIdScheme())); }); @@ -178,8 +170,7 @@ void testProgramIdentifier() { e -> { RequestParams requestParams = RequestParams.builder().programIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getProgramIdScheme().getIdScheme(), is(e.getIdScheme())); }); @@ -192,8 +183,7 @@ void testProgramIdentifierUsingIdSchemeAttribute() { .programIdScheme(TrackerIdSchemeParam.ofAttribute("WSiOAALYocA")) .build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertEquals( TrackerIdSchemeParam.ofAttribute("WSiOAALYocA"), @@ -207,8 +197,7 @@ void testProgramStageIdentifier() { e -> { RequestParams requestParams = RequestParams.builder().programStageIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getProgramStageIdScheme().getIdScheme(), is(e.getIdScheme())); @@ -222,8 +211,7 @@ void testDataElementIdentifier() { e -> { RequestParams requestParams = RequestParams.builder().dataElementIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getDataElementIdScheme().getIdScheme(), is(e.getIdScheme())); @@ -238,8 +226,7 @@ void testCategoryOptionComboIdentifier() { RequestParams requestParams = RequestParams.builder().categoryOptionComboIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getCategoryOptionComboIdScheme().getIdScheme(), is(e.getIdScheme())); @@ -254,8 +241,7 @@ void testCategoryOptionIdentifier() { RequestParams requestParams = RequestParams.builder().categoryOptionIdScheme(e).build(); TrackerImportParams params = - TrackerImportParamsMapper.trackerImportParams( - true, JOB_ID, "userId", requestParams, Body.builder().build()); + TrackerImportParamsMapper.trackerImportParams("userId", requestParams); assertThat( params.getIdSchemes().getCategoryOptionIdScheme().getIdScheme(), is(e.getIdScheme())); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImporterImplTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImporterImplTest.java deleted file mode 100644 index 0d1fd39f68b8..000000000000 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerImporterImplTest.java +++ /dev/null @@ -1,98 +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.webapi.controller.tracker.imports; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.hisp.dhis.artemis.MessageManager; -import org.hisp.dhis.artemis.Topics; -import org.hisp.dhis.scheduling.JobConfiguration; -import org.hisp.dhis.scheduling.JobType; -import org.hisp.dhis.tracker.imports.TrackerBundleReportMode; -import org.hisp.dhis.tracker.imports.TrackerImportParams; -import org.hisp.dhis.tracker.imports.TrackerImportService; -import org.hisp.dhis.tracker.imports.job.TrackerMessage; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class TrackerImporterImplTest { - @InjectMocks TrackerAsyncImporter asyncImporter; - - @InjectMocks TrackerSyncImporter syncImporter; - - @Mock TrackerImportService trackerImportService; - - @Mock MessageManager messageManager; - - @Test - void shouldCreateReportSync() { - TrackerImportParams params = - TrackerImportParams.builder() - .jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId")) - .reportMode(TrackerBundleReportMode.FULL) - .build(); - - syncImporter.importTracker(params); - - verify(trackerImportService).importTracker(params); - verify(trackerImportService).buildImportReport(any(), eq(TrackerBundleReportMode.FULL)); - } - - @Test - void shouldSendMessageToQueueAsync() { - ArgumentCaptor queueNameCaptor = ArgumentCaptor.forClass(String.class); - ArgumentCaptor trackerMessageCaptor = - ArgumentCaptor.forClass(TrackerMessage.class); - - doNothing() - .when(messageManager) - .sendQueue(queueNameCaptor.capture(), trackerMessageCaptor.capture()); - - TrackerImportParams params = - TrackerImportParams.builder() - .jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId")) - .build(); - - asyncImporter.importTracker(params, null, ""); - - verify(trackerImportService, times(0)).importTracker(any()); - verify(messageManager).sendQueue(any(), any()); - assertEquals(Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, queueNameCaptor.getValue()); - assertEquals(params, trackerMessageCaptor.getValue().getTrackerImportParams()); - } -} From ebae39faffdbeebe16c2b302bd9432bd0de50c79 Mon Sep 17 00:00:00 2001 From: David Mackessy <131455290+david-mackessy@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:51:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20Remove=20unnecessary=20calls=20to=20?= =?UTF-8?q?the=20DB=20during=20DataValueSet=20import=20[D=E2=80=A6=20(#156?= =?UTF-8?q?88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16159] * fix: Remove unused dep and clean up test [DHIS2-16159] * fix format --- .../DataValueSetImportValidator.java | 6 +----- .../DataValueSetImportValidatorTest.java | 16 +--------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java index cccdc7053c59..d2c9ec0c6cc7 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java @@ -54,7 +54,6 @@ import org.hisp.dhis.dxf2.importsummary.ImportStatus; import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.security.acl.AclService; @@ -78,8 +77,6 @@ public class DataValueSetImportValidator { private final DataValueService dataValueService; - private final OrganisationUnitService organisationUnitService; - /** Validation on the {@link DataSet} level */ interface DataSetValidation { void validate(DataValueSet dataValueSet, ImportContext context, DataSetContext dataSetContext); @@ -645,8 +642,7 @@ private void checkDataValueOrgUnitValidForAttrOptionCombo( private boolean isOrgUnitValidForAttrOptionCombo(DataValueContext valueContext) { Set aocOrgUnits = valueContext.getAttrOptionCombo().getOrganisationUnits(); - return aocOrgUnits == null - || organisationUnitService.isDescendant(valueContext.getOrgUnit(), aocOrgUnits); + return aocOrgUnits == null || valueContext.getOrgUnit().isDescendant(aocOrgUnits); } private static void checkDataValueTargetDataSets( diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java index a4c87d0ef9ad..da4b9bdfbceb 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java @@ -72,7 +72,6 @@ import org.hisp.dhis.importexport.ImportStrategy; import org.hisp.dhis.option.OptionSet; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.period.PeriodTypeEnum; @@ -99,8 +98,6 @@ class DataValueSetImportValidatorTest { private DataValueSetImportValidator validator; - private OrganisationUnitService organisationUnitService; - private final CategoryCombo defaultCombo = new CategoryCombo(); @BeforeEach @@ -109,16 +106,11 @@ void setUp() { lockExceptionStore = mock(LockExceptionStore.class); approvalService = mock(DataApprovalService.class); dataValueService = mock(DataValueService.class); - organisationUnitService = mock(OrganisationUnitService.class); i18n = mock(I18n.class); validator = new DataValueSetImportValidator( - aclService, - lockExceptionStore, - approvalService, - dataValueService, - organisationUnitService); + aclService, lockExceptionStore, approvalService, dataValueService); validator.init(); setupUserCanWriteCategoryOptions(true); when(i18n.getString(anyString())) @@ -298,12 +290,6 @@ void testValidateDataValueAttrOptionComboAccess() { @Test void testValidateDataValueOrgUnitInUserHierarchy() { - when(organisationUnitService.isDescendant(any(OrganisationUnit.class), any(Set.class))) - .thenReturn(false); - when(organisationUnitService.isDescendant( - any(OrganisationUnit.class), any(OrganisationUnit.class))) - .thenReturn(false); - DataValue dataValue = createRandomDataValue(); DataValueContext valueContext = createDataValueContext(dataValue).build(); DataSetContext dataSetContext = createMinimalDataSetContext().build(); From fac9185811bfea0a68db1d2540fbf1ad044d69ba Mon Sep 17 00:00:00 2001 From: "@dhis2-bot" Date: Wed, 15 Nov 2023 02:38:37 +0100 Subject: [PATCH 3/3] fix(translations): sync translations from transifex (master) Automatically merged. --- .../main/resources/org/hisp/dhis/de/i18n_module_es.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module_es.properties b/dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module_es.properties index 4d181b3c64e1..4df6837164e5 100644 --- a/dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module_es.properties +++ b/dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module_es.properties @@ -30,6 +30,7 @@ saving_value_failed_dataset_is_locked=El set de datos est\u00e1 bloqueado, por f saving_comment_failed_status_code=Guardando comentario fallido con codigo de estado saving_comment_failed_error_code=Guardando comentario fallido con codigo de error saving_minmax_failed_error_code=Guardando m\u00ednimo/m\u00e1ximo valor fallido con c\u00f3digo de error +saving_comment_failed_error_code=Guardando comentario fallido con codigo de error move=Mover date=Fecha min_limit=L\u00edmite m\u00ednimo @@ -119,7 +120,7 @@ print_blank_form=Imprimir en blanco instruction=Instrucci\u00f3n there_is_no_audit_trail_for_this_value=No hay pista de auditor\u00eda para este valor are_you_sure_you_want_to_delete_this_file=Are you sure you want to delete this file? -confirm_deletion=Confirm deletion +confirm_deletion=Confirmar eliminaci\u00f3n file_upload_failed=File upload failed loading_file_info_failed=Loading file info failed orgunit_is_closed=Organisation unit is closed for the selected period.