Search in sources :

Example 11 with CompositeNode

use of io.automatiko.engine.workflow.process.core.node.CompositeNode in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitEscalations.

protected void visitEscalations(Node[] nodes, StringBuilder xmlDump, List<String> escalations) {
    for (Node node : nodes) {
        if (node instanceof FaultNode) {
            FaultNode faultNode = (FaultNode) node;
            if (!faultNode.isTerminateParent()) {
                String escalationCode = faultNode.getFaultName();
                if (!escalations.contains(escalationCode)) {
                    escalations.add(escalationCode);
                    xmlDump.append("  <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(escalationCode) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(escalationCode) + "\" />" + EOL);
                }
            }
        } else if (node instanceof ActionNode) {
            ActionNode actionNode = (ActionNode) node;
            if (actionNode.getAction() instanceof ConsequenceAction) {
                ConsequenceAction action = (ConsequenceAction) actionNode.getAction();
                if (action != null) {
                    String s = action.getConsequence();
                    if (s.startsWith("org.drools.core.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.drools.core.process.instance.context.exception.ExceptionScopeInstance) ((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.drools.core.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"")) {
                        s = s.substring(327);
                        String type = s.substring(0, s.indexOf("\""));
                        if (!escalations.contains(type)) {
                            escalations.add(type);
                            xmlDump.append("  <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" />" + EOL);
                        }
                    }
                }
            } else {
                logger.warn("Cannot serialize custom implementation of the Action interface to XML");
            }
        } else if (node instanceof EventNode) {
            EventNode eventNode = (EventNode) node;
            String type = (String) eventNode.getMetaData("EscalationEvent");
            if (type != null) {
                if (!escalations.contains(type)) {
                    escalations.add(type);
                    xmlDump.append("  <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" />" + EOL);
                }
            }
        }
        if (node instanceof CompositeNode) {
            visitEscalations(((CompositeNode) node).getNodes(), xmlDump, escalations);
        }
    }
}
Also used : FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode)

Example 12 with CompositeNode

use of io.automatiko.engine.workflow.process.core.node.CompositeNode in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitInterfaces.

protected void visitInterfaces(Node[] nodes, StringBuilder xmlDump) {
    for (Node node : nodes) {
        if (node instanceof WorkItemNode) {
            Work work = ((WorkItemNode) node).getWork();
            if (work != null) {
                if ("Service Task".equals(work.getName())) {
                    String interfaceName = (String) work.getParameter("Interface");
                    if (interfaceName == null) {
                        interfaceName = "";
                    }
                    String interfaceRef = (String) work.getParameter("interfaceImplementationRef");
                    if (interfaceRef == null) {
                        interfaceRef = "";
                    }
                    String operationName = (String) work.getParameter("Operation");
                    if (operationName == null) {
                        operationName = "";
                    }
                    String operationRef = (String) work.getParameter("operationImplementationRef");
                    if (operationRef == null) {
                        operationRef = "";
                    }
                    String parameterType = (String) work.getParameter("ParameterType");
                    if (parameterType == null) {
                        parameterType = "";
                    }
                    xmlDump.append("  <itemDefinition id=\"" + getUniqueNodeId(node) + "_InMessageType\" " + ("".equals(parameterType) || "java.lang.Object".equals(parameterType) ? "" : "structureRef=\"" + parameterType + "\" ") + "/>" + EOL + "  <message id=\"" + getUniqueNodeId(node) + "_InMessage\" itemRef=\"" + getUniqueNodeId(node) + "_InMessageType\" />" + EOL + "  <interface id=\"" + getUniqueNodeId(node) + "_ServiceInterface\" name=\"" + interfaceName + "\" implementationRef=\"" + interfaceRef + "\" >" + EOL + "    <operation id=\"" + getUniqueNodeId(node) + "_ServiceOperation\" name=\"" + operationName + "\" implementationRef=\"" + operationRef + "\" >" + EOL + "      <inMessageRef>" + getUniqueNodeId(node) + "_InMessage</inMessageRef>" + EOL + "    </operation>" + EOL + "  </interface>" + EOL + EOL);
                } else if ("Send Task".equals(work.getName())) {
                    String messageType = (String) work.getParameter("MessageType");
                    if (messageType == null) {
                        messageType = "";
                    }
                    xmlDump.append("  <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
                } else if ("Receive Task".equals(work.getName())) {
                    String messageId = (String) work.getParameter("MessageId");
                    String messageType = (String) work.getParameter("MessageType");
                    if (messageType == null) {
                        messageType = "";
                    }
                    xmlDump.append("  <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + messageId + "\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
                }
            }
        } else if (node instanceof EndNode) {
            String messageType = (String) node.getMetaData().get("MessageType");
            if (messageType != null) {
                xmlDump.append("  <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
            }
        } else if (node instanceof ActionNode) {
            String messageType = (String) node.getMetaData().get("MessageType");
            if (messageType != null) {
                xmlDump.append("  <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
            }
        } else if (node instanceof EventNode) {
            List<EventFilter> filters = ((EventNode) node).getEventFilters();
            if (filters.size() > 0) {
                String messageRef = ((EventTypeFilter) filters.get(0)).getType();
                if (messageRef.startsWith("Message-")) {
                    messageRef = messageRef.substring(8);
                    String messageType = (String) node.getMetaData().get("MessageType");
                    xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "Type\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "\" itemRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "Type\" />" + EOL + EOL);
                }
            }
        } else if (node instanceof StartNode) {
            StartNode startNode = (StartNode) node;
            if (startNode.getTriggers() != null && !startNode.getTriggers().isEmpty()) {
                Trigger trigger = startNode.getTriggers().get(0);
                if (trigger instanceof EventTrigger) {
                    String eventType = ((EventTypeFilter) ((EventTrigger) trigger).getEventFilters().get(0)).getType();
                    if (eventType.startsWith("Message-")) {
                        eventType = eventType.substring(8);
                        String messageType = (String) node.getMetaData().get("MessageType");
                        xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "Type\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + "  <message id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "\" itemRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "Type\" />" + EOL + EOL);
                    }
                }
            }
        } else if (node instanceof ForEachNode) {
            ForEachNode forEachNode = (ForEachNode) node;
            String type = null;
            if (forEachNode.getVariableType() instanceof ObjectDataType) {
                type = ((ObjectDataType) forEachNode.getVariableType()).getClassName();
            }
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(forEachNode) + "_multiInstanceItemType\" " + (type == null || "java.lang.Object".equals(type) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" ") + "/>" + EOL + EOL);
        }
        if (node instanceof CompositeNode) {
            visitInterfaces(((CompositeNode) node).getNodes(), xmlDump);
        }
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) List(java.util.List) ArrayList(java.util.ArrayList) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 13 with CompositeNode

use of io.automatiko.engine.workflow.process.core.node.CompositeNode in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method getUniqueNodeId.

public static String getUniqueNodeId(Node node) {
    String result = (String) node.getMetaData().get("UniqueId");
    if (result != null) {
        return result;
    }
    result = node.getId() + "";
    NodeContainer nodeContainer = node.getParentContainer();
    while (nodeContainer instanceof CompositeNode) {
        CompositeNode composite = (CompositeNode) nodeContainer;
        result = composite.getId() + "-" + result;
        nodeContainer = composite.getParentContainer();
    }
    return "_" + result;
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer)

Example 14 with CompositeNode

use of io.automatiko.engine.workflow.process.core.node.CompositeNode in project automatiko-engine by automatiko-io.

the class RuleFlowProcessValidatorTest method testCompositeNodeNoStart.

@Test
void testCompositeNodeNoStart() {
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    process.addNode(endNode);
    CompositeNode compositeNode = new CompositeNode();
    compositeNode.setName("CompositeNode");
    compositeNode.setId(3);
    process.addNode(compositeNode);
    new io.automatiko.engine.workflow.process.core.impl.ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE);
    new io.automatiko.engine.workflow.process.core.impl.ConnectionImpl(compositeNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    ProcessValidationError[] errors = validator.validateProcess(process);
    assertNotNull(errors);
    assertEquals(1, errors.length);
    assertEquals("Node 'CompositeNode' [3] Composite has no start node defined.", errors[0].getMessage());
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ProcessValidationError(io.automatiko.engine.workflow.base.core.validation.ProcessValidationError) Test(org.junit.jupiter.api.Test)

Example 15 with CompositeNode

use of io.automatiko.engine.workflow.process.core.node.CompositeNode in project automatiko-engine by automatiko-io.

the class AssociationHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Association association = new Association();
    association.setId(attrs.getValue("id"));
    association.setSourceRef(attrs.getValue("sourceRef"));
    association.setTargetRef(attrs.getValue("targetRef"));
    String direction = attrs.getValue("associationDirection");
    if (direction != null) {
        boolean acceptableDirection = false;
        direction = direction.toLowerCase();
        String[] possibleDirections = { "none", "one", "both" };
        for (String acceptable : possibleDirections) {
            if (acceptable.equals(direction)) {
                acceptableDirection = true;
                break;
            }
        }
        if (!acceptableDirection) {
            throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
        }
    }
    association.setDirection(direction);
    /**
     * BPMN2 spec, p. 66: "At this point, BPMN provides three standard Artifacts:
     * Associations, Groups, and Text Annotations. ... When an Artifact is defined
     * it is contained within a Collaboration or a FlowElementsContainer (a Process
     * or Choreography)."
     *
     * (In other words: associations must be defined within a process, not outside)
     */
    List<Association> associations = null;
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    if (nodeContainer instanceof Process) {
        ExecutableProcess process = (ExecutableProcess) nodeContainer;
        associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            process.setMetaData(ASSOCIATIONS, associations);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
        associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
        }
    } else {
        associations = new ArrayList<>();
    }
    associations.add(association);
    return association;
}
Also used : CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Process(io.automatiko.engine.api.definition.process.Process) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Association(io.automatiko.engine.workflow.bpmn2.core.Association) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)27 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)16 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)16 ArrayList (java.util.ArrayList)15 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)14 Node (io.automatiko.engine.api.definition.process.Node)13 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)13 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)12 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)12 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)11 List (java.util.List)11 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)10 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)9 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)8 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)8 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)8 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)8 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)7 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)7 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)6