Search in sources :

Example 36 with ProcessAction

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

the class EndEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            String variable = (String) endNode.getMetaData("MappingVariable");
            endNode.setMetaData("MessageType", message.getType());
            endNode.setMetaData("TriggerType", "ProduceMessage");
            endNode.setMetaData("TriggerRef", message.getName());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                endNode.setMetaData(entry.getKey(), entry.getValue());
            }
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable));
            actions.add(action);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Message(io.automatiko.engine.workflow.bpmn2.core.Message) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Entry(java.util.Map.Entry) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 37 with ProcessAction

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

the class EndEventHandler method handleSignalNode.

public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } else if ("signalEventDefinition".equals(nodeName)) {
            String signalName = ((Element) xmlNode).getAttribute("signalRef");
            String variable = (String) endNode.getMetaData("MappingVariable");
            signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
            endNode.setMetaData("EventType", "signal");
            endNode.setMetaData("Ref", signalName);
            endNode.setMetaData("Variable", variable);
            // check if signal should be send async
            if (dataInputs.containsValue("async")) {
                signalName = "ASYNC-" + signalName;
            }
            ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction(signalName, variable, (String) endNode.getMetaData("customScope"), (Transformation) endNode.getMetaData().get("Transformation")));
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            actions.add(action);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ArrayList(java.util.ArrayList)

Example 38 with ProcessAction

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

the class EndNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    EndNode endNode = (EndNode) node;
    String eventType = (String) endNode.getMetaData("EventType");
    String ref = (String) endNode.getMetaData("Ref");
    String variableRef = (String) endNode.getMetaData("Variable");
    writeNode("endEvent", endNode, xmlDump, metaDataType);
    if (endNode.isTerminate()) {
        xmlDump.append(">" + EOL);
        writeExtensionElements(endNode, xmlDump);
        xmlDump.append("        <terminateEventDefinition " + (endNode.getScope() == EndNode.PROCESS_SCOPE ? "tns:scope=\"process\"" : "") + "/>" + EOL);
        endNode("endEvent", xmlDump);
    } else {
        String scope = (String) endNode.getMetaData("customScope");
        List<ProcessAction> actions = endNode.getActions(EndNode.EVENT_NODE_ENTER);
        if (actions != null && !actions.isEmpty()) {
            if (actions.size() == 1) {
                ConsequenceAction action = (ConsequenceAction) actions.get(0);
                String s = action.getConsequence();
                if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    String variable = (String) endNode.getMetaData("MappingVariable");
                    if (variable != null) {
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Message\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if ("signal".equals(eventType)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    if (!s.startsWith("null")) {
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    s = s.substring(44);
                    String type = s.substring(0, s.indexOf("\""));
                    s = s.substring(s.indexOf(",") + 2);
                    String variable = null;
                    if (!s.startsWith("null")) {
                        variable = s.substring(0, s.indexOf(")"));
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT) && "processInstance".equals(scope)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    s = s.substring(43);
                    String type = s.substring(0, s.indexOf("\""));
                    s = s.substring(s.indexOf(",") + 2);
                    String variable = null;
                    if (!s.startsWith("null")) {
                        variable = s.substring(0, s.indexOf(")"));
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    int begin = (PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", ").length() - 2;
                    int end = s.length() - 3;
                    String compensationEvent = s.substring(begin, end);
                    String activityRef = "";
                    if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
                        // specific
                        activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
                    }
                    // else general: activityRef = "" (above)
                    xmlDump.append("      <compensateEventDefinition " + activityRef + "/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else {
                    throw new IllegalArgumentException("Unknown action " + s);
                }
            }
        } else {
            endNode(xmlDump);
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)

Example 39 with ProcessAction

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

the class FileSystemProcessInstancesTest method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    BpmnProcess process = createProcess(null, "BPMN2-UserTask-Script.bpmn2");
    // workaround as BpmnProcess does not compile the scripts but just reads the xml
    for (io.automatiko.engine.api.definition.process.Node node : ((WorkflowProcess) process.process()).getNodes()) {
        if (node instanceof ActionNode) {
            ProcessAction a = ((ActionNode) node).getAction();
            a.removeMetaData("Action");
            a.setMetaData("Action", new Action() {

                @Override
                public void execute(ProcessContext kcontext) throws Exception {
                    System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
                    kcontext.getVariable("s").toString();
                }
            });
        }
    }
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(Collections.singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.errorMessages()).contains("null");
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isOne();
    ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.MUTABLE).get().abort();
    assertThat(instances.size()).isZero();
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) IOException(java.io.IOException) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 40 with ProcessAction

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

the class ExtendedNodeInstanceImpl method triggerEvent.

protected void triggerEvent(String type) {
    ExtendedNodeImpl extendedNode = getExtendedNode();
    if (extendedNode == null) {
        return;
    }
    List<ProcessAction> actions = extendedNode.getActions(type);
    if (actions != null) {
        for (ProcessAction processAction : actions) {
            Action action = (Action) processAction.getMetaData(ACTION);
            executeAction(action);
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl)

Aggregations

ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)47 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)30 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)20 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)18 ArrayList (java.util.ArrayList)18 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)16 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)15 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)14 Action (io.automatiko.engine.workflow.base.instance.impl.Action)13 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)13 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)12 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)11 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)11 CancelNodeInstanceAction (io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction)10 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)9 Node (io.automatiko.engine.api.definition.process.Node)8 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)7 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)7 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)7 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)7