Search in sources :

Example 6 with ComponentURI

use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.

the class ConceptMapSearchMappingRequestSnomedMapTypeReferenceSetTest method filterByComponentUriAndId.

@Test
public void filterByComponentUriAndId() {
    final String refSetId = createSimpleMapTypeRefSet();
    final String filterId = "12345";
    final ComponentURI uri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, filterId);
    final ComponentURI sourceUri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, REFERENCED_COMPONENT);
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, filterId);
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, "Random map target");
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri.toString());
    final ConceptMapMappings conceptMaps = ConceptMapRequests.prepareSearchConceptMapMappings().all().filterByComponentIds(Set.of(uri.toString(), uri.identifier())).filterByConceptMap(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, refSetId).toString()).setLocales("en").buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertEquals(2, conceptMaps.getTotal());
    Set<ComponentURI> componentUris = getComponentUris(conceptMaps);
    assertThat(componentUris).containsOnly(sourceUri, uri, ComponentURI.unspecified(filterId));
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings) Test(org.junit.Test)

Example 7 with ComponentURI

use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.

the class ConceptMapSearchMappingRequestSnomedMapTypeReferenceSetTest method filterByComponentUris.

@Test
public void filterByComponentUris() {
    final String refSetId = createSimpleMapTypeRefSet();
    final ComponentURI uri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, "12345");
    final ComponentURI uri2 = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, "54321");
    final ComponentURI sourceUri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, REFERENCED_COMPONENT);
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri.toString());
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri2.toString());
    createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, "Random map target");
    final ConceptMapMappings conceptMaps = ConceptMapRequests.prepareSearchConceptMapMappings().all().filterByComponentIds(Set.of(uri.toString(), uri2.toString())).filterByConceptMap(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, refSetId).toString()).setLocales("en").buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertEquals(2, conceptMaps.getTotal());
    Set<ComponentURI> componentUris = getComponentUris(conceptMaps);
    assertThat(componentUris).containsOnly(sourceUri, uri, uri2);
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings) Test(org.junit.Test)

Example 8 with ComponentURI

use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.

the class GenericValidationRuleTest method affectedComponentURI.

@Test
public void affectedComponentURI() throws Exception {
    final String ruleId = "45a";
    indexRule(ruleId);
    // index invalid hierarchical relationship to group 1
    final SnomedRelationshipIndexEntry relationship = relationship(Concepts.FINDING_SITE, Concepts.IS_A, Concepts.MODULE_SCT_MODEL_COMPONENT).relationshipGroup(1).build();
    indexRevision(MAIN, relationship);
    ValidationIssues issues = validate(ruleId);
    ComponentURI componentURI = issues.stream().map(issue -> issue.getAffectedComponentURI()).findFirst().orElse(null);
    assertThat(componentURI).isEqualTo(ComponentURI.of(CodeSystem.uri(CODESYSTEM), SnomedRelationship.TYPE, relationship.getId()));
}
Also used : ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Test(org.junit.Test)

Example 9 with ComponentURI

use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.

the class SnomedRf2ImportRequest method doImport.

