/** * Works if we are looking e.g. for modification to inducement item, * and delta contains e.g. REPLACE(inducement[1]/validTo, "..."). * * Does NOT work the way around: if we are looking for modification to inducement/validTo and * delta contains e.g. ADD(inducement, ...). In such a case we would need to do more complex processing, * involving splitting value-to-be-added into remainder and offspring delta. It's probably doable, * but some conditions would have to be met, e.g. inducement to be added must have an ID. */ private FactorOutResultSingle<O> factorOutForModifyDelta(Collection<? extends ItemPath> paths, boolean cloneDelta) { checkMutability(); ObjectDeltaImpl<O> remainder = cloneIfRequested(cloneDelta); ObjectDeltaImpl<O> offspring = null; List<ItemDelta<?, ?>> modificationsFound = new ArrayList<>(); for (Iterator<? extends ItemDelta<?, ?>> iterator = remainder.modifications.iterator(); iterator.hasNext(); ) { ItemDelta<?, ?> modification = iterator.next(); if (ItemPathCollectionsUtil.containsSubpathOrEquivalent(paths, modification.getPath())) { modificationsFound.add(modification); iterator.remove(); } } if (!modificationsFound.isEmpty()) { offspring = createOffspring(); modificationsFound.forEach(offspring::addModification); } return new FactorOutResultSingle<>(remainder, offspring); }
public void removePaths(List<? extends ItemPath> remove) { if (items != null) { for (Iterator<Item<?, ?>> iterator = items.iterator(); iterator.hasNext(); ) { Item<?, ?> item = iterator.next(); ItemPath itemPath = item.getPath().removeIds(); if (ItemPathCollectionsUtil.containsEquivalent(remove, itemPath)) { iterator.remove(); } else if (ItemPathCollectionsUtil.containsSuperpath(remove, itemPath)) { if (item instanceof PrismContainer) { ((PrismContainer<?>) item).getValues().forEach(v -> v.removePaths(remove)); } } } } }
@Override public void trimTo(@NotNull Collection<ItemPath> paths) { if (shared) { // TODO switch this to warning before releasing this code (3.6.1 or 3.7) throw new IllegalStateException("Couldn't trim shared definition: " + this); } for (Iterator<ItemDefinition> iterator = itemDefinitions.iterator(); iterator.hasNext(); ) { ItemDefinition<?> itemDef = iterator.next(); ItemPath itemPath = itemDef.getName(); if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(paths, itemPath)) { iterator.remove(); } else if (itemDef instanceof PrismContainerDefinition) { PrismContainerDefinition<?> itemPcd = (PrismContainerDefinition<?>) itemDef; if (itemPcd.getComplexTypeDefinition() != null) { itemPcd.getComplexTypeDefinition().trimTo(ItemPathCollectionsUtil.remainder(paths, itemPath, false)); } } } }
assertTrue(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyEmpty, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSubpath(onlyEmpty, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyEmpty, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyEmpty, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyEmpty, empty)); assertFalse(ItemPathCollectionsUtil.containsSubpath(onlyEmpty, empty)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyEmpty, empty)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyEmpty, empty)); assertTrue(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyFoo, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSubpath(onlyFoo, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyFoo, empty)); assertFalse(ItemPathCollectionsUtil.containsSubpath(onlyFoo, empty)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, empty)); assertTrue(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, empty)); assertFalse(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyFoo, pathZoo)); assertFalse(ItemPathCollectionsUtil.containsSubpath(onlyFoo, pathZoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, pathZoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, pathZoo)); assertFalse(ItemPathCollectionsUtil.containsSubpathOrEquivalent(onlyFooBar, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSubpath(onlyFooBar, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFooBar, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpath(onlyFooBar, pathFoo));
public List<ItemPath> evaluateUnsatisfierItems() { List<ItemPath> unsatisfiedItems = new ArrayList<>(); if (isAllItems()) { return unsatisfiedItems; } for (ItemPath requiredItem: requiredItems) { if (ItemPathCollectionsUtil.containsEquivalent(getIncludedItems(), requiredItem)) { // allowed continue; } if (!getExcludedItems().isEmpty() && !ItemPathCollectionsUtil.containsEquivalent(getExcludedItems(), requiredItem)) { // not notAllowed = allowed continue; } unsatisfiedItems.add(requiredItem); } return unsatisfiedItems; }
private void removeExcludes(PrismObject<? extends ObjectType> object, List<String> exclude) { object.getValue().removePaths(ItemPathCollectionsUtil.pathListFromStrings(exclude, prismContext)); }
ObjectTemplateType includeObjectType = includeObject.asObjectable(); Map<UniformItemPath, ObjectTemplateItemDefinitionType> includedDefinitions = collectItemDefinitionsFromTemplate(includeObjectType, "include "+includeObject+" in "+objectTemplateType + " in " + contextDesc, task, result); ItemPathCollectionsUtil.putAllToMap(definitions, includedDefinitions); throw new IllegalStateException("Item definition with null ref in " + contextDesc); ItemPathCollectionsUtil.putToMap(definitions, prismContext.toUniformPath(def.getRef()), def); // TODO check for incompatible overrides
public static <T> void putAllToMap(Map<UniformItemPath, T> target, Map<UniformItemPath, T> source) { for (Map.Entry<UniformItemPath, T> entry : source.entrySet()) { putToMap(target, entry.getKey(), entry.getValue()); } }
public void keepPaths(List<? extends ItemPath> keep) { if (items != null) { for (Iterator<Item<?, ?>> iterator = items.iterator(); iterator.hasNext(); ) { Item<?, ?> item = iterator.next(); ItemPath itemPath = item.getPath().removeIds(); if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(keep, itemPath)) { iterator.remove(); } else { if (item instanceof PrismContainer) { ((PrismContainer<?>) item).getValues().forEach(v -> v.keepPaths(keep)); } else { // TODO some additional checks here (e.g. when trying to keep 'name/xyz' - this is illegal) } } } } }
@NotNull public static Set<ItemPath> getFullTextSearchItemPaths(@NotNull FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) { List<QName> types = ObjectTypes.getObjectType(clazz).thisAndSupertypes().stream() .map(ot -> ot.getTypeQName()) .collect(Collectors.toList()); Set<ItemPath> paths = new HashSet<>(); for (FullTextSearchIndexedItemsConfigurationType indexed : config.getIndexed()) { if (isApplicable(indexed, types)) { for (ItemPathType itemPathType : indexed.getItem()) { ItemPath path = itemPathType.getItemPath(); if (!ItemPath.isEmpty(path) && !ItemPathCollectionsUtil.containsEquivalent(paths, path)) { paths.add(path); } } } } return paths; }
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; }
for (ItemDelta itemDelta : deltas) { ItemPath pathToExplain = getPathToExplain(itemDelta); if (pathToExplain == null || ItemPathCollectionsUtil.containsSubpathOrEquivalent(alreadyExplained, pathToExplain)) { continue; // null or already processed
if (extractor.selector.test(filter)) { ItemPath filterPath = extractor.pathExtractor.apply(filter); if (ItemPathCollectionsUtil.containsEquivalent(paths, filterPath)) { filterComponents.addToKnown(filterPath, extractor.valueExtractor.apply(filter), filter); found = true;
try { ResponseBuilder builder; List<ItemPath> ignoreItemPaths = ItemPathCollectionsUtil.pathListFromStrings(restIgnoreItems, prismContext); final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions, DefinitionProcessingOption.ONLY_IF_EXISTS); Collection<SelectorOptions<GetOperationOptions>> readOptions =
if (visitable instanceof PrismReferenceValue) { PrismReferenceValue value = (PrismReferenceValue) visitable; if (!ItemPathCollectionsUtil.containsSubpathOrEquivalent(pathsToResolve, value.getPath())) { return;
public static boolean hasToLoadPath(ItemPath path, Collection<SelectorOptions<GetOperationOptions>> options) { List<SelectorOptions<GetOperationOptions>> retrieveOptions = filterRetrieveOptions(options); if (retrieveOptions.isEmpty()) { return !ItemPathCollectionsUtil.containsEquivalent(PATHS_NOT_RETURNED_BY_DEFAULT, path);