use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class XmlWorkflowProcessDumper method visitVariables.
public static void visitVariables(List<Variable> variables, StringBuilder xmlDump) {
if (variables != null && variables.size() > 0) {
xmlDump.append(" <variables>" + EOL);
for (Variable variable : variables) {
xmlDump.append(" <variable name=\"" + variable.getName() + "\" >" + EOL);
visitDataType(variable.getType(), xmlDump);
Object value = variable.getValue();
if (value != null) {
visitValue(variable.getValue(), variable.getType(), xmlDump);
}
xmlDump.append(" </variable>" + EOL);
}
xmlDump.append(" </variables>" + EOL);
}
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class VariablePersistenceStrategyTest method getKnowledgeBaseForExtendingInterfaceVariablePersistence.
private KieBase getKnowledgeBaseForExtendingInterfaceVariablePersistence(String processId, final String variableText) {
RuleFlowProcess process = new RuleFlowProcess();
process.setId(processId);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("x");
ObjectDataType extendingSerializableDataType = new ObjectDataType();
extendingSerializableDataType.setClassName(MyVariableExtendingSerializable.class.getName());
variable.setType(extendingSerializableDataType);
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);
Work work = new WorkImpl();
work.setName("MyWork");
workItemNode.setWork(work);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
Assert.assertEquals(variableText, ((MyVariableExtendingSerializable) context.getVariable("x")).getText());
;
}
});
actionNode.setAction(action);
actionNode.setId(3);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(4);
connect(startNode, workItemNode);
connect(workItemNode, actionNode);
connect(actionNode, endNode);
process.addNode(startNode);
process.addNode(workItemNode);
process.addNode(actionNode);
process.addNode(endNode);
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
((KnowledgeBaseImpl) kbase).addProcess(process);
return kbase;
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class WorkItemPersistenceTest 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("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);
HumanTaskNode workItemNode = new HumanTaskNode();
workItemNode.setName("workItemNode");
workItemNode.setId(2);
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 XmlBPMNProcessDumper method visitVariables.
public static void visitVariables(List<Variable> variables, StringBuilder xmlDump) {
if (!variables.isEmpty()) {
xmlDump.append(" <!-- process variables -->" + EOL);
for (Variable variable : variables) {
if (variable.getMetaData("DataObject") == null) {
xmlDump.append(" <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
if (variable.getType() != null) {
xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute((String) variable.getMetaData("ItemSubjectRef")) + "\"");
}
// TODO: value?
Map<String, Object> metaData = getMetaData(variable.getMetaData());
if (metaData.isEmpty()) {
xmlDump.append("/>" + EOL);
} else {
xmlDump.append(">" + EOL + " <extensionElements>" + EOL);
writeMetaData(metaData, xmlDump);
xmlDump.append(" </extensionElements>" + EOL + " </property>" + EOL);
}
}
}
for (Variable variable : variables) {
if (variable.getMetaData("DataObject") != null) {
xmlDump.append(" <dataObject id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
if (variable.getType() != null) {
xmlDump.append("itemSubjectRef=\"_" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\"");
}
// TODO: value?
Map<String, Object> metaData = getMetaData(variable.getMetaData());
if (metaData.isEmpty()) {
xmlDump.append("/>" + EOL);
} else {
xmlDump.append(">" + EOL + " <extensionElements>" + EOL);
writeMetaData(metaData, xmlDump);
xmlDump.append(" </extensionElements>" + EOL + " </property>" + EOL);
}
}
}
xmlDump.append(EOL);
}
}
use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.
the class XmlBPMNProcessDumper method visitVariableScope.
private void visitVariableScope(VariableScope variableScope, String prefix, StringBuilder xmlDump, Set<String> dumpedItemDefs) {
if (variableScope != null && !variableScope.getVariables().isEmpty()) {
int variablesAdded = 0;
for (Variable variable : variableScope.getVariables()) {
String itemDefId = (String) variable.getMetaData("ItemSubjectRef");
if (itemDefId == null) {
itemDefId = prefix + variable.getName();
}
if (itemDefId != null && !dumpedItemDefs.add(itemDefId.intern())) {
continue;
}
if (!visitedVariables.add(variable.getName())) {
continue;
}
++variablesAdded;
xmlDump.append(" <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(itemDefId) + "\" ");
if (variable.getType() != null && !"java.lang.Object".equals(variable.getType().getStringType())) {
xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getType().getStringType()) + "\" ");
}
xmlDump.append("/>" + EOL);
}
if (variablesAdded > 0) {
xmlDump.append(EOL);
}
}
}
Aggregations