diff --git a/README.md b/README.md index 5c3c0b71..6eb49b22 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo * Added support for 'queues' domain. * Added support for 'addresshierarchy' domain. * Fix for Liquibase Loader to ensure compatibility with OpenMRS versions 2.5.5+ +* Fix for OCL Loader to ensure it throws an Exception if the OCL import fails #### Version 2.6.0 * Added support for 'cohorttypes' and 'cohortattributetypes' domains. diff --git a/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java b/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java index c8961901..37f4b9a5 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java @@ -1,13 +1,16 @@ package org.openmrs.module.initializer.api.loaders; -import java.io.File; -import java.util.zip.ZipFile; - +import org.apache.commons.lang.StringUtils; import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.api.context.Context; import org.openmrs.module.initializer.Domain; +import org.openmrs.module.openconceptlab.Import; +import org.openmrs.module.openconceptlab.ImportService; import org.openmrs.module.openconceptlab.importer.Importer; +import java.io.File; +import java.util.zip.ZipFile; + @OpenmrsProfile(modules = { "openconceptlab:1.2.9" }) public class OpenConceptLabLoader extends BaseFileLoader { @@ -25,7 +28,29 @@ protected String getFileExtension() { protected void load(File file) throws Exception { ZipFile zip = new ZipFile(file); Importer importer = Context.getRegisteredComponent("openconceptlab.importer", Importer.class); + ImportService importService = Context.getService(ImportService.class); + + Import lastImport = importService.getLastImport(); + log.debug("Starting OCL importer"); importer.run(zip); + Import oclImport = importService.getLastImport(); + + // Import failed to start. This can happen another import is already currently running + if (oclImport == null || oclImport.equals(lastImport)) { + throw new IllegalStateException("OCL import did not start successfully"); + } + + // Import detected errors + if (StringUtils.isNotBlank(oclImport.getErrorMessage())) { + throw new IllegalStateException(oclImport.getErrorMessage()); + } + + // Import never stopped + if (!oclImport.isStopped()) { + throw new IllegalStateException("OCL import did not complete successfully"); + } + + log.debug("OCL import completed successfully: " + oclImport.getLocalDateStopped()); } }