Search in sources :

Example 6 with VariableBindingDefinitionType

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

the class TestParseResource method assertResourceJaxb.

private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
    assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
    assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
    assertEquals("Wrong namespace (JAXB)", MidPointConstants.NS_RI, MidPointConstants.NS_RI);
    ObjectReferenceType connectorRef = resourceType.getConnectorRef();
    assertNotNull("No connectorRef (JAXB)", connectorRef);
    assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
    SearchFilterType filter = connectorRef.getFilter();
    assertNotNull("No filter in connectorRef (JAXB)", filter);
    MapXNode filterElement = filter.getFilterClauseXNode();
    assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
    EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
    }
    XmlSchemaType xmlSchemaType = resourceType.getSchema();
    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (isSimple) {
        assertNull("Schema sneaked in", xmlSchemaType);
        assertNull("SchemaHandling sneaked in", schemaHandling);
    } else {
        assertNotNull("No schema element (JAXB)", xmlSchemaType);
        SchemaDefinitionType definition = xmlSchemaType.getDefinition();
        assertNotNull("No definition element in schema (JAXB)", definition);
        List<Element> anyElements = definition.getAny();
        assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
        assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
        assertNotNull("No schema handling (JAXB)", schemaHandling);
        for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
            String name = accountType.getIntent();
            assertNotNull("Account type without a name", name);
            assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
            boolean foundDescription = false;
            boolean foundDepartmentNumber = false;
            for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
                if ("description".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDescription = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
                    System.out.println("value evaluator for description = " + valueEvaluator);
                    assertNotNull("no expression evaluator for description", valueEvaluator);
                    assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
                    assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
                } else if ("departmentNumber".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDepartmentNumber = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    VariableBindingDefinitionType source = outbound.getSource().get(0);
                    System.out.println("source for departmentNumber = " + source);
                    assertNotNull("no source for outbound mapping for departmentNumber", source);
                    // <path xmlns:z="http://z/">$user/extension/z:dept</path>
                    ItemPath expected = ItemPath.create(new VariableItemPathSegment(new QName("user")), new QName("extension"), namespaces ? new QName("http://z/", "dept") : new QName("dept"));
                    PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
                }
            }
            assertTrue("ri:description attribute was not found", foundDescription);
            assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
        }
        // checking <class> element in fetch result
        OperationResultType fetchResult = resourceType.getFetchResult();
        assertNotNull("No fetchResult (JAXB)", fetchResult);
        JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
        assertNotNull("No fetchResult param value (JAXB)", value);
        assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
        UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
        assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
        assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) VariableItemPathSegment(com.evolveum.midpoint.prism.path.VariableItemPathSegment) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with VariableBindingDefinitionType

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

the class PopulatorUtil method evaluatePopulateExpression.

public static <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, VariablesMap variables, ExpressionEvaluationContext context, PrismContainerDefinition<C> targetContainerDefinition, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    ExpressionType expressionType = populateItem.getExpression();
    if (expressionType == null) {
        LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    VariableBindingDefinitionType targetType = populateItem.getTarget();
    if (targetType == null) {
        LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    ItemPathType itemPathType = targetType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in target definition in " + contextDescription);
    }
    ItemPath targetPath = itemPathType.getItemPath();
    ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, targetContainerDefinition, "target definition in " + contextDescription);
    if (propOutputDefinition == null) {
        throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
    }
    String expressionDesc = "expression in populate expression in " + contextDescription;
    ExpressionFactory expressionFactory = context.getExpressionFactory();
    Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, context.getExpressionProfile(), expressionDesc, task, result);
    ExpressionEvaluationContext localContext = new ExpressionEvaluationContext(null, variables, expressionDesc, task);
    localContext.setExpressionFactory(expressionFactory);
    localContext.setValuePolicySupplier(context.getValuePolicySupplier());
    localContext.setSkipEvaluationMinus(true);
    localContext.setSkipEvaluationPlus(false);
    localContext.setVariableProducer(context.getVariableProducer());
    localContext.setLocalContextDescription(context.getLocalContextDescription());
    PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(localContext, result);
    LOGGER.trace("output triple:\n{}", DebugUtil.debugDumpLazily(outputTriple, 1));
    if (outputTriple == null) {
        return null;
    }
    Collection<IV> pvalues = outputTriple.getNonNegativeValues();
    // Maybe not really clean but it works. TODO: refactor later
    if (targetPath.startsWithVariable()) {
        targetPath = targetPath.rest();
    }
    // noinspection unchecked
    ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
    itemDelta.addValuesToAdd(PrismValueCollectionsUtil.cloneCollection(pvalues));
    LOGGER.trace("Item delta:\n{}", itemDelta.debugDumpLazily(1));
    return itemDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 8 with VariableBindingDefinitionType

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

