Search in sources :

Example 26 with ConnectionImpl

use of org.jbpm.workflow.core.impl.ConnectionImpl in project jbpm by kiegroup.

the class CompositeNode method removeOutgoingConnection.

public void removeOutgoingConnection(String type, Connection connection) {
    super.removeOutgoingConnection(type, connection);
    CompositeNode.NodeAndType nodeAndType = internalGetLinkedOutgoingNode(type);
    if (nodeAndType != null) {
        for (Connection outConnection : nodeAndType.getNode().getOutgoingConnections(nodeAndType.getType())) {
            if (((CompositeNodeEnd) outConnection.getTo()).getOutNodeId() == connection.getTo().getId()) {
                Node compositeNodeEnd = outConnection.getTo();
                ((ConnectionImpl) outConnection).terminate();
                internalRemoveNode(compositeNodeEnd);
                return;
            }
        }
        throw new IllegalArgumentException("Could not find internal outgoing connection for node");
    }
}
Also used : Node(org.kie.api.definition.process.Node) Connection(org.kie.api.definition.process.Connection) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl)

Example 27 with ConnectionImpl

use of org.jbpm.workflow.core.impl.ConnectionImpl in project jbpm by kiegroup.

the class ConnectionHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String fromId = attrs.getValue("from");
    emptyAttributeCheck(localName, "from", fromId, parser);
    String toId = attrs.getValue("to");
    emptyAttributeCheck(localName, "to", toId, parser);
    String bendpoints = attrs.getValue("bendpoints");
    String fromType = attrs.getValue("fromType");
    if (fromType == null || fromType.trim().length() == 0) {
        fromType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    String toType = attrs.getValue("toType");
    if (toType == null || toType.trim().length() == 0) {
        toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    Node fromNode = nodeContainer.getNode(new Long(fromId));
    Node toNode = nodeContainer.getNode(new Long(toId));
    if (fromNode == null) {
        throw new SAXParseException("Node '" + fromId + "'cannot be found", parser.getLocator());
    }
    if (toNode == null) {
        throw new SAXParseException("Node '" + toId + "' cannot be found", parser.getLocator());
    }
    ConnectionImpl connection = new ConnectionImpl(fromNode, fromType, toNode, toType);
    connection.setMetaData("bendpoints", bendpoints);
    return connection;
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Node(org.kie.api.definition.process.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 28 with ConnectionImpl

use of org.jbpm.workflow.core.impl.ConnectionImpl in project jbpm by kiegroup.

the class RuleFlowNodeContainerFactory method connection.

public RuleFlowNodeContainerFactory connection(long fromId, long toId) {
    Node from = nodeContainer.getNode(fromId);
    Node to = nodeContainer.getNode(toId);
    new ConnectionImpl(from, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, to, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    return this;
}
Also used : Node(org.kie.api.definition.process.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl)

Example 29 with ConnectionImpl

use of org.jbpm.workflow.core.impl.ConnectionImpl in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitConnection.

public void visitConnection(Connection connection, StringBuilder xmlDump, int metaDataType) {
    // if the connection was generated by a link event, don't dump.
    if (isConnectionRepresentingLinkEvent(connection)) {
        return;
    }
    // if the connection is a hidden one (compensations), don't dump
    Object hidden = ((ConnectionImpl) connection).getMetaData("hidden");
    if (hidden != null && ((Boolean) hidden)) {
        return;
    }
    xmlDump.append("    <sequenceFlow id=\"" + getUniqueNodeId(connection.getFrom()) + "-" + getUniqueNodeId(connection.getTo()) + "\" sourceRef=\"" + getUniqueNodeId(connection.getFrom()) + "\" ");
    // TODO fromType, toType
    xmlDump.append("targetRef=\"" + getUniqueNodeId(connection.getTo()) + "\" ");
    if (metaDataType == META_DATA_AS_NODE_PROPERTY) {
        String bendpoints = (String) connection.getMetaData().get("bendpoints");
        if (bendpoints != null) {
            xmlDump.append("g:bendpoints=\"" + bendpoints + "\" ");
        }
    }
    if (connection.getFrom() instanceof Split) {
        Split split = (Split) connection.getFrom();
        if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
            Constraint constraint = split.getConstraint(connection);
            if (constraint == null) {
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" />");
            } else {
                if (constraint.getName() != null && constraint.getName().trim().length() > 0) {
                    xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(constraint.getName()) + "\" ");
                }
                if (constraint.getPriority() != 0) {
                    xmlDump.append("tns:priority=\"" + constraint.getPriority() + "\" ");
                }
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" ");
                if ("code".equals(constraint.getType())) {
                    if (JavaDialect.ID.equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVA_LANGUAGE + "\" ");
                    } else if ("XPath".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + XPATH_LANGUAGE + "\" ");
                    } else if ("JavaScript".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVASCRIPT_LANGUAGE + "\" ");
                    }
                } else {
                    xmlDump.append("language=\"" + RULE_LANGUAGE + "\" ");
                }
                String constraintString = constraint.getConstraint();
                if (constraintString == null) {
                    constraintString = "";
                }
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</conditionExpression>");
            }
            xmlDump.append(EOL + "    </sequenceFlow>" + EOL);
        } else {
            xmlDump.append("/>" + EOL);
        }
    } else {
        xmlDump.append("/>" + EOL);
    }
}
Also used : Constraint(org.jbpm.workflow.core.Constraint) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) Split(org.jbpm.workflow.core.node.Split)

Example 30 with ConnectionImpl

use of org.jbpm.workflow.core.impl.ConnectionImpl 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") + "]");
    }
}
Also used : RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) List(java.util.List) ArrayList(java.util.ArrayList) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Connection(org.jbpm.workflow.core.Connection) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) CompositeNode(org.jbpm.workflow.core.node.CompositeNode)

Aggregations

ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)34 EndNode (org.jbpm.workflow.core.node.EndNode)23 StartNode (org.jbpm.workflow.core.node.StartNode)23 ActionNode (org.jbpm.workflow.core.node.ActionNode)21 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)19 ArrayList (java.util.ArrayList)17 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)17 Test (org.junit.Test)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)15 KieSession (org.kie.api.runtime.KieSession)15 DroolsAction (org.jbpm.workflow.core.DroolsAction)13 Action (org.jbpm.process.instance.impl.Action)12 EventNode (org.jbpm.workflow.core.node.EventNode)12 ProcessContext (org.kie.api.runtime.process.ProcessContext)12 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)11 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)9 Variable (org.jbpm.process.core.context.variable.Variable)8 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)8 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)8 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)8