Search in sources :

Example 11 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class EndEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
public void handleErrorNode(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 ("errorEventDefinition".equals(nodeName)) {
            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 IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                        break;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                faultNode.setFaultName(error.getErrorCode());
                faultNode.setTerminateParent(true);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : FaultNode(org.jbpm.workflow.core.node.FaultNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Error(org.jbpm.bpmn2.core.Error) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData 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 13 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData 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);
            }
            String variable = (String) endNode.getMetaData("MappingVariable");
            endNode.setMetaData("MessageType", message.getType());
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(new DroolsConsequenceAction("java", "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) Message(org.jbpm.bpmn2.core.Message) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) EndNode(org.jbpm.workflow.core.node.EndNode) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 14 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

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(org.jbpm.compiler.xml.ProcessBuildData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with ProcessBuildData

use of org.jbpm.compiler.xml.ProcessBuildData in project jbpm by kiegroup.

the class AbstractNodeHandler method checkSignalAndConvertToRealSignalNam.

protected String checkSignalAndConvertToRealSignalNam(ExtensibleXmlParser parser, String signalName) {
    ProcessBuildData buildData = ((ProcessBuildData) parser.getData());
    Set<String> signalNames = (Set<String>) buildData.getMetaData(SIGNAL_NAMES);
    if (signalNames == null) {
        signalNames = new HashSet<>();
        buildData.setMetaData(SIGNAL_NAMES, signalNames);
    }
    signalNames.add(signalName);
    Map<String, Signal> signals = (Map<String, Signal>) buildData.getMetaData("Signals");
    if (signals != null) {
        if (signals.containsKey(signalName)) {
            Signal signal = signals.get(signalName);
            signalName = signal.getName();
            if (signalName == null) {
                throw new IllegalArgumentException("Signal definition must have a name attribute");
            }
        }
    }
    return signalName;
}
Also used : Signal(org.jbpm.bpmn2.core.Signal) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)28 Map (java.util.Map)12 Element (org.w3c.dom.Element)11 Node (org.jbpm.workflow.core.Node)8 NodeContainer (org.jbpm.workflow.core.NodeContainer)8 HashMap (java.util.HashMap)7 List (java.util.List)7 ArrayList (java.util.ArrayList)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)4 Error (org.jbpm.bpmn2.core.Error)3 Escalation (org.jbpm.bpmn2.core.Escalation)3 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)3 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)3 Message (org.jbpm.bpmn2.core.Message)2