Search in sources :

Example 1 with ConnectionRef

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

the class ConstraintHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Constrainable parent = (Constrainable) parser.getParent();
    Constraint constraint = new ConstraintImpl();
    final String toNodeIdString = element.getAttribute("toNodeId");
    String toType = element.getAttribute("toType");
    ConnectionRef connectionRef = null;
    if (toNodeIdString != null && toNodeIdString.trim().length() > 0) {
        int toNodeId = new Integer(toNodeIdString);
        if (toType == null || toType.trim().length() == 0) {
            toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
        }
        connectionRef = new ConnectionRef(toNodeId, toType);
    }
    final String name = element.getAttribute("name");
    constraint.setName(name);
    final String priority = element.getAttribute("priority");
    if (priority != null && priority.length() != 0) {
        constraint.setPriority(new Integer(priority));
    }
    final String type = element.getAttribute("type");
    constraint.setType(type);
    final String dialect = element.getAttribute("dialect");
    constraint.setDialect(dialect);
    String text = ((Text) element.getChildNodes().item(0)).getWholeText();
    if (text != null) {
        text = text.trim();
        if ("".equals(text)) {
            text = null;
        }
    }
    constraint.setConstraint(text);
    parent.addConstraint(connectionRef, constraint);
    return null;
}
Also used : Constrainable(org.jbpm.workflow.core.node.Constrainable) Constraint(org.jbpm.workflow.core.Constraint) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) Constraint(org.jbpm.workflow.core.Constraint)

Example 2 with ConnectionRef

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

the class StateNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    StateNode stateNode = (StateNode) node;
    writeNode("state", stateNode, xmlDump, includeMeta);
    xmlDump.append(">\n");
    if (includeMeta) {
        writeMetaData(stateNode, xmlDump);
    }
    for (String eventType : stateNode.getActionTypes()) {
        writeActions(eventType, stateNode.getActions(eventType), xmlDump);
    }
    writeTimers(stateNode.getTimers(), xmlDump);
    if (!stateNode.getConstraints().isEmpty()) {
        xmlDump.append("      <constraints>" + EOL);
        for (Map.Entry<ConnectionRef, Constraint> entry : stateNode.getConstraints().entrySet()) {
            ConnectionRef connection = entry.getKey();
            Constraint constraint = entry.getValue();
            xmlDump.append("        <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" ");
            String name = constraint.getName();
            if (name != null && !"".equals(name)) {
                xmlDump.append("name=\"" + XmlDumper.replaceIllegalChars(constraint.getName()) + "\" ");
            }
            int priority = constraint.getPriority();
            if (priority != 0) {
                xmlDump.append("priority=\"" + constraint.getPriority() + "\" ");
            }
            String constraintString = constraint.getConstraint();
            if (constraintString != null) {
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
            } else {
                xmlDump.append("/>" + EOL);
            }
        }
        xmlDump.append("      </constraints>" + EOL);
    }
    endNode("state", xmlDump);
}
Also used : Constraint(org.jbpm.workflow.core.Constraint) StateNode(org.jbpm.workflow.core.node.StateNode) Map(java.util.Map) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) Constraint(org.jbpm.workflow.core.Constraint)

Example 3 with ConnectionRef

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

the class ProcessHandler method linkConnections.

public static void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) {
    if (connections != null) {
        for (SequenceFlow connection : connections) {
            String sourceRef = connection.getSourceRef();
            Node source = findNodeByIdOrUniqueIdInMetadata(nodeContainer, sourceRef, "Could not find source node for connection:" + sourceRef);
            if (source instanceof EventNode) {
                for (EventFilter eventFilter : ((EventNode) source).getEventFilters()) {
                    if (eventFilter instanceof EventTypeFilter) {
                        if ("Compensation".equals(((EventTypeFilter) eventFilter).getType())) {
                            // BPMN Method & Style, 2nd Ed. (Silver), states this on P. 131
                            throw new IllegalArgumentException("A Compensation Boundary Event can only be *associated* with a compensation activity via an Association, not via a Sequence Flow element.");
                        }
                    }
                }
            }
            String targetRef = connection.getTargetRef();
            Node target = findNodeByIdOrUniqueIdInMetadata(nodeContainer, targetRef, "Could not find target node for connection:" + targetRef);
            Connection result = new ConnectionImpl(source, NodeImpl.CONNECTION_DEFAULT_TYPE, target, NodeImpl.CONNECTION_DEFAULT_TYPE);
            result.setMetaData("bendpoints", connection.getBendpoints());
            result.setMetaData("UniqueId", connection.getId());
            if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
                NodeImpl nodeImpl = (NodeImpl) source;
                Constraint constraint = buildConstraint(connection, nodeImpl);
                if (constraint != null) {
                    nodeImpl.addConstraint(new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
                }
            } else if (source instanceof Split) {
                Split split = (Split) source;
                Constraint constraint = buildConstraint(connection, split);
                split.addConstraint(new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
            }
        }
    }
}
Also used : NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Constraint(org.jbpm.workflow.core.Constraint) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) 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) Connection(org.jbpm.workflow.core.Connection) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventFilter(org.jbpm.process.core.event.EventFilter) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Split(org.jbpm.workflow.core.node.Split) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

