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;
}
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();
}
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;
}
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);
}
}
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);
}
Aggregations