ImportResponse doImport(final BranchContext context, final File rf2Archive, final Rf2ImportConfiguration importconfig) throws Exception {
    final ResourceURI codeSystemUri = context.service(ResourceURI.class);
    final Rf2ValidationIssueReporter reporter = new Rf2ValidationIssueReporter();
    String latestVersionEffectiveTime = EffectiveTimes.format(ResourceRequests.prepareSearchVersion().one().filterByResource(codeSystemUri.withoutPath()).sortBy("effectiveTime:desc").buildAsync().execute(context).first().map(Version::getEffectiveTime).orElse(LocalDate.EPOCH), DateFormats.SHORT);
    try (final DB db = createDb()) {
        // Read effective time slices from import files
        final Rf2EffectiveTimeSlices effectiveTimeSlices = new Rf2EffectiveTimeSlices(db, isLoadOnDemandEnabled(), latestVersionEffectiveTime, importUntil == null ? null : EffectiveTimes.format(importUntil, DateFormats.SHORT));
        Stopwatch w = Stopwatch.createStarted();
        read(rf2Archive, effectiveTimeSlices, reporter);
        log.info("Preparing RF2 import took: {}", w);
        w.reset().start();
        // Log issues with rows from the import files
        logValidationIssues(reporter);
        if (reporter.hasErrors()) {
            return ImportResponse.defects(reporter.getDefects());
        }
        // Run validation that takes current terminology content into account
        final List<Rf2EffectiveTimeSlice> orderedEffectiveTimeSlices = effectiveTimeSlices.consumeInOrder();
        final Rf2GlobalValidator globalValidator = new Rf2GlobalValidator(log, ignoreMissingReferencesIn);
        /* 
			 * TODO: Use Attachment to get the release file name and/or track file and line number sources for each row 
			 * so that they can be referenced in this stage as well
			 */
        final ImportDefectAcceptor globalDefectAcceptor = reporter.getDefectAcceptor("RF2 release");
        globalValidator.validateTerminologyComponents(orderedEffectiveTimeSlices, globalDefectAcceptor, context);
        // globalValidator.validateMembers(orderedEffectiveTimeSlices, globalDefectAcceptor, context);
        // Log validation issues (but just the ones found during global validation)
        logValidationIssues(globalDefectAcceptor);
        if (reporter.hasErrors()) {
            return ImportResponse.defects(reporter.getDefects());
        }
        // Import effective time slices in chronological order
        final ImmutableSet.Builder<ComponentURI> visitedComponents = ImmutableSet.builder();
        // if not a dryRun, perform import
        if (!dryRun) {
            // Import effective time slices in chronological order
            for (Rf2EffectiveTimeSlice slice : orderedEffectiveTimeSlices) {
                slice.doImport(context, codeSystemUri, importconfig, visitedComponents);
            }
            // Update locales registered on the code system
            updateCodeSystemSettings(context, codeSystemUri);
        }
        return ImportResponse.success(visitedComponents.build(), reporter.getDefects());
    }
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) Rf2GlobalValidator(com.b2international.snowowl.snomed.datastore.request.rf2.validation.Rf2GlobalValidator) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Stopwatch(com.google.common.base.Stopwatch) ImmutableSet(com.google.common.collect.ImmutableSet) Version(com.b2international.snowowl.core.version.Version) Rf2ValidationIssueReporter(com.b2international.snowowl.snomed.datastore.request.rf2.validation.Rf2ValidationIssueReporter) ImportDefectAcceptor(com.b2international.snowowl.core.request.io.ImportDefectAcceptor) DB(org.mapdb.DB)

Example 10 with ComponentURI

use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.

the class ImportRequest method doExecute.

@Override
public final ImportResponse doExecute(TransactionContext context) {
    context.log().info("Importing components from source file '{}'.", this.attachment.getFileName());
    InternalAttachmentRegistry iar = null;
    try {
        iar = (InternalAttachmentRegistry) context.service(AttachmentRegistry.class);
        File attachment = iar.getAttachment(this.attachment.getAttachmentId());
        ImportDefectAcceptor defectsAcceptor = new ImportDefectAcceptor(this.attachment.getFileName());
        doValidate(context, attachment, defectsAcceptor, context.service(IProgressMonitor.class));
        final ImportResponse validationResponse = ImportResponse.defects(defectsAcceptor.getDefects());
        if (!validationResponse.getErrors().isEmpty()) {
            return validationResponse;
        } else {
            final Set<ComponentURI> visitedComponents = Sets.newHashSet();
            doImport(context, attachment, visitedComponents::add, context.service(IProgressMonitor.class));
            context.log().info("Finished importing components from source file '{}'.", this.attachment.getFileName());
            return ImportResponse.success(visitedComponents, validationResponse.getDefects());
        }
    } catch (ApiException e) {
        throw e;
    } catch (Exception e) {
        String error = "Unexpected error happened during the import of the source file: " + attachment.getFileName();
        context.log().error(error, e);
        return ImportResponse.error(error);
    } finally {
        if (attachment != null && iar != null) {
            iar.delete(attachment.getAttachmentId());
        }
    }
}
Also used : InternalAttachmentRegistry(com.b2international.snowowl.core.attachments.InternalAttachmentRegistry) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) File(java.io.File) ApiException(com.b2international.commons.exceptions.ApiException) ApiException(com.b2international.commons.exceptions.ApiException)

Aggregations

ComponentURI (com.b2international.snowowl.core.uri.ComponentURI)10 Test (org.junit.Test)5 ConceptMapMappings (com.b2international.snowowl.core.domain.ConceptMapMappings)3 ApiException (com.b2international.commons.exceptions.ApiException)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 InternalAttachmentRegistry (com.b2international.snowowl.core.attachments.InternalAttachmentRegistry)2 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)2 File (java.io.File)2 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Options (com.b2international.commons.options.Options)1 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)1 BaseRevisionIndexTest (com.b2international.index.revision.BaseRevisionIndexTest)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 Concept (com.b2international.snowowl.core.domain.Concept)1 ConceptMapMapping (com.b2international.snowowl.core.domain.ConceptMapMapping)1 Builder (com.b2international.snowowl.core.domain.ConceptMapMapping.Builder)1 ResourceDocument (com.b2international.snowowl.core.internal.ResourceDocument)1