Search in sources :

Example 36 with StartNode

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

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

the class ChecklistItemFactory method getPendingChecklistItems.

private static void getPendingChecklistItems(NodeContainer container, List<ChecklistItem> result, String processId) {
    for (Node node : container.getNodes()) {
        if (node instanceof HumanTaskNode) {
            Work workItem = ((HumanTaskNode) node).getWork();
            int priority = 0;
            String priorityString = (String) workItem.getParameter("Priority");
            if (priorityString != null) {
                try {
                    priority = new Integer(priorityString);
                } catch (NumberFormatException e) {
                // Do nothing
                }
            }
            String actorId = (String) workItem.getParameter("ActorId");
            if (actorId != null && actorId.trim().length() == 0) {
                actorId = null;
            }
            String groupId = (String) workItem.getParameter("GroupId");
            if (groupId != null && groupId.trim().length() == 0) {
                groupId = null;
            }
            String actors = null;
            if (actorId == null) {
                if (groupId == null) {
                    actors = "";
                } else {
                    actors = groupId;
                }
            } else {
                if (groupId == null) {
                    actors = actorId;
                } else {
                    actors = actorId + "," + groupId;
                }
            }
            Status status = Status.Pending;
            if (((HumanTaskNode) node).getDefaultIncomingConnections().size() == 0) {
                status = Status.Optional;
            }
            result.add(createChecklistItem((String) workItem.getParameter("TaskName"), "HumanTaskNode", actors, (String) workItem.getParameter("Comment"), priority, processId, status));
        } else if (node instanceof NodeContainer) {
            getPendingChecklistItems((NodeContainer) node, result, processId);
        } else {
            String docs = (String) node.getMetaData().get("Documentation");
            if (docs != null) {
                int position = docs.indexOf("OrderingNb=");
                if (position >= 0) {
                    int end = docs.indexOf(";", position + 1);
                    String orderingNumber = docs.substring(position + 11, end);
                    Status status = Status.Pending;
                    if (((NodeImpl) node).getDefaultIncomingConnections().size() == 0 && !(node instanceof StartNode)) {
                        status = Status.Optional;
                    }
                    result.add(createChecklistItem(node.getName(), node.getClass().getSimpleName(), "", orderingNumber, 0, processId, status));
                }
            }
        }
    }
}
Also used : Status(org.jbpm.examples.checklist.ChecklistItem.Status) StartNode(org.jbpm.workflow.core.node.StartNode) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) StartNode(org.jbpm.workflow.core.node.StartNode) Node(org.kie.api.definition.process.Node) Work(org.jbpm.process.core.Work) NodeContainer(org.kie.api.definition.process.NodeContainer) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 38 with StartNode

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

the class ProcessRuntimeImpl method initStartTimers.

public void initStartTimers() {
    KieBase kbase = kruntime.getKieBase();
    Collection<Process> processes = kbase.getProcesses();
    for (Process process : processes) {
        RuleFlowProcess p = (RuleFlowProcess) process;
        List<StartNode> startNodes = p.getTimerStart();
        if (startNodes != null && !startNodes.isEmpty()) {
            kruntime.queueWorkingMemoryAction(new RegisterStartTimerAction(p.getId(), startNodes, this.timerManager));
        }
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) KieBase(org.kie.api.KieBase) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess)

Example 39 with StartNode

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

the class ProcessRuntimeImpl method initProcessEventListener.

