Search in sources :

Example 16 with Connection

use of org.kie.api.definition.process.Connection 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 17 with Connection

use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.

the class StateNodeInstance method activationCreated.

public void activationCreated(MatchCreatedEvent event) {
    Connection selected = null;
    for (Connection connection : getNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
        Constraint constraint = getStateNode().getConstraint(connection);
        if (constraint != null) {
            String constraintName = getActivationEventType() + "-" + connection.getTo().getId() + "-" + connection.getToType();
            if (constraintName.equals(event.getMatch().getRule().getName()) && checkProcessInstance((Activation) event.getMatch())) {
                selected = connection;
            }
        }
    }
    if (selected != null) {
        removeEventListeners();
        ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
        triggerConnection(selected);
    }
}
Also used : NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) Constraint(org.jbpm.workflow.core.Constraint) Connection(org.kie.api.definition.process.Connection) Activation(org.drools.core.spi.Activation)

Example 18 with Connection

use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.

the class StateNodeInstance method internalTrigger.

public void internalTrigger(NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    // TODO: composite states trigger
    StateNode stateNode = getStateNode();
    Connection selected = null;
    int priority = Integer.MAX_VALUE;
    for (Connection connection : stateNode.getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
        Constraint constraint = stateNode.getConstraint(connection);
        if (constraint != null && constraint.getPriority() < priority) {
            String rule = "RuleFlowStateNode-" + getProcessInstance().getProcessId() + "-" + getStateNode().getUniqueId() + "-" + connection.getTo().getId() + "-" + connection.getToType();
            boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", rule, getProcessInstance().getId());
            if (isActive) {
                selected = connection;
                priority = constraint.getPriority();
            }
        }
    }
    if (selected != null) {
        ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
        triggerConnection(selected);
    } else {
        addTriggerListener();
        addActivationListener();
    }
}
Also used : InternalAgenda(org.drools.core.common.InternalAgenda) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) Constraint(org.jbpm.workflow.core.Constraint) StateNode(org.jbpm.workflow.core.node.StateNode) Connection(org.kie.api.definition.process.Connection) Constraint(org.jbpm.workflow.core.Constraint)

Example 19 with Connection

use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.

the class StateNodeInstance method signalEvent.

public void signalEvent(String type, Object event) {
    if ("signal".equals(type)) {
        if (event instanceof String) {
            for (Connection connection : getStateNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
                boolean selected = false;
                Constraint constraint = getStateNode().getConstraint(connection);
                if (constraint == null) {
                    if (((String) event).equals(connection.getTo().getName())) {
                        selected = true;
                    }
                } else if (((String) event).equals(constraint.getName())) {
                    selected = true;
                }
                if (selected) {
                    triggerEvent(ExtendedNodeImpl.EVENT_NODE_EXIT);
                    removeEventListeners();
                    ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                    triggerConnection(connection);
                    return;
                }
            }
        }
    } else if (getActivationEventType().equals(type)) {
        if (event instanceof MatchCreatedEvent) {
            activationCreated((MatchCreatedEvent) event);
        }
    } else {
        super.signalEvent(type, event);
    }
}
Also used : NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) Constraint(org.jbpm.workflow.core.Constraint) Connection(org.kie.api.definition.process.Connection) MatchCreatedEvent(org.kie.api.event.rule.MatchCreatedEvent)

Example 20 with Connection

use of org.kie.api.definition.process.Connection in project jbpm by kiegroup.

the class NodeInstanceImpl method trigger.

public final void trigger(NodeInstance from, String type) {
    boolean hidden = false;
    if (getNode().getMetaData().get("hidden") != null) {
        hidden = true;
    }
    if (from != null) {
        int level = ((org.jbpm.workflow.instance.NodeInstance) from).getLevel();
        ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(level);
        Collection<Connection> incoming = getNode().getIncomingConnections(type);
        for (Connection conn : incoming) {
            if (conn.getFrom().getId() == from.getNodeId()) {
                this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId"));
                break;
            }
        }
    }
    configureSla();
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
    }
    try {
        getExecutionErrorHandler().processing(this);
        internalTrigger(from, type);
    } catch (WorkflowRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new WorkflowRuntimeException(this, getProcessInstance(), e);
    }
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) Connection(org.kie.api.definition.process.Connection) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) ActionNodeInstance(org.jbpm.workflow.instance.node.ActionNodeInstance) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException)

Aggregations

Connection (org.kie.api.definition.process.Connection)24 ArrayList (java.util.ArrayList)10 Node (org.kie.api.definition.process.Node)10 Map (java.util.Map)6 Constraint (org.jbpm.workflow.core.Constraint)6 HashMap (java.util.HashMap)5 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)5 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)5 EventNode (org.jbpm.workflow.core.node.EventNode)5 Split (org.jbpm.workflow.core.node.Split)5 StartNode (org.jbpm.workflow.core.node.StartNode)5 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 EndNode (org.jbpm.workflow.core.node.EndNode)4 List (java.util.List)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)3 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)3 NodeInstance (org.kie.api.runtime.process.NodeInstance)3