use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.
the class NodeInstanceImpl method triggerCompleted.
protected void triggerCompleted(String type, boolean remove) {
getExecutionErrorHandler().processed(this);
Node node = getNode();
if (node != null) {
String uniqueId = (String) node.getMetaData().get("UniqueId");
if (uniqueId == null) {
uniqueId = ((NodeImpl) node).getUniqueId();
}
((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId);
((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId);
}
// if node instance was cancelled, or containing container instance was cancelled
if ((getNodeInstanceContainer().getNodeInstance(getId()) == null) || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) {
return;
}
if (remove) {
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
}
List<Connection> connections = null;
if (node != null) {
if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
int priority = Integer.MAX_VALUE;
connections = ((NodeImpl) node).getDefaultOutgoingConnections();
boolean found = false;
List<NodeInstanceTrigger> nodeInstances = new ArrayList<NodeInstanceTrigger>();
List<Connection> outgoingCopy = new ArrayList<Connection>(connections);
while (!outgoingCopy.isEmpty()) {
priority = Integer.MAX_VALUE;
Connection selectedConnection = null;
ConstraintEvaluator selectedConstraint = null;
for (final Iterator<Connection> iterator = outgoingCopy.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
priority = constraint.getPriority();
selectedConnection = connection;
selectedConstraint = constraint;
}
}
if (selectedConstraint == null) {
break;
}
if (selectedConstraint.evaluate(this, selectedConnection, selectedConstraint)) {
nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType()));
found = true;
}
outgoingCopy.remove(selectedConnection);
}
for (NodeInstanceTrigger nodeInstance : nodeInstances) {
// stop if this process instance has been aborted / completed
if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
}
if (!found) {
for (final Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint.isDefault()) {
triggerConnection(connection);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalArgumentException("Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName());
}
return;
} else {
connections = node.getOutgoingConnections(type);
}
}
if (connections == null || connections.isEmpty()) {
boolean hidden = false;
Node currentNode = getNode();
if (currentNode != null && currentNode.getMetaData().get("hidden") != null) {
hidden = true;
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
}
// notify container
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
} else {
Map<org.jbpm.workflow.instance.NodeInstance, String> nodeInstances = new HashMap<org.jbpm.workflow.instance.NodeInstance, String>();
for (Connection connection : connections) {
nodeInstances.put(followConnection(connection), connection.getToType());
}
for (Map.Entry<org.jbpm.workflow.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
// stop if this process instance has been aborted / completed
if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
}
}
}
use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.
the class CompositeNode method linkOutgoingConnections.
public void linkOutgoingConnections(CompositeNode.NodeAndType outNode, String outType) {
CompositeNode.NodeAndType oldNodeAndType = outConnectionMap.get(outType);
if (oldNodeAndType != null) {
if (oldNodeAndType.equals(outNode)) {
return;
} else {
// remove old end nodes + connections
List<Connection> oldOutConnections = oldNodeAndType.getNode().getOutgoingConnections(oldNodeAndType.getType());
for (Connection connection : new ArrayList<Connection>(oldOutConnections)) {
if (connection.getTo() instanceof CompositeNodeEnd) {
removeNode(connection.getTo());
((ConnectionImpl) connection).terminate();
}
}
}
}
outConnectionMap.put(outType, outNode);
if (outNode != null) {
List<Connection> connections = getOutgoingConnections(outType);
for (Connection connection : connections) {
CompositeNodeEnd end = new CompositeNodeEnd(this, connection.getTo(), outType);
internalAddNode(end);
if (outNode.getNode() != null) {
new ConnectionImpl(outNode.getNode(), outNode.getType(), end, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
}
}
}
}
use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.
the class CompositeNode method linkIncomingConnections.
public void linkIncomingConnections(String inType, CompositeNode.NodeAndType inNode) {
CompositeNode.NodeAndType oldNodeAndType = inConnectionMap.get(inType);
if (oldNodeAndType != null) {
if (oldNodeAndType.equals(inNode)) {
return;
} else {
// remove old start nodes + connections
List<Connection> oldInConnections = oldNodeAndType.getNode().getIncomingConnections(oldNodeAndType.getType());
if (oldInConnections != null) {
for (Connection connection : new ArrayList<Connection>(oldInConnections)) {
if (connection.getFrom() instanceof CompositeNodeStart) {
removeNode(connection.getFrom());
((ConnectionImpl) connection).terminate();
}
}
}
}
}
inConnectionMap.put(inType, inNode);
if (inNode != null) {
List<Connection> connections = getIncomingConnections(inType);
for (Connection connection : connections) {
CompositeNodeStart start = new CompositeNodeStart(this, connection.getFrom(), inType);
internalAddNode(start);
if (inNode.getNode() != null) {
new ConnectionImpl(start, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, inNode.getNode(), inNode.getType());
}
}
}
}
use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.
the class AbstractCompositeNodeHandler method visitConnectionsAndAssociations.
protected void visitConnectionsAndAssociations(Node node, StringBuilder xmlDump, int metaDataType) {
// add associations
List<Connection> connections = getSubConnections((CompositeNode) node);
xmlDump.append(" <!-- connections -->" + EOL);
for (Connection connection : connections) {
XmlBPMNProcessDumper.INSTANCE.visitConnection(connection, xmlDump, metaDataType);
}
// add associations
List<Association> associations = (List<Association>) node.getMetaData().get(ProcessHandler.ASSOCIATIONS);
if (associations != null) {
for (Association association : associations) {
XmlBPMNProcessDumper.INSTANCE.visitAssociation(association, xmlDump);
}
}
}
use of org.kie.api.definition.process.Connection 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);
}
}
}
Aggregations