Search in sources :

Example 26 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestTolerantAttributes method test101ModifyAddAttributesIntolerantPattern.

/**
 * We are trying to add value to the resource (through a mapping). This value matches
 * intolerant pattern. But as this value is explicitly added by a mapping from a primary
 * delta then the value should be set to resource even in that case.
 */
@Test
public void test101ModifyAddAttributesIntolerantPattern() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_JACK_OID);
    PropertyDelta propertyDelta = prismContext.deltaFactory().property().createModificationAddProperty(UserType.F_DESCRIPTION, getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "This value will be not added");
    userDelta.addModification(propertyDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    // WHEN
    when();
    modelService.executeChanges(deltas, executeOptions().reconcile(), task, result);
    // THEN
    then();
    assertSuccess(result);
    // Check value in "quote attribute"
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    accountOid = getSingleLinkOid(userJack);
    assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account in dummy resource
    assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
    // Check value of quote attribute
    assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", "This value will be not added");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 27 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestTolerantAttributes method test102modifyAddAttributeTolerantPattern.

@Test
public void test102modifyAddAttributeTolerantPattern() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, USER_JACK_OID);
    PropertyDelta propertyDelta = prismContext.deltaFactory().property().createModificationAddProperty(UserType.F_DESCRIPTION, getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "res-thiIsOk");
    userDelta.addModification(propertyDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, executeOptions().reconcile(), task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // Check value in "quote attribute"
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
    ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
    accountOid = accountRefType.getOid();
    assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
    PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
    assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
    assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
    // Check account in dummy resource
    assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
    // Check value of quote attribute
    assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", "res-thiIsOk");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 28 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method generateValue.

@Override
public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyItemsDefinitionType policyItemsDefinition, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
    OperationResult result = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
    ValuePolicyType valuePolicy;
    try {
        valuePolicy = getValuePolicy(object, task, result);
    } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
        LOGGER.error("Failed to get value policy for generating value. ", e);
        result.recordFatalError("Error while getting value policy. Reason: " + e.getMessage(), e);
        throw e;
    }
    Collection<PropertyDelta<?>> deltasToExecute = new ArrayList<>();
    for (PolicyItemDefinitionType policyItemDefinition : policyItemsDefinition.getPolicyItemDefinition()) {
        OperationResult generateValueResult = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
        LOGGER.trace("Default value policy: {}", valuePolicy);
        try {
            generateValue(object, valuePolicy, policyItemDefinition, task, generateValueResult);
        } catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
            LOGGER.error("Failed to generate value for {} ", policyItemDefinition, e);
            generateValueResult.recordFatalError("Failed to generate value for " + policyItemDefinition + ". Reason: " + e.getMessage(), e);
            policyItemDefinition.setResult(generateValueResult.createOperationResultType());
            continue;
        }
        // TODO: not sure about the bulk actions here
        ItemPath path = getPath(policyItemDefinition);
        if (path == null) {
            if (isExecute(policyItemDefinition)) {
                LOGGER.error("No item path defined in the target for policy item definition. Cannot generate value");
                generateValueResult.recordFatalError("No item path defined in the target for policy item definition. Cannot generate value");
                continue;
            }
        }
        PrismPropertyDefinition<?> propertyDef = null;
        if (path != null) {
            result.addArbitraryObjectAsParam("policyItemPath", path);
            propertyDef = getItemDefinition(object, path);
            if (propertyDef == null) {
                if (isExecute(policyItemDefinition)) {
                    LOGGER.error("No definition for property {} in object. Is the path referencing prism property?" + path, object);
                    generateValueResult.recordFatalError("No definition for property " + path + " in object " + object + ". Is the path referencing prism property?");
                    continue;
                }
            }
        }
        // end of not sure
        collectDeltasForGeneratedValuesIfNeeded(object, policyItemDefinition, deltasToExecute, path, propertyDef, generateValueResult);
        generateValueResult.computeStatusIfUnknown();
    }
    result.computeStatus();
    if (!result.isAcceptable()) {
        return;
    }
    try {
        if (!deltasToExecute.isEmpty()) {
            if (object == null) {
                LOGGER.error("Cannot execute changes for generated values, no object specified in request.");
                result.recordFatalError("Cannot execute changes for generated values, no object specified in request.");
                throw new SchemaException("Cannot execute changes for generated values, no object specified in request.");
            }
            String oid = object.getOid();
            Class<O> clazz = (Class<O>) object.asObjectable().getClass();
            modelCrudService.modifyObject(clazz, oid, deltasToExecute, null, task, result);
        }
    } catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | ObjectAlreadyExistsException | PolicyViolationException | SecurityViolationException e) {
        LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
        result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
        throw e;
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 29 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class ShadowIntegrityCheckItemProcessor method doCheckNormalization.

private void doCheckNormalization(ShadowCheckResult checkResult, ResourceAttributeDefinition<?> identifier, String value) throws SchemaException {
    QName matchingRuleQName = identifier.getMatchingRuleQName();
    if (matchingRuleQName == null) {
        return;
    }
    MatchingRule<Object> matchingRule;
    try {
        matchingRule = activityRun.getBeans().matchingRuleRegistry.getMatchingRule(matchingRuleQName, identifier.getTypeName());
    } catch (SchemaException e) {
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Couldn't retrieve matching rule for identifier " + identifier.getItemName() + " (rule name = " + matchingRuleQName + ")"));
        return;
    }
    Object normalizedValue = matchingRule.normalize(value);
    if (!(normalizedValue instanceof String)) {
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Normalized value is not a string, it's " + normalizedValue.getClass() + " (identifier " + identifier.getItemName() + ", value " + value));
        return;
    }
    if (value.equals(normalizedValue)) {
        return;
    }
    String normalizedStringValue = (String) normalizedValue;
    checkResult.recordError(ShadowStatistics.NON_NORMALIZED_IDENTIFIER_VALUE, new SchemaException("Non-normalized value of identifier " + identifier.getItemName() + ": " + value + " (normalized form: " + normalizedValue + ")"));
    if (getConfiguration().fixNormalization) {
        // noinspection rawtypes
        PropertyDelta delta = identifier.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, identifier.getItemName()));
        // noinspection unchecked
        delta.setRealValuesToReplace(normalizedStringValue);
        checkResult.addFixDelta(delta, ShadowStatistics.NON_NORMALIZED_IDENTIFIER_VALUE);
    }
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 30 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class TestUserTemplate method test160ModifyUserGivenNameAgain.

