use of org.jbpm.workflow.core.node.Split 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.Split in project jbpm by kiegroup.
the class MultiConditionalSequenceFlowNodeBuilder method build.
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
Map<ConnectionRef, Constraint> constraints = ((NodeImpl) node).getConstraints();
// exclude split as it is handled with separate builder and nodes with non conditional sequence flows
if (node instanceof Split || constraints.size() == 0) {
return;
}
// we need to clone the map, so we can update the original while iterating.
Map<ConnectionRef, Constraint> map = new HashMap<ConnectionRef, Constraint>(constraints);
for (Iterator<Map.Entry<ConnectionRef, Constraint>> it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ConnectionRef, Constraint> entry = it.next();
ConnectionRef connection = entry.getKey();
ConstraintImpl constraint = (ConstraintImpl) entry.getValue();
Connection outgoingConnection = null;
for (Connection out : ((NodeImpl) node).getDefaultOutgoingConnections()) {
if (out.getToType().equals(connection.getToType()) && out.getTo().getId() == connection.getNodeId()) {
outgoingConnection = out;
}
}
if (outgoingConnection == null) {
throw new IllegalArgumentException("Could not find outgoing connection");
}
if ("rule".equals(constraint.getType())) {
RuleConstraintEvaluator ruleConstraint = new RuleConstraintEvaluator();
ruleConstraint.setDialect(constraint.getDialect());
ruleConstraint.setName(constraint.getName());
ruleConstraint.setPriority(constraint.getPriority());
ruleConstraint.setDefault(constraint.isDefault());
((NodeImpl) node).setConstraint(outgoingConnection, ruleConstraint);
} else if ("code".equals(constraint.getType())) {
ReturnValueConstraintEvaluator returnValueConstraint = new ReturnValueConstraintEvaluator();
returnValueConstraint.setDialect(constraint.getDialect());
returnValueConstraint.setName(constraint.getName());
returnValueConstraint.setPriority(constraint.getPriority());
returnValueConstraint.setDefault(constraint.isDefault());
((NodeImpl) node).setConstraint(outgoingConnection, returnValueConstraint);
ReturnValueDescr returnValueDescr = new ReturnValueDescr();
returnValueDescr.setText(constraint.getConstraint());
returnValueDescr.setResource(processDescr.getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(constraint.getDialect());
dialect.getReturnValueEvaluatorBuilder().build(context, returnValueConstraint, returnValueDescr, (NodeImpl) node);
}
}
}
use of org.jbpm.workflow.core.node.Split in project jbpm by kiegroup.
the class SplitNodeBuilder method build.
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
Split splitNode = (Split) node;
if (splitNode.getType() != Split.TYPE_XOR && splitNode.getType() != Split.TYPE_OR) {
// we only process or/xor
return;
}
// we need to clone the map, so we can update the original while iterating.
Map<ConnectionRef, Constraint> map = new HashMap<ConnectionRef, Constraint>(splitNode.getConstraints());
for (Iterator<Map.Entry<ConnectionRef, Constraint>> it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ConnectionRef, Constraint> entry = it.next();
ConnectionRef connection = entry.getKey();
ConstraintImpl constraint = (ConstraintImpl) entry.getValue();
Connection outgoingConnection = null;
for (Connection out : splitNode.getDefaultOutgoingConnections()) {
if (out.getToType().equals(connection.getToType()) && out.getTo().getId() == connection.getNodeId()) {
outgoingConnection = out;
}
}
if (outgoingConnection == null) {
throw new IllegalArgumentException("Could not find outgoing connection");
}
if (constraint == null && splitNode.isDefault(outgoingConnection)) {
// do nothing since conditions are ignored for default sequence flow
} else if (constraint != null && "rule".equals(constraint.getType())) {
RuleConstraintEvaluator ruleConstraint = new RuleConstraintEvaluator();
ruleConstraint.setDialect(constraint.getDialect());
ruleConstraint.setName(constraint.getName());
ruleConstraint.setPriority(constraint.getPriority());
ruleConstraint.setDefault(constraint.isDefault());
ruleConstraint.setType(constraint.getType());
ruleConstraint.setConstraint(constraint.getConstraint());
splitNode.setConstraint(outgoingConnection, ruleConstraint);
} else if (constraint != null && "code".equals(constraint.getType())) {
ReturnValueConstraintEvaluator returnValueConstraint = new ReturnValueConstraintEvaluator();
returnValueConstraint.setDialect(constraint.getDialect());
returnValueConstraint.setName(constraint.getName());
returnValueConstraint.setPriority(constraint.getPriority());
returnValueConstraint.setDefault(constraint.isDefault());
returnValueConstraint.setType(constraint.getType());
returnValueConstraint.setConstraint(constraint.getConstraint());
splitNode.setConstraint(outgoingConnection, returnValueConstraint);
ReturnValueDescr returnValueDescr = new ReturnValueDescr();
returnValueDescr.setText(constraint.getConstraint());
returnValueDescr.setResource(processDescr.getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(constraint.getDialect());
dialect.getReturnValueEvaluatorBuilder().build(context, returnValueConstraint, returnValueDescr, (NodeImpl) node);
}
}
}
use of org.jbpm.workflow.core.node.Split in project jbpm by kiegroup.
the class ProcessBuilderImpl method generateRules.
private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] instanceof Split) {
Split split = (Split) nodes[i];
if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
for (Connection connection : split.getDefaultOutgoingConnections()) {
Constraint constraint = split.getConstraint(connection);
if (constraint != null && "rule".equals(constraint.getType())) {
builder.append(createSplitRule(process, connection, split.getConstraint(connection).getConstraint()));
}
}
}
} else if (nodes[i] instanceof MilestoneNode) {
MilestoneNode milestone = (MilestoneNode) nodes[i];
builder.append(createMilestoneRule(process, milestone));
} else if (nodes[i] instanceof StateNode) {
StateNode state = (StateNode) nodes[i];
builder.append(createStateRules(process, state));
} else if (nodes[i] instanceof StartNode) {
StartNode startNode = (StartNode) nodes[i];
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
builder.append(createStartConstraintRule(process, startNode.getNodeContainer(), (ConstraintTrigger) trigger));
}
}
}
} else if (nodes[i] instanceof NodeContainer) {
generateRules(((NodeContainer) nodes[i]).getNodes(), process, builder);
if (nodes[i] instanceof DynamicNode && "rule".equals(((DynamicNode) nodes[i]).getLanguage())) {
DynamicNode dynamicNode = (DynamicNode) nodes[i];
if (dynamicNode.getCompletionExpression() != null) {
builder.append(createAdHocCompletionRule(process, dynamicNode));
}
if (dynamicNode.getActivationExpression() != null && !dynamicNode.getActivationExpression().isEmpty()) {
builder.append(createAdHocActivationRule(process, dynamicNode));
}
}
} else if (nodes[i] instanceof EventNode) {
EventNode state = (EventNode) nodes[i];
builder.append(createEventStateRule(process, state));
}
}
}
use of org.jbpm.workflow.core.node.Split in project jbpm by kiegroup.
the class SplitNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
Split splitNode = (Split) node;
writeNode("split", splitNode, xmlDump, includeMeta);
int type = splitNode.getType();
if (type != 0) {
xmlDump.append("type=\"" + type + "\" ");
}
if (splitNode.getConstraints().isEmpty()) {
endNode(xmlDump);
} else {
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(splitNode, xmlDump);
}
xmlDump.append(" <constraints>" + EOL);
for (Map.Entry<ConnectionRef, Constraint> entry : splitNode.getConstraints().entrySet()) {
ConnectionRef connection = entry.getKey();
Constraint constraint = entry.getValue();
xmlDump.append(" <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" " + "toType=\"" + connection.getToType() + "\" ");
String name = constraint.getName();
if (name != null && !"".equals(name)) {
xmlDump.append("name=\"" + XmlDumper.replaceIllegalChars(constraint.getName()) + "\" ");
}
int priority = constraint.getPriority();
if (priority != 0) {
xmlDump.append("priority=\"" + constraint.getPriority() + "\" ");
}
xmlDump.append("type=\"" + constraint.getType() + "\" ");
String dialect = constraint.getDialect();
if (dialect != null && !"".equals(dialect)) {
xmlDump.append("dialect=\"" + dialect + "\" ");
}
String constraintString = constraint.getConstraint();
if (constraintString != null) {
xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
} else {
xmlDump.append("/>" + EOL);
}
}
xmlDump.append(" </constraints>" + EOL);
endNode("split", xmlDump);
}
}
Aggregations