Search in sources :

Example 6 with ActionNode

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

the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.

protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
    if (throwEventNode.getMetaData("compensation-activityRef") != null) {
        String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
        NodeContainer nodeParent = (NodeContainer) throwEventNode.getNodeContainer();
        if (nodeParent instanceof EventSubProcessNode) {
            boolean compensationEventSubProcess = false;
            List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
            CESP_CHECK: for (Trigger trigger : startTriggers) {
                if (trigger instanceof EventTrigger) {
                    for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
                        if (((EventTypeFilter) filter).getType().equals("Compensation")) {
                            compensationEventSubProcess = true;
                            break CESP_CHECK;
                        }
                    }
                }
            }
            if (compensationEventSubProcess) {
                // BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
                nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getNodeContainer();
            }
        }
        String parentId;
        if (nodeParent instanceof RuleFlowProcess) {
            parentId = ((RuleFlowProcess) nodeParent).getId();
        } else {
            parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
        }
        String compensationEvent;
        if (activityRef.length() == 0) {
            // general/implicit compensation
            compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
        } else {
            // specific compensation
            compensationEvent = activityRef;
        }
        DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");");
        if (throwEventNode instanceof ActionNode) {
            ((ActionNode) throwEventNode).setAction(compensationAction);
        } else if (throwEventNode instanceof EndNode) {
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(compensationAction);
            ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.kie.api.definition.process.NodeContainer) EventFilter(org.jbpm.process.core.event.EventFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) EndNode(org.jbpm.workflow.core.node.EndNode) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 7 with ActionNode

use of org.jbpm.workflow.core.node.ActionNode 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;
    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 = ((Element) xmlNode).getAttribute("signalRef");
            String variable = (String) actionNode.getMetaData("MappingVariable");
            signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
            actionNode.setMetaData("EventType", "signal");
            actionNode.setMetaData("Ref", signalName);
            actionNode.setMetaData("Variable", variable);
            // check if signal should be send async
            if (dataInputs.containsValue("async")) {
                signalName = "ASYNC-" + signalName;
            }
            String signalExpression = getSignalExpression(actionNode, signalName, "tVariable");
            actionNode.setAction(new DroolsConsequenceAction("java", " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + "  tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + "  .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + signalExpression));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode)

Example 8 with ActionNode

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

the class IntermediateThrowEventHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    ActionNode node = (ActionNode) parser.getCurrent();
    // 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 ("signalEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleSignalNode(node, element, uri, localName, parser);
            break;
        } else if ("messageEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleMessageNode(node, element, uri, localName, parser);
            break;
        } else if ("escalationEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleEscalationNode(node, element, uri, localName, parser);
            break;
        } else if ("compensateEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleThrowCompensationEventNode(node, element, uri, localName, parser);
            break;
        } else if ("linkEventDefinition".equals(nodeName)) {
            ThrowLinkNode linkNode = new ThrowLinkNode();
            linkNode.setId(node.getId());
            handleLinkNode(element, linkNode, xmlNode, parser);
            NodeContainer nodeContainer = (NodeContainer) parser.getParent();
            nodeContainer.addNode(linkNode);
            ((ProcessBuildData) parser.getData()).addNode(node);
            // we break the while and stop the execution of this method.
            return linkNode;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // none event definition
    if (node.getAction() == null) {
        node.setAction(new DroolsConsequenceAction("mvel", ""));
        node.setMetaData("NodeType", "IntermediateThrowEvent-None");
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    return node;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) ThrowLinkNode(org.jbpm.workflow.core.node.ThrowLinkNode)

Example 9 with ActionNode

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

the class IntermediateThrowEventHandler method handleEscalationNode.

@SuppressWarnings("unchecked")
public void handleEscalationNode(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 ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode);
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                String faultName = escalation.getEscalationCode();
                String variable = (String) actionNode.getMetaData("MappingVariable");
                actionNode.setAction(new DroolsConsequenceAction("java", "org.jbpm.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.jbpm.process.instance.context.exception.ExceptionScopeInstance) ((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.jbpm.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"" + faultName + "\");" + EOL + "if (scopeInstance != null) {" + EOL + " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + "  tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + "  .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + "  scopeInstance.handleException(\"" + faultName + "\", tVariable);" + EOL + "} else {" + EOL + "    ((org.jbpm.process.instance.ProcessInstance) kcontext.getProcessInstance()).setState(org.jbpm.process.instance.ProcessInstance.STATE_ABORTED);" + EOL + "}"));
            } else {
                throw new IllegalArgumentException("General escalation is not yet supported");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Escalation(org.jbpm.bpmn2.core.Escalation) ActionNode(org.jbpm.workflow.core.node.ActionNode) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 10 with ActionNode

use of org.jbpm.workflow.core.node.ActionNode 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);
            }
            String variable = (String) actionNode.getMetaData("MappingVariable");
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setAction(new DroolsConsequenceAction("java", " Object tVariable = " + (variable == null ? "null" : variable) + ";" + "org.jbpm.workflow.core.node.Transformation transformation = (org.jbpm.workflow.core.node.Transformation)kcontext.getNodeInstance().getNode().getMetaData().get(\"Transformation\");" + "if (transformation != null) {" + "  tVariable = new org.jbpm.process.core.event.EventTransformerImpl(transformation)" + "  .transformEvent(" + (variable == null ? "null" : variable) + ");" + "}" + "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", tVariable);" + EOL) + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

ActionNode (org.jbpm.workflow.core.node.ActionNode)48 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)41 EndNode (org.jbpm.workflow.core.node.EndNode)29 StartNode (org.jbpm.workflow.core.node.StartNode)28 ArrayList (java.util.ArrayList)25 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)25 DroolsAction (org.jbpm.workflow.core.DroolsAction)24 Action (org.jbpm.process.instance.impl.Action)21 Test (org.junit.Test)20 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)18 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)18 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)18 KieSession (org.kie.api.runtime.KieSession)17 ProcessContext (org.kie.api.runtime.process.ProcessContext)17 EventNode (org.jbpm.workflow.core.node.EventNode)14 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)14 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)12 Variable (org.jbpm.process.core.context.variable.Variable)11 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)9 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)8