private void initProcessEventListener(Process process) {
    if (process instanceof RuleFlowProcess) {
        for (Node node : ((RuleFlowProcess) process).getNodes()) {
            if (node instanceof StartNode) {
                StartNode startNode = (StartNode) node;
                if (startNode != null) {
                    List<Trigger> triggers = startNode.getTriggers();
                    if (triggers != null) {
                        for (Trigger trigger : triggers) {
                            if (trigger instanceof EventTrigger) {
                                final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                                String type = null;
                                for (EventFilter filter : filters) {
                                    if (filter instanceof EventTypeFilter) {
                                        type = ((EventTypeFilter) filter).getType();
                                    }
                                }
                                StartProcessEventListener listener = new StartProcessEventListener(process.getId(), filters, trigger.getInMappings(), startNode.getEventTransformer());
                                signalManager.addEventListener(type, listener);
                                ((RuleFlowProcess) process).getRuntimeMetaData().put("StartProcessEventType", type);
                                ((RuleFlowProcess) process).getRuntimeMetaData().put("StartProcessEventListener", listener);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) StartNode(org.jbpm.workflow.core.node.StartNode) Node(org.kie.api.definition.process.Node) EventFilter(org.jbpm.process.core.event.EventFilter) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 40 with StartNode

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

the class RuleFlowProcessValidator method checkAllNodesConnectedToStart.

private void checkAllNodesConnectedToStart(final NodeContainer container, boolean isDynamic, final List<ProcessValidationError> errors, RuleFlowProcess process) {
    final Map<Node, Boolean> processNodes = new HashMap<Node, Boolean>();
    final Node[] nodes;
    if (container instanceof CompositeNode) {
        nodes = ((CompositeNode) container).internalGetNodes();
    } else {
        nodes = container.getNodes();
    }
    List<Node> eventNodes = new ArrayList<Node>();
    List<CompositeNode> compositeNodes = new ArrayList<CompositeNode>();
    for (int i = 0; i < nodes.length; i++) {
        final Node node = nodes[i];
        processNodes.put(node, Boolean.FALSE);
        if (node instanceof EventNode) {
            eventNodes.add(node);
        }
        if (node instanceof CompositeNode) {
            compositeNodes.add((CompositeNode) node);
        }
    }
    if (isDynamic) {
        for (Node node : nodes) {
            if (node.getIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE).isEmpty()) {
                processNode(node, processNodes);
            }
        }
    } else {
        final List<Node> start = RuleFlowProcess.getStartNodes(nodes);
        if (start != null) {
            for (Node s : start) {
                processNode(s, processNodes);
            }
        }
        if (container instanceof CompositeNode) {
            for (CompositeNode.NodeAndType nodeAndTypes : ((CompositeNode) container).getLinkedIncomingNodes().values()) {
                processNode(nodeAndTypes.getNode(), processNodes);
            }
        }
    }
    for (Node eventNode : eventNodes) {
        processNode(eventNode, processNodes);
    }
    for (CompositeNode compositeNode : compositeNodes) {
        checkAllNodesConnectedToStart(compositeNode, compositeNode instanceof DynamicNode, errors, process);
    }
    for (final Iterator<Node> it = processNodes.keySet().iterator(); it.hasNext(); ) {
        final Node node = it.next();
        if (Boolean.FALSE.equals(processNodes.get(node)) && !(node instanceof StartNode) && !(node instanceof EventSubProcessNode)) {
            addErrorMessage(process, node, errors, "Has no connection to the start node.");
        }
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) HashMap(java.util.HashMap) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) 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) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) ForEachJoinNode(org.jbpm.workflow.core.node.ForEachNode.ForEachJoinNode) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) ThrowLinkNode(org.jbpm.workflow.core.node.ThrowLinkNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) TimerNode(org.jbpm.workflow.core.node.TimerNode) 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) ForEachSplitNode(org.jbpm.workflow.core.node.ForEachNode.ForEachSplitNode) ArrayList(java.util.ArrayList) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) NodeAndType(org.jbpm.workflow.core.node.CompositeNode.NodeAndType) DynamicNode(org.jbpm.workflow.core.node.DynamicNode)

Aggregations

StartNode (org.jbpm.workflow.core.node.StartNode)47 EndNode (org.jbpm.workflow.core.node.EndNode)34 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)32 ActionNode (org.jbpm.workflow.core.node.ActionNode)30 ArrayList (java.util.ArrayList)25 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)24 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)18 Test (org.junit.Test)18 DroolsAction (org.jbpm.workflow.core.DroolsAction)17 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)17 Action (org.jbpm.process.instance.impl.Action)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)16 EventNode (org.jbpm.workflow.core.node.EventNode)16 KieSession (org.kie.api.runtime.KieSession)16 ProcessContext (org.kie.api.runtime.process.ProcessContext)16 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)15 Variable (org.jbpm.process.core.context.variable.Variable)14 Work (org.jbpm.process.core.Work)11 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)11