From c65911fe3de4ce2359cf2a84751b7dc762ae9009 Mon Sep 17 00:00:00 2001 From: Jason Pickering Date: Thu, 16 Nov 2023 14:18:52 +0300 Subject: [PATCH] Patch/2.40.2 15645 15661 (#15722) * fix: always flush the batch handler for CompleteDataSet import [DHIS2-15362] (2.39) (#15625) (#15710) * fix: always flush the batch handler for CompleteDataSet import [DHIS2-15362] * fix: test setup * fix: controller imports use interface not impl * Use try-with-resources to close BatchHandler (#15661) (#15704) (#15711) * Use try-with-resources to close BatchHandler * Rework test to deal with multi-threading * Add try-catch to Analytics table manager --------- Co-authored-by: Jan Bernitt --- .../JdbcOwnershipAnalyticsTableManager.java | 42 ++++---- ...eteDataSetRegistrationExchangeService.java | 24 ----- ...eteDataSetRegistrationExchangeService.java | 95 +++++++++---------- ...mportCompleteDataSetRegistrationsTask.java | 63 ++++-------- .../DefaultDataValueSetService.java | 13 +-- ...ataSetRegistrationExchangeServiceTest.java | 7 -- ...teDataSetRegistrationBatchHandlerTest.java | 10 +- .../DataValueAuditBatchHandlerTest.java | 15 +-- .../DataValueBatchHandlerTest.java | 24 +++-- ...CompleteDataSetRegistrationController.java | 10 +- dhis-2/pom.xml | 2 +- 11 files changed, 128 insertions(+), 177 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java index 387ae6d587f2..b51275922186 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java @@ -177,30 +177,32 @@ private void populateTableInternal(AnalyticsTablePartition partition, String sql List columnNames = getDimensionColumns().stream().map(AnalyticsTableColumn::getName).collect(toList()); - MappingBatchHandler batchHandler = + try (MappingBatchHandler batchHandler = MappingBatchHandler.builder() .jdbcConfiguration(jdbcConfiguration) .tableName(partition.getTempTableName()) .columns(columnNames) - .build(); - - batchHandler.init(); - - JdbcOwnershipWriter writer = JdbcOwnershipWriter.getInstance(batchHandler); - AtomicInteger queryRowCount = new AtomicInteger(); - - jdbcTemplate.query( - sql, - resultSet -> { - writer.write(getRowMap(columnNames, resultSet)); - queryRowCount.getAndIncrement(); - }); - - log.info( - "OwnershipAnalytics query row count was {} for {}", - queryRowCount, - partition.getTempTableName()); - batchHandler.flush(); + .build()) { + batchHandler.init(); + + JdbcOwnershipWriter writer = JdbcOwnershipWriter.getInstance(batchHandler); + AtomicInteger queryRowCount = new AtomicInteger(); + + jdbcTemplate.query( + sql, + resultSet -> { + writer.write(getRowMap(columnNames, resultSet)); + queryRowCount.getAndIncrement(); + }); + + log.info( + "OwnershipAnalytics query row count was {} for {}", + queryRowCount, + partition.getTempTableName()); + batchHandler.flush(); + } catch (Exception ex) { + log.error("Failed to alter table ownership: ", ex); + } } private String getInputSql(Program program) { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/CompleteDataSetRegistrationExchangeService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/CompleteDataSetRegistrationExchangeService.java index 1b74aa20a637..01fdfa18025c 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/CompleteDataSetRegistrationExchangeService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/CompleteDataSetRegistrationExchangeService.java @@ -34,7 +34,6 @@ import org.hisp.dhis.common.IdSchemes; import org.hisp.dhis.dxf2.common.ImportOptions; import org.hisp.dhis.dxf2.importsummary.ImportSummary; -import org.hisp.dhis.scheduling.JobConfiguration; /** * Import/export service for {@link CompleteDataSetRegistration data set completion registrations}. @@ -109,17 +108,6 @@ void writeCompleteDataSetRegistrationsJson( */ ImportSummary saveCompleteDataSetRegistrationsXml(InputStream in, ImportOptions importOptions); - /** - * Imports {@link CompleteDataSetRegistrations} from an XML payload. - * - * @param in the stream providing the XML payload. - * @param importOptions the options for the import. - * @param jobId the task (optional). - * @return a summary of the import process. - */ - ImportSummary saveCompleteDataSetRegistrationsXml( - InputStream in, ImportOptions importOptions, JobConfiguration jobId); - /** * Imports {@link CompleteDataSetRegistrations} from a JSON payload. * @@ -129,22 +117,10 @@ ImportSummary saveCompleteDataSetRegistrationsXml( */ ImportSummary saveCompleteDataSetRegistrationsJson(InputStream in, ImportOptions importOptions); - /** - * Imports {@link CompleteDataSetRegistrations} from a JSON payload. - * - * @param in the stream providing the XML payload. - * @param importOptions the options for the import. - * @param jobId the task (optional). - * @return a summary of the import process. - */ - ImportSummary saveCompleteDataSetRegistrationsJson( - InputStream in, ImportOptions importOptions, JobConfiguration jobId); - /** * Validates the given {@link ExportParams}. * * @param params the export parameters. - * @throws IllegalQueryException if validation failed. */ void validate(ExportParams params); } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeService.java index 741866e68430..d5b1b2b653d1 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeService.java @@ -28,12 +28,14 @@ package org.hisp.dhis.dxf2.dataset; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; +import java.util.concurrent.Callable; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -76,10 +78,7 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.scheduling.JobConfiguration; import org.hisp.dhis.setting.SystemSettingManager; -import org.hisp.dhis.system.notification.NotificationLevel; -import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.system.util.Clock; import org.hisp.dhis.system.util.ValidationUtils; import org.hisp.dhis.user.CurrentUserService; @@ -89,6 +88,7 @@ import org.hisp.quick.BatchHandlerFactory; import org.hisp.staxwax.factory.XMLFactory; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * @author Halvdan Hoem Grelland @@ -113,8 +113,6 @@ public class DefaultCompleteDataSetRegistrationExchangeService private final OrganisationUnitService orgUnitService; - private final Notifier notifier; - private final I18nManager i18nManager; private final BatchHandlerFactory batchHandlerFactory; @@ -198,6 +196,7 @@ public ExportParams paramsFromUrl( } @Override + @Transactional public void writeCompleteDataSetRegistrationsXml(ExportParams params, OutputStream out) { decideAccess(params); validate(params); @@ -206,6 +205,7 @@ public void writeCompleteDataSetRegistrationsXml(ExportParams params, OutputStre } @Override + @Transactional public void writeCompleteDataSetRegistrationsJson(ExportParams params, OutputStream out) { decideAccess(params); validate(params); @@ -214,52 +214,60 @@ public void writeCompleteDataSetRegistrationsJson(ExportParams params, OutputStr } @Override + @Transactional public void writeCompleteDataSetRegistrationsJson( Date lastUpdated, OutputStream outputStream, IdSchemes idSchemes) { cdsrStore.writeCompleteDataSetRegistrationsJson(lastUpdated, outputStream, idSchemes); } @Override + @Transactional public ImportSummary saveCompleteDataSetRegistrationsXml( InputStream in, ImportOptions importOptions) { - return saveCompleteDataSetRegistrationsXml(in, importOptions, null); + return saveCompleteDataSetRegistrations(importOptions, () -> readRegistrationsFromXml(in)); } - @Override - public ImportSummary saveCompleteDataSetRegistrationsXml( - InputStream in, ImportOptions importOptions, JobConfiguration jobId) { - try { - in = StreamUtils.wrapAndCheckCompressionFormat(in); - CompleteDataSetRegistrations completeDataSetRegistrations = - new StreamingXmlCompleteDataSetRegistrations(XMLFactory.getXMLReader(in)); - - return saveCompleteDataSetRegistrations(importOptions, jobId, completeDataSetRegistrations); - } catch (Exception ex) { - return handleImportError(jobId, ex); - } + @Nonnull + private static CompleteDataSetRegistrations readRegistrationsFromXml(InputStream in) + throws IOException { + in = StreamUtils.wrapAndCheckCompressionFormat(in); + return new StreamingXmlCompleteDataSetRegistrations(XMLFactory.getXMLReader(in)); } @Override + @Transactional public ImportSummary saveCompleteDataSetRegistrationsJson( InputStream in, ImportOptions importOptions) { - return saveCompleteDataSetRegistrationsJson(in, importOptions, null); + return saveCompleteDataSetRegistrations(importOptions, () -> readRegistrationsFromJson(in)); } - @Override - public ImportSummary saveCompleteDataSetRegistrationsJson( - InputStream in, ImportOptions importOptions, JobConfiguration jobId) { - try { - in = StreamUtils.wrapAndCheckCompressionFormat(in); + private ImportSummary saveCompleteDataSetRegistrations( + ImportOptions importOptions, + Callable deserializeRegistrations) { + + try (BatchHandler batchHandler = + batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class)) { + CompleteDataSetRegistrations completeDataSetRegistrations = deserializeRegistrations.call(); + ImportSummary summary = + saveCompleteDataSetRegistrations( + importOptions, completeDataSetRegistrations, batchHandler); - CompleteDataSetRegistrations completeDataSetRegistrations = - jsonMapper.readValue(in, CompleteDataSetRegistrations.class); + batchHandler.flush(); - return saveCompleteDataSetRegistrations(importOptions, jobId, completeDataSetRegistrations); + return summary; } catch (Exception ex) { - return handleImportError(jobId, ex); + log.error("Complete data set registrations could not be saved."); + return handleImportError(ex); } } + @Nonnull + private CompleteDataSetRegistrations readRegistrationsFromJson(InputStream in) + throws IOException { + in = StreamUtils.wrapAndCheckCompressionFormat(in); + return jsonMapper.readValue(in, CompleteDataSetRegistrations.class); + } + @Override public void validate(ExportParams params) throws IllegalQueryException { ErrorMessage error = null; @@ -357,21 +365,17 @@ private void decideAccess(ExportParams params) throws IllegalQueryException { } } - private ImportSummary handleImportError(JobConfiguration jobId, Throwable ex) { + private ImportSummary handleImportError(Throwable ex) { log.error(DebugUtils.getStackTrace(ex)); - notifier.notify(jobId, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true); return new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage()); } private ImportSummary saveCompleteDataSetRegistrations( ImportOptions importOptions, - JobConfiguration id, - CompleteDataSetRegistrations completeRegistrations) { + CompleteDataSetRegistrations completeRegistrations, + BatchHandler batchHandler) { Clock clock = - new Clock(log) - .startClock() - .logTime("Starting complete data set registration import, options: " + importOptions); - notifier.clear(id).notify(id, "Process started"); + new Clock(log).startClock().logTime("Starting complete data set registration import"); // Start here so we can access any outer attributes for the // configuration @@ -407,14 +411,9 @@ private ImportSummary saveCompleteDataSetRegistrations( // Perform import // --------------------------------------------------------------------- - notifier.notify(id, "Importing complete data set registrations"); - int totalCount = - batchImport(completeRegistrations, cfg, importSummary, metaDataCallables, caches); - - notifier - .notify(id, NotificationLevel.INFO, "Import done", true) - .addJobSummary(id, importSummary, ImportSummary.class); + batchImport( + completeRegistrations, cfg, importSummary, metaDataCallables, caches, batchHandler); ImportCount count = importSummary.getImportCount(); @@ -436,16 +435,14 @@ private int batchImport( ImportConfig config, ImportSummary summary, MetadataCallables mdCallables, - MetadataCaches mdCaches) { + MetadataCaches mdCaches, + BatchHandler batchHandler) { final User currentUser = currentUserService.getCurrentUser(); final String currentUserName = currentUser.getUsername(); final Set userOrgUnits = currentUserService.getCurrentUserOrganisationUnits(); final I18n i18n = i18nManager.getI18n(); - BatchHandler batchHandler = - batchHandlerFactory - .createBatchHandler(CompleteDataSetRegistrationBatchHandler.class) - .init(); + batchHandler.init(); int importCount = 0, updateCount = 0, deleteCount = 0, totalCount = 0; @@ -615,8 +612,6 @@ private int batchImport( } } - batchHandler.flush(); - finalizeSummary(summary, totalCount, importCount, updateCount, deleteCount); return totalCount; diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/tasks/ImportCompleteDataSetRegistrationsTask.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/tasks/ImportCompleteDataSetRegistrationsTask.java index 5af8740fa5a3..1ed48adc897c 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/tasks/ImportCompleteDataSetRegistrationsTask.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/tasks/ImportCompleteDataSetRegistrationsTask.java @@ -31,71 +31,46 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.hibernate.SessionFactory; import org.hisp.dhis.dbms.DbmsUtils; import org.hisp.dhis.dxf2.common.ImportOptions; import org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistrationExchangeService; +import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.hisp.dhis.scheduling.JobConfiguration; import org.hisp.dhis.security.SecurityContextRunnable; +import org.hisp.dhis.system.notification.Notifier; /** * @author Halvdan Hoem Grelland */ @Slf4j +@RequiredArgsConstructor public class ImportCompleteDataSetRegistrationsTask extends SecurityContextRunnable { - public static final String FORMAT_JSON = "json", FORMAT_XML = "xml"; - - private String format; - - private InputStream input; - - private Path tmpFile; - - private ImportOptions importOptions; - - private JobConfiguration id; - - private SessionFactory sessionFactory; - - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - private CompleteDataSetRegistrationExchangeService registrationService; - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - public ImportCompleteDataSetRegistrationsTask( - CompleteDataSetRegistrationExchangeService registrationService, - SessionFactory sessionFactory, - InputStream input, - Path tmpFile, - ImportOptions importOptions, - String format, - JobConfiguration id) { - this.registrationService = registrationService; - this.sessionFactory = sessionFactory; - this.input = input; - this.tmpFile = tmpFile; - this.importOptions = importOptions; - this.format = format; - this.id = id; - } + public static final String FORMAT_JSON = "json", FORMAT_XML = "xml"; - // ------------------------------------------------------------------------- - // SecurityContextRunnable implementation - // ------------------------------------------------------------------------- + private final CompleteDataSetRegistrationExchangeService registrationService; + private final SessionFactory sessionFactory; + private final InputStream input; + private final Path tmpFile; + private final ImportOptions importOptions; + private final String format; + private final JobConfiguration id; + private final Notifier notifier; @Override public void call() { try { + ImportSummary summary = null; if (FORMAT_XML.equals(format)) { - registrationService.saveCompleteDataSetRegistrationsXml(input, importOptions, id); + summary = registrationService.saveCompleteDataSetRegistrationsXml(input, importOptions); } else if (FORMAT_JSON.equals(format)) { - registrationService.saveCompleteDataSetRegistrationsJson(input, importOptions, id); + summary = registrationService.saveCompleteDataSetRegistrationsJson(input, importOptions); + } + if (summary != null) { + notifier.addJobSummary(id, summary, ImportSummary.class); } } finally { cleanUpTmpFile(tmpFile); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java index 0b75d49f4531..cbaf04994dd3 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java @@ -623,14 +623,13 @@ private ImportSummary importDataValueSet( ImportOptions options, JobConfiguration id, Callable createReader) { options = ObjectUtils.firstNonNull(options, ImportOptions.getDefaultImportOptions()); - BatchHandler dvBatch = - batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class); - BatchHandler dvaBatch = - batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class); - notifier.clear(id); - try (DataValueSetReader reader = createReader.call()) { + try (BatchHandler dvBatch = + batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class); + BatchHandler dvaBatch = + batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class); + DataValueSetReader reader = createReader.call()) { ImportSummary summary = importDataValueSet(options, id, reader, dvBatch, dvaBatch); dvBatch.flush(); @@ -643,8 +642,6 @@ private ImportSummary importDataValueSet( return summary; } catch (Exception ex) { - dvBatch.flush(); - dvaBatch.flush(); log.error(DebugUtils.getStackTrace(ex)); notifier.notify(id, ERROR, "Process failed: " + ex.getMessage(), true); return new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage()); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java index b13d3d7a9887..e89edac7cc7f 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/dataset/DefaultCompleteDataSetRegistrationExchangeServiceTest.java @@ -39,7 +39,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.when; @@ -85,7 +84,6 @@ import org.hisp.dhis.security.acl.AclService; import org.hisp.dhis.setting.SettingKey; import org.hisp.dhis.setting.SystemSettingManager; -import org.hisp.dhis.system.notification.NotificationLevel; import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; @@ -183,7 +181,6 @@ public void setUp() { cdsrStore, idObjManager, orgUnitService, - notifier, i18nManager, batchHandlerFactory, systemSettingManager, @@ -258,7 +255,6 @@ void verifyUserHasNoWritePermissionOnCategoryOption() { when(aclService.canDataWrite(user, categoryOptionA)).thenReturn(false); when(aclService.canDataWrite(user, categoryOptionB)).thenReturn(true); - when(notifier.clear(null)).thenReturn(notifier); when(systemSettingManager.getBoolSetting(SettingKey.DATA_IMPORT_STRICT_PERIODS)) .thenReturn(false); when(systemSettingManager.getBoolSetting( @@ -278,9 +274,6 @@ void verifyUserHasNoWritePermissionOnCategoryOption() { when(batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class)) .thenReturn(batchHandler); - when(notifier.notify(any(), anyString())).thenReturn(notifier); - when(notifier.notify(null, NotificationLevel.INFO, "Import done", true)).thenReturn(notifier); - // call method under test ImportSummary summary = subject.saveCompleteDataSetRegistrationsJson( diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/CompleteDataSetRegistrationBatchHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/CompleteDataSetRegistrationBatchHandlerTest.java index 0a1c66996b50..cf2a368c39a5 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/CompleteDataSetRegistrationBatchHandlerTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/CompleteDataSetRegistrationBatchHandlerTest.java @@ -92,11 +92,11 @@ class CompleteDataSetRegistrationBatchHandlerTest extends IntegrationTestBase { private CompleteDataSetRegistration regD; - private Date now = new Date(); + private final Date now = new Date(); - private String storedBy = "johndoe"; + private final String storedBy = "johndoe"; - private String lastUpdatedBy = "johndoe"; + private final String lastUpdatedBy = "johndoe"; // ------------------------------------------------------------------------- // Fixture @@ -165,9 +165,7 @@ public void setUpTest() { } @Override - public void tearDownTest() { - batchHandler.flush(); - } + public void tearDownTest() {} // ------------------------------------------------------------------------- // Tests diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java index 3eff0bd09422..1e6ac8f700db 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java @@ -72,8 +72,6 @@ class DataValueAuditBatchHandlerTest extends SingleSetupIntegrationTestBase { @Autowired private CategoryService categoryService; - private BatchHandler batchHandler; - private DataElement dataElementA; private CategoryOptionCombo categoryOptionComboA; @@ -107,7 +105,7 @@ class DataValueAuditBatchHandlerTest extends SingleSetupIntegrationTestBase { // ------------------------------------------------------------------------- @Override public void setUpTest() { - batchHandler = batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class); + dataElementA = createDataElement('A'); dataElementService.addDataElement(dataElementA); categoryOptionComboA = categoryService.getDefaultCategoryOptionCombo(); @@ -132,19 +130,18 @@ public void setUpTest() { auditB = new DataValueAudit(dataValueA, "12", storedBy, AuditType.UPDATE); auditC = new DataValueAudit(dataValueB, "21", storedBy, AuditType.UPDATE); auditD = new DataValueAudit(dataValueB, "22", storedBy, AuditType.UPDATE); - batchHandler.init(); } @Override - public void tearDownTest() { - batchHandler.flush(); - } + public void tearDownTest() {} // ------------------------------------------------------------------------- // Tests // ------------------------------------------------------------------------- @Test void testAddObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class).init(); batchHandler.addObject(auditA); batchHandler.addObject(auditB); batchHandler.addObject(auditC); @@ -161,6 +158,8 @@ void testAddObject() { /** DataValueAudit can never equal another. */ @Test void testObjectExists() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class).init(); auditService.addDataValueAudit(auditA); auditService.addDataValueAudit(auditB); assertFalse(batchHandler.objectExists(auditA)); @@ -171,6 +170,8 @@ void testObjectExists() { @Test void testUpdateObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class).init(); auditService.addDataValueAudit(auditA); auditA.setModifiedBy("bill"); batchHandler.updateObject(auditA); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueBatchHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueBatchHandlerTest.java index e76c66da4b6f..e04fdd38e7b8 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueBatchHandlerTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueBatchHandlerTest.java @@ -72,8 +72,6 @@ class DataValueBatchHandlerTest extends IntegrationTestBase { @Autowired private CategoryService categoryService; - private BatchHandler batchHandler; - private DataElement dataElementA; private CategoryOptionCombo categoryOptionComboA; @@ -105,7 +103,7 @@ class DataValueBatchHandlerTest extends IntegrationTestBase { // ------------------------------------------------------------------------- @Override public void setUpTest() { - batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class); + dataElementA = createDataElement('A'); dataElementService.addDataElement(dataElementA); categoryOptionComboA = categoryService.getDefaultCategoryOptionCombo(); @@ -142,19 +140,19 @@ public void setUpTest() { dataElementA, periodB, unitB, categoryOptionComboA, categoryOptionComboA, "15"); // with // 4th - batchHandler.init(); + } @Override - public void tearDownTest() { - batchHandler.flush(); - } + public void tearDownTest() {} // ------------------------------------------------------------------------- // Tests // ------------------------------------------------------------------------- @Test void testInsertObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); batchHandler.insertObject(dataValueA); DataValue dataValue = dataValueService.getDataValue( @@ -164,6 +162,8 @@ void testInsertObject() { @Test void testAddObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); batchHandler.addObject(dataValueA); batchHandler.addObject(dataValueB); batchHandler.addObject(dataValueC); @@ -185,6 +185,8 @@ void testAddObject() { @Test void testAddObjectDuplicates() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); batchHandler.addObject(dataValueA); batchHandler.addObject(dataValueB); batchHandler.addObject(dataValueC); @@ -208,6 +210,8 @@ void testAddObjectDuplicates() { @Test void testFindObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); dataValueService.addDataValue(dataValueA); dataValueService.addDataValue(dataValueC); DataValue retrievedDataValueA = batchHandler.findObject(dataValueA); @@ -224,6 +228,8 @@ void testFindObject() { @Test void testObjectExists() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); dataValueService.addDataValue(dataValueA); dataValueService.addDataValue(dataValueC); assertTrue(batchHandler.objectExists(dataValueA)); @@ -235,6 +241,8 @@ void testObjectExists() { @Test @Disabled("ERROR: cannot execute UPDATE in a read-only transaction") void testUpdateObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); dataValueService.addDataValue(dataValueA); dataValueA.setValue("20"); batchHandler.updateObject(dataValueA); @@ -247,6 +255,8 @@ void testUpdateObject() { @Test void testDeleteObject() { + BatchHandler batchHandler; + batchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init(); dataValueService.addDataValue(dataValueA); dataValueService.addDataValue(dataValueC); assertTrue(batchHandler.objectExists(dataValueA)); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java index fbfd0c258149..0dade874ce80 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java @@ -64,7 +64,7 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.dxf2.common.ImportOptions; -import org.hisp.dhis.dxf2.dataset.DefaultCompleteDataSetRegistrationExchangeService; +import org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistrationExchangeService; import org.hisp.dhis.dxf2.dataset.ExportParams; import org.hisp.dhis.dxf2.dataset.tasks.ImportCompleteDataSetRegistrationsTask; import org.hisp.dhis.dxf2.importsummary.ImportSummary; @@ -76,6 +76,7 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.scheduling.JobConfiguration; +import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.webapi.mvc.annotation.ApiVersion; @@ -113,12 +114,14 @@ public class CompleteDataSetRegistrationController { @Autowired private InputUtils inputUtils; - @Autowired private DefaultCompleteDataSetRegistrationExchangeService registrationExchangeService; + @Autowired private CompleteDataSetRegistrationExchangeService registrationExchangeService; @Autowired private AsyncTaskExecutor taskExecutor; @Autowired private SessionFactory sessionFactory; + @Autowired private Notifier notifier; + // ------------------------------------------------------------------------- // GET // ------------------------------------------------------------------------- @@ -326,7 +329,8 @@ private WebMessage asyncImport( tmpFile.getRight(), importOptions, format, - jobId)); + jobId, + notifier)); return jobConfigurationReport(jobId) .setLocation("/system/tasks/" + COMPLETE_DATA_SET_REGISTRATION_IMPORT); diff --git a/dhis-2/pom.xml b/dhis-2/pom.xml index 55ec19f3152a..ab1794c6b567 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -89,7 +89,7 @@ 2.1.8.0 - 1.4.1 + 1.4.3 2.0.0 0.5.0