Search in sources :

Example 46 with PropertyDelta

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());
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) File(java.io.File) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 47 with PropertyDelta

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"));
}
Also used : PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 48 with PropertyDelta

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;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 49 with 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;
}
Also used : ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 50 with PropertyDelta

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

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