Search in sources :

Example 1 with ComponentURI

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

the class SnomedRefSetMemberDocumentSerializationTest method indexSimpleMapMemberWithComponentURITarget.

@Test
public void indexSimpleMapMemberWithComponentURITarget() throws Exception {
    final String mapTargetId = "targetId01";
    final ComponentURI componentURI = ComponentURI.of(SnomedContentRule.SNOMEDCT, SnomedConcept.TYPE, mapTargetId);
    final SnomedRefSetMemberIndexEntry member = createBaseMember().refsetId(Concepts.REFSET_B2I_EXAMPLE).referenceSetType(SnomedRefSetType.SIMPLE_MAP).field(Fields.MAP_TARGET, componentURI.toString()).build();
    indexRevision(RevisionBranch.MAIN_PATH, member);
    final SnomedRefSetMemberIndexEntry actual = getRevision(RevisionBranch.MAIN_PATH, SnomedRefSetMemberIndexEntry.class, member.getId());
    assertEquals(SnomedConcept.TYPE, actual.getReferencedComponentType());
    assertDocEquals(member, actual);
    assertEquals(ComponentURI.of(actual.getMapTarget()), componentURI);
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Test(org.junit.Test) BaseRevisionIndexTest(com.b2international.index.revision.BaseRevisionIndexTest)

Example 2 with ComponentURI

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

the class ImportResponseSerializationTest method before.

@BeforeClass
public static void before() {
    mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    ComponentURI componentURI = ComponentURI.of("codesystem/SNOMEDCT/100/138875005");
    ImportDefect defect = ImportDefect.info("file", "location", "message");
    response = ImportResponse.success(Set.of(componentURI), List.of(defect));
    serializedResponse = "{\"visitedComponents\":[\"codesystem/SNOMEDCT/100/138875005\"],\"defects\":[{\"file\":\"file\",\"location\":\"location\",\"message\":\"message\",\"type\":\"INFO\"}],\"success\":true}";
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 3 with ComponentURI

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

the class ValueSetMemberSearchSnomedReferenceSetTest method filterByComponentIdAndUri.

@Test
public void filterByComponentIdAndUri() {
    final String filteredId = Concepts.FINDING_SITE;
    final String refSetId = createSimpleMapTypeRefSet();
    createSimpleMapTypeRefSetMember(refSetId, filteredId, Concepts.IS_A);
    createSimpleMapTypeRefSetMember(refSetId, filteredId, Concepts.IS_A);
    createSimpleMapTypeRefSetMember(refSetId, Concepts.IS_A, filteredId);
    createSimpleMapTypeRefSetMember(refSetId, Concepts.IS_A, Concepts.IS_A);
    final ComponentURI uri = ComponentURI.of(SnomedContentRule.SNOMEDCT, SnomedConcept.TYPE, filteredId);
    final SnomedReferenceSetMembers refSetMembers = SnomedRequests.prepareSearchMember().filterByRefSet(refSetId).filterByComponentIds(Set.of(uri.toString(), uri.identifier())).build(CODESYSTEM).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertEquals(3, refSetMembers.getTotal());
    refSetMembers.forEach(refSetMember -> assertTrue(filteredId.equals(refSetMember.getReferencedComponentId()) || filteredId.equals(refSetMember.getProperties().get(SnomedRf2Headers.FIELD_MAP_TARGET))));
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Test(org.junit.Test)

Example 4 with ComponentURI

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

the class SnomedConceptMapSearchRequestEvaluator method toCollectionResource.

private ConceptMapMappings toCollectionResource(SnomedReferenceSetMembers referenceSetMembers, ResourceURI uri, ServiceProvider context, Options search, SnomedDisplayTermType snomedDisplayTermType) {
    final Set<String> refSetsToFetch = referenceSetMembers.stream().map(SnomedReferenceSetMember::getRefsetId).collect(Collectors.toSet());
    final Map<String, SnomedConcept> refSetsById = SnomedRequests.prepareSearchConcept().all().filterByIds(refSetsToFetch).setLocales(search.getList(OptionKey.LOCALES, ExtendedLocale.class)).setExpand("pt(),referenceSet()").build(uri).execute(context.service(IEventBus.class)).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(SnomedConcept::getId, concept -> concept));
    final Map<String, ComponentURI> targetComponentsByRefSetId = getTargetComponentsByRefSetId(context, refSetsById);
    List<ConceptMapMapping> mappings = referenceSetMembers.stream().filter(m -> SnomedConcept.TYPE.equals(m.getReferencedComponent().getComponentType())).map(m -> {
        return toMapping(m, uri, targetComponentsByRefSetId.get(m.getRefsetId()), snomedDisplayTermType, refSetsById);
    }).collect(Collectors.toList());
    if (!mappings.isEmpty()) {
        final Map<String, Concept> conceptsById = Multimaps.index(mappings, mapping -> mapping.getTargetComponentURI().resourceUri()).asMap().entrySet().stream().filter(entry -> !TerminologyRegistry.UNSPECIFIED.equals(entry.getKey().getResourceId())).map(entry -> {
            final Set<String> idsToFetch = entry.getValue().stream().map(map -> map.getTargetComponentURI().identifier()).collect(Collectors.toSet());
            return CodeSystemRequests.prepareSearchConcepts().all().filterByCodeSystemUri(entry.getKey()).filterByIds(idsToFetch).buildAsync().execute(context.service(IEventBus.class)).getSync(5, TimeUnit.MINUTES).stream().collect(Collectors.toMap(Concept::getId, c -> c));
        }).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue(), (concept1, concept2) -> concept1));
        mappings = mappings.stream().map(mapping -> {
            final String mapTargetId = mapping.getTargetComponentURI().identifier();
            if (conceptsById.containsKey(mapTargetId) && !mapping.getTargetComponentURI().isUnspecified()) {
                final Concept concept = conceptsById.get(mapTargetId);
                return mapping.toBuilder().targetTerm(concept.getTerm()).targetIconId(concept.getIconId()).build();
            } else {
                return mapping;
            }
        }).collect(Collectors.toList());
    }
    return new ConceptMapMappings(mappings, referenceSetMembers.getSearchAfter(), referenceSetMembers.getLimit(), referenceSetMembers.getTotal());
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) SnomedRefSetUtil(com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil) ConceptMapMappingSearchRequestEvaluator(com.b2international.snowowl.core.request.ConceptMapMappingSearchRequestEvaluator) SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Multimaps(com.google.common.collect.Multimaps) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings) Map(java.util.Map) ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) Collection(java.util.Collection) MappingCorrelation(com.b2international.snowowl.core.request.MappingCorrelation) Set(java.util.Set) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Builder(com.b2international.snowowl.core.domain.ConceptMapMapping.Builder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) TerminologyRegistry(com.b2international.snowowl.core.terminology.TerminologyRegistry) TimeUnit(java.util.concurrent.TimeUnit) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) List(java.util.List) Concept(com.b2international.snowowl.core.domain.Concept) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) OptionsBuilder(com.b2international.commons.options.OptionsBuilder) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Concept(com.b2international.snowowl.core.domain.Concept) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings)

