Search in sources :

Example 1 with ReleaseImportException

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();
    }
}
Also used : InvalidContent(org.ihtsdo.drools.response.InvalidContent) FileWriter(java.io.FileWriter) ReleaseImportException(org.ihtsdo.otf.snomedboot.ReleaseImportException) IOException(java.io.IOException) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) BufferedWriter(java.io.BufferedWriter)

Example 2 with ReleaseImportException

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);
    }
}
Also used : ReleaseImporter(org.ihtsdo.otf.snomedboot.ReleaseImporter) RF2Type(org.snomed.snowstorm.core.rf2.RF2Type) LoadingProfile(org.ihtsdo.otf.snomedboot.factory.LoadingProfile) IOException(java.io.IOException) ReleaseImportException(org.ihtsdo.otf.snomedboot.ReleaseImportException)

Example 3 with ReleaseImportException

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);
                }
            }
        }
    });
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) ReleaseImportException(org.ihtsdo.otf.snomedboot.ReleaseImportException) IOException(java.io.IOException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with ReleaseImportException

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");
}
Also used : Branch(io.kaicode.elasticvc.domain.Branch) ReleaseImportException(org.ihtsdo.otf.snomedboot.ReleaseImportException) ReleaseImportException(org.ihtsdo.otf.snomedboot.ReleaseImportException) AbstractTest(org.snomed.snowstorm.AbstractTest) Test(org.junit.jupiter.api.Test)

Aggregations

ReleaseImportException (org.ihtsdo.otf.snomedboot.ReleaseImportException)4 IOException (java.io.IOException)3 Branch (io.kaicode.elasticvc.domain.Branch)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 InvalidContent (org.ihtsdo.drools.response.InvalidContent)1 ReleaseImporter (org.ihtsdo.otf.snomedboot.ReleaseImporter)1 LoadingProfile (org.ihtsdo.otf.snomedboot.factory.LoadingProfile)1 Test (org.junit.jupiter.api.Test)1 AbstractTest (org.snomed.snowstorm.AbstractTest)1 RF2Type (org.snomed.snowstorm.core.rf2.RF2Type)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1