use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModifyTest method test140ModifyAccountSynchronizationSituation.
@Test
public void test140ModifyAccountSynchronizationSituation() throws Exception {
final String TEST_NAME = "test140ModifyAccountSynchronizationSituation";
TestUtil.displayTestTile(TEST_NAME);
OperationResult result = new OperationResult("testModifyAccountSynchronizationSituation");
//add account
File accountFile = new File(TEST_DIR, "account-synchronization-situation.xml");
PrismObject<ShadowType> account = prismContext.parseObject(accountFile);
repositoryService.addObject(account, null, result);
// XMLGregorianCalendar timestamp = XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
List<PropertyDelta<?>> syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(account, SynchronizationSituationType.LINKED, null, false);
// PropertyDelta<SynchronizationSituationType> syncSituationDelta = SynchronizationSituationUtil.
// createSynchronizationSituationDelta(account, SynchronizationSituationType.LINKED);
// syncSituationDeltas.add(syncSituationDelta);
repositoryService.modifyObject(ShadowType.class, account.getOid(), syncSituationDeltas, getModifyOptions(), result);
PrismObject<ShadowType> afterFirstModify = repositoryService.getObject(ShadowType.class, account.getOid(), null, result);
AssertJUnit.assertNotNull(afterFirstModify);
ShadowType afterFirstModifyType = afterFirstModify.asObjectable();
assertEquals(1, afterFirstModifyType.getSynchronizationSituationDescription().size());
SynchronizationSituationDescriptionType description = afterFirstModifyType.getSynchronizationSituationDescription().get(0);
assertEquals(SynchronizationSituationType.LINKED, description.getSituation());
// timestamp = XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(afterFirstModify, null, null, false);
// syncSituationDelta = SynchronizationSituationUtil.createSynchronizationSituationDelta(afterFirstModify, null);
// syncSituationDeltas.add(syncSituationDelta);
// XMLGregorianCalendar timestamp = XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
// PropertyDelta syncTimestap = SynchronizationSituationUtil.createSynchronizationTimestampDelta(afterFirstModify, timestamp);
// PropertyDelta.createModificationReplaceProperty(
// ShadowType.F_SYNCHRONIZATION_TIMESTAMP, afterFirstModify.getDefinition(), timestamp);
// syncSituationDeltas.add(syncTimestap);
repositoryService.modifyObject(ShadowType.class, account.getOid(), syncSituationDeltas, getModifyOptions(), result);
PrismObject<ShadowType> afterSecondModify = repositoryService.getObject(ShadowType.class, account.getOid(), null, result);
AssertJUnit.assertNotNull(afterSecondModify);
ShadowType afterSecondModifyType = afterSecondModify.asObjectable();
assertEquals(1, afterSecondModifyType.getSynchronizationSituationDescription().size());
description = afterSecondModifyType.getSynchronizationSituationDescription().get(0);
AssertJUnit.assertNull(description.getSituation());
XMLGregorianCalendar afterModifytimestamp = afterSecondModifyType.getSynchronizationTimestamp();
AssertJUnit.assertNotNull(afterModifytimestamp);
assertEquals(afterSecondModifyType.getSynchronizationTimestamp(), description.getTimestamp());
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).item(ShadowType.F_SYNCHRONIZATION_TIMESTAMP).le(afterModifytimestamp).build();
List<PrismObject<ShadowType>> shadows = repositoryService.searchObjects(ShadowType.class, query, null, result);
AssertJUnit.assertNotNull(shadows);
assertEquals(1, shadows.size());
System.out.println("shadow: " + shadows.get(0).debugDump());
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModifyUser method test050ModifyBigUser.
@Test
public void test050ModifyBigUser() throws Exception {
PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(ObjectType.F_DESCRIPTION, def, "new description");
repositoryService.modifyObject(UserType.class, userBigOid, Arrays.asList(delta), new OperationResult("asdf"));
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TaskQuartzImpl method createExtensionDelta.
public ItemDelta<?, ?> createExtensionDelta(PrismPropertyDefinition definition, Object realValue) {
PrismProperty<?> property = (PrismProperty<?>) definition.instantiate();
property.setRealValue(realValue);
PropertyDelta propertyDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), definition, realValue);
// propertyDelta.setValuesToReplace(PrismValue.cloneCollection(property.getValues()));
return propertyDelta;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TaskQuartzImpl method addExtensionPropertyAndPrepareDelta.
private ItemDelta<?, ?> addExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException {
ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, itemName), definition, getPrismContext());
delta.addValuesToAdd(values);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
modifications.add(delta);
// i.e. here we apply changes only locally (in memory)
PropertyDelta.applyTo(modifications, taskPrism);
return isPersistent() ? delta : null;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ConsistencyTest method test250ModifyObjectTwoTimesCommunicationProblem.
@Test
public void test250ModifyObjectTwoTimesCommunicationProblem() throws Exception {
final String TEST_NAME = "test250ModifyObjectTwoTimesCommunicationProblem";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeStopped();
OperationResult parentResult = new OperationResult(TEST_NAME);
assertUserOneAccountRef(USER_JACK2_OID);
Collection<PropertyDelta> modifications = new ArrayList<PropertyDelta>();
PropertyDelta fullNameDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_FULL_NAME), getUserDefinition(), new PolyString("jackNew2"));
modifications.add(fullNameDelta);
PrismPropertyValue<ActivationStatusType> enabledUserAction = new PrismPropertyValue<ActivationStatusType>(ActivationStatusType.ENABLED, OriginType.USER_ACTION, null);
PropertyDelta<ActivationStatusType> enabledDelta = PropertyDelta.createDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getUserDefinition());
enabledDelta.addValueToAdd(enabledUserAction);
modifications.add(enabledDelta);
ObjectDelta objectDelta = ObjectDelta.createModifyDelta(USER_JACK2_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
Task task = taskManager.createTaskInstance();
modelService.executeChanges(deltas, null, task, parentResult);
parentResult.computeStatus();
String accountOid = assertUserOneAccountRef(USER_JACK2_OID);
PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
assertNotNull(account);
ShadowType shadow = account.asObjectable();
assertNotNull(shadow.getObjectChange());
display("shadow after communication problem", shadow);
Collection<PropertyDelta> newModifications = new ArrayList<PropertyDelta>();
PropertyDelta fullNameDeltaNew = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_FULL_NAME), getUserDefinition(), new PolyString("jackNew2a"));
newModifications.add(fullNameDeltaNew);
PropertyDelta givenNameDeltaNew = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_GIVEN_NAME), getUserDefinition(), new PolyString("jackNew2a"));
newModifications.add(givenNameDeltaNew);
PrismPropertyValue<ActivationStatusType> enabledOutboundAction = new PrismPropertyValue<ActivationStatusType>(ActivationStatusType.ENABLED, OriginType.USER_ACTION, null);
PropertyDelta<ActivationStatusType> enabledDeltaNew = PropertyDelta.createDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getUserDefinition());
enabledDeltaNew.addValueToAdd(enabledOutboundAction);
newModifications.add(enabledDeltaNew);
ObjectDelta newObjectDelta = ObjectDelta.createModifyDelta(USER_JACK2_OID, newModifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> newDeltas = MiscSchemaUtil.createCollection(newObjectDelta);
modelService.executeChanges(newDeltas, null, task, parentResult);
account = modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
assertNotNull(account);
shadow = account.asObjectable();
assertNotNull(shadow.getObjectChange());
display("shadow after communication problem", shadow);
// parentResult.computeStatus();
// assertEquals("expected handled error in the result", OperationResultStatus.HANDLED_ERROR, parentResult.getStatus());
}
Aggregations