Search in sources :

Example 56 with PropertyDelta

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

the class TestParseDiffPatch method testAssignmentActivationDiff.

//@Test
public void testAssignmentActivationDiff() throws Exception {
    System.out.println("===[ testUserCredentialsDiff ]===");
    PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-before.xml"));
    PrismObject<UserType> userAfter = userBefore.clone();
    AssignmentType assignmentBefore = new AssignmentType();
    ActivationType activation = new ActivationType();
    activation.setAdministrativeStatus(ActivationStatusType.DISABLED);
    assignmentBefore.setActivation(activation);
    userBefore.asObjectable().getAssignment().add(assignmentBefore);
    AssignmentType assignmentAfter = new AssignmentType();
    activation = new ActivationType();
    activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
    assignmentAfter.setActivation(activation);
    userAfter.asObjectable().getAssignment().add(assignmentAfter);
    Collection<? extends ItemDelta> userDelta = assignmentBefore.asPrismContainerValue().diff(assignmentAfter.asPrismContainerValue());
    //        ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    System.out.println("DELTA:");
    //        System.out.println(userDelta.debugDump());
    //        userBefore.checkConsistence();
    //        userAfter.checkConsistence();
    //        userDelta.checkConsistence();
    //        userDelta.assertDefinitions();
    ItemDelta assignmentDelta = userDelta.iterator().next();
    System.out.println("Assignment delta: " + assignmentDelta);
    System.out.println("Assignment delta: " + assignmentDelta.debugDump());
    ItemPath path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
    //        PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
    //        path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
    //        		CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
    PropertyDelta propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
    assertNotNull("Property delta for " + path + " not found", propertyDelta);
    //        assertEquals(1, propertyDelta.getValuesToAdd().size());
    assignmentAfter = new AssignmentType();
    activation = new ActivationType();
    activation.setAdministrativeStatus(null);
    assignmentAfter.setActivation(activation);
    userDelta = assignmentBefore.asPrismContainerValue().diff(assignmentAfter.asPrismContainerValue());
    //      ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    System.out.println("DELTA:");
    //      System.out.println(userDelta.debugDump());
    //      userBefore.checkConsistence();
    //      userAfter.checkConsistence();
    //      userDelta.checkConsistence();
    //      userDelta.assertDefinitions();
    assignmentDelta = userDelta.iterator().next();
    System.out.println("Assignment delta: " + assignmentDelta);
    System.out.println("Assignment delta: " + assignmentDelta.debugDump());
    path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
    //      PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
    //      path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
    //      		CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
    propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
    userDelta = assignmentAfter.asPrismContainerValue().diff(assignmentBefore.asPrismContainerValue());
    //    ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    System.out.println("DELTA:");
    //    System.out.println(userDelta.debugDump());
    //    userBefore.checkConsistence();
    //    userAfter.checkConsistence();
    //    userDelta.checkConsistence();
    //    userDelta.assertDefinitions();
    assignmentDelta = userDelta.iterator().next();
    System.out.println("Assignment delta: " + assignmentDelta);
    System.out.println("Assignment delta: " + assignmentDelta.debugDump());
    path = new ItemPath(SchemaConstantsGenerated.C_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
    //    PrismAsserts.assertPropertyAdd(assignmentDelta, path, 1);
    //    path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
    //    		CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
    propertyDelta = ItemDelta.findPropertyDelta(userDelta, path);
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 57 with PropertyDelta

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

the class TestParseDiffPatch method assertConfigurationPropertyChange.

private void assertConfigurationPropertyChange(ObjectDelta<ResourceType> resourceDelta, String propName) {
    resourceDelta.checkConsistence();
    PropertyDelta propertyDelta = resourceDelta.findPropertyDelta(pathConfigProperties(propName));
    assertNotNull("No delta for configuration property " + propName, propertyDelta);
    // TODO
    resourceDelta.checkConsistence();
}
Also used : PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 58 with PropertyDelta

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

the class TestParseDiffPatch method testUserCredentialsDiff.

@Test
public void testUserCredentialsDiff() throws Exception {
    System.out.println("===[ testUserCredentialsDiff ]===");
    PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-before.xml"));
    userBefore.checkConsistence();
    PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-after.xml"));
    userAfter.checkConsistence();
    ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    System.out.println("DELTA:");
    System.out.println(userDelta.debugDump());
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    userDelta.assertDefinitions();
    ItemPath path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
    PrismAsserts.assertPropertyAdd(userDelta, path, 1);
    path = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS);
    PropertyDelta propertyDelta = userDelta.findPropertyDelta(path);
    assertNotNull("Property delta for " + path + " not found", propertyDelta);
    assertEquals(1, propertyDelta.getValuesToAdd().size());
}
Also used : PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 59 with PropertyDelta

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

the class ChangeExecutor method updateSituationInShadow.

private <F extends ObjectType> void updateSituationInShadow(Task task, SynchronizationSituationType situation, LensFocusContext<F> focusContext, LensProjectionContext projectionCtx, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    String projectionOid = projectionCtx.getOid();
    OperationResult result = new OperationResult(OPERATION_UPDATE_SITUATION_ACCOUNT);
    result.addParam("situation", situation);
    result.addParam("accountRef", projectionOid);
    PrismObject<ShadowType> account = null;
    GetOperationOptions getOptions = GetOperationOptions.createNoFetch();
    getOptions.setAllowNotFound(true);
    try {
        account = provisioning.getObject(ShadowType.class, projectionOid, SelectorOptions.createCollection(getOptions), task, result);
    } catch (Exception ex) {
        LOGGER.trace("Problem with getting account, skipping modifying situation in account.");
        return;
    }
    List<PropertyDelta<?>> syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(account, situation, task.getChannel(), projectionCtx.hasFullShadow());
    try {
        Utils.setRequestee(task, focusContext);
        ProvisioningOperationOptions options = ProvisioningOperationOptions.createCompletePostponed(false);
        options.setDoNotDiscovery(true);
        String changedOid = provisioning.modifyObject(ShadowType.class, projectionOid, syncSituationDeltas, null, options, task, result);
        // modifyProvisioningObject(AccountShadowType.class, accountRef,
        // syncSituationDeltas,
        // ProvisioningOperationOptions.createCompletePostponed(false),
        // task, result);
        projectionCtx.setSynchronizationSituationResolved(situation);
        LOGGER.trace("Situation in projection {} was updated to {}.", projectionCtx, situation);
    } catch (ObjectNotFoundException ex) {
        // if the object not found exception is thrown, it's ok..probably
        // the account was deleted by previous execution of changes..just
        // log in the trace the message for the user..
        LOGGER.trace("Situation in account could not be updated. Account not found on the resource. Skipping modifying situation in account");
        return;
    } catch (Exception ex) {
        throw new SystemException(ex.getMessage(), ex);
    } finally {
        Utils.clearRequestee(task);
    }
    // if everything is OK, add result of the situation modification to the
    // parent result
    result.recordSuccess();
    parentResult.addSubresult(result);
}
Also used : GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException)

