Search in sources :

Example 1 with JavaDroolsAction

use of org.jbpm.workflow.core.impl.JavaDroolsAction in project jbpm by kiegroup.

the class ActionNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    ActionNode actionNode = (ActionNode) node;
    String eventType = (String) actionNode.getMetaData("EventType");
    String ref = (String) actionNode.getMetaData("Ref");
    String variableRef = (String) actionNode.getMetaData("Variable");
    if (actionNode.getAction() instanceof DroolsConsequenceAction) {
        DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction();
        String s = action.getConsequence();
        if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            String variable = (String) actionNode.getMetaData("MappingVariable");
            if (variable != null) {
                xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
            }
            xmlDump.append("      <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Message\"/>" + EOL);
            endNode("intermediateThrowEvent", xmlDump);
        } else if ("signal".equals(eventType)) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            if (!s.startsWith("null")) {
                xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
            }
            xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
            endNode("intermediateThrowEvent", xmlDump);
        } else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, 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(actionNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
            }
            xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
            endNode("intermediateThrowEvent", xmlDump);
        } else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            s = s.substring(43);
            assert "Compensation".equals(s.substring(0, s.indexOf("\""))) : "Type is not \"Compensation\" but \"" + s.substring(0, s.indexOf("\"")) + "\"";
            String activityRef = "";
            // : Compensation
            int begin = 12;
            // ");
            int end = s.length() - 3;
            String compensationEvent = s.substring(begin, end);
            if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
                // specific
                activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
            }
            // else general: activityRef = "" (above)
            xmlDump.append("      <compensateEventDefinition " + activityRef + "/>" + EOL);
            endNode("intermediateThrowEvent", xmlDump);
        } else 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, \"")) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            s = s.substring(327);
            String type = s.substring(0, s.indexOf("\""));
            xmlDump.append("      <escalationEventDefinition escalationRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
            endNode("intermediateThrowEvent", xmlDump);
        } else if ("IntermediateThrowEvent-None".equals(actionNode.getMetaData("NodeType"))) {
            writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            endNode("intermediateThrowEvent", xmlDump);
        } else {
            writeNode("scriptTask", actionNode, xmlDump, metaDataType);
            if (JavaDialect.ID.equals(action.getDialect())) {
                xmlDump.append("scriptFormat=\"" + XmlBPMNProcessDumper.JAVA_LANGUAGE + "\" ");
            } else if ("JavaScript".equals(action.getDialect())) {
                xmlDump.append("scriptFormat=\"" + XmlBPMNProcessDumper.JAVASCRIPT_LANGUAGE + "\" ");
            }
            Object isForCompensationObj = actionNode.getMetaData("isForCompensation");
            if (isForCompensationObj != null && (Boolean) isForCompensationObj) {
                xmlDump.append("isForCompensation=\"true\" ");
            }
            xmlDump.append(">" + EOL);
            writeExtensionElements(actionNode, xmlDump);
            if (action.getConsequence() != null) {
                xmlDump.append("      <script>" + XmlDumper.replaceIllegalChars(action.getConsequence()) + "</script>" + EOL);
            }
            endNode("scriptTask", xmlDump);
        }
    } else if (actionNode.getAction() instanceof JavaDroolsAction) {
        JavaAction action = ((JavaDroolsAction) actionNode.getAction()).getAction();
        writeNode("intermediateThrowEvent", actionNode, xmlDump, metaDataType);
        xmlDump.append(">" + EOL);
        writeExtensionElements(actionNode, xmlDump);
        writeJavaAction(node, action, xmlDump);
        endNode("intermediateThrowEvent", xmlDump);
    } else {
        writeNode("scriptTask", actionNode, xmlDump, metaDataType);
        xmlDump.append(">" + EOL);
        writeExtensionElements(actionNode, xmlDump);
        endNode("scriptTask", xmlDump);
    }
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) ActionNode(org.jbpm.workflow.core.node.ActionNode) JavaAction(org.jbpm.process.instance.impl.JavaAction)

Example 2 with JavaDroolsAction

use of org.jbpm.workflow.core.impl.JavaDroolsAction in project jbpm by kiegroup.

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);
            }
            message.addOutgoingNode(node);
            String varName = (String) endNode.getMetaData("MappingVariable");
            endNode.setMetaData("MessageType", message.getType());
            endNode.setActions(EndNode.EVENT_NODE_ENTER, Collections.singletonList(new JavaDroolsAction(new SendMessageAction(varName, message))));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : SendMessageAction(org.jbpm.bpmn2.handler.SendMessageAction) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) EndNode(org.jbpm.workflow.core.node.EndNode) Message(org.jbpm.bpmn2.core.Message) JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) Map(java.util.Map)

