use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method nodeInstanceCompleted.
public void nodeInstanceCompleted(NodeInstance nodeInstance, String outType) {
Node nodeInstanceNode = nodeInstance.getNode();
if (nodeInstanceNode != null) {
Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation");
boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj);
if (isForCompensation) {
return;
}
}
if (nodeInstance instanceof EndNodeInstance || ((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic() || nodeInstance instanceof CompositeNodeInstance) {
if (((org.jbpm.workflow.core.WorkflowProcess) getProcess()).isAutoComplete()) {
if (canComplete()) {
setState(ProcessInstance.STATE_COMPLETED);
}
}
} else {
throw new IllegalArgumentException("Completing a node instance that has no outgoing connection is not supported.");
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class AsyncEventNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
ExecutorService executorService = (ExecutorService) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("ExecutorService");
if (executorService != null) {
RuntimeManager runtimeManager = ((RuntimeManager) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("RuntimeManager"));
CommandContext ctx = new CommandContext();
ctx.setData("deploymentId", runtimeManager.getIdentifier());
ctx.setData("processInstanceId", getProcessInstance().getId());
ctx.setData("Signal", getEventType());
ctx.setData("Event", null);
executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
Node node = getNode();
if (node != null) {
String uniqueId = (String) node.getMetaData().get("UniqueId");
if (uniqueId == null) {
uniqueId = ((NodeImpl) node).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).getIterationLevels().remove(getNode().getMetaData().get("UniqueId"));
}
} else {
logger.warn("No async executor service found continuing as sync operation...");
// if there is no executor service available move as sync node
triggerCompleted();
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class CompensationEventListener method findNode.
private Node findNode(String nodeId) {
Node found = null;
Queue<Node> allProcessNodes = new LinkedList<Node>();
allProcessNodes.addAll(Arrays.asList(instance.getNodeContainer().getNodes()));
while (!allProcessNodes.isEmpty()) {
Node node = allProcessNodes.poll();
if (nodeId.equals(node.getMetaData().get("UniqueId"))) {
found = node;
break;
}
if (node instanceof NodeContainer) {
allProcessNodes.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
}
}
return found;
}
use of org.kie.api.definition.process.Node 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.Node in project jbpm by kiegroup.
the class CompositeNode method addNode.
public void addNode(Node node) {
// and delegate to GUI command that drops node
if (node.getId() <= 0) {
long id = 0;
for (Node n : nodeContainer.getNodes()) {
if (n.getId() > id) {
id = n.getId();
}
}
((org.jbpm.workflow.core.Node) node).setId(++id);
}
nodeContainer.addNode(node);
((org.jbpm.workflow.core.Node) node).setNodeContainer(this);
}
Aggregations