Search in sources :

Example 26 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class Main method modifyRoleAssignment.

private static void modifyRoleAssignment(ModelPortType modelPort, String userOid, boolean isAdd, String... roleOids) throws FaultMessage {
    ItemDeltaType assignmentDelta = new ItemDeltaType();
    if (isAdd) {
        assignmentDelta.setModificationType(ModificationTypeType.ADD);
    } else {
        assignmentDelta.setModificationType(ModificationTypeType.DELETE);
    }
    assignmentDelta.setPath(ModelClientUtil.createItemPathType("assignment"));
    for (String roleOid : roleOids) {
        assignmentDelta.getValue().add(ModelClientUtil.createRoleAssignment(roleOid));
    }
    ObjectDeltaType deltaType = new ObjectDeltaType();
    deltaType.setObjectType(ModelClientUtil.getTypeQName(UserType.class));
    deltaType.setChangeType(ChangeTypeType.MODIFY);
    deltaType.setOid(userOid);
    deltaType.getItemDelta().add(assignmentDelta);
    ObjectDeltaOperationListType objectDeltaOperationList = modelPort.executeChanges(ModelClientUtil.createDeltaList(deltaType), null);
    for (ObjectDeltaOperationType objectDeltaOperation : objectDeltaOperationList.getDeltaOperation()) {
        if (!OperationResultStatusType.SUCCESS.equals(objectDeltaOperation.getExecutionResult().getStatus())) {
            System.out.println("*** Operation result = " + objectDeltaOperation.getExecutionResult().getStatus() + ": " + objectDeltaOperation.getExecutionResult().getMessage());
        }
    }
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 27 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class TestSanity method test502NotifyChangeModifyAccountPassword.

@Test
public void test502NotifyChangeModifyAccountPassword() throws Exception {
    final String TEST_NAME = "test502NotifyChangeModifyAccountPassword";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    String newPassword = "newPassword";
    openDJController.modifyReplace("uid=" + ANGELIKA_NAME + "," + openDJController.getSuffixPeople(), "userPassword", newPassword);
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.MODIFY);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    RawType passwordValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(ModelClientUtil.createProtectedString(newPassword)), prismContext);
    passwordDelta.getValue().add(passwordValue);
    delta.getItemDelta().add(passwordDelta);
    delta.setOid(oid);
    LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(passwordDelta));
    LOGGER.info("delta: {}", DebugUtil.dump(passwordDelta));
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    //    	changeDescription.setCurrentShadow(angelicaShadowType);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    // WHEN
    TaskType task = modelWeb.notifyChange(changeDescription);
    // THEN
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    assertUserLdapPassword(userAngelikaAfterSync, newPassword);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 28 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class TestSanity method test501NotifyChangeModifyAccount.

@Test
public void test501NotifyChangeModifyAccount() throws Exception {
    final String TEST_NAME = "test501NotifyChangeModifyAccount";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.MODIFY);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType path = new ItemPathType(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(resourceTypeOpenDjrepo.getNamespace(), "givenName")));
    mod1.setPath(path);
    RawType value = new RawType(new PrimitiveXNode<String>("newAngelika"), prismContext);
    mod1.getValue().add(value);
    delta.getItemDelta().add(mod1);
    delta.setOid(oid);
    LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(mod1));
    LOGGER.info("delta: {}", DebugUtil.dump(mod1));
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    // WHEN
    TaskType task = modelWeb.notifyChange(changeDescription);
    // THEN
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    UserType userAfterSync = userAngelikaAfterSync.asObjectable();
    PrismAsserts.assertEqualsPolyString("wrong given name in user angelika", PrismTestUtil.createPolyStringType("newAngelika"), userAfterSync.getGivenName());
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 29 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class TestSanity method test023ChangeUserPasswordJAXB.

/**
     * Similar to previous test just the request is constructed a bit differently.
     */
