Search in sources :

Example 1 with VariableScopeResolverFactory

use of org.jbpm.workflow.instance.impl.VariableScopeResolverFactory in project jbpm by kiegroup.

the class SubProcessNodeInstance method handleOutMappings.

private void handleOutMappings(ProcessInstance processInstance) {
    VariableScopeInstance subProcessVariableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
    SubProcessNode subProcessNode = getSubProcessNode();
    if (subProcessNode != null) {
        for (Iterator<org.jbpm.workflow.core.node.DataAssociation> iterator = subProcessNode.getOutAssociations().iterator(); iterator.hasNext(); ) {
            org.jbpm.workflow.core.node.DataAssociation mapping = iterator.next();
            if (mapping.getTransformation() != null) {
                Transformation transformation = mapping.getTransformation();
                DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
                if (transformer != null) {
                    Object parameterValue = transformer.transform(transformation.getCompiledExpression(), subProcessVariableScopeInstance.getVariables());
                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getTarget());
                    if (variableScopeInstance != null && parameterValue != null) {
                        variableScopeInstance.setVariable(mapping.getTarget(), parameterValue);
                    } else {
                        logger.warn("Could not find variable scope for variable {}", mapping.getTarget());
                        logger.warn("Continuing without setting variable.");
                    }
                }
            } else {
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getTarget());
                if (variableScopeInstance != null) {
                    Object value = subProcessVariableScopeInstance.getVariable(mapping.getSources().get(0));
                    if (value == null) {
                        try {
                            value = MVELSafeHelper.getEvaluator().eval(mapping.getSources().get(0), new VariableScopeResolverFactory(subProcessVariableScopeInstance));
                        } catch (Throwable t) {
                        // do nothing
                        }
                    }
                    variableScopeInstance.setVariable(mapping.getTarget(), value);
                } else {
                    logger.error("Could not find variable scope for variable {}", mapping.getTarget());
                    logger.error("when trying to complete SubProcess node {}", getSubProcessNode().getName());
                    logger.error("Continuing without setting variable.");
                }
            }
        }
    } else {
        // handle dynamic sub processes without data output mapping
        mapDynamicOutputData(subProcessVariableScopeInstance.getVariables());
    }
}
Also used : Transformation(org.jbpm.workflow.core.node.Transformation) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) VariableScopeResolverFactory(org.jbpm.workflow.instance.impl.VariableScopeResolverFactory) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) DataTransformer(org.kie.api.runtime.process.DataTransformer) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) DataAssociation(org.jbpm.workflow.core.node.DataAssociation)

Aggregations

VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)1 DataAssociation (org.jbpm.workflow.core.node.DataAssociation)1 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)1 Transformation (org.jbpm.workflow.core.node.Transformation)1 VariableScopeResolverFactory (org.jbpm.workflow.instance.impl.VariableScopeResolverFactory)1 DataTransformer (org.kie.api.runtime.process.DataTransformer)1