Search in sources :

Example 11 with FaultNode

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

the class XmlBPMNProcessDumper method visitNodesDi.

private void visitNodesDi(Node[] nodes, StringBuilder xmlDump) {
    for (Node node : nodes) {
        Integer x = (Integer) node.getMetaData().get("x");
        Integer y = (Integer) node.getMetaData().get("y");
        Integer width = (Integer) node.getMetaData().get("width");
        Integer height = (Integer) node.getMetaData().get("height");
        if (x == null) {
            x = 0;
        }
        if (y == null) {
            y = 0;
        }
        if (width == null) {
            width = 48;
        }
        if (height == null) {
            height = 48;
        }
        if (node instanceof StartNode || node instanceof EndNode || node instanceof EventNode || node instanceof FaultNode) {
            int offsetX = (int) ((width - 48) / 2);
            width = 48;
            x = x + offsetX;
            int offsetY = (int) ((height - 48) / 2);
            y = y + offsetY;
            height = 48;
        } else if (node instanceof Join || node instanceof Split) {
            int offsetX = (int) ((width - 48) / 2);
            width = 48;
            x = x + offsetX;
            int offsetY = (int) ((height - 48) / 2);
            y = y + offsetY;
            height = 48;
        }
        int parentOffsetX = 0;
        int parentOffsetY = 0;
        NodeContainer nodeContainer = node.getNodeContainer();
        while (nodeContainer instanceof CompositeNode) {
            CompositeNode parent = (CompositeNode) nodeContainer;
            Integer parentX = (Integer) parent.getMetaData().get("x");
            if (parentX != null) {
                parentOffsetX += parentX;
            }
            Integer parentY = (Integer) parent.getMetaData().get("y");
            if (parentY != null) {
                parentOffsetY += (Integer) parent.getMetaData().get("y");
            }
            nodeContainer = parent.getNodeContainer();
        }
        x += parentOffsetX;
        y += parentOffsetY;
        xmlDump.append("      <bpmndi:BPMNShape bpmnElement=\"" + getUniqueNodeId(node) + "\" >" + EOL + "        <dc:Bounds x=\"" + x + "\" " + "y=\"" + y + "\" " + "width=\"" + width + "\" " + "height=\"" + height + "\" />" + EOL + "      </bpmndi:BPMNShape>" + EOL);
        if (node instanceof CompositeNode) {
            visitNodesDi(((CompositeNode) node).getNodes(), xmlDump);
        }
    }
}
Also used : FaultNode(org.jbpm.workflow.core.node.FaultNode) StartNode(org.jbpm.workflow.core.node.StartNode) EventNode(org.jbpm.workflow.core.node.EventNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EndNode(org.jbpm.workflow.core.node.EndNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) 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) Join(org.jbpm.workflow.core.node.Join) NodeContainer(org.kie.api.definition.process.NodeContainer) Split(org.jbpm.workflow.core.node.Split) Constraint(org.jbpm.workflow.core.Constraint)

Example 12 with FaultNode

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

the class ProcessHandler method postProcessNodes.