the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.

private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ExpressionType expressionType = populateItem.getExpression();
    if (expressionType == null) {
        LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    VariableBindingDefinitionType targetType = populateItem.getTarget();
    if (targetType == null) {
        LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    ItemPathType itemPathType = targetType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in target definition in " + contextDescription);
    }
    ItemPath targetPath = itemPathType.getItemPath();
    ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
    if (propOutputDefinition == null) {
        throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
    }
    String expressionDesc = "expression in assignment expression in " + contextDescription;
    ExpressionFactory expressionFactory = params.getExpressionFactory();
    Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
    context.setExpressionFactory(expressionFactory);
    context.setStringPolicyResolver(params.getStringPolicyResolver());
    context.setDefaultTargetContext(params.getDefaultTargetContext());
    context.setSkipEvaluationMinus(true);
    context.setSkipEvaluationPlus(false);
    PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
    LOGGER.trace("output triple: {}", outputTriple.debugDump());
    Collection<IV> pvalues = outputTriple.getNonNegativeValues();
    // Maybe not really clean but it works. TODO: refactor later
    NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
    if (first.isVariable()) {
        targetPath = targetPath.rest();
    }
    ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
    itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
    LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
    return itemDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 9 with VariableBindingDefinitionType

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

the class MappingSorter method dependsOn.

// true if any source of mapping1 is equivalent to the target of mapping2
private boolean dependsOn(FocalMappingEvaluationRequest<?, ?> mappingRequest1, FocalMappingEvaluationRequest<?, ?> mappingRequest2) {
    MappingType mapping1 = mappingRequest1.getMapping();
    MappingType mapping2 = mappingRequest2.getMapping();
    if (mapping2.getTarget() == null || mapping2.getTarget().getPath() == null) {
        return false;
    }
    ItemPath targetPath = mapping2.getTarget().getPath().getItemPath().stripVariableSegment();
    for (VariableBindingDefinitionType source : mapping1.getSource()) {
        ItemPath sourcePath = beans.prismContext.toPath(source.getPath());
        if (sourcePath != null && FocalMappingSetEvaluation.stripFocusVariableSegment(sourcePath).equivalent(targetPath)) {
            return true;
        }
    }
    return false;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with VariableBindingDefinitionType

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

the class MappingParser method parseSources.

private void parseSources(OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, SecurityViolationException, ConfigurationException, CommunicationException {
    if (m.defaultSource != null) {
        m.sources.add(m.defaultSource);
        m.defaultSource.recompute();
    }
    // FIXME remove this ugly hack
    if (m.mappingBean instanceof MappingType) {
        for (VariableBindingDefinitionType sourceDefinition : m.mappingBean.getSource()) {
            Source<?, ?> source = parseSource(sourceDefinition, result);
            source.recompute();
            // Override existing sources (e.g. default source)
            m.sources.removeIf(existing -> existing.getName().equals(source.getName()));
            m.sources.add(source);
        }
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) AbstractMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractMappingType) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType)

Aggregations

VariableBindingDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)3 QName (javax.xml.namespace.QName)3 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)2 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)2 ItemPathDto (com.evolveum.midpoint.gui.api.component.path.ItemPathDto)1 ItemPathPanel (com.evolveum.midpoint.gui.api.component.path.ItemPathPanel)1 Item (com.evolveum.midpoint.prism.Item)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)1 VariableItemPathSegment (com.evolveum.midpoint.prism.path.VariableItemPathSegment)1 ItemDeltaItem (com.evolveum.midpoint.prism.util.ItemDeltaItem)1 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1 Source (com.evolveum.midpoint.repo.common.expression.Source)1 ValueSetDefinition (com.evolveum.midpoint.repo.common.expression.ValueSetDefinition)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1