use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.
the class RuleFlowProcessValidator method validateNodes.
private void validateNodes(Node[] nodes, List<ProcessValidationError> errors, RuleFlowProcess process) {
String isForCompensation = "isForCompensation";
for (int i = 0; i < nodes.length; i++) {
final Node node = nodes[i];
if (node instanceof StartNode) {
final StartNode startNode = (StartNode) node;
if (startNode.getTo() == null) {
addErrorMessage(process, node, errors, "Start has no outgoing connection.");
}
if (startNode.getTimer() != null) {
validateTimer(startNode.getTimer(), node, process, errors);
}
} else if (node instanceof EndNode) {
final EndNode endNode = (EndNode) node;
if (endNode.getFrom() == null) {
addErrorMessage(process, node, errors, "End has no incoming connection.");
}
validateCompensationIntermediateOrEndEvent(endNode, process, errors);
} else if (node instanceof RuleSetNode) {
final RuleSetNode ruleSetNode = (RuleSetNode) node;
if (ruleSetNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "RuleSet has no incoming connection.");
}
if (ruleSetNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "RuleSet has no outgoing connection.");
}
final String language = ruleSetNode.getLanguage();
if (RuleSetNode.DRL_LANG.equals(language)) {
final String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
if (ruleFlowGroup == null || "".equals(ruleFlowGroup)) {
addErrorMessage(process, node, errors, "RuleSet (DRL) has no ruleflow-group.");
}
} else if (RuleSetNode.DMN_LANG.equals(language)) {
final String namespace = ruleSetNode.getNamespace();
if (namespace == null || "".equals(namespace)) {
addErrorMessage(process, node, errors, "RuleSet (DMN) has no namespace.");
}
final String model = ruleSetNode.getModel();
if (model == null || "".equals(model)) {
addErrorMessage(process, node, errors, "RuleSet (DMN) has no model.");
}
} else {
addErrorMessage(process, node, errors, "Unsupported rule language '" + language + "'");
}
if (ruleSetNode.getTimers() != null) {
for (Timer timer : ruleSetNode.getTimers().keySet()) {
validateTimer(timer, node, process, errors);
}
}
} else if (node instanceof Split) {
final Split split = (Split) node;
if (split.getType() == Split.TYPE_UNDEFINED) {
addErrorMessage(process, node, errors, "Split has no type.");
}
if (split.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Split has no incoming connection.");
}
if (split.getDefaultOutgoingConnections().size() < 2) {
addErrorMessage(process, node, errors, "Split does not have more than one outgoing connection: " + split.getOutgoingConnections().size() + ".");
}
if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
for (final Iterator<Connection> it = split.getDefaultOutgoingConnections().iterator(); it.hasNext(); ) {
final Connection connection = it.next();
if (split.getConstraint(connection) == null && !split.isDefault(connection) || (!split.isDefault(connection) && (split.getConstraint(connection).getConstraint() == null || split.getConstraint(connection).getConstraint().trim().length() == 0))) {
addErrorMessage(process, node, errors, "Split does not have a constraint for " + connection.toString() + ".");
}
}
}
} else if (node instanceof Join) {
final Join join = (Join) node;
if (join.getType() == Join.TYPE_UNDEFINED) {
addErrorMessage(process, node, errors, "Join has no type.");
}
if (join.getDefaultIncomingConnections().size() < 2) {
addErrorMessage(process, node, errors, "Join does not have more than one incoming connection: " + join.getIncomingConnections().size() + ".");
}
if (join.getTo() == null && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "Join has no outgoing connection.");
}
if (join.getType() == Join.TYPE_N_OF_M) {
String n = join.getN();
if (!n.startsWith("#{") || !n.endsWith("}")) {
try {
new Integer(n);
} catch (NumberFormatException e) {
addErrorMessage(process, node, errors, "Join has illegal n value: " + n);
}
}
}
} else if (node instanceof MilestoneNode) {
final MilestoneNode milestone = (MilestoneNode) node;
if (milestone.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Milestone has no incoming connection.");
}
if (milestone.getTo() == null && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "Milestone has no outgoing connection.");
}
if (milestone.getConstraint() == null) {
addErrorMessage(process, node, errors, "Milestone has no constraint.");
}
if (milestone.getTimers() != null) {
for (Timer timer : milestone.getTimers().keySet()) {
validateTimer(timer, node, process, errors);
}
}
} else if (node instanceof StateNode) {
final StateNode stateNode = (StateNode) node;
if (stateNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "State has no incoming connection");
}
} else if (node instanceof SubProcessNode) {
final SubProcessNode subProcess = (SubProcessNode) node;
if (subProcess.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "SubProcess has no incoming connection.");
}
if (subProcess.getTo() == null && !acceptsNoOutgoingConnections(node)) {
Object compensationObj = subProcess.getMetaData(isForCompensation);
if (compensationObj == null || !((Boolean) compensationObj)) {
addErrorMessage(process, node, errors, "SubProcess has no outgoing connection.");
}
}
if (subProcess.getProcessId() == null && subProcess.getProcessName() == null) {
addErrorMessage(process, node, errors, "SubProcess has no process id.");
}
if (subProcess.getTimers() != null) {
for (Timer timer : subProcess.getTimers().keySet()) {
validateTimer(timer, node, process, errors);
}
}
if (!subProcess.isIndependent() && !subProcess.isWaitForCompletion()) {
addErrorMessage(process, node, errors, "SubProcess you can only set " + "independent to 'false' only when 'Wait for completion' is set to true.");
}
} else if (node instanceof ActionNode) {
final ActionNode actionNode = (ActionNode) node;
if (actionNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Action has no incoming connection.");
}
if (actionNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
Object compensationObj = actionNode.getMetaData(isForCompensation);
if (compensationObj == null || !((Boolean) compensationObj)) {
addErrorMessage(process, node, errors, "Action has no outgoing connection.");
}
}
if (actionNode.getAction() == null) {
addErrorMessage(process, node, errors, "Action has no action.");
} else if (actionNode.getAction() instanceof DroolsConsequenceAction) {
DroolsConsequenceAction droolsAction = (DroolsConsequenceAction) actionNode.getAction();
String actionString = droolsAction.getConsequence();
if (actionString == null) {
addErrorMessage(process, node, errors, "Action has empty action.");
} else if ("mvel".equals(droolsAction.getDialect())) {
try {
ParserContext parserContext = new ParserContext();
// parserContext.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler(actionString, parserContext);
compiler.setVerifying(true);
compiler.compile();
List<ErrorDetail> mvelErrors = parserContext.getErrorList();
if (mvelErrors != null) {
for (Iterator<ErrorDetail> iterator = mvelErrors.iterator(); iterator.hasNext(); ) {
ErrorDetail error = iterator.next();
addErrorMessage(process, node, errors, "Action has invalid action: " + error.getMessage() + ".");
}
}
} catch (Throwable t) {
addErrorMessage(process, node, errors, "Action has invalid action: " + t.getMessage() + ".");
}
}
// TODO: validation for "java" and "drools" scripts!
validateCompensationIntermediateOrEndEvent(actionNode, process, errors);
}
} else if (node instanceof WorkItemNode) {
final WorkItemNode workItemNode = (WorkItemNode) node;
if (workItemNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Task has no incoming connection.");
}
if (workItemNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
Object compensationObj = workItemNode.getMetaData(isForCompensation);
if (compensationObj == null || !((Boolean) compensationObj)) {
addErrorMessage(process, node, errors, "Task has no outgoing connection.");
}
}
if (workItemNode.getWork() == null) {
addErrorMessage(process, node, errors, "Task has no work specified.");
} else {
Work work = workItemNode.getWork();
if (work.getName() == null || work.getName().trim().length() == 0) {
addErrorMessage(process, node, errors, "Task has no task type.");
}
}
if (workItemNode.getTimers() != null) {
for (Timer timer : workItemNode.getTimers().keySet()) {
validateTimer(timer, node, process, errors);
}
}
} else if (node instanceof ForEachNode) {
final ForEachNode forEachNode = (ForEachNode) node;
String variableName = forEachNode.getVariableName();
if (variableName == null || "".equals(variableName)) {
addErrorMessage(process, node, errors, "ForEach has no variable name");
}
String collectionExpression = forEachNode.getCollectionExpression();
if (collectionExpression == null || "".equals(collectionExpression)) {
addErrorMessage(process, node, errors, "ForEach has no collection expression");
}
if (forEachNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "ForEach has no incoming connection");
}
if (forEachNode.getDefaultOutgoingConnections().size() == 0 && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "ForEach has no outgoing connection");
}
// TODO: check, if no linked connections, for start and end node(s)
// if (forEachNode.getLinkedIncomingNode(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE) == null) {
// errors.add(new ProcessValidationErrorImpl(process,
// "ForEach node '%s' [%d] has no linked start node"));
// }
// if (forEachNode.getLinkedOutgoingNode(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE) == null) {
// errors.add(new ProcessValidationErrorImpl(process,
// "ForEach node '%s' [%d] has no linked end node"));
// }
validateNodes(forEachNode.getNodes(), errors, process);
} else if (node instanceof DynamicNode) {
final DynamicNode dynamicNode = (DynamicNode) node;
if (dynamicNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(dynamicNode)) {
addErrorMessage(process, node, errors, "Dynamic has no incoming connection");
}
if (dynamicNode.getDefaultOutgoingConnections().size() == 0 && !acceptsNoOutgoingConnections(dynamicNode)) {
addErrorMessage(process, node, errors, "Dynamic has no outgoing connection");
}
if ("".equals(dynamicNode.getCompletionExpression()) && !dynamicNode.isAutoComplete()) {
addErrorMessage(process, node, errors, "Dynamic has no completion condition set");
}
validateNodes(dynamicNode.getNodes(), errors, process);
} else if (node instanceof CompositeNode) {
final CompositeNode compositeNode = (CompositeNode) node;
for (Map.Entry<String, NodeAndType> inType : compositeNode.getLinkedIncomingNodes().entrySet()) {
if (compositeNode.getIncomingConnections(inType.getKey()).size() == 0 && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Composite has no incoming connection for type " + inType.getKey());
}
if (inType.getValue().getNode() == null && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "Composite has invalid linked incoming node for type " + inType.getKey());
}
}
for (Map.Entry<String, NodeAndType> outType : compositeNode.getLinkedOutgoingNodes().entrySet()) {
if (compositeNode.getOutgoingConnections(outType.getKey()).size() == 0) {
addErrorMessage(process, node, errors, "Composite has no outgoing connection for type " + outType.getKey());
}
if (outType.getValue().getNode() == null) {
addErrorMessage(process, node, errors, "Composite has invalid linked outgoing node for type " + outType.getKey());
}
}
if (compositeNode instanceof EventSubProcessNode) {
if (compositeNode.getIncomingConnections().size() > 0) {
addErrorMessage(process, node, errors, "Event subprocess is not allowed to have any incoming connections.");
}
if (compositeNode.getOutgoingConnections().size() > 0) {
addErrorMessage(process, node, errors, "Event subprocess is not allowed to have any outgoing connections.");
}
Node[] eventSubProcessNodes = compositeNode.getNodes();
int startEventCount = 0;
for (int j = 0; j < eventSubProcessNodes.length; ++j) {
if (eventSubProcessNodes[j] instanceof StartNode) {
StartNode startNode = (StartNode) eventSubProcessNodes[j];
if (++startEventCount == 2) {
addErrorMessage(process, compositeNode, errors, "Event subprocess is not allowed to have more than one start node.");
}
if (startNode.getTriggers() == null || startNode.getTriggers().isEmpty()) {
addErrorMessage(process, startNode, errors, "Start in Event SubProcess '" + compositeNode.getName() + "' [" + compositeNode.getId() + "] must contain a trigger (event definition).");
}
}
}
} else {
Boolean isForCompensationObject = (Boolean) compositeNode.getMetaData("isForCompensation");
if (compositeNode.getIncomingConnections().size() == 0 && !Boolean.TRUE.equals(isForCompensationObject)) {
addErrorMessage(process, node, errors, "Embedded subprocess does not have incoming connection.");
}
if (compositeNode.getOutgoingConnections().size() == 0 && !Boolean.TRUE.equals(isForCompensationObject)) {
addErrorMessage(process, node, errors, "Embedded subprocess does not have outgoing connection.");
}
}
if (compositeNode.getTimers() != null) {
for (Timer timer : compositeNode.getTimers().keySet()) {
validateTimer(timer, node, process, errors);
}
}
validateNodes(compositeNode.getNodes(), errors, process);
} else if (node instanceof EventNode) {
final EventNode eventNode = (EventNode) node;
if (eventNode.getEventFilters().size() == 0) {
addErrorMessage(process, node, errors, "Event should specify an event type");
}
if (eventNode.getDefaultOutgoingConnections().size() == 0) {
addErrorMessage(process, node, errors, "Event has no outgoing connection");
} else {
List<EventFilter> eventFilters = eventNode.getEventFilters();
boolean compensationHandler = false;
for (EventFilter eventFilter : eventFilters) {
if (((EventTypeFilter) eventFilter).getType().startsWith("Compensation")) {
compensationHandler = true;
break;
}
}
if (compensationHandler && eventNode instanceof BoundaryEventNode) {
Connection connection = eventNode.getDefaultOutgoingConnections().get(0);
Boolean isAssociation = (Boolean) connection.getMetaData().get("association");
if (isAssociation == null) {
isAssociation = false;
}
if (!(eventNode.getDefaultOutgoingConnections().size() == 1 && connection != null && isAssociation)) {
addErrorMessage(process, node, errors, "Compensation Boundary Event is only allowed to have 1 association to 1 compensation activity.");
}
}
}
} else if (node instanceof FaultNode) {
final FaultNode faultNode = (FaultNode) node;
if (faultNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Fault has no incoming connection.");
}
if (faultNode.getFaultName() == null) {
addErrorMessage(process, node, errors, "Fault has no fault name.");
}
} else if (node instanceof TimerNode) {
TimerNode timerNode = (TimerNode) node;
if (timerNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
addErrorMessage(process, node, errors, "Timer has no incoming connection.");
}
if (timerNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
addErrorMessage(process, node, errors, "Timer has no outgoing connection.");
}
if (timerNode.getTimer() == null) {
addErrorMessage(process, node, errors, "Timer has no timer specified.");
} else {
validateTimer(timerNode.getTimer(), node, process, errors);
}
} else if (node instanceof CatchLinkNode) {
// catchlink validation here, there also are validations in
// ProcessHandler regarding connection issues
} else if (node instanceof ThrowLinkNode) {
// throw validation here, there also are validations in
// ProcessHandler regarding connection issues
} else {
errors.add(new ProcessValidationErrorImpl(process, "Unknown node type '" + node.getClass().getName() + "'"));
}
}
}
use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.
the class ForEachTest method testForEach.
@Test
public void testForEach() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.foreach");
process.setName("ForEach Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("persons");
ListDataType listDataType = new ListDataType();
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.jbpm.process.test.Person");
listDataType.setType(personDataType);
variable.setType(listDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(2);
process.addNode(endNode);
ForEachNode forEachNode = new ForEachNode();
forEachNode.setName("ForEach");
forEachNode.setId(3);
forEachNode.setCollectionExpression("persons");
personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
process.addNode(forEachNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, forEachNode, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(forEachNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print child");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Executed action for child {}", ((Person) context.getVariable("child")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
forEachNode.addNode(actionNode);
forEachNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, actionNode.getId(), Node.CONNECTION_DEFAULT_TYPE);
forEachNode.linkOutgoingConnections(actionNode.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
forEachNode.setVariable("child", personDataType);
KieSession ksession = createKieSession(process);
Map<String, Object> parameters = new HashMap<String, Object>();
List<Person> persons = new ArrayList<Person>();
persons.add(new Person("John Doe"));
persons.add(new Person("Jane Doe"));
persons.add(new Person("Jack"));
parameters.put("persons", persons);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ksession.startProcess("org.drools.core.process.foreach", parameters);
assertEquals(3, myList.size());
verifyEventHistory(eventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.
the class XMLPersistenceTest method testPersistenceOfFullNodes.
@Test
public void testPersistenceOfFullNodes() 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.setMetaData("routerLayout", 1);
Set<String> imports = new HashSet<String>();
imports.add("import1");
imports.add("import2");
process.setImports(imports);
Map<String, String> globals = new HashMap<String, String>();
globals.put("name1", "type1");
globals.put("name2", "type2");
process.setGlobals(globals);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("variable1");
variable.setType(new StringDataType());
variable.setValue("value");
variables.add(variable);
variable = new Variable();
variable.setName("variable2");
variable.setType(new IntegerDataType());
variable.setValue(2);
variables.add(variable);
variable = new Variable();
variable.setName("variable3");
variable.setType(new ObjectDataType("org.jbpm.integrationtests.test.Person"));
Person person = new Person();
person.setName("John");
variable.setValue(person);
variables.add(variable);
variable = new Variable();
variable.setName("variable4");
ListDataType listDataType = new ListDataType();
listDataType.setType(new ObjectDataType("java.lang.Integer"));
variable.setType(listDataType);
List<Integer> list = new ArrayList<Integer>();
list.add(10);
list.add(20);
variable.setValue(list);
variables.add(variable);
process.getVariableScope().setVariables(variables);
Swimlane swimlane = new Swimlane();
swimlane.setName("actor1");
process.getSwimlaneContext().addSwimlane(swimlane);
swimlane = new Swimlane();
swimlane.setName("actor2");
process.getSwimlaneContext().addSwimlane(swimlane);
ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
exceptionHandler.setFaultVariable("faultVariable");
DroolsConsequenceAction action = new DroolsConsequenceAction("dialect", "consequence");
exceptionHandler.setAction(action);
process.getExceptionScope().setExceptionHandler("myFault", exceptionHandler);
exceptionHandler = new ActionExceptionHandler();
exceptionHandler.setFaultVariable("faultVariable2");
action = new DroolsConsequenceAction("dialect2", "consequence2");
exceptionHandler.setAction(action);
process.getExceptionScope().setExceptionHandler("myFault2", exceptionHandler);
StartNode startNode = new StartNode();
startNode.setName("start");
startNode.setMetaData("x", 1);
startNode.setMetaData("y", 2);
startNode.setMetaData("width", 3);
startNode.setMetaData("height", 4);
startNode.setMetaData("meta1", "someValue");
startNode.setMetaData("meta2", "someOtherValue");
ConstraintTrigger constraintTrigger = new ConstraintTrigger();
constraintTrigger.setConstraint("constraint");
Map<String, String> inMapping = new HashMap<String, String>();
inMapping.put("key", "value");
inMapping.put("key2", "value2");
constraintTrigger.setInMappings(inMapping);
startNode.addTrigger(constraintTrigger);
EventTrigger eventTrigger = new EventTrigger();
EventTypeFilter eventTypeFilter = new EventTypeFilter();
eventTypeFilter.setType("eventType");
eventTrigger.addEventFilter(eventTypeFilter);
inMapping = new HashMap<String, String>();
inMapping.put("key", "value");
inMapping.put("key2", "value2");
eventTrigger.setInMappings(inMapping);
startNode.addTrigger(eventTrigger);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("action");
actionNode.setMetaData("x", 1);
actionNode.setMetaData("y", 2);
actionNode.setMetaData("width", 3);
actionNode.setMetaData("height", 4);
action = new DroolsConsequenceAction("dialect", "consequence");
actionNode.setAction(action);
process.addNode(actionNode);
RuleSetNode ruleSetNode = new RuleSetNode();
ruleSetNode.setName("action");
ruleSetNode.setMetaData("x", 1);
ruleSetNode.setMetaData("y", 2);
ruleSetNode.setMetaData("width", 3);
ruleSetNode.setMetaData("height", 4);
ruleSetNode.setRuleFlowGroup("ruleFlowGroup");
Timer timer = new Timer();
timer.setDelay("100");
timer.setPeriod("100");
action = new DroolsConsequenceAction("dialect", "consequence");
ruleSetNode.addTimer(timer, action);
timer = new Timer();
timer.setDelay("200");
timer.setPeriod("200");
action = new DroolsConsequenceAction("dialect", "consequence");
ruleSetNode.addTimer(timer, action);
process.addNode(ruleSetNode);
FaultNode faultNode = new FaultNode();
faultNode.setName("action");
faultNode.setMetaData("x", 1);
faultNode.setMetaData("y", 2);
faultNode.setMetaData("width", 3);
faultNode.setMetaData("height", 4);
faultNode.setFaultName("faultName");
faultNode.setFaultVariable("faultVariable");
process.addNode(faultNode);
Split split = new Split();
split.setName("split");
split.setMetaData("x", 1);
split.setMetaData("y", 2);
split.setMetaData("width", 3);
split.setMetaData("height", 4);
split.setType(Split.TYPE_XOR);
Connection connection = new ConnectionImpl(split, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
Constraint constraint = new ConstraintImpl();
constraint.setName("constraint1 ><&&");
constraint.setPriority(1);
constraint.setDialect("dialect1");
constraint.setType("type1");
constraint.setConstraint("constraint-text1");
split.setConstraint(connection, constraint);
connection = new ConnectionImpl(split, Node.CONNECTION_DEFAULT_TYPE, ruleSetNode, Node.CONNECTION_DEFAULT_TYPE);
constraint = new ConstraintImpl();
constraint.setName("constraint2");
constraint.setPriority(2);
constraint.setDialect("dialect2");
constraint.setType("type2");
constraint.setConstraint("constraint-text2");
split.setConstraint(connection, constraint);
process.addNode(split);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, split, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
eventNode.setName("action");
eventNode.setMetaData("x", 1);
eventNode.setMetaData("y", 2);
eventNode.setMetaData("width", 3);
eventNode.setMetaData("height", 4);
eventNode.setVariableName("eventVariable");
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("eventType");
eventNode.addEventFilter(eventFilter);
process.addNode(eventNode);
Join join = new Join();
join.setName("join");
join.setMetaData("x", 1);
join.setMetaData("y", 2);
join.setMetaData("width", 3);
join.setMetaData("height", 4);
join.setType(Join.TYPE_N_OF_M);
join.setN("#{var1}");
process.addNode(join);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(ruleSetNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
MilestoneNode milestone = new MilestoneNode();
milestone.setName("milestone");
milestone.setMetaData("x", 1);
milestone.setMetaData("y", 2);
milestone.setMetaData("width", 3);
milestone.setMetaData("height", 4);
milestone.setConstraint("constraint");
timer = new Timer();
timer.setDelay("100");
timer.setPeriod("100");
action = new DroolsConsequenceAction("dialect", "consequence");
milestone.addTimer(timer, action);
timer = new Timer();
timer.setDelay("200");
timer.setPeriod("200");
action = new DroolsConsequenceAction("dialect", "consequence");
milestone.addTimer(timer, action);
List<DroolsAction> actions = new ArrayList<DroolsAction>();
DroolsAction action1 = new DroolsConsequenceAction("java", "System.out.println(\"action1\");");
actions.add(action1);
DroolsAction action2 = new DroolsConsequenceAction("java", "System.out.println(\"action2\");");
actions.add(action2);
milestone.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
milestone.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
process.addNode(milestone);
connection = new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, milestone, Node.CONNECTION_DEFAULT_TYPE);
connection.setMetaData("bendpoints", "[10,10;20,20]");
SubProcessNode subProcess = new SubProcessNode();
subProcess.setName("subProcess");
subProcess.setMetaData("x", 1);
subProcess.setMetaData("y", 2);
subProcess.setMetaData("width", 3);
subProcess.setMetaData("height", 4);
subProcess.setProcessId("processId");
subProcess.setWaitForCompletion(false);
subProcess.setIndependent(false);
subProcess.addInMapping("subvar1", "var1");
subProcess.addOutMapping("subvar2", "var2");
timer = new Timer();
timer.setDelay("100");
timer.setPeriod("100");
action = new DroolsConsequenceAction("dialect", "consequence");
subProcess.addTimer(timer, action);
timer = new Timer();
timer.setDelay("200");
timer.setPeriod("200");
action = new DroolsConsequenceAction("dialect", "consequence");
subProcess.addTimer(timer, action);
subProcess.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
subProcess.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
process.addNode(subProcess);
connection = new ConnectionImpl(milestone, Node.CONNECTION_DEFAULT_TYPE, subProcess, Node.CONNECTION_DEFAULT_TYPE);
connection.setMetaData("bendpoints", "[10,10]");
WorkItemNode workItemNode = new WorkItemNode();
workItemNode.setName("WorkItem");
Work work = new WorkImpl();
work.setName("workname");
Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("param1", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("param2", new IntegerDataType());
parameterDefinitions.add(parameterDefinition);
work.setParameterDefinitions(parameterDefinitions);
work.setParameter("param1", "value1");
work.setParameter("param2", 1);
workItemNode.setWork(work);
workItemNode.setWaitForCompletion(false);
workItemNode.addInMapping("param1", "var1");
workItemNode.addOutMapping("param2", "var2");
timer = new Timer();
timer.setDelay("100");
timer.setPeriod("100");
action = new DroolsConsequenceAction("dialect", "consequence");
workItemNode.addTimer(timer, action);
timer = new Timer();
timer.setDelay("200");
timer.setPeriod("200");
action = new DroolsConsequenceAction("dialect", "consequence");
workItemNode.addTimer(timer, action);
workItemNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
workItemNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
process.addNode(workItemNode);
connection = new ConnectionImpl(subProcess, Node.CONNECTION_DEFAULT_TYPE, workItemNode, Node.CONNECTION_DEFAULT_TYPE);
connection.setMetaData("bendpoints", "[]");
HumanTaskNode humanTaskNode = new HumanTaskNode();
humanTaskNode.setName("Human Task");
work = humanTaskNode.getWork();
parameterDefinitions = new HashSet<ParameterDefinition>();
parameterDefinition = new ParameterDefinitionImpl("TaskName", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("Priority", new StringDataType());
parameterDefinitions.add(parameterDefinition);
parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
parameterDefinitions.add(parameterDefinition);
work.setParameterDefinitions(parameterDefinitions);
work.setParameter("TaskName", "Do something");
work.setParameter("ActorId", "John Doe");
humanTaskNode.setWaitForCompletion(false);
humanTaskNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
humanTaskNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
process.addNode(humanTaskNode);
connection = new ConnectionImpl(workItemNode, Node.CONNECTION_DEFAULT_TYPE, humanTaskNode, Node.CONNECTION_DEFAULT_TYPE);
TimerNode timerNode = new TimerNode();
timerNode.setName("timer");
timerNode.setMetaData("x", 1);
timerNode.setMetaData("y", 2);
timerNode.setMetaData("width", 3);
timerNode.setMetaData("height", 4);
timer = new Timer();
timer.setDelay("1000");
timer.setPeriod("1000");
timerNode.setTimer(timer);
process.addNode(timerNode);
new ConnectionImpl(humanTaskNode, Node.CONNECTION_DEFAULT_TYPE, timerNode, Node.CONNECTION_DEFAULT_TYPE);
ForEachNode forEachNode = new ForEachNode();
forEachNode.setName("ForEach");
forEachNode.setCollectionExpression("collection");
forEachNode.setVariable("variableName", new ObjectDataType());
forEachNode.setWaitForCompletion(false);
ActionNode subActionNode1 = new ActionNode();
forEachNode.getCompositeNode().addNode(subActionNode1);
ActionNode subActionNode2 = new ActionNode();
forEachNode.getCompositeNode().addNode(subActionNode2);
new ConnectionImpl(subActionNode1, Node.CONNECTION_DEFAULT_TYPE, subActionNode2, Node.CONNECTION_DEFAULT_TYPE);
forEachNode.getCompositeNode().linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, subActionNode1.getId(), Node.CONNECTION_DEFAULT_TYPE);
forEachNode.getCompositeNode().linkOutgoingConnections(subActionNode2.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
process.addNode(forEachNode);
new ConnectionImpl(timerNode, Node.CONNECTION_DEFAULT_TYPE, forEachNode, Node.CONNECTION_DEFAULT_TYPE);
CompositeContextNode compositeNode = new CompositeContextNode();
compositeNode.setName("Composite");
VariableScope variableScope = new VariableScope();
compositeNode.addContext(variableScope);
compositeNode.setDefaultContext(variableScope);
variableScope.setVariables(variables);
ExceptionScope exceptionScope = new ExceptionScope();
compositeNode.addContext(exceptionScope);
compositeNode.setDefaultContext(exceptionScope);
exceptionHandler = new ActionExceptionHandler();
exceptionHandler.setFaultVariable("faultVariable");
action = new DroolsConsequenceAction("dialect", "consequence");
exceptionHandler.setAction(action);
exceptionScope.setExceptionHandler("MyFault", exceptionHandler);
exceptionHandler = new ActionExceptionHandler();
exceptionHandler.setFaultVariable("faultVariable2");
action = new DroolsConsequenceAction("dialect2", "consequence2");
exceptionHandler.setAction(action);
exceptionScope.setExceptionHandler("MyFault2", exceptionHandler);
subActionNode1 = new ActionNode();
compositeNode.addNode(subActionNode1);
subActionNode2 = new ActionNode();
compositeNode.addNode(subActionNode2);
new ConnectionImpl(subActionNode1, Node.CONNECTION_DEFAULT_TYPE, subActionNode2, Node.CONNECTION_DEFAULT_TYPE);
compositeNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, subActionNode1.getId(), Node.CONNECTION_DEFAULT_TYPE);
compositeNode.linkOutgoingConnections(subActionNode2.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
process.addNode(compositeNode);
new ConnectionImpl(forEachNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("end");
endNode.setTerminate(false);
endNode.setMetaData("x", 1);
endNode.setMetaData("y", 2);
endNode.setMetaData("width", 3);
endNode.setMetaData("height", 4);
process.addNode(endNode);
StateNode stateNode = new StateNode();
stateNode.setName("state");
stateNode.setMetaData("x", 1);
stateNode.setMetaData("y", 2);
stateNode.setMetaData("width", 3);
stateNode.setMetaData("height", 4);
timer = new Timer();
timer.setDelay("100");
timer.setPeriod("100");
action = new DroolsConsequenceAction("dialect", "consequence");
stateNode.addTimer(timer, action);
timer = new Timer();
timer.setDelay("200");
timer.setPeriod("200");
action = new DroolsConsequenceAction("dialect", "consequence");
stateNode.addTimer(timer, action);
actions = new ArrayList<DroolsAction>();
action1 = new DroolsConsequenceAction("java", "System.out.println(\"action1\");");
actions.add(action1);
action2 = new DroolsConsequenceAction("java", "System.out.println(\"action2\");");
actions.add(action2);
stateNode.setActions(ExtendedNodeImpl.EVENT_NODE_ENTER, actions);
stateNode.setActions(ExtendedNodeImpl.EVENT_NODE_EXIT, actions);
new ConnectionImpl(compositeNode, Node.CONNECTION_DEFAULT_TYPE, stateNode, Node.CONNECTION_DEFAULT_TYPE);
connection = new ConnectionImpl(stateNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
constraint = new ConstraintImpl();
constraint.setName("constraint1 ><&&");
constraint.setPriority(1);
constraint.setDialect("dialect1");
constraint.setType("type1");
constraint.setConstraint("constraint-text1 %&<>");
stateNode.setConstraint(connection, constraint);
connection = new ConnectionImpl(stateNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
constraint = new ConstraintImpl();
constraint.setName("constraint2");
constraint.setPriority(2);
constraint.setDialect("dialect2");
constraint.setType("type2");
constraint.setConstraint("constraint-text2");
stateNode.setConstraint(connection, constraint);
process.addNode(stateNode);
String xml = XmlRuleFlowProcessDumper.INSTANCE.dump(process, true);
if (xml == null) {
throw new IllegalArgumentException("Failed to persist full 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(16, process.getNodes().length);
assertEquals(2, process.getImports().size());
assertEquals(2, process.getGlobals().size());
assertEquals(4, process.getVariableScope().getVariables().size());
assertEquals(2, process.getSwimlaneContext().getSwimlanes().size());
assertEquals(2, process.getExceptionScope().getExceptionHandlers().size());
String xml2 = XmlRuleFlowProcessDumper.INSTANCE.dump(process, true);
if (xml2 == null) {
throw new IllegalArgumentException("Failed to persist empty nodes!");
}
Document control = XMLUnit.buildDocument(XMLUnit.newControlParser(), new StringReader(xml));
Document test = XMLUnit.buildDocument(XMLUnit.newTestParser(), new StringReader(xml2));
Diff diff = new Diff(control, test, null, new ElementNameAndAttributeQualifier("name"));
assertTrue(diff.toString(), diff.similar());
// test serialization of process elements
}
use of org.jbpm.workflow.core.node.ForEachNode 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.ForEachNode in project jbpm by kiegroup.
the class ForEachNodeHandler method writeAttributes.
protected void writeAttributes(CompositeNode compositeNode, StringBuilder xmlDump, boolean includeMeta) {
ForEachNode forEachNode = (ForEachNode) compositeNode;
String variableName = forEachNode.getVariableName();
if (variableName != null) {
xmlDump.append("variableName=\"" + variableName + "\" ");
}
String collectionExpression = forEachNode.getCollectionExpression();
if (collectionExpression != null) {
xmlDump.append("collectionExpression=\"" + XmlDumper.replaceIllegalChars(collectionExpression) + "\" ");
}
boolean waitForCompletion = forEachNode.isWaitForCompletion();
if (!waitForCompletion) {
xmlDump.append("waitForCompletion=\"false\" ");
}
}
Aggregations