Search in sources :

Example 11 with CompositeContextNode

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

the class CompositeNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    super.writeNode(getNodeName(), node, xmlDump, includeMeta);
    CompositeNode compositeNode = (CompositeNode) node;
    writeAttributes(compositeNode, xmlDump, includeMeta);
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(compositeNode, xmlDump);
    }
    for (String eventType : compositeNode.getActionTypes()) {
        writeActions(eventType, compositeNode.getActions(eventType), xmlDump);
    }
    writeTimers(compositeNode.getTimers(), xmlDump);
    if (compositeNode instanceof CompositeContextNode) {
        VariableScope variableScope = (VariableScope) ((CompositeContextNode) compositeNode).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope != null) {
            List<Variable> variables = variableScope.getVariables();
            XmlWorkflowProcessDumper.visitVariables(variables, xmlDump);
        }
        ExceptionScope exceptionScope = (ExceptionScope) ((CompositeContextNode) compositeNode).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
        if (exceptionScope != null) {
            XmlWorkflowProcessDumper.visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
        }
    }
    List<Node> subNodes = getSubNodes(compositeNode);
    xmlDump.append("      <nodes>" + EOL);
    for (Node subNode : subNodes) {
        XmlRuleFlowProcessDumper.INSTANCE.visitNode(subNode, xmlDump, includeMeta);
    }
    xmlDump.append("      </nodes>" + EOL);
    List<Connection> connections = getSubConnections(compositeNode);
    xmlDump.append("      <connections>" + EOL);
    for (Connection connection : connections) {
        XmlRuleFlowProcessDumper.INSTANCE.visitConnection(connection, xmlDump, includeMeta);
    }
    xmlDump.append("      </connections>" + EOL);
    Map<String, CompositeNode.NodeAndType> inPorts = getInPorts(compositeNode);
    xmlDump.append("      <in-ports>" + EOL);
    for (Map.Entry<String, CompositeNode.NodeAndType> entry : inPorts.entrySet()) {
        xmlDump.append("        <in-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeInType=\"" + entry.getValue().getType() + "\" />" + EOL);
    }
    xmlDump.append("      </in-ports>" + EOL);
    Map<String, CompositeNode.NodeAndType> outPorts = getOutPorts(compositeNode);
    xmlDump.append("      <out-ports>" + EOL);
    for (Map.Entry<String, CompositeNode.NodeAndType> entry : outPorts.entrySet()) {
        xmlDump.append("        <out-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeOutType=\"" + entry.getValue().getType() + "\" />" + EOL);
    }
    xmlDump.append("      </out-ports>" + EOL);
    endNode(getNodeName(), xmlDump);
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Connection(org.kie.api.definition.process.Connection) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Map(java.util.Map) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 12 with CompositeContextNode

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

