Search in sources :

Example 16 with PropertyDelta

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

the class ResourceObjectConverter method collectAttributeAndEntitlementChanges.

private void collectAttributeAndEntitlementChanges(ProvisioningContext ctx, Collection<? extends ItemDelta> objectChange, Collection<Operation> operations, PrismObject<ShadowType> shadow, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (operations == null) {
        operations = new ArrayList<Operation>();
    }
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    for (ItemDelta itemDelta : objectChange) {
        if (isAttributeDelta(itemDelta) || SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            if (itemDelta instanceof PropertyDelta) {
                PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
                RefinedAttributeDefinition<Object> attrDef = objectClassDefinition.findAttributeDefinition(itemDelta.getElementName());
                if (attrDef != null) {
                    attributeModification.setMatchingRuleQName(attrDef.getMatchingRuleQName());
                    if (itemDelta.getDefinition() == null) {
                        itemDelta.setDefinition(attrDef);
                    }
                }
                operations.add(attributeModification);
            } else if (itemDelta instanceof ContainerDelta) {
                // - it is processed earlier
                continue;
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else if (SchemaConstants.PATH_ACTIVATION.equivalent(itemDelta.getParentPath())) {
            Collection<Operation> activationOperations = determineActivationChange(ctx, shadow.asObjectable(), objectChange, result);
            if (activationOperations != null) {
                operations.addAll(activationOperations);
            }
        } else if (new ItemPath(ShadowType.F_ASSOCIATION).equivalent(itemDelta.getPath())) {
            if (itemDelta instanceof ContainerDelta) {
                entitlementConverter.collectEntitlementChange(ctx, (ContainerDelta<ShadowAssociationType>) itemDelta, operations);
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else if (new ItemPath(ShadowType.F_AUXILIARY_OBJECT_CLASS).equivalent(itemDelta.getPath())) {
            if (itemDelta instanceof PropertyDelta) {
                PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
                operations.add(attributeModification);
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else {
            LOGGER.trace("Skip converting item delta: {}. It's not resource object change, but it is shadow change.", itemDelta);
        }
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 17 with PropertyDelta

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

the class SqlRepositoryServiceImpl method modifyObject.

@Override
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, RepoModifyOptions options, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    Validate.notNull(modifications, "Modifications must not be null.");
    Validate.notNull(type, "Object class in delta must not be null.");
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(result, "Operation result must not be null.");
    OperationResult subResult = result.createSubresult(MODIFY_OBJECT);
    subResult.addParam("type", type.getName());
    subResult.addParam("oid", oid);
    subResult.addCollectionOfSerializablesAsParam("modifications", modifications);
    if (modifications.isEmpty() && !RepoModifyOptions.isExecuteIfNoChanges(options)) {
        LOGGER.debug("Modification list is empty, nothing was modified.");
        subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
        return;
    }
    if (InternalsConfig.encryptionChecks) {
        CryptoUtil.checkEncrypted(modifications);
    }
    if (InternalsConfig.consistencyChecks) {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    } else {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
    }
    if (LOGGER.isTraceEnabled()) {
        for (ItemDelta modification : modifications) {
            if (modification instanceof PropertyDelta<?>) {
                PropertyDelta<?> propDelta = (PropertyDelta<?>) modification;
                if (propDelta.getPath().equivalent(new ItemPath(ObjectType.F_NAME))) {
                    Collection<PrismPropertyValue<PolyString>> values = propDelta.getValues(PolyString.class);
                    for (PrismPropertyValue<PolyString> pval : values) {
                        PolyString value = pval.getValue();
                        LOGGER.trace("NAME delta: {} - {}", value.getOrig(), value.getNorm());
                    }
                }
            }
        }
    }
    final String operation = "modifying";
    int attempt = 1;
    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("modifyObject");
    try {
        while (true) {
            try {
                objectUpdater.modifyObjectAttempt(type, oid, modifications, options, subResult);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 18 with PropertyDelta

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

the class ConsistencyTest method test124AddAccountDirectAlreadyExists.

//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
    final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    Task task = taskManager.createTaskInstance();
    SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
    SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
    try {
        // we will reapply this schema handling after this test finish
        ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
        assertNotNull("null definition for sync delta", syncDef);
        ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
        ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
        requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
        PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
        // LOGGER.trace("resource schema handling after modify: {}",
        // prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
        repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
        String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
        assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
        repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
        String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
        ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
        assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
        ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
        ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
        repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
        ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
        ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
        modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
        assertUserNoAccountRef(USER_ABOM_OID, parentResult);
        try {
            repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
            fail("Expected that shadow abom does not exist, but it is");
        } catch (ObjectNotFoundException ex) {
        // this is expected
        } catch (Exception ex) {
            fail("Expected object not found exception but got " + ex);
        }
        LOGGER.info("starting second execution request for user abomba");
        OperationResult result = new OperationResult("Add account already exist result.");
        requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
        String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
        ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
        assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
        result.computeStatus();
        LOGGER.info("Displaying execute changes result");
        display(result);
        // return the previous changes of resource back
        Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
        PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
        ((Collection) schemaHandlingDelta).add(syncDelta);
        repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
    } catch (Exception ex) {
        LOGGER.info("error: " + ex.getMessage(), ex);
        throw ex;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBException(javax.xml.bind.JAXBException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 19 with PropertyDelta

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

the class ConsistencyTest method modifyResourceAvailabilityStatus.

private void modifyResourceAvailabilityStatus(AvailabilityStatusType status, OperationResult parentResult) throws Exception {
    PropertyDelta resourceStatusDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(ResourceType.F_OPERATIONAL_STATE, OperationalStateType.F_LAST_AVAILABILITY_STATUS), resourceTypeOpenDjrepo.asPrismObject().getDefinition(), status);
    Collection<PropertyDelta> modifications = new ArrayList<PropertyDelta>();
    modifications.add(resourceStatusDelta);
    repositoryService.modifyObject(ResourceType.class, resourceTypeOpenDjrepo.getOid(), modifications, parentResult);
}
Also used : ArrayList(java.util.ArrayList) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 20 with PropertyDelta

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

the class TestTolerantAttributes method test101modifyAddAttributesIntolerantPattern.

@Test
public void test101modifyAddAttributesIntolerantPattern() throws Exception {
    TestUtil.displayTestTile(this, "test101modifyAddAttributesIntolerantPattern");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test101modifyAddAttributesIntolerantPattern");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(new ItemPath(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);
    modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), 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", null);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) 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