Skip to content

Commit

Permalink
#263 OCL loader should throw an exception upon failure (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton committed Mar 14, 2024
1 parent 935aaa2 commit 583aee2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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());
}

}

0 comments on commit 583aee2

Please sign in to comment.