private void postProcessNodes(NodeContainer container) { for (Node node : container.getNodes()) { if (node instanceof StateNode) { StateNode stateNode = (StateNode) node; String condition = (String) stateNode.getMetaData().get("Condition"); Constraint constraint = new ConstraintImpl(); constraint.setConstraint(condition); constraint.setType("rule"); for (org.drools.definition.process.Connection connection : stateNode.getDefaultOutgoingConnections()) { stateNode.setConstraint(connection, constraint); } } else if (node instanceof NodeContainer) { postProcessNodes((NodeContainer) node); } } }
private void assignLanes(NodeContainer nodeContainer, Map<String, String> laneMapping) { for (Node node : nodeContainer.getNodes()) { String lane = null; String uniqueId = (String) node.getMetaData().get("UniqueId"); if (uniqueId != null) { lane = laneMapping.get(uniqueId); } else { lane = laneMapping.get(XmlBPMNProcessDumper.getUniqueNodeId(node)); } if (lane != null) { ((NodeImpl) node).setMetaData("Lane", lane); if (node instanceof HumanTaskNode) { ((HumanTaskNode) node).setSwimlane(lane); } } if (node instanceof NodeContainer) { assignLanes((NodeContainer) node, laneMapping); } } }
public static void linkBoundaryEvents(NodeContainer nodeContainer) { for (Node node : nodeContainer.getNodes()) { if (node instanceof EventNode) { String attachedTo = (String) node.getMetaData().get("AttachedTo"); if (attachedTo != null) { String type = ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).getType(); Node attachedNode = null; try { // remove starting _ String attachedToString = attachedTo.substring(1); // remove ids of parent nodes attachedToString = attachedToString.substring(attachedToString.lastIndexOf("-") + 1); attachedNode = nodeContainer.getNode(new Integer(attachedToString)); } catch (NumberFormatException e) { // try looking for a node with same "UniqueId" (in metadata) for (Node subnode : nodeContainer.getNodes()) { if (attachedTo.equals(subnode.getMetaData().get("UniqueId"))) { attachedNode = subnode; break; } } if (attachedNode == null) { throw new IllegalArgumentException("Could not find node to attach to: " + attachedTo); } } if (type.startsWith("Escalation-")) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE); if (exceptionScope == null) { exceptionScope = new ExceptionScope(); compositeNode.addContext(exceptionScope); compositeNode.setDefaultContext(exceptionScope); } String escalationCode = (String) node.getMetaData().get("EscalationEvent"); ActionExceptionHandler exceptionHandler = new ActionExceptionHandler(); exceptionHandler.setAction( new DroolsConsequenceAction( "java", (cancelActivity ? "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") + "kcontext.getProcessInstance().signalEvent(\"Escalation-" + attachedTo + "-" + escalationCode + "\", null);")); exceptionScope.setExceptionHandler(escalationCode, exceptionHandler); } else if (type.startsWith("Error-")) { CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE); if (exceptionScope == null) { exceptionScope = new ExceptionScope(); compositeNode.addContext(exceptionScope); compositeNode.setDefaultContext(exceptionScope); } String errorCode = (String) node.getMetaData().get("ErrorEvent"); ActionExceptionHandler exceptionHandler = new ActionExceptionHandler(); exceptionHandler.setAction( new DroolsConsequenceAction( "java", "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" + "kcontext.getProcessInstance().signalEvent(\"Error-" + attachedTo + "-" + errorCode + "\", null);")); exceptionScope.setExceptionHandler(errorCode, exceptionHandler); } else if (type.startsWith("Timer-")) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; String timeCycle = (String) node.getMetaData().get("TimeCycle"); Timer timer = new Timer(); timer.setDelay(timeCycle); compositeNode.addTimer( timer, new DroolsConsequenceAction( "java", (cancelActivity ? "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") + "kcontext.getProcessInstance().signalEvent(\"Timer-" + attachedTo + "-" + timeCycle + "\", null);")); } else if (type.startsWith("Compensate-")) { String uniqueId = (String) node.getMetaData().get("UniqueId"); String eventType = "Compensate-" + uniqueId; ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).setType(eventType); } } } } }
public static void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) { if (connections != null) { for (SequenceFlow connection : connections) { String sourceRef = connection.getSourceRef(); String targetRef = connection.getTargetRef(); Node source = null; Node target = null; try { // remove starting _ sourceRef = sourceRef.substring(1); // remove ids of parent nodes sourceRef = sourceRef.substring(sourceRef.lastIndexOf("-") + 1); source = nodeContainer.getNode(new Integer(sourceRef)); } catch (NumberFormatException e) { // try looking for a node with same "UniqueId" (in metadata) for (Node node : nodeContainer.getNodes()) { if (connection.getSourceRef().equals(node.getMetaData().get("UniqueId"))) { source = node; break; } } if (source == null) { throw new IllegalArgumentException( "Could not find source node for connection:" + connection.getSourceRef()); } } try { // remove starting _ targetRef = targetRef.substring(1); // remove ids of parent nodes targetRef = targetRef.substring(targetRef.lastIndexOf("-") + 1); target = nodeContainer.getNode(new Integer(targetRef)); } catch (NumberFormatException e) { // try looking for a node with same "UniqueId" (in metadata) for (Node node : nodeContainer.getNodes()) { if (connection.getTargetRef().equals(node.getMetaData().get("UniqueId"))) { target = node; break; } } if (target == null) { throw new IllegalArgumentException( "Could not find target node for connection:" + connection.getTargetRef()); } } Connection result = new ConnectionImpl( source, NodeImpl.CONNECTION_DEFAULT_TYPE, target, NodeImpl.CONNECTION_DEFAULT_TYPE); result.setMetaData("bendpoints", connection.getBendpoints()); if (source instanceof Split) { Split split = (Split) source; Constraint constraint = new ConstraintImpl(); String defaultConnection = (String) split.getMetaData("Default"); if (defaultConnection != null && defaultConnection.equals(connection.getId())) { constraint.setDefault(true); } if (connection.getName() != null) { constraint.setName(connection.getName()); } else { constraint.setName(""); } if (connection.getType() != null) { constraint.setType(connection.getType()); } else { constraint.setType("code"); } if (connection.getLanguage() != null) { constraint.setDialect(connection.getLanguage()); } if (connection.getExpression() != null) { constraint.setConstraint(connection.getExpression()); } split.addConstraint( new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint); } } } }