Search in sources :

Example 41 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestDeltaConverter method testModifyGivenName.

@Test
public void testModifyGivenName() throws Exception {
    System.out.println("===[ testModifyGivenName ]====");
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-givenname.xml"), ObjectModificationType.COMPLEX_TYPE);
    // WHEN
    ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext());
    // THEN
    assertNotNull("No object delta", objectDelta);
    objectDelta.checkConsistence();
    assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid());
    PropertyDelta<String> givenNameDelta = objectDelta.findPropertyDelta(UserType.F_GIVEN_NAME);
    assertNotNull("No givenName delta", givenNameDelta);
    Collection<PrismPropertyValue<String>> valuesToReplace = givenNameDelta.getValuesToReplace();
    assertEquals("Wrong number of values to replace", 0, valuesToReplace.size());
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
    // apply to user
    objectDelta.applyTo(user);
    PrismProperty<String> protectedStringProperty = user.findProperty(UserType.F_GIVEN_NAME);
    assertNull("givenName porperty sneaked in after delta was applied", protectedStringProperty);
    objectDelta.assertDefinitions();
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) Test(org.testng.annotations.Test)

Example 42 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class DeltaConvertor method toObjectDeltaType.

public static ObjectDeltaType toObjectDeltaType(ObjectDelta<? extends ObjectType> objectDelta, DeltaConversionOptions options) throws SchemaException {
    Validate.notNull(objectDelta.getPrismContext(), "ObjectDelta without prismContext cannot be converted to ObjectDeltaType");
    ObjectDeltaType objectDeltaType = new ObjectDeltaType();
    objectDeltaType.setChangeType(convertChangeType(objectDelta.getChangeType()));
    Class<? extends Objectable> type = objectDelta.getObjectTypeClass();
    PrismObjectDefinition<? extends Objectable> objDef = objectDelta.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
    if (objDef == null) {
        throw new SchemaException("Unknown compile time class: " + type);
    }
    objectDeltaType.setObjectType(objDef.getTypeName());
    objectDeltaType.setOid(objectDelta.getOid());
    if (objectDelta.getChangeType() == ChangeType.ADD) {
        PrismObject<? extends ObjectType> prismObject = objectDelta.getObjectToAdd();
        if (prismObject != null) {
            objectDeltaType.setObjectToAdd(prismObject.asObjectable());
        }
    } else if (objectDelta.getChangeType() == ChangeType.MODIFY) {
        ObjectModificationType modType = new ObjectModificationType();
        modType.setOid(objectDelta.getOid());
        for (ItemDelta<?, ?> propDelta : objectDelta.getModifications()) {
            Collection<ItemDeltaType> propPropModTypes;
            try {
                propPropModTypes = toItemDeltaTypes(propDelta, options);
            } catch (SchemaException e) {
                throw new SchemaException(e.getMessage() + " in " + objectDelta.toString(), e);
            }
            objectDeltaType.getItemDelta().addAll(propPropModTypes);
        }
    } else if (objectDelta.getChangeType() == ChangeType.DELETE) {
    // Nothing to do
    } else {
        throw new SystemException("Unknown changetype " + objectDelta.getChangeType());
    }
    return objectDeltaType;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) SystemException(com.evolveum.midpoint.util.exception.SystemException) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 43 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test105ApplyDefinitionModifyDelta.

@Test
public void test105ApplyDefinitionModifyDelta() throws Exception {
    final String TEST_NAME = "test105ApplyDefinitionModifyDelta";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    ObjectModificationType changeAddRoleCaptain = PrismTestUtil.parseAtomicValue(MODIFY_ACCOUNT_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> accountDelta = DeltaConvertor.createObjectDelta(changeAddRoleCaptain, ShadowType.class, prismContext);
    // WHEN
    provisioningService.applyDefinition(accountDelta, task, result);
    // THEN
    result.computeStatus();
    display("applyDefinition result", result);
    TestUtil.assertSuccess(result);
    accountDelta.checkConsistence(true, true, true);
    TestUtil.assertSuccess("applyDefinition(modify delta) result", result);
    assertSteadyResource();
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) 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) Test(org.testng.annotations.Test)

Example 44 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDj method test140AddAndModifyAccountJack.

