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;
}
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()));
}
}
}
Aggregations