the class SubProcessHandler 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();
    // determine type of event definition, so the correct type of node can be generated
    boolean found = false;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            Boolean isAsync = Boolean.parseBoolean((String) node.getMetaData().get("customAsync"));
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            forEachNode.setName(node.getName());
            forEachNode.setAutoComplete(((CompositeContextNode) node).isAutoComplete());
            for (org.kie.api.definition.process.Node subNode : ((CompositeContextNode) node).getNodes()) {
                forEachNode.addNode(subNode);
            }
            forEachNode.setMetaData("UniqueId", ((CompositeContextNode) node).getMetaData("UniqueId"));
            forEachNode.setMetaData(ProcessHandler.CONNECTIONS, ((CompositeContextNode) node).getMetaData(ProcessHandler.CONNECTIONS));
            VariableScope v = (VariableScope) ((CompositeContextNode) node).getDefaultContext(VariableScope.VARIABLE_SCOPE);
            ((VariableScope) ((CompositeContextNode) forEachNode.internalGetNode(2)).getDefaultContext(VariableScope.VARIABLE_SCOPE)).setVariables(v.getVariables());
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser, isAsync);
            found = true;
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (!found) {
        handleCompositeContextNode(node, element, uri, localName, parser);
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Element(org.w3c.dom.Element) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 13 with CompositeContextNode

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

the class ProcessHandler method checkBoundaryEventCompensationHandler.

/**
 * This logic belongs in {@link RuleFlowProcessValidator} -- except that {@link Association}s are a jbpm-bpmn2 class,
 * and {@link RuleFlowProcessValidator} is a jbpm-flow class..
 * </p>
 * Maybe we should have a BPMNProcessValidator class?
 *
 * @param association The association to check.
 * @param source The source of the association.
 * @param target The target of the association.
 */
private static void checkBoundaryEventCompensationHandler(Association association, Node source, Node target) {
    // - event node is boundary event node
    if (!(source instanceof BoundaryEventNode)) {
        throw new IllegalArgumentException("(Compensation) activities may only be associated with Boundary Event Nodes (not with" + source.getClass().getSimpleName() + " nodes [node " + ((String) source.getMetaData().get("UniqueId")) + "].");
    }
    BoundaryEventNode eventNode = (BoundaryEventNode) source;
    // - event node has compensationEvent
    List<EventFilter> eventFilters = eventNode.getEventFilters();
    boolean compensationCheckPassed = false;
    if (eventFilters != null) {
        for (EventFilter filter : eventFilters) {
            if (filter instanceof EventTypeFilter) {
                String type = ((EventTypeFilter) filter).getType();
                if (type != null && type.equals("Compensation")) {
                    compensationCheckPassed = true;
                }
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] linked from an association [" + association.getId() + "] must be a (Boundary) Compensation Event.");
    }
    // - boundary event node is attached to the correct type of node?
    /**
     * Tasks:
     * business: RuleSetNode
     * manual: WorkItemNode
     * receive: WorkItemNode
     * script: ActionNode
     * send: WorkItemNode
     * service: WorkItemNode
     * task: WorkItemNode
     * user: HumanTaskNode
     */
    String attachedToId = eventNode.getAttachedToNodeId();
    Node attachedToNode = null;
    for (Node node : eventNode.getNodeContainer().getNodes()) {
        if (attachedToId.equals(node.getMetaData().get("UniqueId"))) {
            attachedToNode = node;
            break;
        }
    }
    if (attachedToNode == null) {
        throw new IllegalArgumentException("Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] is not attached to a node [" + attachedToId + "] that can be found.");
    }
    if (!(attachedToNode instanceof RuleSetNode || attachedToNode instanceof WorkItemNode || attachedToNode instanceof ActionNode || attachedToNode instanceof HumanTaskNode || attachedToNode instanceof CompositeNode || attachedToNode instanceof SubProcessNode)) {
        throw new IllegalArgumentException("Compensation Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] must be attached to a task or sub-process.");
    }
    // - associated node is a task or subProcess
    compensationCheckPassed = false;
    if (target instanceof WorkItemNode || target instanceof HumanTaskNode || target instanceof CompositeContextNode || target instanceof SubProcessNode) {
        compensationCheckPassed = true;
    } else if (target instanceof ActionNode) {
        Object nodeTypeObj = ((ActionNode) target).getMetaData("NodeType");
        if (nodeTypeObj != null && nodeTypeObj.equals("ScriptTask")) {
            compensationCheckPassed = true;
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Activity [" + ((String) ((NodeImpl) target).getMetaData("UniqueId")) + "] associated with a Boundary Compensation Event must be a Task or a (non-Event) Sub-Process");
    }
    // - associated node does not have outgoingConnections of it's own
    compensationCheckPassed = true;
    NodeImpl targetNode = (NodeImpl) target;
    Map<String, List<org.kie.api.definition.process.Connection>> connectionsMap = targetNode.getOutgoingConnections();
    ConnectionImpl outgoingConnection = null;
    for (String connectionType : connectionsMap.keySet()) {
        List<org.kie.api.definition.process.Connection> connections = connectionsMap.get(connectionType);
        if (connections != null && !connections.isEmpty()) {
            for (org.kie.api.definition.process.Connection connection : connections) {
                Object hiddenObj = connection.getMetaData().get("hidden");
                if (hiddenObj != null && ((Boolean) hiddenObj)) {
                    continue;
                }
                outgoingConnection = (ConnectionImpl) connection;
                compensationCheckPassed = false;
                break;
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("A Compensation Activity [" + ((String) targetNode.getMetaData("UniqueId")) + "] may not have any outgoing connection [" + (String) outgoingConnection.getMetaData("UniqueId") + "]");
    }
}
Also used : RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) 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) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) List(java.util.List) ArrayList(java.util.ArrayList) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Connection(org.jbpm.workflow.core.Connection) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) CompositeNode(org.jbpm.workflow.core.node.CompositeNode)

Aggregations

CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)13 ActionNode (org.jbpm.workflow.core.node.ActionNode)7 StartNode (org.jbpm.workflow.core.node.StartNode)7 VariableScope (org.jbpm.process.core.context.variable.VariableScope)6 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)6 Node (org.jbpm.workflow.core.Node)6 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)6 EndNode (org.jbpm.workflow.core.node.EndNode)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Variable (org.jbpm.process.core.context.variable.Variable)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 NodeCreator (org.jbpm.process.test.NodeCreator)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)3 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)3