/** * Returns true if the collection contains a path equivalent to pathToBeFound. */ public static boolean containsEquivalent(Collection<? extends ItemPath> paths, ItemPath pathToBeFound) { for (ItemPath path : paths) { if (path.equivalent(pathToBeFound)) { return true; } } return false; }
@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 <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) { if (path.size() == 1 && path.startsWithName()) { return findLocalItemDefinition(ItemPath.toName(path.first()), clazz, false); } throw new UnsupportedOperationException("TODO implement if needed"); }
/** * Returns the value of the first segment if it is a variable name segment; otherwise null. */ default QName firstToVariableNameOrNull() { if (isEmpty()) { return null; } else { Object first = first(); return isVariable(first) ? toVariableName(first) : null; } }
private void checkSchemaHandlingObjectTypes(ResourceValidationContext ctx, SchemaHandlingType schemaHandling) { int i = 1; for (ResourceObjectTypeDefinitionType objectType : schemaHandling.getObjectType()) { ItemPath path = ItemPath.create(ResourceType.F_SCHEMA_HANDLING, SchemaHandlingType.F_OBJECT_TYPE, i); checkSchemaHandlingObjectType(ctx, path, objectType); i++; } }
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; } }
/** * Returns true if the path contains the specified name (requires exact match). */ default boolean containsNameExactly(QName name) { return getSegments().stream().anyMatch(component -> isName(component) && name.equals(toName(component))); }
@NotNull public ItemName getElementName() { if (definition != null) { return definition.getName(); // this is more precise, as the name in path can be unqualified } if (fullPath.isEmpty()) { throw new IllegalStateException("Empty full path in filter "+this); } Object last = fullPath.last(); if (ItemPath.isName(last)) { return ItemPath.toName(last); } else { throw new IllegalStateException("Got "+last+" as a last path segment in value filter "+this); } }
private void preparePassword() { if (valueItemPath == null) { return; } if (!valueItemPath.startsWithName(UserType.F_CREDENTIALS)) { return; } Object secondPathSegment = valueItemPath.getSegment(1); if (!ItemPath.isName(secondPathSegment)) { return; } credentialQName = ItemPath.toName(secondPathSegment); if (!QNameUtil.match(CredentialsType.F_PASSWORD, credentialQName)) { return; } if (securityPolicy == null) { return; } credentialPolicy = SecurityUtil.getEffectivePasswordCredentialsPolicy(securityPolicy); }
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; }
private void checkItemRef(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceItemDefinitionType itemDef, String noRefKey) { ItemPath refPath = itemDef.getRef() != null ? itemDef.getRef().getItemPath() : null; if (ItemPath.isEmpty(refPath)) { ctx.validationResult.add(Issue.Severity.ERROR, CAT_SCHEMA_HANDLING, noRefKey, getString(CLASS_DOT + noRefKey, getName(objectType)), ctx.resourceRef, path.append(ItemRefinedDefinitionType.F_REF)); } else if (refPath.size() > 1 || !refPath.startsWithName()) { ctx.validationResult.add(Issue.Severity.ERROR, CAT_SCHEMA_HANDLING, C_WRONG_ITEM_NAME, getString(CLASS_DOT + C_WRONG_ITEM_NAME, getName(objectType), refPath.toString()), ctx.resourceRef, path.append(ItemRefinedDefinitionType.F_REF)); } else if (StringUtils.isBlank(refPath.asSingleName().getNamespaceURI())) { ctx.validationResult.add(Issue.Severity.WARNING, CAT_SCHEMA_HANDLING, C_NO_ITEM_NAMESPACE, getString(CLASS_DOT + C_NO_ITEM_NAMESPACE, getName(objectType), refPath.toString()), ctx.resourceRef, path.append(ItemRefinedDefinitionType.F_REF)); } }
@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); }
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]); } } }
/** * If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. * Otherwise returns null. */ default QName asSingleName() { return isSingleName() ? ItemPath.toName(first()) : null; }
/** * Returns true if the path starts with variable name ($...). */ default boolean startsWithVariable() { return !isEmpty() && ItemPath.isVariable(first()); }
@Test public void test210ModifyCaseProperties() throws Exception { OperationResult result = new OperationResult("test210ModifyCaseProperties"); List<ItemDelta<?, ?>> modifications = new ArrayList<>(); ItemPath case1 = ItemPath.create(F_CASE, 1L); modifications.add(prismContext.deltaFactory().property().createModificationReplaceProperty(case1.append(F_CURRENT_STAGE_OUTCOME), campaignDef, SchemaConstants.MODEL_CERTIFICATION_OUTCOME_REDUCE)); modifications.add(prismContext.deltaFactory().property().createModificationReplaceProperty(case1.append(AccessCertificationCaseType.F_STAGE_NUMBER), campaignDef, 300)); executeAndCheckModification(modifications, result, 0); checksCountsStandard(result); }