use of org.jbpm.workflow.core.node.Join in project jbpm by kiegroup.
the class XMLPersistenceTest method testPersistenceOfEmptyNodes.
@Test
public void testPersistenceOfEmptyNodes() throws Exception {
RuleFlowProcess process = new RuleFlowProcess() {
private static final long serialVersionUID = 510l;
int id = 0;
public void addNode(org.kie.api.definition.process.Node node) {
((Node) node).setId(++id);
super.addNode(node);
}
};
process.addNode(new StartNode());
process.addNode(new EndNode());
process.addNode(new ActionNode());
process.addNode(new Split());
process.addNode(new Join());
process.addNode(new MilestoneNode());
process.addNode(new RuleSetNode());
process.addNode(new SubProcessNode());
process.addNode(new WorkItemNode());
process.addNode(new TimerNode());
process.addNode(new HumanTaskNode());
process.addNode(new ForEachNode());
process.addNode(new CompositeContextNode());
process.addNode(new EventNode());
process.addNode(new FaultNode());
process.addNode(new StateNode());
process.addNode(new DynamicNode());
String xml = XmlRuleFlowProcessDumper.INSTANCE.dump(process, false);
if (xml == null) {
throw new IllegalArgumentException("Failed to persist empty nodes!");
}
SemanticModules modules = new SemanticModules();
modules.addSemanticModule(new ProcessSemanticModule());
XmlProcessReader reader = new XmlProcessReader(modules, getClass().getClassLoader());
List<Process> processes = reader.read(new StringReader(xml));
assertNotNull(processes);
process = (RuleFlowProcess) processes.get(0);
if (process == null) {
throw new IllegalArgumentException("Failed to reload process!");
}
assertEquals(17, process.getNodes().length);
String xml2 = XmlRuleFlowProcessDumper.INSTANCE.dump(process, false);
if (xml2 == null) {
throw new IllegalArgumentException("Failed to persist empty nodes!");
}
assertXMLEqual(xml, xml2);
// assertEquals(xml, xml2);
}
use of org.jbpm.workflow.core.node.Join in project jbpm by kiegroup.
the class ComplexGatewayHandler method createNode.
protected Node createNode(Attributes attrs) {
final String type = attrs.getValue("gatewayDirection");
if ("Converging".equals(type)) {
Join join = new Join();
join.setType(Join.TYPE_UNDEFINED);
return join;
} else if ("Diverging".equals(type)) {
Split split = new Split();
split.setType(Split.TYPE_UNDEFINED);
return split;
} else {
throw new IllegalArgumentException("Unknown gateway direction: " + type);
}
}
use of org.jbpm.workflow.core.node.Join in project jbpm by kiegroup.
the class ParallelGatewayHandler method createNode.
protected Node createNode(Attributes attrs) {
final String type = attrs.getValue("gatewayDirection");
if ("Converging".equals(type)) {
Join join = new Join();
join.setType(Join.TYPE_AND);
return join;
} else if ("Diverging".equals(type)) {
Split split = new Split();
split.setType(Split.TYPE_AND);
return split;
} else {
throw new IllegalArgumentException("Unknown gateway direction: " + type);
}
}
use of org.jbpm.workflow.core.node.Join in project jbpm by kiegroup.
the class ExclusiveGatewayHandler method createNode.
protected Node createNode(Attributes attrs) {
final String type = attrs.getValue("gatewayDirection");
if ("Converging".equals(type)) {
Join join = new Join();
join.setType(Join.TYPE_XOR);
return join;
} else if ("Diverging".equals(type)) {
Split split = new Split();
split.setType(Split.TYPE_XOR);
String isDefault = attrs.getValue("default");
split.setMetaData("Default", isDefault);
return split;
} else {
throw new IllegalArgumentException("Unknown gateway direction: " + type);
}
}
use of org.jbpm.workflow.core.node.Join in project jbpm by kiegroup.
the class EventTest method testEvent3.
@Test
public void testEvent3() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
eventNode.setId(3);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
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 {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(4);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode2 = new EventNode();
eventFilter = new EventTypeFilter();
eventFilter.setType("myOtherEvent");
eventNode2.addEventFilter(eventFilter);
eventNode2.setVariableName("event");
eventNode2.setId(5);
process.addNode(eventNode2);
ActionNode actionNode2 = new ActionNode();
actionNode2.setName("Print");
action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected other event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode2.setAction(action);
actionNode2.setId(6);
process.addNode(actionNode2);
new ConnectionImpl(eventNode2, Node.CONNECTION_DEFAULT_TYPE, actionNode2, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("AND Join");
join.setType(Join.TYPE_AND);
join.setId(7);
process.addNode(join);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode2, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(8);
process.addNode(endNode);
new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
Person john = new Person();
john.setName("John");
processInstance.signalEvent("myOtherEvent", john);
assertEquals(2, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test3EventOrder, procEventListener.getEventHistory());
}
Aggregations