Search in sources :

Example 16 with MappingType

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

the class MappingTestEvaluator method createInboudMapping.

public <T> Mapping<PrismPropertyValue<T>, PrismPropertyDefinition<T>> createInboudMapping(String filename, String testName, ItemDelta delta, UserType user, ShadowType account, ResourceType resource, final StringPolicyType policy) throws SchemaException, IOException, JAXBException {
    MappingType mappingType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), MappingType.COMPLEX_TYPE);
    Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> builder = mappingFactory.createMappingBuilder(mappingType, testName);
    Source<PrismPropertyValue<T>, PrismPropertyDefinition<T>> defaultSource = new Source<>(null, delta, null, ExpressionConstants.VAR_INPUT);
    defaultSource.recompute();
    builder.setDefaultSource(defaultSource);
    builder.setTargetContext(getUserDefinition());
    builder.addVariableDefinition(ExpressionConstants.VAR_USER, user);
    builder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, user);
    builder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, account.asPrismObject());
    builder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, account.asPrismObject());
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        ItemPath outputPath;

        ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            return policy;
        }
    };
    builder.setStringPolicyResolver(stringPolicyResolver);
    builder.setOriginType(OriginType.INBOUND);
    builder.setOriginObject(resource);
    return builder.build();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) File(java.io.File) Source(com.evolveum.midpoint.repo.common.expression.Source) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 17 with MappingType

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

the class Construction method evaluateAssociation.

private Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluateAssociation(ResourceObjectAssociationType associationDefinitionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    QName assocName = ItemPathUtil.getOnlySegmentQName(associationDefinitionType.getRef());
    if (assocName == null) {
        throw new SchemaException("Missing 'ref' in association in construction in " + getSource());
    }
    MappingType outboundMappingType = associationDefinitionType.getOutbound();
    if (outboundMappingType == null) {
        throw new SchemaException("No outbound section in definition of association " + assocName + " in construction in " + getSource());
    }
    PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
    Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>createMappingBuilder().mappingType(outboundMappingType).contextDescription("for association " + PrettyPrinter.prettyPrint(assocName) + " in " + getSource()).originType(OriginType.ASSIGNMENTS).originObject(getSource());
    RefinedAssociationDefinition rAssocDef = refinedObjectClassDefinition.findAssociationDefinition(assocName);
    if (rAssocDef == null) {
        throw new SchemaException("No association " + assocName + " in object class " + refinedObjectClassDefinition.getHumanReadableName() + " in construction in " + getSource());
    }
    Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = evaluateMapping(mappingBuilder, assocName, outputDefinition, rAssocDef.getAssociationTarget(), task, result);
    LOGGER.trace("Evaluated mapping for association " + assocName + ": " + evaluatedMapping);
    return evaluatedMapping;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)

Example 18 with MappingType

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

the class Construction method evaluateAttribute.

private <T> Mapping<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> evaluateAttribute(ResourceAttributeDefinitionType attribudeDefinitionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    QName attrName = ItemPathUtil.getOnlySegmentQName(attribudeDefinitionType.getRef());
    if (attrName == null) {
        throw new SchemaException("Missing 'ref' in attribute construction in account construction in " + getSource());
    }
    if (!attribudeDefinitionType.getInbound().isEmpty()) {
        throw new SchemaException("Cannot process inbound section in definition of attribute " + attrName + " in account construction in " + getSource());
    }
    MappingType outboundMappingType = attribudeDefinitionType.getOutbound();
    if (outboundMappingType == null) {
        throw new SchemaException("No outbound section in definition of attribute " + attrName + " in account construction in " + getSource());
    }
    ResourceAttributeDefinition<T> outputDefinition = findAttributeDefinition(attrName);
    if (outputDefinition == null) {
        throw new SchemaException("Attribute " + attrName + " not found in schema for account type " + getIntent() + ", " + getResource(task, result) + " as definied in " + getSource(), attrName);
    }
    Mapping.Builder<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "for attribute " + PrettyPrinter.prettyPrint(attrName) + " in " + getSource());
    Mapping<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> evaluatedMapping = evaluateMapping(builder, attrName, outputDefinition, null, task, result);
    LOGGER.trace("Evaluated mapping for attribute " + attrName + ": " + evaluatedMapping);
    return evaluatedMapping;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 19 with MappingType

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

the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.

