Search in sources :

Example 6 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class AbstractLogOrThrowWorkItemHandler method handleException.

protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) {
    String service = (String) handlerInfoMap.get("Interface");
    String operation = (String) handlerInfoMap.get("Operation");
    if (this.logThrownException) {
        String message;
        if (service != null) {
            message = this.getClass().getSimpleName() + " failed when calling " + service + "." + operation;
        } else {
            message = this.getClass().getSimpleName() + " failed while trying to complete the task.";
        }
        logger.error(message, cause);
    } else {
        WorkItemHandlerRuntimeException wihRe = new WorkItemHandlerRuntimeException(cause);
        for (String key : handlerInfoMap.keySet()) {
            wihRe.setInformation(key, handlerInfoMap.get(key));
        }
        wihRe.setInformation(WorkItemHandlerRuntimeException.WORKITEMHANDLERTYPE, this.getClass().getSimpleName());
        throw wihRe;
    }
}
Also used : WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)

Example 7 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class BoundaryEventHandler method handleMessageNode.

protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setMetaData("CancelActivity", cancelActivity);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } 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);
            }
            eventNode.setMetaData("MessageType", message.getType());
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setType("Message-" + messageRef);
            eventFilters.add(eventFilter);
            eventNode.setScope("external");
            eventNode.setEventFilters(eventFilters);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Map(java.util.Map)

Example 8 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class IntermediateCatchEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    EventNode eventNode = (EventNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } 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);
            }
            eventNode.setMetaData("MessageType", message.getType());
            List<EventFilter> eventFilters = new ArrayList<EventFilter>();
            EventTypeFilter eventFilter = new EventTypeFilter();
            eventFilter.setType("Message-" + messageRef);
            eventFilters.add(eventFilter);
            eventNode.setEventFilters(eventFilters);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EventFilter(org.jbpm.process.core.event.EventFilter) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 9 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class InMessageRefHandler method end.

@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    String messageId = element.getTextContent();
    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(messageId);
    if (message == null) {
        throw new IllegalArgumentException("Could not find message " + messageId);
    }
    Operation operation = (Operation) parser.getParent();
    operation.setMessage(message);
    return parser.getCurrent();
}
Also used : Message(org.jbpm.bpmn2.core.Message) Element(org.w3c.dom.Element) Operation(org.jbpm.bpmn2.core.Interface.Operation) Map(java.util.Map)

Example 10 with Message

use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.

the class IntermediateEventTest method testEventSubprocessMessage.

@Test
public void testEventSubprocessMessage() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessMessage.bpmn2");
    final List<Long> executednodes = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessMessage");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(listener);
    ksession.signalEvent("Message-HelloMessage", null, processInstance.getId());
    ksession.signalEvent("Message-HelloMessage", null);
    ksession.signalEvent("Message-HelloMessage", null);
    ksession.signalEvent("Message-HelloMessage", null);
    ksession.getProcessInstance(processInstance.getId());
    ksession.getProcessInstance(processInstance.getId());
    ksession.getProcessInstance(processInstance.getId());
    ksession.getProcessInstance(processInstance.getId());
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertThat(executednodes.size()).isEqualTo(4);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Aggregations

Map (java.util.Map)8 Message (org.jbpm.bpmn2.core.Message)8 ArrayList (java.util.ArrayList)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)6 Test (org.junit.Test)5 KieBase (org.kie.api.KieBase)5 Element (org.w3c.dom.Element)5 HashMap (java.util.HashMap)4 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 LinkedList (java.util.LinkedList)2 List (java.util.List)2 SemanticModules (org.drools.core.xml.SemanticModules)2 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)2 BPMNDISemanticModule (org.jbpm.bpmn2.xml.BPMNDISemanticModule)2 BPMNSemanticModule (org.jbpm.bpmn2.xml.BPMNSemanticModule)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 XmlProcessReader (org.jbpm.compiler.xml.XmlProcessReader)2 EventFilter (org.jbpm.process.core.event.EventFilter)2