@Test
public void test160ModifyUserGivenNameAgain() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    dummyAuditService.clear();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_GIVEN_NAME, new PolyString("JACKIE"));
    deltas.add(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    assertSuccess(result);
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    PrismAsserts.assertPropertyValue(userJack.findContainer(UserType.F_EXTENSION), PIRACY_BAD_LUCK, 123L);
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    ObjectDeltaOperation<?> objectDeltaOperation = dummyAuditService.getExecutionDelta(0, ChangeType.MODIFY, UserType.class);
    assertEquals("unexpected number of modifications in audited delta", 10, // givenName + badLuck + modifyTimestamp
    objectDeltaOperation.getObjectDelta().getModifications().size());
    PropertyDelta badLuckDelta = objectDeltaOperation.getObjectDelta().findPropertyDelta(ItemPath.create(UserType.F_EXTENSION, PIRACY_BAD_LUCK));
    assertNotNull("badLuck delta was not found", badLuckDelta);
    // noinspection unchecked
    List<PrismValue> oldValues = (List<PrismValue>) badLuckDelta.getEstimatedOldValues();
    assertNotNull("badLuck delta has null estimatedOldValues field", oldValues);
    ItemFactory factory = prismContext.itemFactory();
    PrismAsserts.assertEqualsCollectionUnordered("badLuck delta has wrong estimatedOldValues", oldValues, factory.createPropertyValue(123L), factory.createPropertyValue(456L));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemFactory(com.evolveum.midpoint.prism.ItemFactory) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ArrayList(java.util.ArrayList) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)90 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 QName (javax.xml.namespace.QName)28 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)20 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 Task (com.evolveum.midpoint.task.api.Task)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 Collection (java.util.Collection)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6