Search in sources :

Example 1 with OptionsBuilder

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

the class SearchResourceRequest method processSpecialOptionKey.

@VisibleForTesting
static Options processSpecialOptionKey(Options options, Enum<?> specialOptionKey, BiFunction<Options, Enum<?>, String> extractSpecialOption) {
    if (specialOptionKey != null && options.containsKey(specialOptionKey)) {
        // this will throw a CCE if non-String value is encountered in the option key and that is okay
        String specialOption = extractSpecialOption.apply(options, specialOptionKey);
        if (specialOption.startsWith(SPECIAL_OPTION_CHARACTER) && specialOption.endsWith(")")) {
            // strip of the leading and trailing characters so we end up with a field(value expression that can be split on the first occurence of
            // the ( character
            String fieldAndValueWithParenSeparator = specialOption.substring(1, specialOption.length() - 1);
            int separatorIdx = fieldAndValueWithParenSeparator.indexOf("(");
            if (separatorIdx != -1) {
                String field = fieldAndValueWithParenSeparator.substring(0, separatorIdx).toUpperCase();
                String value = fieldAndValueWithParenSeparator.substring(separatorIdx + 1);
                if (!CompareUtils.isEmpty(field) && !CompareUtils.isEmpty(value)) {
                    OptionsBuilder newOptions = Options.builder().put(field, value);
                    for (String key : options.keySet()) {
                        if (!specialOptionKey.name().equals(key)) {
                            newOptions.put(key, options.get(key));
                        }
                    }
                    return newOptions.build();
                }
            }
        }
    }
    return options;
}
Also used : OptionsBuilder(com.b2international.commons.options.OptionsBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with OptionsBuilder

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

the class MembersExpander method expand.

void expand(List<? extends SnomedCoreComponent> results, Set<String> componentIds) {
    if (expand.containsKey("members")) {
        final Options membersOptions = expand.get("members", Options.class);
        // TODO better support for limit, offset, filtering, selection
        final SnomedRefSetMemberSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchMember().all().filterByReferencedComponent(componentIds);
        addActiveFilter(requestBuilder, membersOptions);
        addRefSetTypesFilter(requestBuilder, membersOptions);
        final OptionsBuilder propertyOptionsBuilder = OptionsBuilder.newBuilder();
        addCharacteristicTypeFilter(propertyOptionsBuilder, membersOptions);
        final Options propertyOptions = propertyOptionsBuilder.build();
        if (!propertyOptions.isEmpty()) {
            requestBuilder.filterByProps(propertyOptions);
        }
        final SnomedReferenceSetMembers matchingMembers = requestBuilder.setLocales(locales).setExpand(membersOptions.get("expand", Options.class)).build().execute(context);
        final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps.index(matchingMembers, input -> input.getReferencedComponent().getId());
        for (SnomedCoreComponent component : results) {
            final Collection<SnomedReferenceSetMember> members = membersByReferencedComponentId.get(component.getId());
            ((SnomedCoreComponent) component).setMembers(new SnomedReferenceSetMembers(ImmutableList.copyOf(members), null, members.size(), members.size()));
        }
    }
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Options(com.b2international.commons.options.Options) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) OptionsBuilder(com.b2international.commons.options.OptionsBuilder)

Aggregations

OptionsBuilder (com.b2international.commons.options.OptionsBuilder)2 Options (com.b2international.commons.options.Options)1 SnomedCoreComponent (com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent)1 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)1 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)1 SnomedRefSetMemberSearchRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1