Search in sources :

Example 6 with EventNode

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

the class ProcessHandler method linkBoundaryEvents.

public static void linkBoundaryEvents(NodeContainer nodeContainer) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof EventNode) {
            final String attachedTo = (String) node.getMetaData().get("AttachedTo");
            if (attachedTo != null) {
                for (EventFilter filter : ((EventNode) node).getEventFilters()) {
                    String type = ((EventTypeFilter) filter).getType();
                    Node attachedNode = findNodeByIdOrUniqueIdInMetadata(nodeContainer, attachedTo, "Could not find node to attach to: " + attachedTo);
                    // 
                    if (!(attachedNode instanceof StateBasedNode) && !type.equals("Compensation")) {
                        throw new IllegalArgumentException("Boundary events are supported only on StateBasedNode, found node: " + attachedNode.getClass().getName() + " [" + attachedNode.getMetaData().get("UniqueId") + "]");
                    }
                    if (type.startsWith("Escalation")) {
                        linkBoundaryEscalationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Error-")) {
                        linkBoundaryErrorEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Timer-")) {
                        linkBoundaryTimerEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.equals("Compensation")) {
                        linkBoundaryCompensationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (node.getMetaData().get("SignalName") != null || type.startsWith("Message-")) {
                        linkBoundarySignalEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Condition-")) {
                        linkBoundaryConditionEvent(nodeContainer, node, attachedTo, attachedNode);
                    }
                }
            }
        }
    }
}
Also used : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) 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) EventFilter(org.jbpm.process.core.event.EventFilter)

Example 7 with EventNode

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

the class ProcessHandler method linkBoundaryErrorEvent.

