Search in sources :

Example 1 with ExpressionVariableDefinitionType

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

the class Expression method processInnerVariables.

private ExpressionVariables processInnerVariables(ExpressionVariables variables, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    if (expressionType == null) {
        // shortcut
        return variables;
    }
    ExpressionVariables newVariables = new ExpressionVariables();
    // We need to add actor variable before we switch user identity (runAs)
    ExpressionUtil.addActorVariable(newVariables, securityEnforcer);
    for (Entry<QName, Object> entry : variables.entrySet()) {
        newVariables.addVariableDefinition(entry.getKey(), entry.getValue());
    }
    for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
        QName varName = variableDefType.getName();
        if (varName == null) {
            throw new SchemaException("No variable name in expression in " + contextDescription);
        }
        if (variableDefType.getObjectRef() != null) {
            ObjectReferenceType ref = variableDefType.getObjectRef();
            ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
            ObjectType varObject = objectResolver.resolve(ref, ObjectType.class, null, "variable " + varName + " in " + contextDescription, task, result);
            newVariables.addVariableDefinition(varName, varObject);
        } else if (variableDefType.getValue() != null) {
            // Only string is supported now
            Object valueObject = variableDefType.getValue();
            if (valueObject instanceof String) {
                newVariables.addVariableDefinition(varName, valueObject);
            } else if (valueObject instanceof Element) {
                newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent());
            } else if (valueObject instanceof RawType) {
                newVariables.addVariableDefinition(varName, ((RawType) valueObject).getParsedValue(null, varName));
            } else {
                throw new SchemaException("Unexpected type " + valueObject.getClass() + " in variable definition " + varName + " in " + contextDescription);
            }
        } else if (variableDefType.getPath() != null) {
            ItemPath itemPath = variableDefType.getPath().getItemPath();
            Object resolvedValue = ExpressionUtil.resolvePath(itemPath, variables, null, objectResolver, contextDescription, task, result);
            newVariables.addVariableDefinition(varName, resolvedValue);
        } else {
            throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
        }
    }
    return newVariables;
}
Also used : ExpressionVariableDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionVariableDefinitionType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ExpressionVariableDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionVariableDefinitionType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 Element (org.w3c.dom.Element)1