Search in sources :

Example 6 with ConnectionRef

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

the class SplitNodeBuilder method build.

public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
    Split splitNode = (Split) node;
    if (splitNode.getType() != Split.TYPE_XOR && splitNode.getType() != Split.TYPE_OR) {
        // we only process or/xor
        return;
    }
    // we need to clone the map, so we can update the original while iterating.
    Map<ConnectionRef, Constraint> map = new HashMap<ConnectionRef, Constraint>(splitNode.getConstraints());
    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 : splitNode.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 (constraint == null && splitNode.isDefault(outgoingConnection)) {
        // do nothing since conditions are ignored for default sequence flow
        } else if (constraint != null && "rule".equals(constraint.getType())) {
            RuleConstraintEvaluator ruleConstraint = new RuleConstraintEvaluator();
            ruleConstraint.setDialect(constraint.getDialect());
            ruleConstraint.setName(constraint.getName());
            ruleConstraint.setPriority(constraint.getPriority());
            ruleConstraint.setDefault(constraint.isDefault());
            ruleConstraint.setType(constraint.getType());
            ruleConstraint.setConstraint(constraint.getConstraint());
            splitNode.setConstraint(outgoingConnection, ruleConstraint);
        } else if (constraint != null && "code".equals(constraint.getType())) {
            ReturnValueConstraintEvaluator returnValueConstraint = new ReturnValueConstraintEvaluator();
            returnValueConstraint.setDialect(constraint.getDialect());
            returnValueConstraint.setName(constraint.getName());
            returnValueConstraint.setPriority(constraint.getPriority());
            returnValueConstraint.setDefault(constraint.isDefault());
            returnValueConstraint.setType(constraint.getType());
            returnValueConstraint.setConstraint(constraint.getConstraint());
            splitNode.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 : 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)

Example 7 with ConnectionRef

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

the class Split method isDefault.

public boolean isDefault(final Connection connection) {
    if (connection == null) {
        throw new IllegalArgumentException("connection is null");
    }
    if (this.type == TYPE_OR || this.type == TYPE_XOR) {
        ConnectionRef ref = new ConnectionRef(connection.getTo().getId(), connection.getToType());
        Constraint constraint = this.constraints.get(ref);
        String defaultConnection = (String) getMetaData().get("Default");
        String connectionId = (String) connection.getMetaData().get("UniqueId");
        if (constraint != null) {
            return constraint.isDefault();
        } else if (constraint == null && connectionId.equals(defaultConnection)) {
            return true;
        } else {
            return false;
        }
    }
    throw new UnsupportedOperationException("Constraints are " + "only supported with XOR or OR split types, not with: " + getType());
}
Also used : Constraint(org.jbpm.workflow.core.Constraint) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

Example 8 with ConnectionRef

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

the class Split method removeConstraint.

public void removeConstraint(Connection connection) {
    ConnectionRef ref = new ConnectionRef(connection.getTo().getId(), connection.getToType());
    internalRemoveConstraint(ref);
}
Also used : ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

Example 9 with ConnectionRef

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

the class SplitNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    Split splitNode = (Split) node;
    writeNode("split", splitNode, xmlDump, includeMeta);
    int type = splitNode.getType();
    if (type != 0) {
        xmlDump.append("type=\"" + type + "\" ");
    }
    if (splitNode.getConstraints().isEmpty()) {
        endNode(xmlDump);
    } else {
        xmlDump.append(">" + EOL);
        if (includeMeta) {
            writeMetaData(splitNode, xmlDump);
        }
        xmlDump.append("      <constraints>" + EOL);
        for (Map.Entry<ConnectionRef, Constraint> entry : splitNode.getConstraints().entrySet()) {
            ConnectionRef connection = entry.getKey();
            Constraint constraint = entry.getValue();
            xmlDump.append("        <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" " + "toType=\"" + connection.getToType() + "\" ");
            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() + "\" ");
            }
            xmlDump.append("type=\"" + constraint.getType() + "\" ");
            String dialect = constraint.getDialect();
            if (dialect != null && !"".equals(dialect)) {
                xmlDump.append("dialect=\"" + dialect + "\" ");
            }
            String constraintString = constraint.getConstraint();
            if (constraintString != null) {
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
            } else {
                xmlDump.append("/>" + EOL);
            }
        }
        xmlDump.append("      </constraints>" + EOL);
        endNode("split", xmlDump);
    }
}
Also used : Constraint(org.jbpm.workflow.core.Constraint) Split(org.jbpm.workflow.core.node.Split) Map(java.util.Map) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) Constraint(org.jbpm.workflow.core.Constraint)

Example 10 with ConnectionRef

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

the class SplitHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    Split split = (Split) node;
    String type = null;
    switch(split.getType()) {
        case Split.TYPE_AND:
            type = "parallelGateway";
            writeNode(type, node, xmlDump, metaDataType);
            break;
        case Split.TYPE_XOR:
            type = "exclusiveGateway";
            writeNode(type, node, xmlDump, metaDataType);
            for (Map.Entry<ConnectionRef, Constraint> entry : split.getConstraints().entrySet()) {
                if (entry.getValue() != null && entry.getValue().isDefault()) {
                    xmlDump.append("default=\"" + XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" + XmlBPMNProcessDumper.getUniqueNodeId(node.getNodeContainer().getNode(entry.getKey().getNodeId())) + "\" ");
                    break;
                }
            }
            break;
        case Split.TYPE_OR:
            type = "inclusiveGateway";
            writeNode(type, node, xmlDump, metaDataType);
            for (Map.Entry<ConnectionRef, Constraint> entry : split.getConstraints().entrySet()) {
                if (entry.getValue() != null && entry.getValue().isDefault()) {
                    xmlDump.append("default=\"" + XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" + XmlBPMNProcessDumper.getUniqueNodeId(node.getNodeContainer().getNode(entry.getKey().getNodeId())) + "\" ");
                    break;
                }
            }
            break;
        case Split.TYPE_XAND:
            type = "eventBasedGateway";
            writeNode(type, node, xmlDump, metaDataType);
            break;
        default:
            type = "complexGateway";
            writeNode(type, node, xmlDump, metaDataType);
    }
    xmlDump.append("gatewayDirection=\"Diverging\" >" + EOL);
    writeExtensionElements(node, xmlDump);
    endNode(type, xmlDump);
}
Also used : Constraint(org.jbpm.workflow.core.Constraint) Split(org.jbpm.workflow.core.node.Split) Map(java.util.Map) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

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