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());
}
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());
}
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());
}
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();
}
}
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);
}
}
Aggregations