Example 3 with JavaDroolsAction

use of org.jbpm.workflow.core.impl.JavaDroolsAction in project jbpm by kiegroup.

the class IntermediateThrowEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) 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)) {
            readDataInputAssociation(xmlNode, actionNode);
        } 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);
            }
            message.addOutgoingNode(node);
            String varName = (String) actionNode.getMetaData("MappingVariable");
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setAction(new JavaDroolsAction(new SendMessageAction(varName, message)));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : SendMessageAction(org.jbpm.bpmn2.handler.SendMessageAction) Message(org.jbpm.bpmn2.core.Message) JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 4 with JavaDroolsAction

use of org.jbpm.workflow.core.impl.JavaDroolsAction in project jbpm by kiegroup.

the class IntermediateThrowEventHandler method handleSignalNode.

public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    String executeActionAfterCompleteMetadata = (String) node.getMetaData().get("executeActionAfterComplete");
    Boolean executeActionAfterComplete = executeActionAfterCompleteMetadata != null && Boolean.parseBoolean(executeActionAfterCompleteMetadata);
    actionNode.setExecuteActionAfterComplete(executeActionAfterComplete);
    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)) {
            readDataInputAssociation(xmlNode, actionNode);
        } else if ("signalEventDefinition".equals(nodeName)) {
            String signalName = checkSignalAndConvertToRealSignalNam(parser, ((Element) xmlNode).getAttribute("signalRef"), s -> s.addOutgoingNode(node));
            String variable = (String) actionNode.getMetaData("MappingVariable");
            actionNode.setMetaData("EventType", "signal");
            actionNode.setMetaData("Ref", signalName);
            actionNode.setMetaData("Variable", variable);
            actionNode.setAction(new JavaDroolsAction(new SendSignalAction(actionNode, variable, signalName, dataInputs.containsValue("async"))));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) SendSignalAction(org.jbpm.bpmn2.handler.SendSignalAction)

Example 5 with JavaDroolsAction

use of org.jbpm.workflow.core.impl.JavaDroolsAction in project jbpm by kiegroup.

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, s -> s.addOutgoingNode(node));
            endNode.setMetaData("EventType", "signal");
            endNode.setMetaData("Ref", signalName);
            endNode.setMetaData("Variable", variable);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, Collections.singletonList(new JavaDroolsAction(new SendSignalAction(endNode, variable, signalName, dataInputs.containsValue("async")))));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Text(org.w3c.dom.Text) EndNode(org.jbpm.workflow.core.node.EndNode) NodeList(org.w3c.dom.NodeList) Escalation(org.jbpm.bpmn2.core.Escalation) ExtensibleXmlParser(org.drools.core.xml.ExtensibleXmlParser) JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) Message(org.jbpm.bpmn2.core.Message) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) Node(org.jbpm.workflow.core.Node) Map(java.util.Map) SAXException(org.xml.sax.SAXException) SendMessageAction(org.jbpm.bpmn2.handler.SendMessageAction) Attributes(org.xml.sax.Attributes) FaultNode(org.jbpm.workflow.core.node.FaultNode) Collections(java.util.Collections) SendSignalAction(org.jbpm.bpmn2.handler.SendSignalAction) EndNode(org.jbpm.workflow.core.node.EndNode) JavaDroolsAction(org.jbpm.workflow.core.impl.JavaDroolsAction) Element(org.w3c.dom.Element) SendSignalAction(org.jbpm.bpmn2.handler.SendSignalAction)

Aggregations

JavaDroolsAction (org.jbpm.workflow.core.impl.JavaDroolsAction)6 Map (java.util.Map)3 Message (org.jbpm.bpmn2.core.Message)3 SendMessageAction (org.jbpm.bpmn2.handler.SendMessageAction)3 ActionNode (org.jbpm.workflow.core.node.ActionNode)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 Element (org.w3c.dom.Element)3 SendSignalAction (org.jbpm.bpmn2.handler.SendSignalAction)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 JavaAction (org.jbpm.process.instance.impl.JavaAction)2 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)2 Collections (java.util.Collections)1 List (java.util.List)1 ExtensibleXmlParser (org.drools.core.xml.ExtensibleXmlParser)1 Error (org.jbpm.bpmn2.core.Error)1 Escalation (org.jbpm.bpmn2.core.Escalation)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 Node (org.jbpm.workflow.core.Node)1 NodeContainer (org.jbpm.workflow.core.NodeContainer)1 FaultNode (org.jbpm.workflow.core.node.FaultNode)1