Search in sources :

Example 26 with VariableScopeInstance

use of org.jbpm.process.instance.context.variable.VariableScopeInstance in project jbpm by kiegroup.

the class StateBasedNodeInstance method resolveVariable.

protected String resolveVariable(String s) {
    if (s == null) {
        return null;
    }
    // cannot parse delay, trying to interpret it
    Map<String, String> replacements = new HashMap<String, String>();
    Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s);
    while (matcher.find()) {
        String paramName = matcher.group(1);
        if (replacements.get(paramName) == null) {
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
            if (variableScopeInstance != null) {
                Object variableValue = variableScopeInstance.getVariable(paramName);
                String variableValueString = variableValue == null ? "" : variableValue.toString();
                replacements.put(paramName, variableValueString);
            } else {
                try {
                    Object variableValue = MVELSafeHelper.getEvaluator().eval(paramName, new NodeInstanceResolverFactory(this));
                    String variableValueString = variableValue == null ? "" : variableValue.toString();
                    replacements.put(paramName, variableValueString);
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", paramName);
                    logger.error("when trying to replace variable in processId for sub process {}", getNodeName());
                    logger.error("Continuing without setting process id.");
                }
            }
        }
    }
    for (Map.Entry<String, String> replacement : replacements.entrySet()) {
        s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue());
    }
    return s;
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) NodeInstanceResolverFactory(org.jbpm.workflow.instance.impl.NodeInstanceResolverFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with VariableScopeInstance

use of org.jbpm.process.instance.context.variable.VariableScopeInstance in project jbpm by kiegroup.

the class EventNodeInstance method signalEvent.

public void signalEvent(String type, Object event) {
    String variableName = getEventNode().getVariableName();
    if (variableName != null) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
        if (variableScopeInstance == null) {
            throw new IllegalArgumentException("Could not find variable for event node: " + variableName);
        }
        EventTransformer transformer = getEventNode().getEventTransformer();
        if (transformer != null) {
            event = transformer.transformEvent(event);
        }
        variableScopeInstance.setVariable(variableName, event);
    }
    triggerCompleted();
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) EventTransformer(org.jbpm.process.core.event.EventTransformer)

Example 28 with VariableScopeInstance

use of org.jbpm.process.instance.context.variable.VariableScopeInstance in project jbpm by kiegroup.

the class FaultNodeInstance method getFaultData.

protected Object getFaultData() {
    Object value = null;
    String faultVariable = getFaultNode().getFaultVariable();
    if (faultVariable != null) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, faultVariable);
        if (variableScopeInstance != null) {
            value = variableScopeInstance.getVariable(faultVariable);
        } else {
            logger.error("Could not find variable scope for variable {}", faultVariable);
            logger.error("when trying to execute fault node {}", getFaultNode().getName());
            logger.error("Continuing without setting value.");
        }
    }
    return value;
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance)

Example 29 with VariableScopeInstance

use of org.jbpm.process.instance.context.variable.VariableScopeInstance in project jbpm by kiegroup.

the class WorkflowRuntimeException method initialize.

private void initialize(NodeInstance nodeInstance, ProcessInstance processInstance) {
    this.processInstanceId = processInstance.getId();
    this.processId = processInstance.getProcessId();
    this.setDeploymentId(((ProcessInstanceImpl) processInstance).getDeploymentId());
    if (nodeInstance != null) {
        this.nodeInstanceId = nodeInstance.getId();
        this.nodeId = nodeInstance.getNodeId();
        if (((ProcessInstanceImpl) processInstance).getKnowledgeRuntime() != null) {
            this.nodeName = nodeInstance.getNodeName();
        }
    }
    VariableScopeInstance variableScope = (VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
    // set input parameters
    if (variableScope != null) {
        this.variables = variableScope.getVariables();
    } else {
        this.variables = new HashMap<String, Object>(0);
    }
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance)

Example 30 with VariableScopeInstance

use of org.jbpm.process.instance.context.variable.VariableScopeInstance in project jbpm by kiegroup.

the class NodeInstanceImpl method setVariable.

public void setVariable(String variableName, Object value) {
    VariableScopeInstance variableScope = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
    if (variableScope == null) {
        variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScope.getVariableScope().findVariable(variableName) == null) {
            variableScope = null;
        }
    }
    if (variableScope == null) {
        logger.error("Could not find variable {}", variableName);
        logger.error("Using process-level scope");
        variableScope = (VariableScopeInstance) ((ProcessInstance) getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
    }
    variableScope.setVariable(variableName, value);
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Aggregations

VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)38 HashMap (java.util.HashMap)17 Map (java.util.Map)12 NodeInstanceResolverFactory (org.jbpm.workflow.instance.impl.NodeInstanceResolverFactory)9 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)8 NodeInstance (org.kie.api.runtime.process.NodeInstance)8 ArrayList (java.util.ArrayList)6 Matcher (java.util.regex.Matcher)6 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)6 DataAssociation (org.jbpm.workflow.core.node.DataAssociation)6 Transformation (org.jbpm.workflow.core.node.Transformation)6 DataTransformer (org.kie.api.runtime.process.DataTransformer)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 ContextInstance (org.jbpm.process.instance.ContextInstance)5 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)5 Process (org.kie.api.definition.process.Process)5 MarshallerReaderContext (org.drools.core.marshalling.impl.MarshallerReaderContext)4 MarshallerWriteContext (org.drools.core.marshalling.impl.MarshallerWriteContext)4 Context (org.jbpm.process.core.Context)4 SwimlaneContext (org.jbpm.process.core.context.swimlane.SwimlaneContext)4