@Test
public void test023ChangeUserPasswordJAXB() throws Exception {
    final String TEST_NAME = "test023ChangeUserPasswordJAXB";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final String NEW_PASSWORD = "abandonSHIP";
    Document doc = ModelClientUtil.getDocumnent();
    ObjectDeltaType userDelta = new ObjectDeltaType();
    userDelta.setOid(USER_JACK_OID);
    userDelta.setChangeType(ChangeTypeType.MODIFY);
    userDelta.setObjectType(UserType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    ProtectedStringType pass = new ProtectedStringType();
    pass.setClearValue(NEW_PASSWORD);
    XNode passValue = ((PrismContextImpl) prismContext).getBeanMarshaller().marshall(pass);
    System.out.println("PASSWORD VALUE: " + passValue.debugDump());
    RawType passwordValue = new RawType(passValue, prismContext);
    passwordDelta.getValue().add(passwordValue);
    userDelta.getItemDelta().add(passwordDelta);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(userDelta);
    // THEN
    assertUserPasswordChange(NEW_PASSWORD, result);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Document(org.w3c.dom.Document) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 30 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class TestParseDiffPatch method testUser.

@Test
public void testUser() throws SchemaException, SAXException, IOException, JAXBException {
    System.out.println("===[ testUser ]===");
    PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-before.xml"));
    userBefore.checkConsistence();
    PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-after.xml"));
    userAfter.checkConsistence();
    // sanity
    assertFalse("Equals does not work", userBefore.equals(userAfter));
    // WHEN
    ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
    // THEN
    System.out.println("DELTA:");
    System.out.println(userDelta.debugDump());
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    userDelta.assertDefinitions();
    assertEquals("Wrong delta OID", userBefore.getOid(), userDelta.getOid());
    assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
    Collection<? extends ItemDelta> modifications = userDelta.getModifications();
    assertEquals("Unexpected number of modifications", 3, modifications.size());
    PrismAsserts.assertPropertyReplace(userDelta, new QName(SchemaConstants.NS_C, "fullName"), new PolyString("Cpt. Jack Sparrow", "cpt jack sparrow"));
    PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
    PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "locality"), new PolyString("Tortuga", "tortuga"));
    ObjectModificationType objectModificationType = DeltaConvertor.toObjectModificationType(userDelta);
    System.out.println("Modification XML:");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectModificationType));
    assertEquals("Wrong delta OID", userBefore.getOid(), objectModificationType.getOid());
    List<ItemDeltaType> propertyModifications = objectModificationType.getItemDelta();
    assertEquals("Unexpected number of modifications", 3, propertyModifications.size());
    PolyStringType polyString = new PolyStringType();
    polyString.setOrig("Cpt. Jack Sparrow");
    polyString.setNorm("cpt jack sparrow");
    assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "fullName"), ModificationTypeType.REPLACE, polyString);
    polyString = new PolyStringType();
    polyString.setOrig("Cpt.");
    polyString.setNorm("cpt");
    assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "honorificPrefix"), ModificationTypeType.ADD, polyString);
    polyString = new PolyStringType();
    polyString.setOrig("Tortuga");
    polyString.setNorm("tortuga");
    assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "locality"), ModificationTypeType.ADD, polyString);
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    // ROUNDTRIP
    userDelta.applyTo(userBefore);
    userBefore.checkConsistence();
    userAfter.checkConsistence();
    userDelta.checkConsistence();
    //assertEquals("Round trip failed", userAfter, userBefore);
    assertTrue("Not equivalent", userBefore.equivalent(userAfter));
    ObjectDelta<UserType> roundTripDelta = DiffUtil.diff(userBefore, userAfter);
    System.out.println("roundtrip DELTA:");
    System.out.println(roundTripDelta.debugDump());
    assertTrue("Roundtrip delta is not empty", roundTripDelta.isEmpty());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test)

Aggregations

ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)39 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)28 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)11 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)11 Test (org.testng.annotations.Test)11 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 QName (javax.xml.namespace.QName)8 Document (org.w3c.dom.Document)8 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)6 XNode (com.evolveum.midpoint.prism.xnode.XNode)4 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)4 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)4 ResourceObjectShadowChangeDescriptionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType)4