Example 5 with ComponentURI

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

the class ResourcesImportRequest method execute.

@Override
public ImportResponse execute(ServiceProvider context) {
    final InternalAttachmentRegistry attachmentRegistry = (InternalAttachmentRegistry) context.service(AttachmentRegistry.class);
    final File file = attachmentRegistry.getAttachment(sourceFile.getAttachmentId());
    try {
        final List<R> sourceFileContent = loadSourceFileContent(context, file);
        final Map<String, R> existingResources = newHashMap(loadExistingResources(context, sourceFileContent));
        final ImportDefectAcceptor defectAcceptor = new ImportDefectAcceptor(sourceFile.getFileName());
        validateSourceFileContent(context, sourceFileContent, existingResources, defectAcceptor);
        List<ImportDefect> defects = defectAcceptor.getDefects();
        // Content with validation errors can not be imported
        ImportResponse validationResponse = ImportResponse.defects(defects);
        if (!validationResponse.getErrors().isEmpty()) {
            return validationResponse;
        }
        final Set<ComponentURI> visitedComponents = Sets.newHashSet();
        // Import each resource present in the source file, along with its content
        for (final R resource : sourceFileContent) {
            final String id = resource.getId();
            ComponentURI importedResource = importResource(context, resource, existingResources.get(id));
            if (importedResource != null) {
                visitedComponents.add(importedResource);
            }
            visitedComponents.addAll(importContent(context, resource, existingResources.get(id)));
        }
        return ImportResponse.success(visitedComponents, defects);
    } catch (final ApiException e) {
        throw e;
    } catch (final Exception e) {
        String error = "Unexpected error happened during the import of the source file: " + sourceFile.getFileName();
        context.log().error(error, e);
        return ImportResponse.error(error);
    } finally {
        if (sourceFile != null && attachmentRegistry != null) {
            attachmentRegistry.delete(sourceFile.getAttachmentId());
        }
    }
}
Also used : InternalAttachmentRegistry(com.b2international.snowowl.core.attachments.InternalAttachmentRegistry) InternalAttachmentRegistry(com.b2international.snowowl.core.attachments.InternalAttachmentRegistry) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ApiException(com.b2international.commons.exceptions.ApiException) File(java.io.File) 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