Search in sources :

Example 11 with Split

use of org.jbpm.workflow.core.node.Split in project jbpm by kiegroup.

the class ExclusiveGatewayHandler method createNode.

protected Node createNode(Attributes attrs) {
    final String type = attrs.getValue("gatewayDirection");
    if ("Converging".equals(type)) {
        Join join = new Join();
        join.setType(Join.TYPE_XOR);
        return join;
    } else if ("Diverging".equals(type)) {
        Split split = new Split();
        split.setType(Split.TYPE_XOR);
        String isDefault = attrs.getValue("default");
        split.setMetaData("Default", isDefault);
        return split;
    } else {
        throw new IllegalArgumentException("Unknown gateway direction: " + type);
    }
}
Also used : Join(org.jbpm.workflow.core.node.Join) Split(org.jbpm.workflow.core.node.Split)

Example 12 with Split

use of org.jbpm.workflow.core.node.Split 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)

Example 13 with Split

use of org.jbpm.workflow.core.node.Split 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 14 with Split

use of org.jbpm.workflow.core.node.Split in project jbpm by kiegroup.

the class ProcessBuilderImpl method generateRules.

private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
    for (int i = 0; i < nodes.length; i++) {
        if (nodes[i] instanceof Split) {
            Split split = (Split) nodes[i];
            if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
                for (Connection connection : split.getDefaultOutgoingConnections()) {
                    Constraint constraint = split.getConstraint(connection);
                    if (constraint != null && "rule".equals(constraint.getType())) {
                        builder.append(createSplitRule(process, connection, split.getConstraint(connection).getConstraint()));
                    }
                }
            }
        } else if (nodes[i] instanceof MilestoneNode) {
            MilestoneNode milestone = (MilestoneNode) nodes[i];
            builder.append(createMilestoneRule(process, milestone));
        } else if (nodes[i] instanceof StateNode) {
            StateNode state = (StateNode) nodes[i];
            builder.append(createStateRules(process, state));
        } else if (nodes[i] instanceof StartNode) {
            StartNode startNode = (StartNode) nodes[i];
            List<Trigger> triggers = startNode.getTriggers();
            if (triggers != null) {
                for (Trigger trigger : triggers) {
                    if (trigger instanceof ConstraintTrigger) {
                        builder.append(createStartConstraintRule(process, startNode.getNodeContainer(), (ConstraintTrigger) trigger));
                    }
                }
            }
        } else if (nodes[i] instanceof NodeContainer) {
            generateRules(((NodeContainer) nodes[i]).getNodes(), process, builder);
            if (nodes[i] instanceof DynamicNode && "rule".equals(((DynamicNode) nodes[i]).getLanguage())) {
                DynamicNode dynamicNode = (DynamicNode) nodes[i];
                if (dynamicNode.getCompletionExpression() != null) {
                    builder.append(createAdHocCompletionRule(process, dynamicNode));
                }
                if (dynamicNode.getActivationExpression() != null && !dynamicNode.getActivationExpression().isEmpty()) {
                    builder.append(createAdHocActivationRule(process, dynamicNode));
                }
            }
        } else if (nodes[i] instanceof EventNode) {
            EventNode state = (EventNode) nodes[i];
            builder.append(createEventStateRule(process, state));
        }
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Constraint(org.jbpm.workflow.core.Constraint) Connection(org.kie.api.definition.process.Connection) StateNode(org.jbpm.workflow.core.node.StateNode) NodeContainer(org.kie.api.definition.process.NodeContainer) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) Constraint(org.jbpm.workflow.core.Constraint) EventNode(org.jbpm.workflow.core.node.EventNode) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) List(java.util.List) ArrayList(java.util.ArrayList) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) Split(org.jbpm.workflow.core.node.Split)

Example 15 with Split

use of org.jbpm.workflow.core.node.Split 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)

Aggregations

Split (org.jbpm.workflow.core.node.Split)18 Constraint (org.jbpm.workflow.core.Constraint)9 Join (org.jbpm.workflow.core.node.Join)8 EventNode (org.jbpm.workflow.core.node.EventNode)6 StartNode (org.jbpm.workflow.core.node.StartNode)6 ActionNode (org.jbpm.workflow.core.node.ActionNode)5 EndNode (org.jbpm.workflow.core.node.EndNode)5 FaultNode (org.jbpm.workflow.core.node.FaultNode)5 StateNode (org.jbpm.workflow.core.node.StateNode)5 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)5 Connection (org.kie.api.definition.process.Connection)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConnectionRef (org.jbpm.workflow.core.impl.ConnectionRef)4 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)4 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)4 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)4 MilestoneNode (org.jbpm.workflow.core.node.MilestoneNode)4 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)4 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)4