Search in sources :

Example 1 with Escalation

use of io.automatiko.engine.workflow.bpmn2.core.Escalation in project jbpm by kiegroup.

the class EndEventHandler method handleEscalationNode.

@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    FaultNode faultNode = (FaultNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readFaultDataInputAssociation(xmlNode, faultNode);
        } 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);
                }
                faultNode.setFaultName(escalation.getEscalationCode());
            } else {
                // are _required_ to reference a specific escalation(-code).
                throw new IllegalArgumentException("End events throwing an escalation must throw *specific* escalations (and not general ones).");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : FaultNode(org.jbpm.workflow.core.node.FaultNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Escalation(org.jbpm.bpmn2.core.Escalation) Map(java.util.Map)

Example 2 with Escalation

use of io.automatiko.engine.workflow.bpmn2.core.Escalation 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 3 with Escalation

use of io.automatiko.engine.workflow.bpmn2.core.Escalation in project kogito-runtimes by kiegroup.

the class StartEventHandler method handleNode.

@Override
@SuppressWarnings("unchecked")
protected Node handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to true
    // The spec says that Escalation start events should default to not interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    startNode.setIoSpecification(readCatchSpecification(parser, element));
    findTargetMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
        startNode.getMetaData().put(TRIGGER_MAPPING, data.getLabel());
        startNode.getMetaData().put(MAPPING_VARIABLE, data.getLabel());
    });
    findSourceMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
        startNode.getMetaData().put(TRIGGER_MAPPING_INPUT, data.getLabel());
    });
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            type = checkSignalAndConvertToRealSignalNam(parser, type);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
            startNode.setMetaData(MESSAGE_TYPE, type);
            startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
            Signal signal = findSignalByName(parser, type);
            if (signal != null) {
                String eventType = signal.getStructureRef();
                startNode.setMetaData(TRIGGER_REF, eventType);
            } else {
                startNode.setMetaData(TRIGGER_REF, type);
            }
        } 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 ProcessParsingValidationException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new ProcessParsingValidationException("Could not find message " + messageRef);
            }
            startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE);
            startNode.setMetaData(MESSAGE_TYPE, message.getType());
            startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.ConsumeMessage.name());
            startNode.setMetaData(TRIGGER_REF, message.getName());
            addTriggerWithInMappings(startNode, "Message-" + message.getName(), message.getId(), ((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
        // following event definitions are only for event sub process and will be validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            // BPMN2 spec (p.245-246, (2011-01-03)) implies that
            // - a <startEvent> in an Event Sub-Process
            // - *without* the 'isInterupting' attribute always interrupts (containing process)
            startNode.setInterrupting(true);
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new ProcessParsingValidationException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new ProcessParsingValidationException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                startNode.setMetaData(MESSAGE_TYPE, error.getErrorCode());
                startNode.setMetaData(TRIGGER_REF, error.getErrorCode());
                startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
            }
        } 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 ProcessParsingValidationException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new ProcessParsingValidationException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, xmlNode);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (startNode.getName() == null) {
        startNode.setName("Start");
    }
    return startNode;
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) Signal(org.jbpm.bpmn2.core.Signal) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 4 with Escalation

use of io.automatiko.engine.workflow.bpmn2.core.Escalation in project automatiko-engine by automatiko-io.

the class EndEventHandler method handleEscalationNode.

@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    FaultNode faultNode = (FaultNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readFaultDataInputAssociation(xmlNode, faultNode);
        } 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);
                }
                faultNode.setFaultName(escalation.getEscalationCode());
            } else {
                // are _required_ to reference a specific escalation(-code).
                throw new IllegalArgumentException("End events throwing an escalation must throw *specific* escalations (and not general ones).");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) Map(java.util.Map)

Example 5 with Escalation

use of io.automatiko.engine.workflow.bpmn2.core.Escalation in project automatiko-engine by automatiko-io.

the class EscalationHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String id = attrs.getValue("id");
    String escalationCode = attrs.getValue("escalationCode");
    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    Map<String, Escalation> escalations = (Map<String, Escalation>) buildData.getMetaData(ProcessHandler.ESCALATIONS);
    if (escalations == null) {
        escalations = new HashMap<String, Escalation>();
        buildData.setMetaData(ProcessHandler.ESCALATIONS, escalations);
    }
    Escalation e = new Escalation(id, escalationCode);
    escalations.put(id, e);
    return e;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)14 Escalation (org.jbpm.bpmn2.core.Escalation)8 Element (org.w3c.dom.Element)8 ArrayList (java.util.ArrayList)7 Escalation (io.automatiko.engine.workflow.bpmn2.core.Escalation)6 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)5 List (java.util.List)4 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)4 EventFilter (org.jbpm.process.core.event.EventFilter)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 NonAcceptingEventTypeFilter (org.jbpm.process.core.event.NonAcceptingEventTypeFilter)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)2 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)2 Error (io.automatiko.engine.workflow.bpmn2.core.Error)2 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)2 Message (io.automatiko.engine.workflow.bpmn2.core.Message)2 Signal (io.automatiko.engine.workflow.bpmn2.core.Signal)2 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)2 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)2