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) } } } } }
public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException { List<ItemPath> keep = convert(expression.getKeep()); List<ItemPath> remove = convert(expression.getRemove()); if (keep.isEmpty() && remove.isEmpty()) { return input; // nothing to do here } for (PipelineItem pipelineItem : input.getData()) { PrismValue value = pipelineItem.getValue(); if (!(value instanceof PrismContainerValue)) { String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value; if (context.isContinueOnAnyError()) { LOGGER.error(message); } else { throw new ScriptExecutionException(message); } } else { PrismContainerValue<?> pcv = (PrismContainerValue) value; if (!keep.isEmpty()) { pcv.keepPaths(keep); } else { pcv.removePaths(remove); } } } return input; }