use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JoinInstance method existsActiveDirectFlow.
private boolean existsActiveDirectFlow(NodeInstanceContainer nodeInstanceContainer, final Node lookFor) {
Collection<NodeInstance> activeNodeInstancesOrig = nodeInstanceContainer.getNodeInstances();
List<NodeInstance> activeNodeInstances = new ArrayList<NodeInstance>(activeNodeInstancesOrig);
// sort active instances in the way that lookFor nodeInstance will be last to not finish too early
Collections.sort(activeNodeInstances, new Comparator<NodeInstance>() {
@Override
public int compare(NodeInstance o1, NodeInstance o2) {
if (o1.getNodeId() == lookFor.getId()) {
return 1;
} else if (o2.getNodeId() == lookFor.getId()) {
return -1;
}
return 0;
}
});
for (NodeInstance nodeInstance : activeNodeInstances) {
// do not consider NodeInstanceContainers to be checked, enough to treat is as black box
if (((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getLevel() != getLevel()) {
continue;
}
Node node = nodeInstance.getNode();
Set<Long> vistedNodes = new HashSet<Long>();
checkNodes(vistedNodes, node, node, lookFor);
if (vistedNodes.contains(lookFor.getId()) && !vistedNodes.contains(node.getId())) {
return true;
}
}
return false;
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class CompositeNodeInstance method signalEvent.
@Override
public void signalEvent(String type, Object event) {
List<NodeInstance> currentView = new ArrayList<NodeInstance>(this.nodeInstances);
super.signalEvent(type, event);
for (Node node : getCompositeNode().internalGetNodes()) {
if (node instanceof EventNodeInterface) {
if (((EventNodeInterface) node).acceptsEvent(type, event)) {
if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else if (node instanceof EventSubProcessNode) {
EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
if (nodeInstances != null && !nodeInstances.isEmpty()) {
for (NodeInstance nodeInstance : nodeInstances) {
((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
}
}
}
}
}
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class CompositeNodeInstance 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 || nodeInstance instanceof EventSubProcessNodeInstance) {
if (getCompositeNode().isAutoComplete()) {
if (nodeInstances.isEmpty()) {
triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
}
}
} else {
throw new IllegalArgumentException("Completing a node instance that has no outgoing connection not supported.");
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class CompositeNodeInstance method getNodeInstance.
public NodeInstance getNodeInstance(final Node node) {
// TODO do this cleaner for start / end of composite?
if (node instanceof CompositeNode.CompositeNodeStart) {
CompositeNodeStartInstance nodeInstance = new CompositeNodeStartInstance();
nodeInstance.setNodeId(node.getId());
nodeInstance.setNodeInstanceContainer(this);
nodeInstance.setProcessInstance(getProcessInstance());
return nodeInstance;
} else if (node instanceof CompositeNode.CompositeNodeEnd) {
CompositeNodeEndInstance nodeInstance = new CompositeNodeEndInstance();
nodeInstance.setNodeId(node.getId());
nodeInstance.setNodeInstanceContainer(this);
nodeInstance.setProcessInstance(getProcessInstance());
return nodeInstance;
}
Node actualNode = node;
// async continuation handling
if (node instanceof AsyncEventNode) {
actualNode = ((AsyncEventNode) node).getActualNode();
} else if (useAsync(node)) {
actualNode = new AsyncEventNode(node);
}
NodeInstanceFactory conf = NodeInstanceFactoryRegistry.getInstance(getProcessInstance().getKnowledgeRuntime().getEnvironment()).getProcessNodeInstanceFactory(actualNode);
if (conf == null) {
throw new IllegalArgumentException("Illegal node type: " + node.getClass());
}
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) conf.getNodeInstance(actualNode, getProcessInstance(), this);
if (nodeInstance == null) {
throw new IllegalArgumentException("Illegal node type: " + node.getClass());
}
return nodeInstance;
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class DynamicNodeInstance method nodeInstanceCompleted.
public void nodeInstanceCompleted(org.jbpm.workflow.instance.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;
}
}
String completionCondition = getDynamicNode().getCompletionExpression();
// TODO are we sure there will always be node instances left if we are not done yet?
if (isTerminated(nodeInstance)) {
triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE);
} else if (getDynamicNode().isAutoComplete() && getNodeInstances(false).isEmpty()) {
triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE);
} else if (completionCondition != null && "mvel".equals(getDynamicNode().getLanguage())) {
Object value = MVELSafeHelper.getEvaluator().eval(completionCondition, new NodeInstanceResolverFactory(this));
if (!(value instanceof Boolean)) {
throw new RuntimeException("Completion condition expression must return boolean values: " + value + " for expression " + completionCondition);
}
if (((Boolean) value).booleanValue()) {
triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE);
}
}
}
Aggregations