use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class RuleSetNodeInstance method processOutputs.
private void processOutputs(Map<String, Object> objects) {
RuleSetNode ruleSetNode = getRuleSetNode();
if (ruleSetNode != null) {
for (Iterator<DataAssociation> iterator = ruleSetNode.getOutAssociations().iterator(); iterator.hasNext(); ) {
DataAssociation association = iterator.next();
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), objects);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, association.getTarget());
if (variableScopeInstance != null && parameterValue != null) {
variableScopeInstance.setVariable(association.getTarget(), parameterValue);
} else {
logger.warn("Could not find variable scope for variable {}", association.getTarget());
logger.warn("Continuing without setting variable.");
}
if (parameterValue != null) {
variableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, association.getTarget());
if (variableScopeInstance != null) {
Object value = objects.get(association.getSources().get(0));
if (value == null) {
try {
value = MVELSafeHelper.getEvaluator().eval(association.getSources().get(0), new MapVariableResolverFactory(objects));
} catch (Throwable t) {
// do nothing
}
}
Variable varDef = variableScopeInstance.getVariableScope().findVariable(association.getTarget());
DataType dataType = varDef.getType();
// exclude java.lang.Object as it is considered unknown type
if (!dataType.getStringType().endsWith("java.lang.Object") && value instanceof String) {
value = dataType.readValue((String) value);
}
variableScopeInstance.setVariable(association.getTarget(), value);
} else {
logger.warn("Could not find variable scope for variable {}", association.getTarget());
}
}
}
}
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class StateBasedNodeInstance method mapDynamicOutputData.
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());
}
}
}
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class WorkItemTest method getWorkItemProcess.
private RuleFlowProcess getWorkItemProcess(String processId, String workName) {
RuleFlowProcess process = new RuleFlowProcess();
process.setId(processId);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("UserName");
variable.setType(new StringDataType());
variables.add(variable);
variable = new Variable();
variable.setName("Person");
variable.setType(new ObjectDataType(Person.class.getName()));
variables.add(variable);
variable = new Variable();
variable.setName("MyObject");
variable.setType(new ObjectDataType());
variables.add(variable);
variable = new Variable();
variable.setName("Number");
variable.setType(new IntegerDataType());
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
WorkItemNode workItemNode = new WorkItemNode();
workItemNode.setName("workItemNode");
workItemNode.setId(2);
workItemNode.addInMapping("Comment", "Person.name");
workItemNode.addInMapping("Attachment", "MyObject");
workItemNode.addOutMapping("Result", "MyObject");
workItemNode.addOutMapping("Result.length()", "Number");
Work work = new WorkImpl();
work.setName(workName);
Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("Content", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
parameterDefinitions.add(parameterDefinition);
work.setParameterDefinitions(parameterDefinitions);
work.setParameter("ActorId", "#{UserName}");
work.setParameter("Content", "#{Person.name}");
workItemNode.setWork(work);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
connect(startNode, workItemNode);
connect(workItemNode, endNode);
process.addNode(startNode);
process.addNode(workItemNode);
process.addNode(endNode);
return process;
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class ForEachNode method setVariable.
public void setVariable(String variableName, DataType type) {
this.variableName = variableName;
VariableScope variableScope = (VariableScope) getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE);
List<Variable> variables = variableScope.getVariables();
if (variables == null) {
variables = new ArrayList<Variable>();
variableScope.setVariables(variables);
}
Variable variable = new Variable();
variable.setName(variableName);
variable.setType(type);
variables.add(variable);
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class ServicesProcessDataEventListener method onBuildComplete.
@SuppressWarnings("unchecked")
@Override
public void onBuildComplete(Process process) {
// process java dialect types
Set<String> referencedTypes = (Set<String>) process.getMetaData().get("JavaDialectReferencedTypes");
if (referencedTypes != null && !referencedTypes.isEmpty()) {
processDescriptor.getReferencedClasses().addAll(referencedTypes);
}
Set<String> unqualifiedClasses = (Set<String>) process.getMetaData().get("JavaDialectUnqualifiedTypes");
if (unqualifiedClasses != null && !unqualifiedClasses.isEmpty()) {
processDescriptor.getUnqualifiedClasses().addAll(unqualifiedClasses);
}
// process java return value types
referencedTypes = (Set<String>) process.getMetaData().get("JavaReturnValueReferencedTypes");
if (referencedTypes != null && !referencedTypes.isEmpty()) {
processDescriptor.getReferencedClasses().addAll(referencedTypes);
}
unqualifiedClasses = (Set<String>) process.getMetaData().get("JavaReturnValueUnqualifiedTypes");
if (unqualifiedClasses != null && !unqualifiedClasses.isEmpty()) {
processDescriptor.getUnqualifiedClasses().addAll(unqualifiedClasses);
}
// process mvel dialect types
referencedTypes = (Set<String>) process.getMetaData().get("MVELDialectReferencedTypes");
if (referencedTypes != null && !referencedTypes.isEmpty()) {
processDescriptor.getReferencedClasses().addAll(referencedTypes);
}
// process mvel return value types
referencedTypes = (Set<String>) process.getMetaData().get("MVELReturnValueReferencedTypes");
if (referencedTypes != null && !referencedTypes.isEmpty()) {
processDescriptor.getReferencedClasses().addAll(referencedTypes);
}
// process unqualified classes
resolveUnqualifiedClasses();
// process variables
if (variables != null) {
for (Variable data : variables) {
String type = data.getType().getStringType();
String itemSubjectRef = (String) data.getMetaData("ItemSubjectRef");
if (itemSubjectRef != null && itemDefinitions != null) {
ItemDefinition itemDef = itemDefinitions.get(itemSubjectRef);
type = itemDef.getStructureRef();
}
processDescriptor.getInputs().put(data.getName(), type);
}
}
// process signals
if (signals != null) {
processDescriptor.setSignals(signals);
}
}
Aggregations