Example 4 with ConnectionRef

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

the class SplitFactory method constraint.

public SplitFactory constraint(long toNodeId, String name, String type, String dialect, String constraint, int priority) {
    ConstraintImpl constraintImpl = new ConstraintImpl();
    constraintImpl.setName(name);
    constraintImpl.setType(type);
    constraintImpl.setDialect(dialect);
    constraintImpl.setConstraint(constraint);
    constraintImpl.setPriority(priority);
    getSplit().addConstraint(new ConnectionRef(toNodeId, Node.CONNECTION_DEFAULT_TYPE), constraintImpl);
    return this;
}
Also used : ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

Example 5 with ConnectionRef

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

the class MultiConditionalSequenceFlowNodeBuilder method build.

public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
    Map<ConnectionRef, Constraint> constraints = ((NodeImpl) node).getConstraints();
    // exclude split as it is handled with separate builder and nodes with non conditional sequence flows
    if (node instanceof Split || constraints.size() == 0) {
        return;
    }
    // we need to clone the map, so we can update the original while iterating.
    Map<ConnectionRef, Constraint> map = new HashMap<ConnectionRef, Constraint>(constraints);
    for (Iterator<Map.Entry<ConnectionRef, Constraint>> it = map.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<ConnectionRef, Constraint> entry = it.next();
        ConnectionRef connection = entry.getKey();
        ConstraintImpl constraint = (ConstraintImpl) entry.getValue();
        Connection outgoingConnection = null;
        for (Connection out : ((NodeImpl) node).getDefaultOutgoingConnections()) {
            if (out.getToType().equals(connection.getToType()) && out.getTo().getId() == connection.getNodeId()) {
                outgoingConnection = out;
            }
        }
        if (outgoingConnection == null) {
            throw new IllegalArgumentException("Could not find outgoing connection");
        }
        if ("rule".equals(constraint.getType())) {
            RuleConstraintEvaluator ruleConstraint = new RuleConstraintEvaluator();
            ruleConstraint.setDialect(constraint.getDialect());
            ruleConstraint.setName(constraint.getName());
            ruleConstraint.setPriority(constraint.getPriority());
            ruleConstraint.setDefault(constraint.isDefault());
            ((NodeImpl) node).setConstraint(outgoingConnection, ruleConstraint);
        } else if ("code".equals(constraint.getType())) {
            ReturnValueConstraintEvaluator returnValueConstraint = new ReturnValueConstraintEvaluator();
            returnValueConstraint.setDialect(constraint.getDialect());
            returnValueConstraint.setName(constraint.getName());
            returnValueConstraint.setPriority(constraint.getPriority());
            returnValueConstraint.setDefault(constraint.isDefault());
            ((NodeImpl) node).setConstraint(outgoingConnection, returnValueConstraint);
            ReturnValueDescr returnValueDescr = new ReturnValueDescr();
            returnValueDescr.setText(constraint.getConstraint());
            returnValueDescr.setResource(processDescr.getResource());
            ProcessDialect dialect = ProcessDialectRegistry.getDialect(constraint.getDialect());
            dialect.getReturnValueEvaluatorBuilder().build(context, returnValueConstraint, returnValueDescr, (NodeImpl) node);
        }
    }
}
Also used : NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) Constraint(org.jbpm.workflow.core.Constraint) HashMap(java.util.HashMap) ReturnValueDescr(org.drools.compiler.compiler.ReturnValueDescr) Connection(org.kie.api.definition.process.Connection) ReturnValueConstraintEvaluator(org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) RuleConstraintEvaluator(org.jbpm.process.instance.impl.RuleConstraintEvaluator) Split(org.jbpm.workflow.core.node.Split) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConnectionRef (org.jbpm.workflow.core.impl.ConnectionRef)10 Constraint (org.jbpm.workflow.core.Constraint)8 Map (java.util.Map)5 Split (org.jbpm.workflow.core.node.Split)5 ConstraintImpl (org.jbpm.workflow.core.impl.ConstraintImpl)4 HashMap (java.util.HashMap)2 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)2 ProcessDialect (org.jbpm.process.builder.dialect.ProcessDialect)2 ReturnValueConstraintEvaluator (org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator)2 RuleConstraintEvaluator (org.jbpm.process.instance.impl.RuleConstraintEvaluator)2 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)2 StateNode (org.jbpm.workflow.core.node.StateNode)2 Connection (org.kie.api.definition.process.Connection)2 SequenceFlow (org.jbpm.bpmn2.core.SequenceFlow)1 EventFilter (org.jbpm.process.core.event.EventFilter)1 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)1 Connection (org.jbpm.workflow.core.Connection)1 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)1 ExtendedNodeImpl (org.jbpm.workflow.core.impl.ExtendedNodeImpl)1 ActionNode (org.jbpm.workflow.core.node.ActionNode)1