use of org.jbpm.process.test.NodeCreator in project jbpm by kiegroup.
the class CompensationTest method createBoundaryEventCompensationHandler.
private void createBoundaryEventCompensationHandler(org.jbpm.workflow.core.NodeContainer nodeContainer, Node attachedToNode, final List<String> eventList, final String id) throws Exception {
NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(nodeContainer, BoundaryEventNode.class);
BoundaryEventNode boundaryNode = boundaryNodeCreator.createNode("boundary" + id);
String attachedTo = (String) attachedToNode.getMetaData().get("UniqueId");
boundaryNode.setMetaData("AttachedTo", attachedTo);
boundaryNode.setAttachedToNodeId(attachedTo);
EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
eventFilter.setType("Compensation");
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
boundaryNode.setEventFilters(eventFilters);
eventFilters.add(eventFilter);
addCompensationScope(boundaryNode, nodeContainer, attachedTo);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(nodeContainer, ActionNode.class);
ActionNode actionNode = actionNodeCreator.createNode("handlerAction" + id);
actionNode.setMetaData("isForCompensation", true);
actionNode.setName("Execute");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
eventList.add("action" + id);
}
});
actionNode.setAction(action);
connect(boundaryNode, actionNode);
}
use of org.jbpm.process.test.NodeCreator in project jbpm by kiegroup.
the class CompensationTest method createCompensationEventSubProcessProcess.
private RuleFlowProcess createCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
process.setId(processId);
process.setName("CESP Process");
process.setMetaData("Compensation", true);
NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
// outer process
StartNode startNode = startNodeCreator.createNode("start0");
WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
workItemNode.getWork().setName(workItemNames[0]);
connect(startNode, workItemNode);
CompositeNode compositeNode = compNodeCreator.createNode("sub0");
connect(workItemNode, compositeNode);
workItemNode = workItemNodeCreator.createNode("work0-post");
workItemNode.getWork().setName(workItemNames[2]);
connect(compositeNode, workItemNode);
EndNode endNode = endNodeCreator.createNode("end0");
connect(workItemNode, endNode);
// 1rst level nested subprocess
startNodeCreator.setNodeContainer(compositeNode);
workItemNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
startNode = startNodeCreator.createNode("start1");
workItemNode = workItemNodeCreator.createNode("work1");
workItemNode.getWork().setName(workItemNames[1]);
connect(startNode, workItemNode);
endNode = endNodeCreator.createNode("end1");
connect(workItemNode, endNode);
// 2nd level nested event subprocess in 1rst level subprocess
NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
EventSubProcessNode espNode = espNodeCreator.createNode("eventSub1");
EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
eventFilter.setType("Compensation");
espNode.addEvent(eventFilter);
addCompensationScope(espNode, process, (String) compositeNode.getMetaData("UniqueId"));
startNodeCreator.setNodeContainer(espNode);
endNodeCreator.setNodeContainer(espNode);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
startNode = startNodeCreator.createNode("start1*");
ActionNode actionNode = actionNodeCreator.createNode("action1*");
actionNode.setName("Execute");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
eventList.add("Executed action");
}
});
actionNode.setAction(action);
connect(startNode, actionNode);
endNode = endNodeCreator.createNode("end1*");
connect(actionNode, endNode);
return process;
}
use of org.jbpm.process.test.NodeCreator in project jbpm by kiegroup.
the class CompensationTest method createCompensationBoundaryEventProcess.
private RuleFlowProcess createCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
process.setId(processId);
process.setName("CESP Process");
process.setMetaData("Compensation", true);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("java.lang.String");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(process, BoundaryEventNode.class);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(process, ActionNode.class);
// Create process
StartNode startNode = startNodeCreator.createNode("start");
Node lastNode = startNode;
WorkItemNode[] workItemNodes = new WorkItemNode[3];
for (int i = 0; i < 3; ++i) {
workItemNodes[i] = workItemNodeCreator.createNode("work" + (i + 1));
workItemNodes[i].getWork().setName(workItemNames[i]);
connect(lastNode, workItemNodes[i]);
lastNode = workItemNodes[i];
}
EndNode endNode = endNodeCreator.createNode("end");
connect(workItemNodes[2], endNode);
// Compensation (boundary event) handlers
for (int i = 0; i < 3; ++i) {
createBoundaryEventCompensationHandler(process, workItemNodes[i], eventList, "" + i + 1);
}
return process;
}
use of org.jbpm.process.test.NodeCreator in project jbpm by kiegroup.
the class CompensationTest method createNestedCompensationEventSubProcessProcess.
private RuleFlowProcess createNestedCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
process.setId(processId);
process.setName("CESP Process");
process.setMetaData("Compensation", true);
NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
// outer process
CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
{
StartNode startNode = startNodeCreator.createNode("start0");
WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
workItemNode.getWork().setName(workItemNames[0]);
connect(startNode, workItemNode);
connect(workItemNode, compositeNode);
EndNode endNode = endNodeCreator.createNode("end0");
connect(compositeNode, endNode);
}
// 1rst level nested subprocess (contains compensation visibility scope)
CompositeContextNode compensationScopeContainerNode = compositeNode;
{
startNodeCreator.setNodeContainer(compositeNode);
workItemNodeCreator.setNodeContainer(compositeNode);
compNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
StartNode startNode = startNodeCreator.createNode("start1");
CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
connect(startNode, subCompNode);
WorkItemNode workItemNode = workItemNodeCreator.createNode("work1-post");
workItemNode.getWork().setName(workItemNames[2]);
connect(subCompNode, workItemNode);
EndNode endNode = endNodeCreator.createNode("end1");
connect(workItemNode, endNode);
compositeNode = subCompNode;
}
// 2nd level nested subprocess
{
startNodeCreator.setNodeContainer(compositeNode);
workItemNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
StartNode startNode = startNodeCreator.createNode("start2");
WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
workItemNode.getWork().setName(workItemNames[1]);
connect(startNode, workItemNode);
EndNode endNode = endNodeCreator.createNode("end2");
connect(workItemNode, endNode);
}
// 3nd level nested event subprocess in 2nd level subprocess
{
NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
startNodeCreator.setNodeContainer(espNode);
endNodeCreator.setNodeContainer(espNode);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
eventFilter.setType("Compensation");
espNode.addEvent(eventFilter);
addCompensationScope(espNode, compensationScopeContainerNode, (String) compositeNode.getMetaData("UniqueId"));
StartNode startNode = startNodeCreator.createNode("start3*");
ActionNode actionNode = actionNodeCreator.createNode("action3*");
actionNode.setName("Execute");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
eventList.add("Executed action");
}
});
actionNode.setAction(action);
connect(startNode, actionNode);
EndNode endNode = endNodeCreator.createNode("end3*");
connect(actionNode, endNode);
}
return process;
}
use of org.jbpm.process.test.NodeCreator in project jbpm by kiegroup.
the class CompensationTest method createNestedCompensationBoundaryEventProcess.
private RuleFlowProcess createNestedCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
process.setId(processId);
process.setName("CESP Process");
process.setMetaData("Compensation", true);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("java.lang.String");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
// process level
CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
{
StartNode startNode = startNodeCreator.createNode("start0");
connect(startNode, compositeNode);
EndNode endNode = endNodeCreator.createNode("end0");
connect(compositeNode, endNode);
}
// 1rst level nested subprocess (contains compensation visibility scope)
{
startNodeCreator.setNodeContainer(compositeNode);
compNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
StartNode startNode = startNodeCreator.createNode("start1");
CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
connect(startNode, subCompNode);
EndNode endNode = endNodeCreator.createNode("end1");
connect(subCompNode, endNode);
compositeNode = subCompNode;
}
// 2nd level nested subprocess (contains compensation visibility scope)
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
{
startNodeCreator.setNodeContainer(compositeNode);
compNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
StartNode startNode = startNodeCreator.createNode("start2");
CompositeContextNode subCompNode = compNodeCreator.createNode("sub2");
connect(startNode, subCompNode);
WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
workItemNode.getWork().setName(workItemNames[2]);
connect(subCompNode, workItemNode);
EndNode endNode = endNodeCreator.createNode("end2");
connect(workItemNode, endNode);
createBoundaryEventCompensationHandler(compositeNode, workItemNode, eventList, "2");
compositeNode = subCompNode;
}
// Fill 3rd level with process with compensation
{
startNodeCreator.setNodeContainer(compositeNode);
workItemNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
StartNode startNode = startNodeCreator.createNode("start");
Node lastNode = startNode;
WorkItemNode[] workItemNodes = new WorkItemNode[3];
for (int i = 0; i < 2; ++i) {
workItemNodes[i] = workItemNodeCreator.createNode("work-comp-" + (i + 1));
workItemNodes[i].getWork().setName(workItemNames[i]);
connect(lastNode, workItemNodes[i]);
lastNode = workItemNodes[i];
}
EndNode endNode = endNodeCreator.createNode("end");
connect(workItemNodes[1], endNode);
// Compensation (boundary event) handlers
for (int i = 0; i < 2; ++i) {
createBoundaryEventCompensationHandler(compositeNode, workItemNodes[i], eventList, "" + i + 1);
}
}
return process;
}
Aggregations