@NotNull @Override public ItemPath getPath() { if (fullPath != null) { return fullPath; } if (getParentPath() == null) { throw new IllegalStateException("No parent path in "+this); } fullPath = getParentPath().append(elementName); return fullPath; }
private void checkBidirectionalMapping(ResourceValidationContext ctx, ItemPath path, QName itemName, ResourceObjectTypeDefinitionType objectType, @Nullable ResourceBidirectionalMappingType bidirectionalMapping) { if (bidirectionalMapping == null) { return; } ItemPath itemPath = path.append(itemName); int i = 1; for (MappingType inbound : bidirectionalMapping.getInbound()) { checkMapping(ctx, itemPath.append(ResourceBidirectionalMappingType.F_INBOUND), objectType, itemName, inbound, false, i, true); i++; } i = 1; for (MappingType outbound : bidirectionalMapping.getOutbound()) { checkMapping(ctx, itemPath.append(ResourceBidirectionalMappingType.F_OUTBOUND), objectType, itemName, outbound, true, i, true); i++; } }
private void checkPasswordMapping(ResourceValidationContext ctx, ItemPath path, QName itemName, ResourceObjectTypeDefinitionType objectType, @Nullable ResourcePasswordDefinitionType passwordDefinition) { if (passwordDefinition == null) { return; } ItemPath itemPath = path.append(itemName); int i = 1; for (MappingType inbound : passwordDefinition.getInbound()) { checkMapping(ctx, itemPath.append(ResourcePasswordDefinitionType.F_INBOUND), objectType, itemName, inbound, false, i, true); i++; } i = 1; for (MappingType outbound : passwordDefinition.getOutbound()) { checkMapping(ctx, itemPath.append(ResourcePasswordDefinitionType.F_OUTBOUND), objectType, itemName, outbound, true, i, true); i++; } }
/** * E.g. "credentials/password/value" */ protected ItemPath getCredentialValuePath() { return getCredentialsContainerPath().append(getCredentialRelativeValuePath()); }
@NotNull public ItemPath getPath() { Itemable parent = getParent(); @NotNull ItemPath parentPath = ItemPath.EMPTY_PATH; if (parent != null) { parentPath = parent.getPath(); } if (getId() != null) { return parentPath.append(getId()); } else { return parentPath; } }
public <F extends ObjectType, T extends ObjectType> Collection<ItemDelta<?,?>> createModifyMetadataDeltas(LensContext<F> context, ItemPath metadataPath, Class<T> objectType, XMLGregorianCalendar now, Task task) throws SchemaException { return prismContext.deltaFor(objectType) .item(metadataPath.append(MetadataType.F_MODIFY_CHANNEL)).replace(LensUtil.getChannel(context, task)) .item(metadataPath.append(MetadataType.F_MODIFY_TIMESTAMP)).replace(now) .item(metadataPath.append(MetadataType.F_MODIFIER_REF)).replace(createObjectRef(task.getOwner(), prismContext)) .item(metadataPath.append(MetadataType.F_MODIFY_TASK_REF)).replaceRealValues( task.getOid() != null ? singleton(createObjectRef(task.getTaskPrismObject(), prismContext)) : emptySet()) .asItemDeltas(); }
private void checkSchemaHandlingItem(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceItemDefinitionType itemDef) { QName itemName = itemRefToName(itemDef.getRef()); if (itemDef.getOutbound() != null) { checkMapping(ctx, path.append(ResourceItemDefinitionType.F_OUTBOUND), objectType, itemName, itemDef.getOutbound(), true, 0, false); } int i = 1; for (MappingType inbound : itemDef.getInbound()) { checkMapping(ctx, path.append(ItemPath.create(ResourceItemDefinitionType.F_INBOUND, i)), objectType, itemName, inbound, false, i, false); i++; } }
private void checkObjectClass(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType) { if (objectType.getObjectClass() == null) { ctx.validationResult.add(Issue.Severity.ERROR, CAT_SCHEMA_HANDLING, C_MISSING_OBJECT_CLASS, getString(CLASS_DOT + C_MISSING_OBJECT_CLASS, getName(objectType)), ctx.resourceRef, path.append(ResourceObjectTypeDefinitionType.F_OBJECT_CLASS)); } }
private void checkObjectClassDefinition(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType, ObjectClassComplexTypeDefinition ocdef) { if (ocdef == null) { ctx.validationResult.add(Issue.Severity.WARNING, CAT_SCHEMA_HANDLING, C_UNKNOWN_OBJECT_CLASS, getString(CLASS_DOT + C_UNKNOWN_OBJECT_CLASS, getName(objectType), objectType.getObjectClass()), ctx.resourceRef, path.append(ResourceObjectTypeDefinitionType.F_OBJECT_CLASS)); } }
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)); } }
private <T> void addPropertyDelta(Collection repoDeltas, ItemPath containerPath, QName propertyName, T propertyValue, PrismObjectDefinition<ShadowType> shadowDef) { ItemPath propPath = containerPath.append(propertyName); PropertyDelta<T> delta; if (propertyValue == null) { delta = prismContext.deltaFactory().property().createModificationReplaceProperty(propPath, shadowDef /* no value */); } else { delta = prismContext.deltaFactory().property().createModificationReplaceProperty(propPath, shadowDef, propertyValue); } repoDeltas.add(delta); }
private void addMetadataDelta() throws SchemaException { Collection<? extends ItemDelta<?, ?>> metaDeltas = metadataManager.createModifyMetadataDeltas( context, getCredentialsContainerPath().append(AbstractCredentialType.F_METADATA), context.getFocusClass(), now, task); for (ItemDelta<?, ?> metaDelta : metaDeltas) { context.getFocusContext().swallowToSecondaryDelta(metaDelta); } }
private void checkMatchingRule(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceAttributeDefinitionType attributeDef, QName ref, ResourceAttributeDefinition<?> rad) { QName matchingRule = attributeDef.getMatchingRule(); if (matchingRule == null) { return; } try { matchingRuleRegistry.getMatchingRule(matchingRule, rad != null ? rad.getTypeName() : null); } catch (Throwable t) { ctx.validationResult.add(Issue.Severity.WARNING, CAT_SCHEMA_HANDLING, C_WRONG_MATCHING_RULE, getString(CLASS_DOT + C_WRONG_MATCHING_RULE, getName(objectType), prettyPrintUsingStandardPrefix(ref), t.getMessage()), ctx.resourceRef, path.append(ResourceItemDefinitionType.F_MATCHING_RULE)); } }
private <T> PropertyDelta<T> createPendingOperationDelta(PrismContainerDefinition<PendingOperationType> containerDefinition, ItemPath containerPath, QName propName, T valueToReplace) { PrismPropertyDefinition<T> propDef = containerDefinition.findPropertyDefinition(ItemName.fromQName(propName)); PropertyDelta<T> propDelta = prismContext.deltaFactory().property().create(containerPath.append(propName), propDef); if (valueToReplace == null) { propDelta.setValueToReplace(); } else { propDelta.setRealValuesToReplace(valueToReplace); } return propDelta; }
@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); }
private void addMissingMetadata(PrismContainerValue<R> cVal) throws SchemaException { if (hasValueChange(cVal)) { if (!hasMetadata(cVal)) { MetadataType metadataType = metadataManager.createCreateMetadata(context, now, task); ContainerDelta<MetadataType> metadataDelta = prismContext.deltaFactory().container().createModificationAdd( getCredentialsContainerPath().append(AbstractCredentialType.F_METADATA), UserType.class, metadataType); context.getFocusContext().swallowToSecondaryDelta(metadataDelta); } } }
@Test public void testEmployeeNumberProtectedString() throws Exception { // WHEN PrismValueDeltaSetTriple<PrismPropertyValue<ProtectedStringType>> outputTriple = evaluator.evaluateMappingDynamicReplace( "mapping-script-system-variables-employee-number.xml", "testEmployeeNumberProtectedString", UserType.F_CREDENTIALS.append(CredentialsType.F_PASSWORD).append(PasswordType.F_VALUE), // target "employeeNumber", // changed property "666"); // changed values // THEN evaluator.assertProtectedString("plus set", outputTriple.getPlusSet(), "666"); PrismAsserts.assertTripleNoZero(outputTriple); PrismAsserts.assertTripleNoMinus(outputTriple); }
private void checkDependencies(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType) { for (ResourceObjectTypeDependencyType dependency : objectType.getDependency()) { if (dependency.getResourceRef() == null || (ctx.resourceObject.getOid() != null && ctx.resourceObject.getOid().equals(dependency.getResourceRef().getOid()))) { if (ResourceTypeUtil.findObjectTypeDefinition(ctx.resourceObject, dependency.getKind(), dependency.getIntent()) == null) { ctx.validationResult.add(Issue.Severity.WARNING, CAT_SCHEMA_HANDLING, C_DEPENDENT_OBJECT_TYPE_DOES_NOT_EXIST, getString(CLASS_DOT + C_DEPENDENT_OBJECT_TYPE_DOES_NOT_EXIST, getName(objectType), fillDefault(dependency.getKind()) + "/" + fillDefault(dependency.getIntent())), ctx.resourceRef, path.append(ResourceObjectTypeDefinitionType.F_DEPENDENCY)); } } else { // check in 'remote' resource only if thorough validation is required } } }
@Override public ItemDelta<?,?> getSubDelta(ItemPath path) { if (path.isEmpty()) { return this; } Long id = null; if (path.startsWithId()) { id = path.firstToIdOrNull(); path = path.rest(); } ItemDefinition itemDefinition = getDefinition().findItemDefinition(path); if (itemDefinition == null) { throw new IllegalStateException("No definition of " + path + " in " + getDefinition()); } ItemDelta<?,?> itemDelta = itemDefinition.createEmptyDelta(getPath().append(path)); itemDelta.addValuesToAdd(findItemValues(id, path, getValuesToAdd())); itemDelta.addValuesToDelete(findItemValues(id, path, getValuesToDelete())); itemDelta.setValuesToReplace(findItemValues(id, path, getValuesToReplace())); if (itemDelta.isEmpty()) { return null; } return itemDelta; }
private void checkSchemaHandlingAssociation(ResourceValidationContext ctx, ObjectClassComplexTypeDefinition ocdef, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceObjectAssociationType associationDef) { checkSchemaHandlingItem(ctx, path, objectType, associationDef); checkItemRef(ctx, path, objectType, associationDef, C_NO_ASSOCIATION_NAME); checkNotEmpty(ctx, path, objectType, associationDef, associationDef.getKind(), ResourceObjectAssociationType.F_KIND, C_MISSING_ASSOCIATION_TARGET_KIND); checkNotEmpty(ctx, path, objectType, associationDef, associationDef.getIntent(), ResourceObjectAssociationType.F_INTENT, C_MISSING_ASSOCIATION_TARGET_INTENT); checkNotEmpty(ctx, path, objectType, associationDef, associationDef.getDirection(), ResourceObjectAssociationType.F_DIRECTION, C_MISSING_ASSOCIATION_DIRECTION); checkNotEmpty(ctx, path, objectType, associationDef, associationDef.getAssociationAttribute(), ResourceObjectAssociationType.F_ASSOCIATION_ATTRIBUTE, C_MISSING_ASSOCIATION_ASSOCIATION_ATTRIBUTE); checkNotEmpty(ctx, path, objectType, associationDef, associationDef.getValueAttribute(), ResourceObjectAssociationType.F_VALUE_ATTRIBUTE, C_MISSING_ASSOCIATION_VALUE_ATTRIBUTE); // TODO checking matching rule for associations? QName ref = itemRefToName(associationDef.getRef()); if (ocdef != null) { if (ref != null) { if (ocdef.findAttributeDefinition(ref, ResourceTypeUtil.isCaseIgnoreAttributeNames(ctx.resourceObject.asObjectable())) != null) { ctx.validationResult.add(Issue.Severity.ERROR, CAT_SCHEMA_HANDLING, C_COLLIDING_ASSOCIATION_NAME, getString(CLASS_DOT + C_COLLIDING_ASSOCIATION_NAME, getName(objectType), prettyPrintUsingStandardPrefix(ref)), ctx.resourceRef, path.append(ResourceItemDefinitionType.F_REF)); } } } for (String intent : associationDef.getIntent()) { checkAssociationTargetIntent(ctx, path, objectType, associationDef, ref, intent); } }