Search in sources :

Example 11 with MappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.

the class TestParseMappingConst method testParseSerialize.

@Test
public void testParseSerialize() throws Exception {
    displayTestTitle("testParseSerialize");
    PrismContext prismContext = getPrismContext();
    PrismParser parser = prismContext.parserFor(getFile());
    PrismPropertyValue<MappingType> mappingPval = parser.parseItemValue();
    System.out.println("\nmappingPval:\n" + mappingPval.debugDump(1));
    PrismSerializer<RootXNode> xserializer = prismContext.xnodeSerializer();
    RootXNode xnode = xserializer.root(new QName("dummy")).serialize(mappingPval);
    System.out.println("\nSerialized xnode:\n" + xnode.debugDump(1));
    MapXNode xexpression = (MapXNode) ((MapXNode) xnode.getSubnode()).get(new QName("expression"));
    ListXNode xconstList = (ListXNode) xexpression.get(new QName("const"));
    XNode xconst = xconstList.get(0);
    if (!(xconst instanceof PrimitiveXNode<?>)) {
        AssertJUnit.fail("const is not primitive: " + xconst);
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismParser(com.evolveum.midpoint.prism.PrismParser) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) Test(org.testng.annotations.Test)

Example 12 with MappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.

the class TestParseMappingConst method assertPrismPropertyValueLocal.

@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<MappingType> value) throws SchemaException {
    MappingType mappingType = value.getValue();
    ExpressionType expressionType = mappingType.getExpression();
    List<JAXBElement<?>> expressionEvaluatorElements = expressionType.getExpressionEvaluator();
    assertEquals("Wrong number of expression evaluator elemenets", 1, expressionEvaluatorElements.size());
    JAXBElement<?> expressionEvaluatorElement = expressionEvaluatorElements.get(0);
    Object evaluatorElementObject = expressionEvaluatorElement.getValue();
    if (!(evaluatorElementObject instanceof ConstExpressionEvaluatorType)) {
        AssertJUnit.fail("Const expression is of type " + evaluatorElementObject.getClass().getName());
    }
    ConstExpressionEvaluatorType constExpressionEvaluatorType = (ConstExpressionEvaluatorType) evaluatorElementObject;
    System.out.println("ConstExpressionEvaluatorType: " + constExpressionEvaluatorType);
    assertEquals("Wrong value in const evaluator", "foo", constExpressionEvaluatorType.getValue());
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ConstExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstExpressionEvaluatorType) JAXBElement(javax.xml.bind.JAXBElement) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 13 with MappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.

the class TestIteration method test200JackAssignAccountDummyPinkConflicting.

@Test
public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
    final String TEST_NAME = "test200JackAssignAccountDummyPinkConflicting";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    // Make sure there is a conflicting account and also a shadow for it
    DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
    account.setEnabled(true);
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Pinky");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Red Sea");
    dummyResourcePink.addAccount(account);
    repoAddObject(createShadow(resourceDummyPink, ACCOUNT_JACK_DUMMY_USERNAME), result);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    // assignment with weapon := 'pistol' (test for
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    AssignmentType assignmentType = createConstructionAssignment(RESOURCE_DUMMY_PINK_OID, ShadowKindType.ACCOUNT, null);
    ConstructionType constructionType = assignmentType.getConstruction();
    ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
    attributeDefinitionType.setRef(new ItemPathType(new ItemPath(dummyResourceCtlPink.getAttributeWeaponQName())));
    MappingType mappingType = new MappingType();
    mappingType.setStrength(MappingStrengthType.STRONG);
    ExpressionType expressionType = new ExpressionType();
    expressionType.getExpressionEvaluator().add(new ObjectFactory().createValue(RawType.create("pistol", prismContext)));
    mappingType.setExpression(expressionType);
    attributeDefinitionType.setOutbound(mappingType);
    constructionType.getAttribute().add(attributeDefinitionType);
    modifications.add(createAssignmentModification(assignmentType, true));
    ObjectDelta<UserType> accountAssignmentUserDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    deltas.add(accountAssignmentUserDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack);
    assertLinks(userJack, 2);
    assertAccount(userJack, RESOURCE_DUMMY_OID);
    assertAccount(userJack, RESOURCE_DUMMY_PINK_OID);
    String accountPinkOid = getLinkRefOid(userJack, RESOURCE_DUMMY_PINK_OID);
    // Check shadow
    PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
    assertAccountShadowRepo(accountPinkShadow, accountPinkOid, "jack1", resourceDummyPinkType);
    // Check account
    PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
    assertAccountShadowModel(accountPinkModel, accountPinkOid, "jack1", resourceDummyPinkType);
    display("accountPinkModel", accountPinkModel);
    PrismAsserts.assertPropertyValue(accountPinkModel, dummyResourceCtlPink.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "pistol");
    // Check account in dummy resource
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
    // The original conflicting account should still remain
    assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Pinky", true);
    // The new account
    assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "jack1", "Jack Sparrow", true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(3);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
    dummyAuditService.assertExecutionSuccess();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with MappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.

the class ConsistencyTest method test511AssignAccountMorgan.

/**
	 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
	 * account should be linked to the user.
	 * @throws Exception
	 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    final String TEST_NAME = "test511AssignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    //prepare new OU in opendj
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
    JAXBElement val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    //		assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account        
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) 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) Entry(org.opends.server.types.Entry) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 15 with MappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.

the class WizardUtil method createEmptyMapping.

public static MappingType createEmptyMapping() {
    MappingType mapping = new MappingType();
    mapping.setAuthoritative(true);
    return mapping;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)

Aggregations

MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 QName (javax.xml.namespace.QName)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 JAXBElement (javax.xml.bind.JAXBElement)6 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)5 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)5 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)5 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)4 Task (com.evolveum.midpoint.task.api.Task)4 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 ResourceAttributeDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType)4 Test (org.testng.annotations.Test)4