use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class ProcessHandler method checkBoundaryEventCompensationHandler.
/**
* This logic belongs in {@link RuleFlowProcessValidator} -- except that {@link Association}s are a jbpm-bpmn2 class,
* and {@link RuleFlowProcessValidator} is a jbpm-flow class..
* </p>
* Maybe we should have a BPMNProcessValidator class?
*
* @param association The association to check.
* @param source The source of the association.
* @param target The target of the association.
*/
private static void checkBoundaryEventCompensationHandler(Association association, Node source, Node target) {
// - event node is boundary event node
if (!(source instanceof BoundaryEventNode)) {
throw new IllegalArgumentException("(Compensation) activities may only be associated with Boundary Event Nodes (not with" + source.getClass().getSimpleName() + " nodes [node " + ((String) source.getMetaData().get("UniqueId")) + "].");
}
BoundaryEventNode eventNode = (BoundaryEventNode) source;
// - event node has compensationEvent
List<EventFilter> eventFilters = eventNode.getEventFilters();
boolean compensationCheckPassed = false;
if (eventFilters != null) {
for (EventFilter filter : eventFilters) {
if (filter instanceof EventTypeFilter) {
String type = ((EventTypeFilter) filter).getType();
if (type != null && type.equals("Compensation")) {
compensationCheckPassed = true;
}
}
}
}
if (!compensationCheckPassed) {
throw new IllegalArgumentException("An Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] linked from an association [" + association.getId() + "] must be a (Boundary) Compensation Event.");
}
// - boundary event node is attached to the correct type of node?
/**
* Tasks:
* business: RuleSetNode
* manual: WorkItemNode
* receive: WorkItemNode
* script: ActionNode
* send: WorkItemNode
* service: WorkItemNode
* task: WorkItemNode
* user: HumanTaskNode
*/
String attachedToId = eventNode.getAttachedToNodeId();
Node attachedToNode = null;
for (Node node : eventNode.getNodeContainer().getNodes()) {
if (attachedToId.equals(node.getMetaData().get("UniqueId"))) {
attachedToNode = node;
break;
}
}
if (attachedToNode == null) {
throw new IllegalArgumentException("Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] is not attached to a node [" + attachedToId + "] that can be found.");
}
if (!(attachedToNode instanceof RuleSetNode || attachedToNode instanceof WorkItemNode || attachedToNode instanceof ActionNode || attachedToNode instanceof HumanTaskNode || attachedToNode instanceof CompositeNode || attachedToNode instanceof SubProcessNode)) {
throw new IllegalArgumentException("Compensation Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] must be attached to a task or sub-process.");
}
// - associated node is a task or subProcess
compensationCheckPassed = false;
if (target instanceof WorkItemNode || target instanceof HumanTaskNode || target instanceof CompositeContextNode || target instanceof SubProcessNode) {
compensationCheckPassed = true;
} else if (target instanceof ActionNode) {
Object nodeTypeObj = ((ActionNode) target).getMetaData("NodeType");
if (nodeTypeObj != null && nodeTypeObj.equals("ScriptTask")) {
compensationCheckPassed = true;
}
}
if (!compensationCheckPassed) {
throw new IllegalArgumentException("An Activity [" + ((String) ((NodeImpl) target).getMetaData("UniqueId")) + "] associated with a Boundary Compensation Event must be a Task or a (non-Event) Sub-Process");
}
// - associated node does not have outgoingConnections of it's own
compensationCheckPassed = true;
NodeImpl targetNode = (NodeImpl) target;
Map<String, List<org.kie.api.definition.process.Connection>> connectionsMap = targetNode.getOutgoingConnections();
ConnectionImpl outgoingConnection = null;
for (String connectionType : connectionsMap.keySet()) {
List<org.kie.api.definition.process.Connection> connections = connectionsMap.get(connectionType);
if (connections != null && !connections.isEmpty()) {
for (org.kie.api.definition.process.Connection connection : connections) {
Object hiddenObj = connection.getMetaData().get("hidden");
if (hiddenObj != null && ((Boolean) hiddenObj)) {
continue;
}
outgoingConnection = (ConnectionImpl) connection;
compensationCheckPassed = false;
break;
}
}
}
if (!compensationCheckPassed) {
throw new IllegalArgumentException("A Compensation Activity [" + ((String) targetNode.getMetaData("UniqueId")) + "] may not have any outgoing connection [" + (String) outgoingConnection.getMetaData("UniqueId") + "]");
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class ProcessHandler method linkIntermediateLinks.
public static void linkIntermediateLinks(NodeContainer process, List<IntermediateLink> links) {
if (null != links) {
// Search throw links
ArrayList<IntermediateLink> throwLinks = new ArrayList<IntermediateLink>();
for (IntermediateLink aLinks : links) {
if (aLinks.isThrowLink()) {
throwLinks.add(aLinks);
}
}
// Look for catch links for a throw link
for (IntermediateLink throwLink : throwLinks) {
ArrayList<IntermediateLink> linksWithSharedNames = new ArrayList<IntermediateLink>();
for (IntermediateLink aLink : links) {
if (throwLink.getName().equals(aLink.getName())) {
linksWithSharedNames.add(aLink);
}
}
if (linksWithSharedNames.size() < 2) {
throw new IllegalArgumentException("There should be at least 2 link events to make a connection");
}
linksWithSharedNames.remove(throwLink);
// Make the connections
Node t = findNodeByIdOrUniqueIdInMetadata(process, throwLink.getUniqueId());
// connect throw to catch
for (IntermediateLink catchLink : linksWithSharedNames) {
Node c = findNodeByIdOrUniqueIdInMetadata(process, catchLink.getUniqueId());
if (t != null && c != null) {
Connection result = new ConnectionImpl(t, NodeImpl.CONNECTION_DEFAULT_TYPE, c, NodeImpl.CONNECTION_DEFAULT_TYPE);
result.setMetaData("linkNodeHidden", "yes");
}
}
// Remove processed links
links.remove(throwLink);
links.removeAll(linksWithSharedNames);
}
if (links.size() > 0) {
throw new IllegalArgumentException(links.size() + " links were not processed");
}
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class BPMNPlaneHandler method postProcessNodeOffset.
private void postProcessNodeOffset(Node[] nodes, int xOffset, int yOffset) {
for (Node node : nodes) {
Integer x = (Integer) node.getMetaData().get("x");
if (x != null) {
((org.jbpm.workflow.core.Node) node).setMetaData("x", x - xOffset);
}
Integer y = (Integer) node.getMetaData().get("y");
if (y != null) {
((org.jbpm.workflow.core.Node) node).setMetaData("y", y - yOffset);
}
if (node instanceof NodeContainer) {
postProcessNodeOffset(((NodeContainer) node).getNodes(), xOffset + (x == null ? 0 : x), yOffset + (y == null ? 0 : y));
}
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JbpmJUnitBaseTestCase method assertNumOfOutgoingConnections.
public void assertNumOfOutgoingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getOutgoingConnections().size() != num) {
fail("Expected outgoing connections: " + num + " - found " + node.getOutgoingConnections().size());
} else {
break;
}
}
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JbpmJUnitBaseTestCase method assertNumOfIncommingConnections.
public void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getIncomingConnections().size() != num) {
fail("Expected incomming connections: " + num + " - found " + node.getIncomingConnections().size());
} else {
break;
}
}
}
}
Aggregations