/**
     * We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
     *
     */
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
    final String TEST_NAME = "test191ModifyUserJackModifyAssignment";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    //PrismPropertyDefinition definition = getAssignmentDefinition().findPropertyDefinition(new QName(SchemaConstantsGenerated.NS_COMMON, "accountConstruction"));
    PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(dummyResource, prismContext);
    // This explicitly parses the schema, therefore ...
    assertResourceSchemaParseCountIncrement(1);
    RefinedObjectClassDefinition accountDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
    PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
    assertNotNull("gossip attribute definition not found", gossipDefinition);
    ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
    ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
    radt.setRef(new ItemPathType(new ItemPath(gossipDefinition.getName())));
    MappingType outbound = new MappingType();
    radt.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    MappingType value = new MappingType();
    PrismProperty<String> property = gossipDefinition.instantiate();
    property.add(new PrismPropertyValue<String>("q"));
    List evaluators = expression.getExpressionEvaluator();
    Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property, null);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> obj : collection) {
        evaluators.add(of.createValue(obj.getValue()));
    }
    value.setExpression(expression);
    radt.setOutbound(value);
    accountConstruction.getAttribute().add(radt);
    PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
    assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
    Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
    ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
    deltas.add(accountAssignmentUserDelta);
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
    display("User before change execution", userJackOld);
    display("Deltas to execute execution", deltas);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    // First fetch: initial account read
    // Second fetch: fetchback after modification to correctly process inbound
    assertShadowFetchOperationCountIncrement(2);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
    DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
    display(dummyAccount.debugDump());
    assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
    //assertEquals("Missing or incorrect attribute value", "soda", dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, String.class));
    assertDummyScriptsModify(userJack, true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
    assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    assertScriptCompileIncrement(0);
    assertSteadyResources();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) 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) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) List(java.util.List) ArrayList(java.util.ArrayList) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) QName(javax.xml.namespace.QName) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) JAXBElement(javax.xml.bind.JAXBElement) 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 20 with MappingType

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

the class ActivationProcessor method evaluateExistenceMapping.

private <F extends FocusType> boolean evaluateExistenceMapping(final LensContext<F> context, final LensProjectionContext accCtx, final XMLGregorianCalendar now, final boolean current, Task task, final OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    final String accCtxDesc = accCtx.toHumanReadableString();
    final Boolean legal = accCtx.isLegal();
    if (legal == null) {
        throw new IllegalStateException("Null 'legal' for " + accCtxDesc);
    }
    ResourceObjectTypeDefinitionType resourceAccountDefType = accCtx.getResourceObjectTypeDefinitionType();
    if (resourceAccountDefType == null) {
        return legal;
    }
    ResourceActivationDefinitionType activationType = resourceAccountDefType.getActivation();
    if (activationType == null) {
        return legal;
    }
    ResourceBidirectionalMappingType existenceType = activationType.getExistence();
    if (existenceType == null) {
        return legal;
    }
    List<MappingType> outbound = existenceType.getOutbound();
    if (outbound == null || outbound.isEmpty()) {
        // "default mapping"
        return legal;
    }
    MappingEvaluatorParams<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>, ShadowType, F> params = new MappingEvaluatorParams<>();
    params.setMappingTypes(outbound);
    params.setMappingDesc("outbound existence mapping in projection " + accCtxDesc);
    params.setNow(now);
    params.setAPrioriTargetObject(accCtx.getObjectOld());
    params.setEvaluateCurrent(current);
    params.setTargetContext(accCtx);
    params.setFixTarget(true);
    params.setContext(context);
    params.setInitializer(builder -> {
        ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> legalSourceIdi = getLegalIdi(accCtx);
        Source<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> legalSource = new Source<>(legalSourceIdi, ExpressionConstants.VAR_LEGAL);
        builder.defaultSource(legalSource);
        ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> assignedIdi = getAssignedIdi(accCtx);
        Source<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> assignedSource = new Source<>(assignedIdi, ExpressionConstants.VAR_ASSIGNED);
        builder.addSource(assignedSource);
        ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> focusExistsSourceIdi = getFocusExistsIdi(context.getFocusContext());
        Source<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> focusExistsSource = new Source<>(focusExistsSourceIdi, ExpressionConstants.VAR_FOCUS_EXISTS);
        builder.addSource(focusExistsSource);
        builder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, context.getFocusContext().getObjectDeltaObject());
        builder.addVariableDefinition(ExpressionConstants.VAR_USER, context.getFocusContext().getObjectDeltaObject());
        builder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, accCtx.getObjectDeltaObject());
        builder.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, accCtx.getResource());
        builder.originType(OriginType.OUTBOUND);
        builder.originObject(accCtx.getResource());
        return builder;
    });
    final MutableBoolean output = new MutableBoolean(false);
    params.setProcessor((mappingOutputPath, outputStruct) -> {
        PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = outputStruct.getOutputTriple();
        if (outputTriple == null) {
            // The "default existence mapping"
            output.setValue(legal);
            return false;
        }
        Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues();
        // (e.g. because the condition is false). This should be fixed.
        if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
            throw new ExpressionEvaluationException("Activation existence expression resulted in null or empty value for projection " + accCtxDesc);
        }
        if (nonNegativeValues.size() > 1) {
            throw new ExpressionEvaluationException("Activation existence expression resulted in too many values (" + nonNegativeValues.size() + ") for projection " + accCtxDesc);
        }
        output.setValue(nonNegativeValues.iterator().next().getValue());
        return false;
    });
    PrismPropertyDefinitionImpl<Boolean> shadowExistsDef = new PrismPropertyDefinitionImpl<>(SHADOW_EXISTS_PROPERTY_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    shadowExistsDef.setMinOccurs(1);
    shadowExistsDef.setMaxOccurs(1);
    params.setTargetItemDefinition(shadowExistsDef);
    mappingEvaluator.evaluateMappingSetProjection(params, task, result);
    return (boolean) output.getValue();
}
Also used : ResourceBidirectionalMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBidirectionalMappingType) MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) Source(com.evolveum.midpoint.repo.common.expression.Source) ResourceActivationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceActivationDefinitionType) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) ResourceBidirectionalMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBidirectionalMappingType) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean)

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