public static <T> Map<T, Collection<UniformItemPath>> extractOptionValues(Collection<SelectorOptions<GetOperationOptions>> options, Function<GetOperationOptions, T> supplier, PrismContext prismContext) { Map<T, Collection<UniformItemPath>> rv = new HashMap<>(); final UniformItemPath EMPTY_PATH = prismContext.emptyPath(); for (SelectorOptions<GetOperationOptions> selectorOption : CollectionUtils.emptyIfNull(options)) { T value = supplier.apply(selectorOption.getOptions()); if (value != null) { Collection<UniformItemPath> itemPaths = rv.computeIfAbsent(value, t -> new HashSet<>()); itemPaths.add(selectorOption.getItemPath(EMPTY_PATH)); } } return rv; }
@NotNull private List<? extends ItemPath> getPathsToResolve(Collection<SelectorOptions<GetOperationOptions>> options) { final UniformItemPath EMPTY_PATH = prismContext.emptyPath(); List<UniformItemPath> rv = new ArrayList<>(); for (SelectorOptions<GetOperationOptions> option : CollectionUtils.emptyIfNull(options)) { if (GetOperationOptions.isResolveNames(option.getOptions())) { rv.add(option.getItemPath(EMPTY_PATH)); } } return rv; } }
@NotNull @SafeVarargs public static Collection<SelectorOptions<GetOperationOptions>> merge(PrismContext prismContext, Collection<SelectorOptions<GetOperationOptions>>... parts) { UniformItemPath EMPTY_PATH = prismContext.emptyPath(); Collection<SelectorOptions<GetOperationOptions>> merged = new ArrayList<>(); for (Collection<SelectorOptions<GetOperationOptions>> part : parts) { for (SelectorOptions<GetOperationOptions> increment : CollectionUtils.emptyIfNull(part)) { if (increment != null) { // should always be so Collection<GetOperationOptions> existing = SelectorOptions.findOptionsForPath(merged, increment.getItemPath(EMPTY_PATH)); if (existing.isEmpty()) { merged.add(increment); } else if (existing.size() == 1) { existing.iterator().next().merge(increment.getOptions()); } else { throw new AssertionError("More than one options for path: " + increment.getItemPath(EMPTY_PATH)); } } } } return merged; }
@Override public GetOperationOptionsBuilder setFrom(Collection<SelectorOptions<GetOperationOptions>> newOptions) { options.clear(); currentPaths = singleton(prismContext.emptyPath()); relationalValueSearchQuery = null; for (SelectorOptions<GetOperationOptions> newOption : emptyIfNull(newOptions)) { if (newOption.getOptions() != null) { UniformItemPath itemPath = newOption.getItemPath(prismContext.emptyPath()); if (options.containsKey(itemPath)) { throw new IllegalStateException( "Options for item path '" + itemPath + "' are defined more than once in " + newOptions); } else { options.put(itemPath, newOption.getOptions().clone()); } } } return this; }
@Override public GetOperationOptionsBuilder mergeFrom(Collection<SelectorOptions<GetOperationOptions>> newOptions) { currentPaths = singleton(prismContext.emptyPath()); relationalValueSearchQuery = null; for (SelectorOptions<GetOperationOptions> newOption : emptyIfNull(newOptions)) { if (newOption.getOptions() != null) { UniformItemPath itemPath = newOption.getItemPath(prismContext.emptyPath()); GetOperationOptions currentOptions = options.get(itemPath); if (currentOptions != null) { currentOptions.merge(newOption.getOptions()); } else { options.put(itemPath, newOption.getOptions().clone()); } } } return this; }