Search in sources :

Example 6 with MappingType

use of io.atlasmap.v2.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 7 with MappingType

use of io.atlasmap.v2.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 8 with MappingType

use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.

the class OutboundProcessor method processOutbound.

public <F extends FocusType> void processOutbound(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    ResourceShadowDiscriminator discr = projCtx.getResourceShadowDiscriminator();
    ObjectDelta<ShadowType> projectionDelta = projCtx.getDelta();
    if (projectionDelta != null && projectionDelta.getChangeType() == ChangeType.DELETE) {
        LOGGER.trace("Processing outbound expressions for {} skipped, DELETE account delta", discr);
        // No point in evaluating outbound
        return;
    }
    LOGGER.trace("Processing outbound expressions for {} starting", discr);
    RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
    if (rOcDef == null) {
        LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
        throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
    }
    ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
    ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();
    Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
    outboundConstruction.setRefinedObjectClassDefinition(rOcDef);
    Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
    if (auxiliaryObjectClassDefinitions != null) {
        for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
            outboundConstruction.addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
        }
    }
    String operation = projCtx.getOperation().getValue();
    for (QName attributeName : rOcDef.getNamesOfAttributesWithOutboundExpressions()) {
        RefinedAttributeDefinition<?> refinedAttributeDefinition = rOcDef.findAttributeDefinition(attributeName);
        final MappingType outboundMappingType = refinedAttributeDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        if (refinedAttributeDefinition.isIgnored(LayerType.MODEL)) {
            LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", attributeName);
            continue;
        }
        Mapping.Builder<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(refinedAttributeDefinition.getName()) + " in " + rOcDef.getResourceType());
        builder = builder.originObject(rOcDef.getResourceType()).originType(OriginType.OUTBOUND);
        Mapping<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> evaluatedMapping = evaluateMapping(builder, attributeName, refinedAttributeDefinition, focusOdo, projectionOdo, operation, rOcDef, null, context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAttributeMapping(evaluatedMapping);
        }
    }
    for (QName assocName : rOcDef.getNamesOfAssociationsWithOutboundExpressions()) {
        RefinedAssociationDefinition associationDefinition = rOcDef.findAssociationDefinition(assocName);
        final MappingType outboundMappingType = associationDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        //			if (associationDefinition.isIgnored(LayerType.MODEL)) {
        //				LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", assocName);
        //				continue;
        //			}
        Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(associationDefinition.getName()) + " in " + rOcDef.getResourceType());
        PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
        Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = (Mapping) evaluateMapping(mappingBuilder, assocName, outputDefinition, focusOdo, projectionOdo, operation, rOcDef, associationDefinition.getAssociationTarget(), context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAssociationMapping(evaluatedMapping);
        }
    }
    projCtx.setOutboundConstruction(outboundConstruction);
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Construction(com.evolveum.midpoint.model.impl.lens.Construction) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 9 with MappingType

use of io.atlasmap.v2.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 10 with MappingType

use of io.atlasmap.v2.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)8 QName (javax.xml.namespace.QName)8 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)5 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)5 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)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 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 Test (org.testng.annotations.Test)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3