Example 60 with PropertyDelta

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

the class ShadowIntegrityCheckResultHandler method doCheckNormalization.

private void doCheckNormalization(ShadowCheckResult checkResult, RefinedAttributeDefinition<?> identifier, String value, ObjectTypeContext context) throws SchemaException {
    QName matchingRuleQName = identifier.getMatchingRuleQName();
    if (matchingRuleQName == null) {
        return;
    }
    MatchingRule<Object> matchingRule;
    try {
        matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, identifier.getTypeName());
    } catch (SchemaException e) {
        checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Couldn't retrieve matching rule for identifier " + identifier.getName() + " (rule name = " + matchingRuleQName + ")"));
        return;
    }
    Object normalizedValue = matchingRule.normalize(value);
    if (!(normalizedValue instanceof String)) {
        checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Normalized value is not a string, it's " + normalizedValue.getClass() + " (identifier " + identifier.getName() + ", value " + value));
        return;
    }
    if (value.equals(normalizedValue)) {
        // OK
        return;
    }
    String normalizedStringValue = (String) normalizedValue;
    checkResult.recordError(Statistics.NON_NORMALIZED_IDENTIFIER_VALUE, new SchemaException("Non-normalized value of identifier " + identifier.getName() + ": " + value + " (normalized form: " + normalizedValue + ")"));
    if (fixNormalization) {
        PropertyDelta delta = identifier.createEmptyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, identifier.getName()));
        delta.setValueToReplace(new PrismPropertyValue<>(normalizedStringValue));
        checkResult.addFixDelta(delta, Statistics.NON_NORMALIZED_IDENTIFIER_VALUE);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)83 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 QName (javax.xml.namespace.QName)24 Test (org.testng.annotations.Test)24 ArrayList (java.util.ArrayList)22 Task (com.evolveum.midpoint.task.api.Task)21 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)11 SystemException (com.evolveum.midpoint.util.exception.SystemException)11 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)11 Collection (java.util.Collection)11 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)10 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)9 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)8