/** * No not fetch any information from external sources, e.g. do not fetch account data from resource, * do not fetch resource schema, etc. * Such operation returns only the data stored in midPoint repository. */ public static Collection<SelectorOptions<GetOperationOptions>> createNoFetchCollection() { return SelectorOptions.createCollection(createNoFetch()); }
private boolean isRaw(Collection<SelectorOptions<GetOperationOptions>> options) { GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options); return rootOptions == null ? false : GetOperationOptions.isRaw(rootOptions); }
public Collection<SelectorOptions<GetOperationOptions>> createGetOptions(SelectorQualifiedGetOptionsType optionsBean, boolean noFetch) { LOGGER.trace("optionsBean = {}, noFetch = {}", optionsBean, noFetch); Collection<SelectorOptions<GetOperationOptions>> rv = MiscSchemaUtil.optionsTypeToOptions(optionsBean, prismContext); if (noFetch) { if (rv == null) { return SelectorOptions.createCollection(GetOperationOptions.createNoFetch()); } GetOperationOptions root = SelectorOptions.findRootOptions(rv); if (root != null) { root.setNoFetch(true); } else { rv.add(SelectorOptions.create(GetOperationOptions.createNoFetch())); } } return rv; }
/** * 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> Collection<SelectorOptions<T>> updateRootOptions(Collection<SelectorOptions<T>> options, Consumer<T> updater, Supplier<T> newValueSupplier) { if (options == null) { options = new ArrayList<>(); } T rootOptions = findRootOptions(options); if (rootOptions == null) { rootOptions = newValueSupplier.get(); options.add(new SelectorOptions<>(rootOptions)); } updater.accept(rootOptions); return options; }
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; }
if (GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options))) { repoOptions = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
public static Collection<SelectorOptions<GetOperationOptions>> fromRestOptions(List<String> options, List<String> include, List<String> exclude, DefinitionProcessingOption definitionProcessing, PrismContext prismContext) { if (CollectionUtils.isEmpty(options) && CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)) { if (definitionProcessing != null) { return SelectorOptions.createCollection(GetOperationOptions.createDefinitionProcessing(definitionProcessing)); } return null; } Collection<SelectorOptions<GetOperationOptions>> rv = new ArrayList<>(); GetOperationOptions rootOptions = fromRestOptions(options, definitionProcessing); if (rootOptions != null) { rv.add(SelectorOptions.create(rootOptions)); } for (ItemPath includePath : ItemPathCollectionsUtil.pathListFromStrings(include, prismContext)) { rv.add(SelectorOptions.create(prismContext.toUniformPath(includePath), GetOperationOptions.createRetrieve())); } for (ItemPath excludePath : ItemPathCollectionsUtil.pathListFromStrings(exclude, prismContext)) { rv.add(SelectorOptions.create(prismContext.toUniformPath(excludePath), GetOperationOptions.createDontRetrieve())); } // Do NOT set executionPhase here! return rv; }
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 ClusterStatusInformation getClusterStatusInformation(Collection<SelectorOptions<GetOperationOptions>> options, Class<? extends ObjectType> objectClass, boolean allowCached, OperationResult result) { boolean noFetch = GetOperationOptions.isNoFetch(SelectorOptions.findRootOptions(options)); boolean retrieveStatus; if (noFetch) { retrieveStatus = false; } else { if (objectClass.equals(TaskType.class)) { retrieveStatus = SelectorOptions.hasToLoadPath(TaskType.F_NODE_AS_OBSERVED, options); } else if (objectClass.equals(NodeType.class)) { retrieveStatus = true; // implement some determination algorithm if needed } else { throw new IllegalArgumentException("object class: " + objectClass); } } if (retrieveStatus) { return executionManager.getClusterStatusInformation(true, allowCached, result); } else { 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; }
readOptions = new ArrayList<>(); GetOperationOptions root = SelectorOptions.findRootOptions(readOptions); if (root == null) { readOptions.add(SelectorOptions.create(GetOperationOptions.createAllowNotFound())); } else { root.setAllowNotFound(true);
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; }
private PrismObject<TaskType> getTaskAsObject(String oid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException, ObjectNotFoundException { ClusterStatusInformation clusterStatusInformation = getClusterStatusInformation(options, TaskType.class, true, result); // returns null if noFetch is set Task task = getTask(oid, options, result); addTransientTaskInformation(task.getTaskPrismObject(), clusterStatusInformation, SelectorOptions.hasToLoadPath(TaskType.F_NEXT_RUN_START_TIMESTAMP, options), SelectorOptions.hasToLoadPath(TaskType.F_NEXT_RETRY_TIMESTAMP, options), SelectorOptions.hasToLoadPath(TaskType.F_NODE_AS_OBSERVED, options), result); if (SelectorOptions.hasToLoadPath(TaskType.F_SUBTASK, options)) { fillInSubtasks(task, clusterStatusInformation, options, result); } fillOperationExecutionState(task); return task.getTaskPrismObject(); }
public static <T> Collection<SelectorOptions<T>> createCollection(UniformItemPath path, T options) { Collection<SelectorOptions<T>> optionsCollection = new ArrayList<>(1); optionsCollection.add(create(path, options)); return optionsCollection; }
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); } } } }
@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; }
@Deprecated // use GetOperationOptionsBuilder public static <T> Collection<SelectorOptions<T>> set(Collection<SelectorOptions<T>> options, UniformItemPath path, Supplier<T> constructor, Consumer<T> setter) { if (options == null) { options = new ArrayList<>(); } Collection<T> optionsForPath = findOptionsForPath(options, path); T option; if (optionsForPath.isEmpty()) { option = constructor.get(); options.add(SelectorOptions.create(path, option)); } else { option = optionsForPath.iterator().next(); } setter.accept(option); return options; } //endregion
/** * 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; }
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; }