Search in sources :

Example 41 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class DescendantsExpander method expand.

public final void expand(List<R> results, Set<String> ids) {
    if (!expand().containsKey(descendantsExpandKey)) {
        return;
    }
    final Options descendantExpandOptions = expand().get(descendantsExpandKey, Options.class);
    final boolean direct = checkDirect(descendantExpandOptions);
    expand(results, ids, descendantExpandOptions, direct);
}
Also used : Options(com.b2international.commons.options.Options)

Example 42 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class ResourceConverter method expandVersions.

private void expandVersions(List<Resource> results) {
    if (expand().containsKey(TerminologyResource.Expand.VERSIONS)) {
        Options expandOptions = expand().getOptions(TerminologyResource.Expand.VERSIONS);
        // version searches must be performed on individual terminology resources to provide correct results
        results.stream().filter(TerminologyResource.class::isInstance).map(TerminologyResource.class::cast).forEach(res -> {
            Versions versions = ResourceRequests.prepareSearchVersion().filterByResource(res.getResourceURI()).setLimit(getLimit(expandOptions)).setFields(expandOptions.containsKey("fields") ? expandOptions.getList("fields", String.class) : null).sortBy(expandOptions.containsKey("sort") ? expandOptions.getString("sort") : null).setLocales(locales()).build().execute(context());
            res.setVersions(versions);
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) Versions(com.b2international.snowowl.core.version.Versions) TerminologyResource(com.b2international.snowowl.core.TerminologyResource)

Example 43 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class InactivationPropertiesExpander method expand.

void expand(List<? extends SnomedCoreComponent> results, Set<String> referencedComponentIds) {
    if (!expand.containsKey(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES)) {
        return;
    }
    final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = ArrayListMultimap.create();
    SnomedRequests.prepareSearchMember().setLimit(10_000).filterByActive(true).filterByRefSet(String.format("<%s OR %s", Concepts.REFSET_ASSOCIATION_TYPE, inactivationIndicatorRefSetId)).filterByReferencedComponent(referencedComponentIds).stream(context).flatMap(SnomedReferenceSetMembers::stream).forEachOrdered(member -> {
        membersByReferencedComponentId.put(member.getReferencedComponentId(), member);
    });
    final Options inactivationPropertiesExpand = expand.getOptions(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES);
    Map<String, SnomedConcept> associationTargetComponentsById = Collections.emptyMap();
    Map<String, SnomedConcept> inactivationIndicatorsById = Collections.emptyMap();
    final Options nestedExpands = inactivationPropertiesExpand.getOptions("expand");
    if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.ASSOCIATION_TARGETS)) {
        final Options associationTargetsExpand = nestedExpands.getOptions(InactivationProperties.Expand.ASSOCIATION_TARGETS).getOptions("expand");
        final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ASSOCIATION.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
        if (associationTargetsExpand != null && associationTargetsExpand.containsKey(AssociationTarget.Expand.TARGET_COMPONENT)) {
            associationTargetComponentsById = expandConceptByIdMap(associationTargetsExpand.getOptions(AssociationTarget.Expand.TARGET_COMPONENT).getOptions("expand"), componentsToExpand, context);
        }
    }
    if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.INACTIVATION_INDICATOR)) {
        final Options inactivationIndicatorExpand = nestedExpands.getOptions(InactivationProperties.Expand.INACTIVATION_INDICATOR);
        final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ATTRIBUTE_VALUE.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
        inactivationIndicatorsById = expandConceptByIdMap(inactivationIndicatorExpand.getOptions("expand"), componentsToExpand, context);
    }
    for (SnomedCoreComponent result : results) {
        final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId.get(result.getId());
        final ImmutableList.Builder<AssociationTarget> associationTargets = ImmutableList.builder();
        final Set<String> inactivationIndicatorIds = Sets.newHashSet();
        for (SnomedReferenceSetMember referringMember : referringMembers) {
            if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) {
                final AssociationTarget associationTarget = new AssociationTarget();
                final String targetComponentId = (String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID);
                associationTarget.setReferenceSetId(referringMember.getRefsetId());
                associationTarget.setTargetComponentId(targetComponentId);
                if (associationTargetComponentsById.containsKey(targetComponentId)) {
                    associationTarget.setTargetComponent(associationTargetComponentsById.get(targetComponentId));
                }
                associationTargets.add(associationTarget);
            } else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) {
                inactivationIndicatorIds.add((String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
            }
        }
        final String inactivationIndicatorId = Iterables.getFirst(inactivationIndicatorIds, null);
        InactivationProperties inactivationProperties = new InactivationProperties();
        inactivationProperties.setInactivationIndicatorId(inactivationIndicatorId);
        inactivationProperties.setAssociationTargets(associationTargets.build());
        if (!Strings.isNullOrEmpty(inactivationIndicatorId) && inactivationIndicatorsById.containsKey(inactivationIndicatorId)) {
            inactivationProperties.setInactivationIndicator(inactivationIndicatorsById.get(inactivationIndicatorId));
        }
        result.setInactivationProperties(inactivationProperties);
    }
}
Also used : java.util(java.util) com.b2international.snowowl.snomed.core.domain(com.b2international.snowowl.snomed.core.domain) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) com.google.common.collect(com.google.common.collect) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Options(com.b2international.commons.options.Options) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)

Example 44 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class ModuleExpander method expand.

void expand(List<? extends SnomedComponent> results) {
    if (expand.containsKey(SnomedComponent.Expand.MODULE)) {
        final Options moduleOptions = expand.get(SnomedComponent.Expand.MODULE, Options.class);
        final Iterable<String> moduleIds = results.stream().map(SnomedComponent::getModuleId)::iterator;
        context.service(SnomedConceptRequestCache.class).request(moduleIds, moduleOptions.getOptions("expand"), locales, modulesById -> {
            for (SnomedComponent component : results) {
                component.setModule(modulesById.get(component.getModuleId()));
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) SnomedComponent(com.b2international.snowowl.snomed.core.domain.SnomedComponent)

Example 45 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedRelationshipConverter method expandType.

private void expandType(List<SnomedRelationship> results) {
    if (expand().containsKey(SnomedRelationship.Expand.TYPE)) {
        final Options typeOptions = expand().get(SnomedRelationship.Expand.TYPE, Options.class);
        final Iterable<String> typeConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getTypeId);
        context().service(SnomedConceptRequestCache.class).request(typeConceptIds, typeOptions.getOptions("expand"), locales(), typeConceptsById -> {
            for (SnomedRelationship relationship : results) {
                final String typeId = relationship.getTypeId();
                if (typeConceptsById.containsKey(typeId)) {
                    final SnomedConcept typeConcept = typeConceptsById.get(typeId);
                    ((SnomedRelationship) relationship).setType(typeConcept);
                }
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Aggregations

Options (com.b2international.commons.options.Options)57 List (java.util.List)15 Collectors (java.util.stream.Collectors)14 Set (java.util.Set)13 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)11 BranchContext (com.b2international.snowowl.core.domain.BranchContext)11 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)11 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)11 Test (org.junit.Test)9 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)8 Map (java.util.Map)8 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)7 BadRequestException (com.b2international.commons.exceptions.BadRequestException)6 ResourceURI (com.b2international.snowowl.core.ResourceURI)6 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)6 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)6 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)6 Multimaps (com.google.common.collect.Multimaps)6 Collection (java.util.Collection)6