/** * Returns the rest of the path (the tail), starting at position "n". */ @NotNull ItemPath rest(int n);
/** * Removes the leading variable segment, if present. */ @NotNull default ItemPath stripVariableSegment() { return startsWithVariable() ? rest() : this; }
@NotNull private ItemPath skipFirstId(@NotNull ItemPath path) { if (path.startsWithName()) { return path; } else if (path.startsWithId()) { return path.rest(); } else { throw new IllegalArgumentException("Unexpected path segment in "+path); } }
private ItemPath stripFirstIds(ItemPath itemPath) { while (!itemPath.isEmpty() && itemPath.startsWithId()) { itemPath = itemPath.rest(); } return itemPath; }
public static boolean matchesAttribute(ItemPath path, QName attributeName) { return path.startsWithName(ShadowType.F_ATTRIBUTES) && path.rest().startsWithName(attributeName); }
@NotNull @Override public Collection<PrismValue> getAllValues(ItemPath path) { if (path.isEmpty()) { return singleton(this); } Item<PrismValue, ItemDefinition> item = findItem(path.firstToName()); if (item == null) { return emptySet(); } ItemPath rest = path.rest(); List<PrismValue> rv = new ArrayList<>(); for (PrismValue prismValue : item.getValues()) { rv.addAll(prismValue.getAllValues(rest)); } return rv; }
@Override public <T extends ItemDefinition> T findItemDefinition(@NotNull ItemPath path, @NotNull Class<T> clazz) { if (!path.startsWithObjectReference()) { return super.findItemDefinition(path, clazz); } else { ItemPath rest = path.rest(); PrismObjectDefinition referencedObjectDefinition = getSchemaRegistry().determineReferencedObjectDefinition(targetTypeName, rest); return (T) ((ItemDefinition) referencedObjectDefinition).findItemDefinition(rest, clazz); } }
public static boolean pathMatches(@NotNull Collection<? extends ItemDelta<?, ?>> deltas, @NotNull ItemPath path, int segmentsToSkip, boolean exactMatch) { for (ItemDelta<?, ?> delta : deltas) { ItemPath modifiedPath = delta.getPath().rest(segmentsToSkip).removeIds(); // because of extension/cities[2]/name (in delta) vs. extension/cities/name (in spec) if (exactMatch) { if (path.equivalent(modifiedPath)) { return true; } } else { if (path.isSubPathOrEquivalent(modifiedPath)) { return true; } } } return false; }
@Override public <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I findCreateItem(ItemPath itemPath, Class<I> type, ID itemDefinition, boolean create) throws SchemaException { if (ItemPath.isEmpty(itemPath)) { throw new IllegalArgumentException("Empty path specified"); } Long id = itemPath.firstToIdOrNull(); PrismContainerValue<C> cval = findValue(id); if (cval == null) { return null; } // descent to the correct value ItemPath rest = itemPath.startsWithId() ? itemPath.rest() : itemPath; return ((PrismContainerValueImpl<C>) cval).findCreateItem(rest, type, itemDefinition, create); }
private ObjectQuery narrowQueryForBucket(ObjectQuery query, Task localCoordinatorTask, WorkBucketType workBucket, ObjectClassComplexTypeDefinition objectclassDef, OperationResult opResult) throws SchemaException, ObjectNotFoundException { return taskManager.narrowQueryForWorkBucket(query, ShadowType.class, itemPath -> { if (itemPath.startsWithName(ShadowType.F_ATTRIBUTES)) { return objectclassDef.findAttributeDefinition(itemPath.rest().asSingleName()); } else { return null; } }, localCoordinatorTask, workBucket, opResult); }
@Override public Object find(ItemPath path) { if (path == null || path.isEmpty()) { return this; } Object first = path.first(); if (!ItemPath.isName(first)) { throw new IllegalArgumentException("Attempt to lookup item using a non-name path "+path+" in "+this); } ItemName subName = ItemPath.toName(first); ItemPath rest = path.rest(); Item<?,?> subItem = findItem(subName); if (subItem == null) { return null; } return subItem.find(rest); }
@Override public <IV extends PrismValue,ID extends ItemDefinition> PartiallyResolvedItem<IV,ID> findPartial(ItemPath path) { if (path == null || path.isEmpty()) { // Incomplete path return null; } Object first = path.first(); if (!ItemPath.isName(first)) { throw new IllegalArgumentException("Attempt to lookup item using a non-name path "+path+" in "+this); } ItemName subName = ItemPath.toName(first); ItemPath rest = path.rest(); Item<?,?> subItem = findItem(subName); if (subItem == null) { return null; } return subItem.findPartial(rest); }
@Override public Object find(ItemPath path) { if (ItemPath.isEmpty(path)) { return this; } Long id = path.firstToIdOrNull(); PrismContainerValue<C> cval = findValue(id); if (cval == null) { return null; } // descent to the correct value ItemPath rest = path.startsWithId() ? path.rest() : path; return cval.find(rest); }
@Override public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) { if (ItemPath.isObjectReference(path.first())) { // returning artificially created transition definition, used to allow dereferencing target object in a generic way return new DataSearchResult<>( new JpaLinkDefinition<>(SchemaConstants.PATH_OBJECT_REFERENCE, "target", null, false, referencedEntityDefinition.getResolvedEntityDefinition()), path.rest()); } else { return null; } }
private void swallowIntoValues(Collection<AssignmentType> assignments, AssignmentType assignmentToFind, List<ItemDelta<?, ?>> modifications) throws SchemaException { for (AssignmentType assignment : assignments) { PrismContainerValue<?> pcv = assignment.asPrismContainerValue(); PrismContainerValue<?> pcvToFind = assignmentToFind.asPrismContainerValue(); if (pcv.representsSameValue(pcvToFind, false) || pcv.equals(pcvToFind, EquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS)) { // TODO what if ID of the assignment being added is changed in repo? Hopefully it will be not. for (ItemDelta<?, ?> modification : modifications) { ItemPath newParentPath = modification.getParentPath().rest(2); // killing assignment + ID ItemDelta<?, ?> pathRelativeModification = modification.cloneWithChangedParentPath(newParentPath); pathRelativeModification.applyTo(pcv); } return; } } // TODO change to warning throw new IllegalStateException("We have 'plus' assignment to modify but it couldn't be found in assignment delta. Assignment=" + assignmentToFind + ", new assignments=" + assignments); }
@Override public <IV extends PrismValue,ID extends ItemDefinition> PartiallyResolvedItem<IV,ID> findPartial(ItemPath path) { if (ItemPath.isEmpty(path)) { return new PartiallyResolvedItem<>((Item<IV, ID>) this, null); } Long id = path.firstToIdOrNull(); PrismContainerValue<C> cval = findValue(id); if (cval == null) { return null; } // descent to the correct value ItemPath rest = path.startsWithId() ? path.rest() : path; return cval.findPartial(rest); }
private <C extends Containerable> ItemDefinition locateItemDefinition(XNodeImpl valueXnode, ItemPath itemPath, PrismContainerDefinition<C> pcd) throws SchemaException{ ItemDefinition itemDefinition = null; if (pcd != null) { itemDefinition = pcd.findItemDefinition(itemPath); if (itemDefinition == null) { ItemPath rest = itemPath.rest(); QName first = itemPath.firstToName(); itemDefinition = ((PrismContextImpl) prismContext).getPrismUnmarshaller().locateItemDefinition(pcd, first, valueXnode); if (rest.isEmpty()) { return itemDefinition; } else{ if (itemDefinition instanceof PrismContainerDefinition){ //noinspection unchecked return locateItemDefinition(valueXnode, rest, (PrismContainerDefinition) itemDefinition); } } } } return itemDefinition; }
@Override protected Function<ItemPath, ItemDefinition<?>> getIdentifierDefinitionProvider(Task localCoordinatorTask, OperationResult opResult) { TaskRunResult dummyRunResult = new TaskRunResult(); ResourceType resource = resolveObjectRef(ResourceType.class, dummyRunResult, localCoordinatorTask, opResult); if (resource == null) { return null; } ObjectClassComplexTypeDefinition objectClass = determineObjectClassDefinition(resource, null, dummyRunResult, localCoordinatorTask, opResult); if (objectClass == null) { return null; } return itemPath -> { if (itemPath.startsWithName(ShadowType.F_ATTRIBUTES)) { return objectClass.findAttributeDefinition(itemPath.rest().asSingleName()); } else { return null; } }; }
public static void applyConfigurationDefinition(PrismObject<ReportType> report, ObjectDelta delta, PrismContext prismContext) throws SchemaException { PrismSchema schema = ReportTypeUtil.parseReportConfigurationSchema(report, prismContext); PrismContainerDefinition<ReportConfigurationType> definition = ReportTypeUtil.findReportConfigurationDefinition(schema); if (definition == null) { //no definition found for container throw new SchemaException("Couldn't find definitions for report type " + report + "."); } Collection<ItemDelta> modifications = delta.getModifications(); for (ItemDelta itemDelta : modifications){ if (itemDelta.hasCompleteDefinition()){ continue; } ItemDefinition def = definition.findItemDefinition(itemDelta.getPath().rest()); if (def != null){ itemDelta.applyDefinition(def); } } } }
@Override public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition<?> itemDefinition, PrismContext prismContext) throws QueryException { if (ItemPath.isEmpty(path)) { // doesn't fulfill precondition return null; } Object first = path.first(); if (ItemPath.isId(first)) { throw new QueryException("ID item path segments are not allowed in query: " + path); } else if (ItemPath.isObjectReference(first)) { throw new QueryException("'@' path segment cannot be used in the context of an entity " + this); } JpaLinkDefinition<?> link = findRawLinkDefinition(path, JpaDataNodeDefinition.class, false); if (link == null) { return null; } else { link.resolveEntityPointer(); return new DataSearchResult<>(link, path.rest(link.getItemPath().size())); } }