private static void linkBoundaryErrorEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String errorCode = (String) node.getMetaData().get("ErrorEvent");
    boolean hasErrorCode = (Boolean) node.getMetaData().get("HasErrorEvent");
    String errorStructureRef = (String) node.getMetaData().get("ErrorStructureRef");
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    String variable = ((EventNode) node).getVariableName();
    DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Error-" + attachedTo + "-" + errorCode + "\", kcontext.getVariable(\"" + variable + "\"));");
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(hasErrorCode ? errorCode : null, exceptionHandler);
    if (errorStructureRef != null) {
        exceptionScope.setExceptionHandler(errorStructureRef, exceptionHandler);
    }
    List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
    if (actions == null) {
        actions = new ArrayList<DroolsAction>();
    }
    DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
    cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
    actions.add(cancelAction);
    ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) ContextContainer(org.jbpm.process.core.ContextContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 8 with EventNode

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

the class BoundaryEventHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    String attachedTo = element.getAttribute("attachedToRef");
    Attr cancelActivityAttr = element.getAttributeNode("cancelActivity");
    boolean cancelActivity = Boolean.parseBoolean(cancelActivityAttr.getValue());
    // determine type of event definition, so the correct type of node can be generated
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("escalationEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleEscalationNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("errorEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleErrorNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("timerEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleTimerNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("compensateEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleCompensationNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleSignalNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            handleConditionNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        } else if ("messageEventDefinition".equals(nodeName)) {
            handleMessageNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer) Attr(org.w3c.dom.Attr)

Example 9 with EventNode

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

the class BoundaryEventHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    EventNode eventNode = (EventNode) node;
    String attachedTo = (String) eventNode.getMetaData("AttachedTo");
    if (attachedTo != null) {
        String type = ((EventTypeFilter) eventNode.getEventFilters().get(0)).getType();
        if (type.startsWith("Escalation-")) {
            type = type.substring(attachedTo.length() + 12);
            boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            if (!cancelActivity) {
                xmlDump.append("cancelActivity=\"false\" ");
            }
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            xmlDump.append("      <escalationEventDefinition escalationRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" />" + EOL);
            endNode("boundaryEvent", xmlDump);
        } else if (type.startsWith("Error-")) {
            type = type.substring(attachedTo.length() + 7);
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            writeVariableName(eventNode, xmlDump);
            String errorId = getErrorIdForErrorCode(type, eventNode);
            xmlDump.append("      <errorEventDefinition errorRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(errorId) + "\" ");
            xmlDump.append("/>" + EOL);
            endNode("boundaryEvent", xmlDump);
        } else if (type.startsWith("Timer-")) {
            type = type.substring(attachedTo.length() + 7);
            boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            if (!cancelActivity) {
                xmlDump.append("cancelActivity=\"false\" ");
            }
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            String duration = (String) eventNode.getMetaData("TimeDuration");
            String cycle = (String) eventNode.getMetaData("TimeCycle");
            String date = (String) eventNode.getMetaData("TimeDate");
            if (duration != null && cycle != null) {
                String lang = (String) eventNode.getMetaData("Language");
                String language = "";
                if (lang != null && !lang.isEmpty()) {
                    language = "language=\"" + lang + "\" ";
                }
                xmlDump.append("      <timerEventDefinition>" + EOL + "        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(duration) + "</timeDuration>" + EOL + "        <timeCycle xsi:type=\"tFormalExpression\" " + language + ">" + XmlDumper.replaceIllegalChars(cycle) + "</timeCycle>" + EOL + "      </timerEventDefinition>" + EOL);
            } else if (duration != null) {
                xmlDump.append("      <timerEventDefinition>" + EOL + "        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(duration) + "</timeDuration>" + EOL + "      </timerEventDefinition>" + EOL);
            } else if (date != null) {
                xmlDump.append("      <timerEventDefinition>" + EOL + "        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(date) + "</timeDate>" + EOL + "      </timerEventDefinition>" + EOL);
            } else {
                String lang = (String) eventNode.getMetaData("Language");
                String language = "";
                if (lang != null && !lang.isEmpty()) {
                    language = "language=\"" + lang + "\" ";
                }
                xmlDump.append("      <timerEventDefinition>" + EOL + "        <timeCycle xsi:type=\"tFormalExpression\" " + language + ">" + XmlDumper.replaceIllegalChars(cycle) + "</timeCycle>" + EOL + "      </timerEventDefinition>" + EOL);
            }
            endNode("boundaryEvent", xmlDump);
        } else if (type.equals("Compensation")) {
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            xmlDump.append("      <compensateEventDefinition/>" + EOL);
            endNode("boundaryEvent", xmlDump);
        } else if (node.getMetaData().get("SignalName") != null) {
            boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            if (!cancelActivity) {
                xmlDump.append("cancelActivity=\"false\" ");
            }
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            xmlDump.append("      <signalEventDefinition signalRef=\"" + type + "\"/>" + EOL);
            endNode("boundaryEvent", xmlDump);
        } else if (node.getMetaData().get("Condition") != null) {
            boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            if (!cancelActivity) {
                xmlDump.append("cancelActivity=\"false\" ");
            }
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            xmlDump.append("      <conditionalEventDefinition>" + EOL);
            xmlDump.append("        <condition xsi:type=\"tFormalExpression\" language=\"http://www.jboss.org/drools/rule\">" + eventNode.getMetaData("Condition") + "</condition>" + EOL);
            xmlDump.append("      </conditionalEventDefinition>" + EOL);
            endNode("boundaryEvent", xmlDump);
        } else if (type.startsWith("Message-")) {
            type = type.substring(8);
            writeNode("boundaryEvent", eventNode, xmlDump, metaDataType);
            xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
            xmlDump.append(">" + EOL);
            writeExtensionElements(node, xmlDump);
            xmlDump.append("      <messageEventDefinition messageRef=\"" + type + "\"/>" + EOL);
            endNode("boundaryEvent", xmlDump);
        }
    }
}
Also used : BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter)

Example 10 with EventNode

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

the class RuleFlowProcessValidator method validateNodes.

private void validateNodes(Node[] nodes, List<ProcessValidationError> errors, RuleFlowProcess process) {
    String isForCompensation = "isForCompensation";
    for (int i = 0; i < nodes.length; i++) {
        final Node node = nodes[i];
        if (node instanceof StartNode) {
            final StartNode startNode = (StartNode) node;
            if (startNode.getTo() == null) {
                addErrorMessage(process, node, errors, "Start has no outgoing connection.");
            }
            if (startNode.getTimer() != null) {
                validateTimer(startNode.getTimer(), node, process, errors);
            }
        } else if (node instanceof EndNode) {
            final EndNode endNode = (EndNode) node;
            if (endNode.getFrom() == null) {
                addErrorMessage(process, node, errors, "End has no incoming connection.");
            }
            validateCompensationIntermediateOrEndEvent(endNode, process, errors);
        } else if (node instanceof RuleSetNode) {
            final RuleSetNode ruleSetNode = (RuleSetNode) node;
            if (ruleSetNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "RuleSet has no incoming connection.");
            }
            if (ruleSetNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                addErrorMessage(process, node, errors, "RuleSet has no outgoing connection.");
            }
            final String language = ruleSetNode.getLanguage();
            if (RuleSetNode.DRL_LANG.equals(language)) {
                final String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
                if (ruleFlowGroup == null || "".equals(ruleFlowGroup)) {
                    addErrorMessage(process, node, errors, "RuleSet (DRL) has no ruleflow-group.");
                }
            } else if (RuleSetNode.DMN_LANG.equals(language)) {
                final String namespace = ruleSetNode.getNamespace();
                if (namespace == null || "".equals(namespace)) {
                    addErrorMessage(process, node, errors, "RuleSet (DMN) has no namespace.");
                }
                final String model = ruleSetNode.getModel();
                if (model == null || "".equals(model)) {
                    addErrorMessage(process, node, errors, "RuleSet (DMN) has no model.");
                }
            } else {
                addErrorMessage(process, node, errors, "Unsupported rule language '" + language + "'");
            }
            if (ruleSetNode.getTimers() != null) {
                for (Timer timer : ruleSetNode.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                }
            }
        } else if (node instanceof Split) {
            final Split split = (Split) node;
            if (split.getType() == Split.TYPE_UNDEFINED) {
                addErrorMessage(process, node, errors, "Split has no type.");
            }
            if (split.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Split has no incoming connection.");
            }
            if (split.getDefaultOutgoingConnections().size() < 2) {
                addErrorMessage(process, node, errors, "Split does not have more than one outgoing connection: " + split.getOutgoingConnections().size() + ".");
            }
            if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
                for (final Iterator<Connection> it = split.getDefaultOutgoingConnections().iterator(); it.hasNext(); ) {
                    final Connection connection = it.next();
                    if (split.getConstraint(connection) == null && !split.isDefault(connection) || (!split.isDefault(connection) && (split.getConstraint(connection).getConstraint() == null || split.getConstraint(connection).getConstraint().trim().length() == 0))) {
                        addErrorMessage(process, node, errors, "Split does not have a constraint for " + connection.toString() + ".");
                    }
                }
            }
        } else if (node instanceof Join) {
            final Join join = (Join) node;
            if (join.getType() == Join.TYPE_UNDEFINED) {
                addErrorMessage(process, node, errors, "Join has no type.");
            }
            if (join.getDefaultIncomingConnections().size() < 2) {
                addErrorMessage(process, node, errors, "Join does not have more than one incoming connection: " + join.getIncomingConnections().size() + ".");
            }
            if (join.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                addErrorMessage(process, node, errors, "Join has no outgoing connection.");
            }
            if (join.getType() == Join.TYPE_N_OF_M) {
                String n = join.getN();
                if (!n.startsWith("#{") || !n.endsWith("}")) {
                    try {
                        new Integer(n);
                    } catch (NumberFormatException e) {
                        addErrorMessage(process, node, errors, "Join has illegal n value: " + n);
                    }
                }
            }
        } else if (node instanceof MilestoneNode) {
            final MilestoneNode milestone = (MilestoneNode) node;
            if (milestone.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Milestone has no incoming connection.");
            }
            if (milestone.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                addErrorMessage(process, node, errors, "Milestone has no outgoing connection.");
            }
            if (milestone.getConstraint() == null) {
                addErrorMessage(process, node, errors, "Milestone has no constraint.");
            }
            if (milestone.getTimers() != null) {
                for (Timer timer : milestone.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                }
            }
        } else if (node instanceof StateNode) {
            final StateNode stateNode = (StateNode) node;
            if (stateNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "State has no incoming connection");
            }
        } else if (node instanceof SubProcessNode) {
            final SubProcessNode subProcess = (SubProcessNode) node;
            if (subProcess.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "SubProcess has no incoming connection.");
            }
            if (subProcess.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                Object compensationObj = subProcess.getMetaData(isForCompensation);
                if (compensationObj == null || !((Boolean) compensationObj)) {
                    addErrorMessage(process, node, errors, "SubProcess has no outgoing connection.");
                }
            }
            if (subProcess.getProcessId() == null && subProcess.getProcessName() == null) {
                addErrorMessage(process, node, errors, "SubProcess has no process id.");
            }
            if (subProcess.getTimers() != null) {
                for (Timer timer : subProcess.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                }
            }
            if (!subProcess.isIndependent() && !subProcess.isWaitForCompletion()) {
                addErrorMessage(process, node, errors, "SubProcess you can only set " + "independent to 'false' only when 'Wait for completion' is set to true.");
            }
        } else if (node instanceof ActionNode) {
            final ActionNode actionNode = (ActionNode) node;
            if (actionNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Action has no incoming connection.");
            }
            if (actionNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                Object compensationObj = actionNode.getMetaData(isForCompensation);
                if (compensationObj == null || !((Boolean) compensationObj)) {
                    addErrorMessage(process, node, errors, "Action has no outgoing connection.");
                }
            }
            if (actionNode.getAction() == null) {
                addErrorMessage(process, node, errors, "Action has no action.");
            } else if (actionNode.getAction() instanceof DroolsConsequenceAction) {
                DroolsConsequenceAction droolsAction = (DroolsConsequenceAction) actionNode.getAction();
                String actionString = droolsAction.getConsequence();
                if (actionString == null) {
                    addErrorMessage(process, node, errors, "Action has empty action.");
                } else if ("mvel".equals(droolsAction.getDialect())) {
                    try {
                        ParserContext parserContext = new ParserContext();
                        // parserContext.setStrictTypeEnforcement(true);
                        ExpressionCompiler compiler = new ExpressionCompiler(actionString, parserContext);
                        compiler.setVerifying(true);
                        compiler.compile();
                        List<ErrorDetail> mvelErrors = parserContext.getErrorList();
                        if (mvelErrors != null) {
                            for (Iterator<ErrorDetail> iterator = mvelErrors.iterator(); iterator.hasNext(); ) {
                                ErrorDetail error = iterator.next();
                                addErrorMessage(process, node, errors, "Action has invalid action: " + error.getMessage() + ".");
                            }
                        }
                    } catch (Throwable t) {
                        addErrorMessage(process, node, errors, "Action has invalid action: " + t.getMessage() + ".");
                    }
                }
                // TODO: validation for "java" and "drools" scripts!
                validateCompensationIntermediateOrEndEvent(actionNode, process, errors);
            }
        } else if (node instanceof WorkItemNode) {
            final WorkItemNode workItemNode = (WorkItemNode) node;
            if (workItemNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Task has no incoming connection.");
            }
            if (workItemNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                Object compensationObj = workItemNode.getMetaData(isForCompensation);
                if (compensationObj == null || !((Boolean) compensationObj)) {
                    addErrorMessage(process, node, errors, "Task has no outgoing connection.");
                }
            }
            if (workItemNode.getWork() == null) {
                addErrorMessage(process, node, errors, "Task has no work specified.");
            } else {
                Work work = workItemNode.getWork();
                if (work.getName() == null || work.getName().trim().length() == 0) {
                    addErrorMessage(process, node, errors, "Task has no task type.");
                }
            }
            if (workItemNode.getTimers() != null) {
                for (Timer timer : workItemNode.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                }
            }
        } else if (node instanceof ForEachNode) {
            final ForEachNode forEachNode = (ForEachNode) node;
            String variableName = forEachNode.getVariableName();
            if (variableName == null || "".equals(variableName)) {
                addErrorMessage(process, node, errors, "ForEach has no variable name");
            }
            String collectionExpression = forEachNode.getCollectionExpression();
            if (collectionExpression == null || "".equals(collectionExpression)) {
                addErrorMessage(process, node, errors, "ForEach has no collection expression");
            }
            if (forEachNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "ForEach has no incoming connection");
            }
            if (forEachNode.getDefaultOutgoingConnections().size() == 0 && !acceptsNoOutgoingConnections(node)) {
                addErrorMessage(process, node, errors, "ForEach has no outgoing connection");
            }
            // TODO: check, if no linked connections, for start and end node(s)
            // if (forEachNode.getLinkedIncomingNode(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE) == null) {
            // errors.add(new ProcessValidationErrorImpl(process,
            // "ForEach node '%s' [%d] has no linked start node"));
            // }
            // if (forEachNode.getLinkedOutgoingNode(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE) == null) {
            // errors.add(new ProcessValidationErrorImpl(process,
            // "ForEach node '%s' [%d] has no linked end node"));
            // }
            validateNodes(forEachNode.getNodes(), errors, process);
        } else if (node instanceof DynamicNode) {
            final DynamicNode dynamicNode = (DynamicNode) node;
            if (dynamicNode.getDefaultIncomingConnections().size() == 0 && !acceptsNoIncomingConnections(dynamicNode)) {
                addErrorMessage(process, node, errors, "Dynamic has no incoming connection");
            }
            if (dynamicNode.getDefaultOutgoingConnections().size() == 0 && !acceptsNoOutgoingConnections(dynamicNode)) {
                addErrorMessage(process, node, errors, "Dynamic has no outgoing connection");
            }
            if ("".equals(dynamicNode.getCompletionExpression()) && !dynamicNode.isAutoComplete()) {
                addErrorMessage(process, node, errors, "Dynamic has no completion condition set");
            }
            validateNodes(dynamicNode.getNodes(), errors, process);
        } else if (node instanceof CompositeNode) {
            final CompositeNode compositeNode = (CompositeNode) node;
            for (Map.Entry<String, NodeAndType> inType : compositeNode.getLinkedIncomingNodes().entrySet()) {
                if (compositeNode.getIncomingConnections(inType.getKey()).size() == 0 && !acceptsNoIncomingConnections(node)) {
                    addErrorMessage(process, node, errors, "Composite has no incoming connection for type " + inType.getKey());
                }
                if (inType.getValue().getNode() == null && !acceptsNoOutgoingConnections(node)) {
                    addErrorMessage(process, node, errors, "Composite has invalid linked incoming node for type " + inType.getKey());
                }
            }
            for (Map.Entry<String, NodeAndType> outType : compositeNode.getLinkedOutgoingNodes().entrySet()) {
                if (compositeNode.getOutgoingConnections(outType.getKey()).size() == 0) {
                    addErrorMessage(process, node, errors, "Composite has no outgoing connection for type " + outType.getKey());
                }
                if (outType.getValue().getNode() == null) {
                    addErrorMessage(process, node, errors, "Composite has invalid linked outgoing node for type " + outType.getKey());
                }
            }
            if (compositeNode instanceof EventSubProcessNode) {
                if (compositeNode.getIncomingConnections().size() > 0) {
                    addErrorMessage(process, node, errors, "Event subprocess is not allowed to have any incoming connections.");
                }
                if (compositeNode.getOutgoingConnections().size() > 0) {
                    addErrorMessage(process, node, errors, "Event subprocess is not allowed to have any outgoing connections.");
                }
                Node[] eventSubProcessNodes = compositeNode.getNodes();
                int startEventCount = 0;
                for (int j = 0; j < eventSubProcessNodes.length; ++j) {
                    if (eventSubProcessNodes[j] instanceof StartNode) {
                        StartNode startNode = (StartNode) eventSubProcessNodes[j];
                        if (++startEventCount == 2) {
                            addErrorMessage(process, compositeNode, errors, "Event subprocess is not allowed to have more than one start node.");
                        }
                        if (startNode.getTriggers() == null || startNode.getTriggers().isEmpty()) {
                            addErrorMessage(process, startNode, errors, "Start in Event SubProcess '" + compositeNode.getName() + "' [" + compositeNode.getId() + "] must contain a trigger (event definition).");
                        }
                    }
                }
            } else {
                Boolean isForCompensationObject = (Boolean) compositeNode.getMetaData("isForCompensation");
                if (compositeNode.getIncomingConnections().size() == 0 && !Boolean.TRUE.equals(isForCompensationObject)) {
                    addErrorMessage(process, node, errors, "Embedded subprocess does not have incoming connection.");
                }
                if (compositeNode.getOutgoingConnections().size() == 0 && !Boolean.TRUE.equals(isForCompensationObject)) {
                    addErrorMessage(process, node, errors, "Embedded subprocess does not have outgoing connection.");
                }
            }
            if (compositeNode.getTimers() != null) {
                for (Timer timer : compositeNode.getTimers().keySet()) {
                    validateTimer(timer, node, process, errors);
                }
            }
            validateNodes(compositeNode.getNodes(), errors, process);
        } else if (node instanceof EventNode) {
            final EventNode eventNode = (EventNode) node;
            if (eventNode.getEventFilters().size() == 0) {
                addErrorMessage(process, node, errors, "Event should specify an event type");
            }
            if (eventNode.getDefaultOutgoingConnections().size() == 0) {
                addErrorMessage(process, node, errors, "Event has no outgoing connection");
            } else {
                List<EventFilter> eventFilters = eventNode.getEventFilters();
                boolean compensationHandler = false;
                for (EventFilter eventFilter : eventFilters) {
                    if (((EventTypeFilter) eventFilter).getType().startsWith("Compensation")) {
                        compensationHandler = true;
                        break;
                    }
                }
                if (compensationHandler && eventNode instanceof BoundaryEventNode) {
                    Connection connection = eventNode.getDefaultOutgoingConnections().get(0);
                    Boolean isAssociation = (Boolean) connection.getMetaData().get("association");
                    if (isAssociation == null) {
                        isAssociation = false;
                    }
                    if (!(eventNode.getDefaultOutgoingConnections().size() == 1 && connection != null && isAssociation)) {
                        addErrorMessage(process, node, errors, "Compensation Boundary Event is only allowed to have 1 association to 1 compensation activity.");
                    }
                }
            }
        } else if (node instanceof FaultNode) {
            final FaultNode faultNode = (FaultNode) node;
            if (faultNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Fault has no incoming connection.");
            }
            if (faultNode.getFaultName() == null) {
                addErrorMessage(process, node, errors, "Fault has no fault name.");
            }
        } else if (node instanceof TimerNode) {
            TimerNode timerNode = (TimerNode) node;
            if (timerNode.getFrom() == null && !acceptsNoIncomingConnections(node)) {
                addErrorMessage(process, node, errors, "Timer has no incoming connection.");
            }
            if (timerNode.getTo() == null && !acceptsNoOutgoingConnections(node)) {
                addErrorMessage(process, node, errors, "Timer has no outgoing connection.");
            }
            if (timerNode.getTimer() == null) {
                addErrorMessage(process, node, errors, "Timer has no timer specified.");
            } else {
                validateTimer(timerNode.getTimer(), node, process, errors);
            }
        } else if (node instanceof CatchLinkNode) {
        // catchlink validation here, there also are validations in
        // ProcessHandler regarding connection issues
        } else if (node instanceof ThrowLinkNode) {
        // throw validation here, there also are validations in
        // ProcessHandler regarding connection issues
        } else {
            errors.add(new ProcessValidationErrorImpl(process, "Unknown node type '" + node.getClass().getName() + "'"));
        }
    }
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) NodeAndType(org.jbpm.workflow.core.node.CompositeNode.NodeAndType) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) 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) StateNode(org.jbpm.workflow.core.node.StateNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) ErrorDetail(org.mvel2.ErrorDetail) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Iterator(java.util.Iterator) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TimerNode(org.jbpm.workflow.core.node.TimerNode) StartNode(org.jbpm.workflow.core.node.StartNode) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) Connection(org.kie.api.definition.process.Connection) Join(org.jbpm.workflow.core.node.Join) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) ThrowLinkNode(org.jbpm.workflow.core.node.ThrowLinkNode) EventFilter(org.jbpm.process.core.event.EventFilter) FaultNode(org.jbpm.workflow.core.node.FaultNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EndNode(org.jbpm.workflow.core.node.EndNode) Timer(org.jbpm.process.core.timer.Timer) ProcessValidationErrorImpl(org.jbpm.process.core.validation.impl.ProcessValidationErrorImpl) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) Split(org.jbpm.workflow.core.node.Split) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

EventNode (org.jbpm.workflow.core.node.EventNode)36 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)21 ActionNode (org.jbpm.workflow.core.node.ActionNode)21 EndNode (org.jbpm.workflow.core.node.EndNode)21 StartNode (org.jbpm.workflow.core.node.StartNode)21 ArrayList (java.util.ArrayList)18 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)16 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)14 DroolsAction (org.jbpm.workflow.core.DroolsAction)13 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)13 FaultNode (org.jbpm.workflow.core.node.FaultNode)12 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)12 Node (org.kie.api.definition.process.Node)12 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)11 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)11 StateNode (org.jbpm.workflow.core.node.StateNode)11 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)10 EventFilter (org.jbpm.process.core.event.EventFilter)9 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)9 Join (org.jbpm.workflow.core.node.Join)9