public static List<SelectorOptions<GetOperationOptions>> filterRetrieveOptions( Collection<SelectorOptions<GetOperationOptions>> options) { List<SelectorOptions<GetOperationOptions>> retrieveOptions = new ArrayList<>(); if (options == null) { return retrieveOptions; } for (SelectorOptions<GetOperationOptions> option : options) { if (option.getOptions() == null || option.getOptions().getRetrieve() == null) { continue; } retrieveOptions.add(option); } return retrieveOptions; }
/** * Returns options that apply to the "root" object. I.e. options that have null selector, null path, empty path, ... * Must return 'live object' that could be modified. */ public static <T> T findRootOptions(Collection<SelectorOptions<T>> options) { if (options == null) { return null; } for (SelectorOptions<T> oooption: options) { if (oooption.isRoot()) { return oooption.getOptions(); } } return null; }
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; }
/** * Finds all the options for given path. TODO could there be more than one? * Returns live objects that could be modified by client. */ @NotNull public static <T> Collection<T> findOptionsForPath(Collection<SelectorOptions<T>> options, @NotNull UniformItemPath path) { Collection<T> rv = new ArrayList<>(); for (SelectorOptions<T> oooption: CollectionUtils.emptyIfNull(options)) { if (path.equivalent(oooption.getItemPathOrNull())) { rv.add(oooption.getOptions()); } } return rv; }
@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; }
@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; } }
@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; }
@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; }
private <O extends ObjectType> PrismObject<O> resolveReferenceUsingOption(@NotNull PrismReferenceValue refVal, SelectorOptions<GetOperationOptions> option, Containerable containerable, Task task, OperationResult parentResult) { OperationResult result = parentResult.createMinorSubresult(RESOLVE_REFERENCE); try { PrismObject<O> refObject; refObject = objectResolver.resolve(refVal, containerable.toString(), option.getOptions(), task, result); refObject = refObject.cloneIfImmutable(); schemaTransformer.applySchemasAndSecurity(refObject, option.getOptions(), SelectorOptions.createCollection(option.getOptions()), null, task, result); refVal.setObject(refObject); return refObject; } catch (CommonException e) { result.recordWarning("Couldn't resolve reference to " + ObjectTypeUtil.toShortString(refVal) + ": " + e.getMessage(), e); return null; } finally { result.computeStatusIfUnknown(); } }
private boolean nullOrHarmlessOptions(Collection<SelectorOptions<GetOperationOptions>> options) { if (options == null || options.isEmpty()) { return true; } if (options.size() > 1) { return false; } SelectorOptions<GetOperationOptions> selectorOptions = options.iterator().next(); if (!selectorOptions.isRoot()) { return false; } GetOperationOptions options1 = selectorOptions.getOptions(); // TODO FIX THIS!!! if (options1 == null || options1.equals(new GetOperationOptions()) || options1.equals(GetOperationOptions.createAllowNotFound()) || options1.equals(GetOperationOptions.createExecutionPhase())) { return true; } return false; }
private void executeResolveOptions(@NotNull Containerable containerable, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) { if (options == null) { return; } for (SelectorOptions<GetOperationOptions> option: options) { if (GetOperationOptions.isResolve(option.getOptions())) { ObjectSelector selector = option.getSelector(); if (selector != null) { ItemPath path = selector.getPath(); ItemPath.checkNoSpecialSymbolsExceptParent(path); executeResolveOption(containerable, path, option, task, result); } } } }
public GetOperationOptions findLookupTableGetOption(Collection<SelectorOptions<GetOperationOptions>> options) { Collection<SelectorOptions<GetOperationOptions>> filtered = SelectorOptions.filterRetrieveOptions(options); for (SelectorOptions<GetOperationOptions> option : filtered) { ObjectSelector selector = option.getSelector(); if (selector == null) { // Ignore this. These are top-level options. There will not // apply to lookup table continue; } if (LookupTableType.F_ROW.equivalent(selector.getPath())) { return option.getOptions(); } } return null; }
public static boolean isExplicitlyIncluded(UniformItemPath path, Collection<SelectorOptions<GetOperationOptions>> options) { List<SelectorOptions<GetOperationOptions>> retrieveOptions = filterRetrieveOptions(options); if (retrieveOptions.isEmpty()) { return false; } for (SelectorOptions<GetOperationOptions> option : retrieveOptions) { ObjectSelector selector = option.getSelector(); if (selector != null) { UniformItemPath selected = selector.getPath(); if (!isPathInSelected(path, selected)) { continue; } } RetrieveOption retrieveOption = option.getOptions().getRetrieve(); switch (retrieveOption) { case INCLUDE: return true; case EXCLUDE: case DEFAULT: default: return false; } } return false; }
private static SelectorQualifiedGetOptionType selectorOptionToSelectorQualifiedGetOptionType(SelectorOptions<GetOperationOptions> selectorOption) { OptionObjectSelectorType selectorType = selectorToSelectorType(selectorOption.getSelector()); GetOperationOptionsType getOptionsType = getOptionsToGetOptionsType(selectorOption.getOptions()); SelectorQualifiedGetOptionType selectorOptionType = new SelectorQualifiedGetOptionType(); selectorOptionType.setOptions(getOptionsType); selectorOptionType.setSelector(selectorType); return selectorOptionType; }
RetrieveOption retrieveOption = option.getOptions().getRetrieve(); for (ItemPath notByDefault : PATHS_NOT_RETURNED_BY_DEFAULT) { if (path.equivalent(notByDefault)) {