@Override public Object next() { if (i >= components.size()) { throw new IndexOutOfBoundsException("Index: " + i + ", path size: " + components.size() + ", path: " + path); } else if (nextIsArtificialId) { nextIsArtificialId = false; return NULL_ID_ITEM_PATH_SEGMENT; } else if (i == components.size() - 1) { // the last segment: nothing will be added return components.get(i++); } else { Object rv = components.get(i++); if (!ItemPath.isId(rv) && !(ItemPath.isId(components.get(i)))) { nextIsArtificialId = true; // next one returned will be artificial id segment } return rv; } } }
QName firstName = ItemPath.toName(first); return findNamedItemDefinition(firstName, path.rest(), clazz); } else if (ItemPath.isId(first)) { path = path.rest(); } else if (ItemPath.isParent(first)) {
/** * Returns true if the path starts with with value Id. */ default boolean startsWithId() { return !isEmpty() && ItemPath.isId(first()); }
private ItemPath getDeltaParentItemPath(ItemPath deltaParentPath) { if (ItemPath.isId(deltaParentPath.last())) { return deltaParentPath.allExceptLast(); } else { return deltaParentPath; } }
private long checkPathSanity(ItemPath deltaPath, List<Long> casesAddedOrDeleted) { Object secondSegment = deltaPath.getSegment(1); if (!ItemPath.isId(secondSegment)) { throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]"); } Long id = ItemPath.toId(secondSegment); if (id == null) { throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]"); } if (deltaPath.size() == 2) { // not enough throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id] and contain additional path"); } if (casesAddedOrDeleted == null || casesAddedOrDeleted.contains(id)) { throw new IllegalArgumentException("Couldn't update certification case that was added/deleted in this operation. Path=" + deltaPath); } return id; }
public <T extends ObjectType> Collection<? extends ItemDelta> filterLookupTableModifications(Class<T> type, Collection<? extends ItemDelta> modifications) { Collection<ItemDelta> tableDelta = new ArrayList<>(); if (!LookupTableType.class.equals(type)) { return tableDelta; } for (ItemDelta delta : modifications) { ItemPath path = delta.getPath(); if (path.isEmpty()) { throw new UnsupportedOperationException("Lookup table cannot be modified via empty-path modification"); } else if (path.equivalent(LookupTableType.F_ROW)) { tableDelta.add(delta); } else if (path.isSuperPath(LookupTableType.F_ROW)) { // should be row[id]/xxx where xxx=key|value|label? if (path.size() != 3 || !ItemPath.isId(path.getSegment(1)) || !ItemPath.isName(path.getSegment(2))) { throw new UnsupportedOperationException("Unsupported modification path for lookup tables: " + path); } tableDelta.add(delta); } } modifications.removeAll(tableDelta); return tableDelta; } }
sb.append(ItemPath.toName(segment).getLocalPart()); } else if (ItemPath.isId(segment)) { sb.append("[").append(ItemPath.toId(segment)).append("]");
public static Long getAssignmentIdFromDeltaPath(PrismContainer<AssignmentType> assignmentsOld, ItemPath path) throws SchemaException { assert path.size() > 1; Object idSegment = path.getSegment(1); if (ItemPath.isId(idSegment)) { return ItemPath.toId(idSegment); } // id-less path, e.g. assignment/validFrom -- we try to determine ID from the objectOld. if (assignmentsOld.size() == 0) { return null; } else if (assignmentsOld.size() == 1) { return assignmentsOld.getValues().get(0).getId(); } else { throw new SchemaException("Illegal path " + path + ": cannot determine which assignment to modify"); } }
private void assertNormalizedPath(UniformItemPath normalized, Object... expected) { assertEquals("wrong path length",normalized.size(), expected.length); for(int i=0; i<normalized.size(); i+=2) { ItemPathSegment nameSegment = normalized.getSegment(i); assert ItemPath.isName(nameSegment) : "Expected name segment but it was "+nameSegment.getClass(); QName name = ItemPath.toName(nameSegment); assert name != null : "name is null"; assert name.getNamespaceURI().equals(NS) : "wrong namespace: "+name.getNamespaceURI(); assert name.getLocalPart().equals(expected[i]) : "wrong local name, expected "+expected[i]+", was "+name.getLocalPart(); if (i + 1 < expected.length) { Object idSegment = normalized.getSegment(i+1); assert ItemPath.isId(idSegment) : "Expected is segment but it was "+idSegment.getClass(); Long id = ItemPath.toId(idSegment); assertId(id, (Long)expected[i+1]); } } }
private ItemPath getPathToExplain(ItemDelta itemDelta) { ItemPath path = itemDelta.getPath(); for (int i = 0; i < path.size(); i++) { Object segment = path.getSegment(i); if (ItemPath.isId(segment)) { if (i < path.size()-1 || itemDelta.isDelete()) { return path.allUpToIncluding(i); } else { // this means that the path ends with [id] segment *and* the value(s) are // only added and deleted, i.e. they are shown in the delta anyway // (actually it is questionable whether path in delta can end with [id] segment, // but we test for this case just to be sure) return null; } } } return null; }
static boolean segmentsEquivalent(Object o1, Object o2) { if (ItemPath.isName(o1)) { return ItemPath.isName(o2) && QNameUtil.match(ItemPath.toName(o1), ItemPath.toName(o2)); } else if (ItemPath.isVariable(o1)) { return ItemPath.isVariable(o2) && QNameUtil.match(ItemPath.toVariableName(o1), ItemPath.toVariableName(o2)); } else if (ItemPath.isSpecial(o1)) { return ItemPath.isSpecial(o2) && QNameUtil.match(ItemPathSegmentUtil.getSpecialSymbol(o1), ItemPathSegmentUtil.getSpecialSymbol(o2)); } else if (ItemPath.isId(o1)) { return ItemPath.isId(o2) && Objects.equals(ItemPath.toId(o1), ItemPath.toId(o2)); } else { return false; } }
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) { for (;;) { if (path.isEmpty()) { if (clazz.isAssignableFrom(PrismContainerDefinition.class)) { return (ID) this; } else { return null; } } Object first = path.first(); if (ItemPath.isName(first)) { return findNamedItemDefinition(ItemPath.toName(first), path.rest(), clazz); } else if (ItemPath.isId(first)) { path = path.rest(); } else if (ItemPath.isParent(first)) { ItemPath rest = path.rest(); ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest); if (rest.isEmpty()) { // requires that the parent is defined as an item (container, object) return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName()); } else { return parent.findItemDefinition(rest, clazz); } } else if (ItemPath.isObjectReference(first)) { throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path); } else { throw new IllegalStateException("Unexpected path segment: " + first + " in " + path); } } }
if (!ItemPath.isId(secondSegment)) { throw new IllegalStateException("Assignment modification contains no assignment ID. Offending path = " + deltaPath);
public CanonicalItemPathImpl(ItemPath path, Class<? extends Containerable> clazz, PrismContext prismContext) { ItemDefinition def = clazz != null && prismContext != null ? prismContext.getSchemaRegistry().findContainerDefinitionByCompileTimeClass(clazz) : null; while (!ItemPath.isEmpty(path)) { Object first = path.first(); if (ItemPath.isName(first)) { ItemName name = ItemPath.toName(first); if (def instanceof PrismContainerDefinition) { def = ((PrismContainerDefinition) def).findItemDefinition(name); if (def != null && !QNameUtil.hasNamespace(name)) { name = def.getName(); } } addToSegments(name); } else if (ItemPath.isId(first)) { // ignored (for now) } else { throw new UnsupportedOperationException("Canonicalization of non-name/non-ID segments is not supported: " + first); } path = path.rest(); } }
if (!ItemPath.isId(secondSegment)) { throw new IllegalStateException("Assignment modification contains no assignment ID. Offending path = " + deltaPath);
@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())); } }