Search in sources :

Example 11 with VariableBindingDefinitionType

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

the class MappingParser method parseSource.

private <IV extends PrismValue, ID extends ItemDefinition<?>> Source<IV, ID> parseSource(VariableBindingDefinitionType sourceDefinition, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    ItemPath path = getSourcePath(sourceDefinition);
    @NotNull QName sourceQName = sourceDefinition.getName() != null ? sourceDefinition.getName() : ItemPath.toName(path.last());
    String variableName = sourceQName.getLocalPart();
    TypedValue<?> typedSourceObject = ExpressionUtil.resolvePathGetTypedValue(path, m.variables, true, m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext, "source definition in " + m.getMappingContextDescription(), m.getTask(), result);
    Object sourceObject = typedSourceObject != null ? typedSourceObject.getValue() : null;
    Item<IV, ID> itemOld = null;
    ItemDelta<IV, ID> delta = null;
    Item<IV, ID> itemNew = null;
    ItemPath resolvePath = path;
    ItemPath residualPath = null;
    Collection<? extends ItemDelta<?, ?>> subItemDeltas = null;
    if (sourceObject != null) {
        if (sourceObject instanceof ItemDeltaItem<?, ?>) {
            // noinspection unchecked
            itemOld = ((ItemDeltaItem<IV, ID>) sourceObject).getItemOld();
            // noinspection unchecked
            delta = ((ItemDeltaItem<IV, ID>) sourceObject).getDelta();
            // noinspection unchecked
            itemNew = ((ItemDeltaItem<IV, ID>) sourceObject).getItemNew();
            // noinspection unchecked
            residualPath = ((ItemDeltaItem<IV, ID>) sourceObject).getResidualPath();
            // noinspection unchecked
            resolvePath = ((ItemDeltaItem<IV, ID>) sourceObject).getResolvePath();
            // noinspection unchecked
            subItemDeltas = ((ItemDeltaItem<IV, ID>) sourceObject).getSubItemDeltas();
        } else if (sourceObject instanceof Item<?, ?>) {
            // noinspection unchecked
            itemOld = (Item<IV, ID>) sourceObject;
            // noinspection unchecked
            itemNew = (Item<IV, ID>) sourceObject;
        } else {
            throw new IllegalStateException("Unknown resolve result " + sourceObject);
        }
    }
    ID sourceItemDefinition = typedSourceObject != null ? typedSourceObject.getDefinition() : null;
    // apply domain
    ValueSetDefinitionType domainSetType = sourceDefinition.getSet();
    if (domainSetType != null) {
        ValueSetDefinition<IV, ID> setDef = new ValueSetDefinition<>(domainSetType, sourceItemDefinition, m.valueMetadataDefinition, m.expressionProfile, variableName, null, "domain of " + variableName, "domain of " + variableName + " in " + m.getMappingContextDescription(), m.getTask(), result);
        setDef.init(m.beans.expressionFactory);
        setDef.setAdditionalVariables(m.variables);
        try {
            if (itemOld != null) {
                // noinspection unchecked
                itemOld = itemOld.clone();
                itemOld.filterValues(setDef::containsTunnel);
                itemOld.filterYields(setDef::containsYieldTunnel);
            }
            if (itemNew != null) {
                // noinspection unchecked
                itemNew = itemNew.clone();
                itemNew.filterValues(setDef::containsTunnel);
                itemNew.filterYields(setDef::containsYieldTunnel);
            }
            if (delta != null) {
                delta = delta.clone();
                delta.filterValues(setDef::containsTunnel);
                delta.filterYields(setDef::containsYieldTunnel);
            }
        } catch (TunnelException te) {
            unwrapTunnelException(te);
        }
    }
    Source<IV, ID> source = new Source<>(itemOld, delta, itemNew, sourceQName, sourceItemDefinition);
    source.setResidualPath(residualPath);
    source.setResolvePath(resolvePath);
    source.setSubItemDeltas(subItemDeltas);
    return source;
}
Also used : QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Source(com.evolveum.midpoint.repo.common.expression.Source) Item(com.evolveum.midpoint.prism.Item) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ValueSetDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValueSetDefinitionType) ValueSetDefinition(com.evolveum.midpoint.repo.common.expression.ValueSetDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with VariableBindingDefinitionType

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

the class TimeConstraintsEvaluation method parseTime.

private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeBean, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (timeBean == null) {
        return null;
    }
    XMLGregorianCalendar referenceTime;
    ExpressionType expressionBean = timeBean.getExpression();
    VariableBindingDefinitionType referenceTimeBean = timeBean.getReferenceTime();
    if (referenceTimeBean == null) {
        if (expressionBean == null) {
            throw new SchemaException("No reference time specified, there is also no default and no expression; in time specification in " + m.getMappingContextDescription());
        } else {
            referenceTime = null;
        }
    } else {
        referenceTime = parseTimeSource(referenceTimeBean, result);
    }
    LOGGER.trace("reference time = {}", referenceTime);
    XMLGregorianCalendar time;
    if (expressionBean == null) {
        if (referenceTime == null) {
            return null;
        } else {
            time = (XMLGregorianCalendar) referenceTime.clone();
        }
    } else {
        MutablePrismPropertyDefinition<XMLGregorianCalendar> timeDefinition = m.beans.prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, PrimitiveType.XSD_DATETIME);
        timeDefinition.setMaxOccurs(1);
        VariablesMap timeVariables = new VariablesMap();
        timeVariables.addVariableDefinitions(m.variables);
        timeVariables.addVariableDefinition(ExpressionConstants.VAR_REFERENCE_TIME, referenceTime, timeDefinition);
        PrismPropertyValue<XMLGregorianCalendar> timePropVal = ExpressionUtil.evaluateExpression(m.sources, timeVariables, timeDefinition, expressionBean, m.expressionProfile, m.beans.expressionFactory, "time expression in " + m.getMappingContextDescription(), m.getTask(), result);
        if (timePropVal == null) {
            return null;
        }
        time = timePropVal.getValue();
        LOGGER.trace("Expression evaluated. Time = {}", time);
    }
    Duration offset = timeBean.getOffset();
    if (offset != null) {
        time.add(offset);
        LOGGER.trace("Offset {} applied; time = {}", offset, time);
    }
    return time;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) Duration(javax.xml.datatype.Duration) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

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