private void postProcessNodes(RuleFlowProcess process, NodeContainer container) {
    List<String> eventSubProcessHandlers = new ArrayList<String>();
    for (Node node : container.getNodes()) {
        if (node instanceof StateNode) {
            StateNode stateNode = (StateNode) node;
            String condition = (String) stateNode.getMetaData("Condition");
            Constraint constraint = new ConstraintImpl();
            constraint.setConstraint(condition);
            constraint.setType("rule");
            for (org.kie.api.definition.process.Connection connection : stateNode.getDefaultOutgoingConnections()) {
                stateNode.setConstraint(connection, constraint);
            }
        } else if (node instanceof NodeContainer) {
            // prepare event sub process
            if (node instanceof EventSubProcessNode) {
                EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
                Node[] nodes = eventSubProcessNode.getNodes();
                for (Node subNode : nodes) {
                    // avoids cyclomatic complexity
                    if (subNode == null || !(subNode instanceof StartNode)) {
                        continue;
                    }
                    List<Trigger> triggers = ((StartNode) subNode).getTriggers();
                    if (triggers == null) {
                        continue;
                    }
                    for (Trigger trigger : triggers) {
                        if (trigger instanceof EventTrigger) {
                            final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                            for (EventFilter filter : filters) {
                                if (filter instanceof EventTypeFilter) {
                                    eventSubProcessNode.addEvent((EventTypeFilter) filter);
                                    String type = ((EventTypeFilter) filter).getType();
                                    if (type.startsWith("Error-") || type.startsWith("Escalation")) {
                                        String faultCode = (String) subNode.getMetaData().get("FaultCode");
                                        String replaceRegExp = "Error-|Escalation-";
                                        final String signalType = type;
                                        ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getNodeContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
                                        if (exceptionScope == null) {
                                            exceptionScope = new ExceptionScope();
                                            ((ContextContainer) eventSubProcessNode.getNodeContainer()).addContext(exceptionScope);
                                            ((ContextContainer) eventSubProcessNode.getNodeContainer()).setDefaultContext(exceptionScope);
                                        }
                                        String faultVariable = null;
                                        if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
                                            faultVariable = trigger.getInAssociations().get(0).getTarget();
                                        }
                                        ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
                                        DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + signalType + "\", " + (faultVariable == null ? "null" : "kcontext.getVariable(\"" + faultVariable + "\")") + ");");
                                        exceptionHandler.setAction(action);
                                        exceptionHandler.setFaultVariable(faultVariable);
                                        if (faultCode != null) {
                                            String trimmedType = type.replaceFirst(replaceRegExp, "");
                                            exceptionScope.setExceptionHandler(trimmedType, exceptionHandler);
                                            eventSubProcessHandlers.add(trimmedType);
                                        } else {
                                            exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
                                        }
                                    } else if (type.equals("Compensation")) {
                                        // 1. Find the parent sub-process to this event sub-process
                                        NodeContainer parentSubProcess;
                                        NodeContainer subProcess = eventSubProcessNode.getNodeContainer();
                                        Object isForCompensationObj = eventSubProcessNode.getMetaData("isForCompensation");
                                        if (isForCompensationObj == null) {
                                            eventSubProcessNode.setMetaData("isForCompensation", true);
                                            logger.warn("Overriding empty or false value of \"isForCompensation\" attribute on Event Sub-Process [" + eventSubProcessNode.getMetaData("UniqueId") + "] and setting it to true.");
                                        }
                                        if (subProcess instanceof RuleFlowProcess) {
                                            // ..how do you expect to signal compensation on the completed process (instance)?!?
                                            throw new IllegalArgumentException("Compensation Event Sub-Processes at the process level are not supported.");
                                        }
                                        parentSubProcess = ((Node) subProcess).getNodeContainer();
                                        // 2. The event filter (never fires, purely for dumping purposes) has already been added
                                        // 3. Add compensation scope
                                        String compensationHandlerId = (String) ((CompositeNode) subProcess).getMetaData("UniqueId");
                                        addCompensationScope(process, eventSubProcessNode, parentSubProcess, compensationHandlerId);
                                    }
                                }
                            }
                        } else if (trigger instanceof ConstraintTrigger) {
                            ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
                            if (constraintTrigger.getConstraint() != null) {
                                String processId = ((RuleFlowProcess) container).getId();
                                String type = "RuleFlowStateEventSubProcess-Event-" + processId + "-" + eventSubProcessNode.getUniqueId();
                                EventTypeFilter eventTypeFilter = new EventTypeFilter();
                                eventTypeFilter.setType(type);
                                eventSubProcessNode.addEvent(eventTypeFilter);
                            }
                        }
                    }
                }
            // for( Node subNode : nodes)
            }
            postProcessNodes(process, (NodeContainer) node);
        } else if (node instanceof EndNode) {
            handleIntermediateOrEndThrowCompensationEvent((EndNode) node);
        } else if (node instanceof ActionNode) {
            handleIntermediateOrEndThrowCompensationEvent((ActionNode) node);
        } else if (node instanceof EventNode) {
            final EventNode eventNode = (EventNode) node;
            if (!(eventNode instanceof BoundaryEventNode) && eventNode.getDefaultIncomingConnections().size() == 0) {
                throw new IllegalArgumentException("Event node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection");
            }
        }
    }
    // process fault node to disable termnate parent if there is event subprocess handler
    for (Node node : container.getNodes()) {
        if (node instanceof FaultNode) {
            FaultNode faultNode = (FaultNode) node;
            if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
                faultNode.setTerminateParent(false);
            }
        }
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Constraint(org.jbpm.workflow.core.Constraint) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) 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) ArrayList(java.util.ArrayList) StateNode(org.jbpm.workflow.core.node.StateNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.kie.api.definition.process.NodeContainer) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) FaultNode(org.jbpm.workflow.core.node.FaultNode) ContextContainer(org.jbpm.process.core.ContextContainer) EndNode(org.jbpm.workflow.core.node.EndNode)

Aggregations

FaultNode (org.jbpm.workflow.core.node.FaultNode)12 EndNode (org.jbpm.workflow.core.node.EndNode)7 ActionNode (org.jbpm.workflow.core.node.ActionNode)6 EventNode (org.jbpm.workflow.core.node.EventNode)6 StartNode (org.jbpm.workflow.core.node.StartNode)6 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)5 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)5 ArrayList (java.util.ArrayList)4 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)4 Join (org.jbpm.workflow.core.node.Join)4 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)4 Split (org.jbpm.workflow.core.node.Split)4 StateNode (org.jbpm.workflow.core.node.StateNode)4 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)4 List (java.util.List)3 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)3 Node (org.jbpm.workflow.core.Node)3