.getContextInstance(VariableScope.VARIABLE_SCOPE);
public void execute(ProcessContext context) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); engine.put("kcontext", context); // insert globals into context Globals globals = context.getKieRuntime().getGlobals(); if (globals != null && globals.getGlobalKeys() != null) { for (String gKey : globals.getGlobalKeys()) { engine.put(gKey, globals.get(gKey)); } } if (context.getProcessInstance() != null && context.getProcessInstance().getProcess() != null) { // insert process variables VariableScopeInstance variableScope = (VariableScopeInstance) ((WorkflowProcessInstance)context.getProcessInstance()) .getContextInstance(VariableScope.VARIABLE_SCOPE); Map<String, Object> variables = variableScope.getVariables(); if (variables != null ) { for (Entry<String, Object> variable : variables.entrySet()) { engine.put(variable.getKey(), variable.getValue()); } } } engine.eval(expr); }
(VariableScopeInstance) ((WorkflowProcessInstance)event.getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
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); }
protected void mapDynamicOutputData(Map<String, Object> results) { if (results != null && !results.isEmpty()) { VariableScope variableScope = (VariableScope) ((ContextContainer) getProcessInstance().getProcess()).getDefaultContext( VariableScope.VARIABLE_SCOPE ); VariableScopeInstance variableScopeInstance = (VariableScopeInstance)getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE); for (Entry<String, Object> result : results.entrySet()) { String variableName = result.getKey(); Variable variable = variableScope.findVariable(variableName); if (variable == null) { // check if there is any match for case file data variableName = VariableScope.CASE_FILE_PREFIX + variableName; // check only those that are defined and avoid dynamically created case file variables List<String> definedVariables = Arrays.asList(variableScope.getVariableNames()); if (definedVariables.contains(variableName)) { variable = variableScope.findVariable(variableName); } } if (variable != null) { variableScopeInstance.getVariableScope().validateVariable(getProcessInstance().getProcessName(), variableName, result.getValue()); variableScopeInstance.setVariable(variableName, result.getValue()); } } } } }
.getContextInstance(VariableScope.VARIABLE_SCOPE);
.getContextInstance(VariableScope.VARIABLE_SCOPE);
public void execute(ProcessContext context) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); engine.put("kcontext", context); // insert globals into context Globals globals = context.getKieRuntime().getGlobals(); if (globals != null && globals.getGlobalKeys() != null) { for (String gKey : globals.getGlobalKeys()) { engine.put(gKey, globals.get(gKey)); } } if (context.getProcessInstance() != null && context.getProcessInstance().getProcess() != null) { // insert process variables VariableScopeInstance variableScope = (VariableScopeInstance) ((WorkflowProcessInstance)context.getProcessInstance()) .getContextInstance(VariableScope.VARIABLE_SCOPE); Map<String, Object> variables = variableScope.getVariables(); if (variables != null ) { for (Entry<String, Object> variable : variables.entrySet()) { engine.put(variable.getKey(), variable.getValue()); } } } engine.eval(expr); }
(VariableScopeInstance) ((WorkflowProcessInstance)event.getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
protected void mapDynamicOutputData(Map<String, Object> results) { if (results != null && !results.isEmpty()) { VariableScope variableScope = (VariableScope) ((ContextContainer) getProcessInstance().getProcess()).getDefaultContext( VariableScope.VARIABLE_SCOPE ); VariableScopeInstance variableScopeInstance = (VariableScopeInstance)getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE); for (Entry<String, Object> result : results.entrySet()) { String variableName = result.getKey(); Variable variable = variableScope.findVariable(variableName); if (variable == null) { // check if there is any match for case file data variableName = VariableScope.CASE_FILE_PREFIX + variableName; // check only those that are defined and avoid dynamically created case file variables List<String> definedVariables = Arrays.asList(variableScope.getVariableNames()); if (definedVariables.contains(variableName)) { variable = variableScope.findVariable(variableName); } } if (variable != null) { variableScopeInstance.getVariableScope().validateVariable(getProcessInstance().getProcessName(), variableName, result.getValue()); variableScopeInstance.setVariable(variableName, result.getValue()); } } } } }
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); }
.getContextInstance(VariableScope.VARIABLE_SCOPE);