use of org.ihtsdo.otf.snomedboot.ReleaseImportException in project snomed-drools by IHTSDO.
the class DroolsRF2Validator method validate.
private void validate(Set<String> assertionGroups, Set<String> extractedRF2FilesDirectories, String currentEffectiveTime, Set<String> includedModuleSets, Set<String> previousReleaseDirectories) {
File report = new File("validation-report-" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date()) + ".txt");
try {
// Load test resources from public S3 location
// Run assertions
List<InvalidContent> invalidContents = validateRF2Files(extractedRF2FilesDirectories, previousReleaseDirectories, assertionGroups, currentEffectiveTime, includedModuleSets, false);
// Write report
report.createNewFile();
try (BufferedWriter reportWriter = new BufferedWriter(new FileWriter(report))) {
reportWriter.write("conceptId\tcomponentId\tmessage\tseverity\tignorePublishedCheck");
reportWriter.newLine();
for (InvalidContent invalidContent : invalidContents) {
reportWriter.write(invalidContent.getConceptId());
reportWriter.write(TAB);
reportWriter.write(invalidContent.getComponentId());
reportWriter.write(TAB);
reportWriter.write(invalidContent.getMessage().replace("\n", " "));
reportWriter.write(TAB);
reportWriter.write(invalidContent.getSeverity().toString());
reportWriter.write(TAB);
reportWriter.write(invalidContent.isIgnorePublishedCheck() + "");
reportWriter.newLine();
}
}
} catch (ReleaseImportException | IOException e) {
e.printStackTrace();
}
}
use of org.ihtsdo.otf.snomedboot.ReleaseImportException in project snowstorm by IHTSDO.
the class ImportService method importArchive.
public void importArchive(String importId, InputStream releaseFileStream) throws ReleaseImportException {
ImportJob job = getJob(importId);
if (job.getStatus() != ImportJob.ImportStatus.WAITING_FOR_FILE) {
throw new IllegalStateException("Import Job must be in state " + ImportJob.ImportStatus.WAITING_FOR_FILE);
}
RF2Type importType = job.getType();
String branchPath = job.getBranchPath();
Integer patchReleaseVersion = job.getPatchReleaseVersion();
setImportMetadata(importType, branchPath, job.isCreateCodeSystemVersion());
try {
Date start = new Date();
logger.info("Starting RF2 {}{} import on branch {}. ID {}", importType, patchReleaseVersion != null ? " RELEASE PATCH on effectiveTime " + patchReleaseVersion : "", branchPath, importId);
job.setStatus(ImportJob.ImportStatus.RUNNING);
LoadingProfile loadingProfile = DEFAULT_LOADING_PROFILE.withModuleIds(job.getModuleIds().toArray(new String[] {}));
final Integer maxEffectiveTime = importFiles(releaseFileStream, job, importType, branchPath, patchReleaseVersion, new ReleaseImporter(), loadingProfile);
if (job.isCreateCodeSystemVersion() && importType != FULL && maxEffectiveTime != null) {
// Create Code System version if a code system exists on this path
codeSystemService.createVersionIfCodeSystemFoundOnPath(branchPath, maxEffectiveTime, job.isInternalRelease());
}
job.setStatus(ImportJob.ImportStatus.COMPLETED);
long seconds = (new Date().getTime() - start.getTime()) / 1_000;
logger.info("Completed RF2 {} import on branch {} in {} seconds. ID {}", importType, branchPath, seconds, importId);
} catch (Exception e) {
logger.error("Failed RF2 {} import on branch {}. ID {}", importType, branchPath, importId, e);
job.setStatus(ImportJob.ImportStatus.FAILED);
throw e;
} finally {
clearImportMetadata(branchPath);
}
}
use of org.ihtsdo.otf.snomedboot.ReleaseImportException in project snowstorm by IHTSDO.
the class ImportService method importArchiveAsync.
@PreAuthorize("hasPermission('AUTHOR', #branchPath)")
public void importArchiveAsync(String importId, @SuppressWarnings("unused") String branchPath, InputStream releaseFileStream) {
final SecurityContext securityContext = SecurityContextHolder.getContext();
executorService.submit(() -> {
SecurityContextHolder.setContext(securityContext);
try {
importArchive(importId, releaseFileStream);
} catch (ReleaseImportException e) {
// Swallow exception - already logged and this is an async method
} finally {
if (releaseFileStream != null) {
try {
releaseFileStream.close();
} catch (IOException e) {
logger.info("Failed to close input stream for import {}", importId);
}
}
}
});
}
use of org.ihtsdo.otf.snomedboot.ReleaseImportException in project snowstorm by IHTSDO.
the class ImportServiceTest method testImportBadFileRollback.
@Test
void testImportBadFileRollback() throws IOException, ReleaseImportException {
final long commitBeforeImport = branchService.findLatest("MAIN").getHeadTimestamp();
File zipFile = ZipUtil.zipDirectoryRemovingCommentsAndBlankLines("src/test/resources/dummy-snomed-content/SnomedCT_MiniRF2_bad_delta");
String importId = importService.createJob(RF2Type.DELTA, "MAIN", false, false);
Exception exceptionThrown = null;
try {
importService.importArchive(importId, new FileInputStream(zipFile));
} catch (ReleaseImportException e) {
exceptionThrown = e;
}
Assertions.assertNotNull(exceptionThrown);
final ImportJob importJob = importService.getImportJobOrThrow(importId);
Assertions.assertEquals(ImportJob.ImportStatus.FAILED, importJob.getStatus());
final Branch mainBranch = branchService.findLatest("MAIN");
Assertions.assertFalse(mainBranch.isLocked());
final long commitAfterImport = mainBranch.getHeadTimestamp();
Assertions.assertEquals(commitBeforeImport, commitAfterImport, "Commit after import must be equal to commit before import because the import commut must roll back");
}
Aggregations