Search in sources :

Example 21 with ObjectDelta

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

the class TestDiffEquals method testUserSimplePropertyDiff.

@Test
public void testUserSimplePropertyDiff() throws SchemaException {
    System.out.println("\n\n===[ testUserSimplePropertyDiff ]===\n");
    UserType userType1 = new UserType();
    userType1.setName(PrismTestUtil.createPolyStringType("test name"));
    UserType userType2 = new UserType();
    userType2.setName(PrismTestUtil.createPolyStringType("test name"));
    PrismTestUtil.getPrismContext().adopt(userType1);
    PrismTestUtil.getPrismContext().adopt(userType2);
    ObjectDelta delta = userType1.asPrismObject().diff(userType2.asPrismObject());
    assertNotNull(delta);
    assertEquals(0, delta.getModifications().size());
    userType2.setDescription(null);
    delta = userType1.asPrismObject().diff(userType2.asPrismObject());
    assertNotNull(delta);
    assertEquals("Delta should be empty, nothing changed.", 0, delta.getModifications().size());
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 22 with ObjectDelta

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

the class TestDiffEquals method testContextlessAssignmentEquals2.

@Test
public void testContextlessAssignmentEquals2() throws Exception {
    System.out.println("\n\n===[ testContextlessAssignmentEquals2 ]===\n");
    // (1) user without prismContext - the functionality is reduced
    UserType user = new UserType();
    // no prismContext here
    AssignmentType a1 = new AssignmentType();
    a1.setDescription("descr1");
    user.getAssignment().add(a1);
    // no prismContext here
    AssignmentType a2 = new AssignmentType();
    a2.setDescription("descr2");
    user.getAssignment().add(a2);
    AssignmentType a2identical = new AssignmentType();
    a2identical.setDescription("descr2");
    assertTrue(user.getAssignment().contains(a2identical));
    // delta1 is without prismContext
    ObjectDelta delta1 = user.asPrismObject().createDelta(ChangeType.DELETE);
    assertNull(delta1.getPrismContext());
    // (2) user with prismContext
    UserType userWithContext = new UserType(PrismTestUtil.getPrismContext());
    // no prismContext here
    AssignmentType b1 = new AssignmentType();
    b1.setDescription("descr1");
    userWithContext.getAssignment().add(b1);
    // no prismContext here
    AssignmentType b2 = new AssignmentType();
    b2.setDescription("descr2");
    userWithContext.getAssignment().add(b2);
    AssignmentType b2identical = new AssignmentType();
    b2identical.setDescription("descr2");
    assertTrue(user.getAssignment().contains(b2identical));
    // b1 and b2 obtain context when they are added to the container
    assertNotNull(b1.asPrismContainerValue().getPrismContext());
    assertNotNull(b2.asPrismContainerValue().getPrismContext());
    assertFalse(b1.equals(b2));
    ObjectDelta delta2 = userWithContext.asPrismObject().createDelta(ChangeType.DELETE);
    assertNotNull(delta2.getPrismContext());
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 23 with ObjectDelta

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

the class TestDiffEquals method testUserListSimpleDiff.

@Test
public void testUserListSimpleDiff() throws SchemaException {
    System.out.println("\n\n===[ testUserListSimpleDiff ]===\n");
    UserType u1 = new UserType();
    u1.setName(PrismTestUtil.createPolyStringType("test name"));
    UserType u2 = new UserType();
    u2.setName(PrismTestUtil.createPolyStringType("test name"));
    PrismTestUtil.getPrismContext().adopt(u1);
    PrismTestUtil.getPrismContext().adopt(u2);
    ObjectDelta delta = u1.asPrismObject().diff(u2.asPrismObject());
    assertNotNull(delta);
    assertEquals(0, delta.getModifications().size());
    u2.getAdditionalName();
    delta = u1.asPrismObject().diff(u2.asPrismObject());
    assertNotNull(delta);
    assertEquals("Delta should be empty, nothing changed.", 0, delta.getModifications().size());
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 24 with ObjectDelta

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

the class ModelCrudService method modifyObject.

/**
	 * <p>
	 * Modifies object using relative change description.
	 * </p>
	 * <p>
	 * Must fail if user with provided OID does not exists. Must fail if any of
	 * the described changes cannot be applied. Should be atomic.
	 * </p>
	 * <p>
	 * If two or more modify operations are executed in parallel, the operations
	 * should be merged. In case that the operations are in conflict (e.g. one
	 * operation adding a value and the other removing the same value), the
	 * result is not deterministic.
	 * </p>
	 * <p>
	 * The operation may fail if the modified object does not conform to the
	 * underlying schema of the storage system or the schema enforced by the
	 * implementation.
	 * </p>
	 * 
	 * @param parentResult
	 *            parent OperationResult (in/out)
	 * @throws ObjectNotFoundException
	 *             specified object does not exist
	 * @throws SchemaException
	 *             resulting object would violate the schema
	 * @throws ExpressionEvaluationException
	 * 				evaluation of expression associated with the object has failed
	 * @throws CommunicationException 
	 * @throws ObjectAlreadyExistsException
	 * 				If the account or another "secondary" object already exists and cannot be created
	 * @throws PolicyViolationException 
	 * 				Policy violation was detected during processing of the object
	 * @throws IllegalArgumentException
	 *             wrong OID format, described change is not applicable
	 * @throws SystemException
	 *             unknown error from underlying layers or other unexpected
	 *             state
	 */
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Validate.notNull(modifications, "Object modification must not be null.");
    Validate.notEmpty(oid, "Change oid must not be null or empty.");
    Validate.notNull(parentResult, "Result type must not be null.");
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Modifying object with oid {}", oid);
        LOGGER.trace(DebugUtil.debugDump(modifications));
    }
    if (modifications.isEmpty()) {
        LOGGER.warn("Calling modifyObject with empty modificaiton set");
        return;
    }
    ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    // TODO: check definitions, but tolerate missing definitions in <attributes>
    OperationResult result = parentResult.createSubresult(MODIFY_OBJECT);
    result.addCollectionOfSerializablesAsParam("modifications", modifications);
    RepositoryCache.enter();
    try {
        ObjectDelta<T> objectDelta = (ObjectDelta<T>) ObjectDelta.createModifyDelta(oid, modifications, type, prismContext);
        Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
        modelService.executeChanges(deltas, options, task, result);
        result.computeStatus();
    } catch (ExpressionEvaluationException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (ObjectNotFoundException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (SchemaException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (ConfigurationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (SecurityViolationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (RuntimeException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } finally {
        RepositoryCache.exit();
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 25 with ObjectDelta

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

the class ModelWebService method executeChanges.

@Override
public ObjectDeltaOperationListType executeChanges(ObjectDeltaListType deltaList, ModelExecuteOptionsType optionsType) throws FaultMessage {
    notNullArgument(deltaList, "Object delta list must not be null.");
    Task task = createTaskInstance(EXECUTE_CHANGES);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        Collection<ObjectDelta> deltas = DeltaConvertor.createObjectDeltas(deltaList, prismContext);
        for (ObjectDelta delta : deltas) {
            prismContext.adopt(delta);
        }
        ModelExecuteOptions options = ModelExecuteOptions.fromModelExecutionOptionsType(optionsType);
        // brutally eliminating type-safety compiler barking
        Collection<ObjectDeltaOperation<? extends ObjectType>> objectDeltaOperations = modelService.executeChanges((Collection) deltas, options, task, operationResult);
        ObjectDeltaOperationListType retval = new ObjectDeltaOperationListType();
        for (ObjectDeltaOperation objectDeltaOperation : objectDeltaOperations) {
            ObjectDeltaOperationType objectDeltaOperationType = DeltaConvertor.toObjectDeltaOperationType(objectDeltaOperation, null);
            retval.getDeltaOperation().add(objectDeltaOperationType);
        }
        return retval;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL executeChanges() failed", ex);
        throwFault(ex, operationResult);
        // notreached
        return null;
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26