@Test
public void test140AddAndModifyAccountJack() throws Exception {
    final String TEST_NAME = "test140AddAndModifyAccountJack";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    ShadowType object = unmarshallValueFromFile(ACCOUNT_JACK_FILE, ShadowType.class);
    System.out.println(SchemaDebugUtil.prettyPrint(object));
    System.out.println(object.asPrismObject().debugDump());
    String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result);
    assertEquals(ACCOUNT_JACK_OID, addedObjectOid);
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(ACCOUNT_JACK_CHANGE_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, object.asPrismObject().getDefinition());
    ItemPath icfNamePath = new ItemPath(ShadowType.F_ATTRIBUTES, getSecondaryIdentifierQName());
    PrismPropertyDefinition icfNameDef = object.asPrismObject().getDefinition().findPropertyDefinition(icfNamePath);
    ItemDelta renameDelta = PropertyDelta.createModificationReplaceProperty(icfNamePath, icfNameDef, "uid=rename,ou=People,dc=example,dc=com");
    ((Collection) delta.getModifications()).add(renameDelta);
    display("Object change", delta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, taskManager.createTaskInstance(), result).asObjectable();
    display("Object after change", accountType);
    String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
    List<Object> snValues = ShadowUtil.getAttributeValues(accountType, new QName(RESOURCE_NS, "sn"));
    assertNotNull("No 'sn' attribute", snValues);
    assertFalse("Surname attributes must not be empty", snValues.isEmpty());
    assertEquals(1, snValues.size());
    //check icf_name in the shadow object fetched only from the repository
    ShadowType repoShadow = repositoryService.getObject(ShadowType.class, objectChange.getOid(), null, result).asObjectable();
    String name = ShadowUtil.getSingleStringAttributeValue(repoShadow, getSecondaryIdentifierQName());
    assertEquals("After rename, dn is not equal.", "uid=rename,ou=people,dc=example,dc=com", name);
    assertEquals("shadow name not changed after rename", "uid=rename,ou=People,dc=example,dc=com", repoShadow.getName().getOrig());
    String changedSn = (String) snValues.get(0);
    assertNotNull(uid);
    // Check if object was modified in LDAP
    Entry response = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account", response);
    OpenDJController.assertAttribute(response, "sn", "First");
    assertEquals("First", changedSn);
    assertShadows(3);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Entry(org.opends.server.types.Entry) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 45 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestOpenDj method test170DisableAccount.

@Test
public void test170DisableAccount() throws Exception {
    final String TEST_NAME = "test170DisableAccount";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    ShadowType object = parseObjectType(ACCOUNT_DISABLE_SIMULATED_FILE, ShadowType.class);
    System.out.println(SchemaDebugUtil.prettyPrint(object));
    System.out.println(object.asPrismObject().debugDump());
    String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result);
    assertEquals(ACCOUNT_DISABLE_SIMULATED_OID, addedObjectOid);
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(REQUEST_DISABLE_ACCOUNT_SIMULATED_FILE, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, object.asPrismObject().getDefinition());
    display("Object change", delta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_DISABLE_SIMULATED_OID, null, taskManager.createTaskInstance(), result).asObjectable();
    display("Object after change", accountType);
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, accountType.getActivation().getAdministrativeStatus());
    String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
    assertNotNull(uid);
    // Check if object was modified in LDAP
    Entry response = openDJController.searchAndAssertByEntryUuid(uid);
    display("LDAP account", response);
    String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled");
    assertNotNull("no ds-pwp-account-disabled attribute in account " + uid, disabled);
    display("ds-pwp-account-disabled after change: " + disabled);
    assertEquals("ds-pwp-account-disabled not set to \"TRUE\"", "TRUE", disabled);
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, ACCOUNT_DISABLE_SIMULATED_OID, null, result);
    ActivationType repoActivation = repoShadow.asObjectable().getActivation();
    assertNotNull("No activation in repo", repoActivation);
    XMLGregorianCalendar repoDisableTimestamp = repoActivation.getDisableTimestamp();
    assertNotNull("No activation disableTimestamp in repo", repoDisableTimestamp);
    assertEquals("Wrong activation disableTimestamp in repo", XmlTypeConverter.createXMLGregorianCalendar(2001, 2, 3, 4, 5, 6), repoDisableTimestamp);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) Entry(org.opends.server.types.Entry) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)45 Test (org.testng.annotations.Test)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 File (java.io.File)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Session (org.hibernate.Session)6 ROrgClosure (com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)5 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)5 Entry (org.opends.server.types.Entry)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)3 QName (javax.xml.namespace.QName)3 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2