Search in sources :

Example 21 with Error

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

the class StartEventHandler method handleNode.

@SuppressWarnings("unchecked")
protected void 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")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode, startNode);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these elements)
        } else 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);
            }
        } 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);
            }
            startNode.setMetaData("MessageType", message.getType());
            addTriggerWithInMappings(startNode, "Message-" + messageRef);
        } 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)) {
            if (!startNode.isInterrupting()) {
                // 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)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            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;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                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 IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, element, xmlNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Message(org.jbpm.bpmn2.core.Message) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 22 with Error

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

the class XmlBPMNProcessDumper method visitErrors.

protected void visitErrors(Definitions definitions, StringBuilder xmlDump) {
    if (definitions == null) {
        return;
    }
    List<Error> errors = definitions.getErrors();
    if (errors == null || errors.isEmpty()) {
        return;
    }
    for (org.jbpm.bpmn2.core.Error error : errors) {
        String id = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(error.getId());
        String code = error.getErrorCode();
        xmlDump.append("  <error id=\"" + id + "\"");
        if (error.getErrorCode() != null) {
            code = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(code);
            xmlDump.append(" errorCode=\"" + code + "\"");
        }
        String structureRef = error.getStructureRef();
        if (structureRef != null) {
            structureRef = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(structureRef);
            xmlDump.append(" structureRef=\"" + structureRef + "\"");
        }
        xmlDump.append("/>" + EOL);
    }
}
Also used : Error(org.jbpm.bpmn2.core.Error) Error(org.jbpm.bpmn2.core.Error)

Example 23 with Error

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

the class StandaloneBPMNProcessTest method runTestErrorSignallingExceptionServiceTask.

public static void runTestErrorSignallingExceptionServiceTask(KieSession ksession) throws Exception {
    // Setup
    String eventType = "Error-code";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Object[] caughtEventObjectHolder = new Object[1];
    caughtEventObjectHolder[0] = null;
    ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    // Start process
    Map<String, Object> params = new HashMap<String, Object>();
    String input = "this is my service input";
    params.put("serviceInputItem", input);
    ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler);
    assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess.");
    workItem = (WorkItem) caughtEventObjectHolder[0];
    Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName);
    assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable.");
    assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input.");
    // Complete process
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertThat(processInstance == null || processInstance.getState() == ProcessInstance.STATE_ABORTED).isTrue().withFailMessage("Process instance has not been aborted.");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 24 with Error

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

the class EventSubprocessTest method testErrorCodeException.

@Test
@BZ("1082111")
public void testErrorCodeException() {
    KieSession ksession = createKSession(ERROR_CODE_EXCEPTION);
    ksession.getWorkItemManager().registerWorkItemHandler("Request Handler", new SignallingTaskHandlerDecorator(ExceptionOnPurposeHandler.class, "Error-90277"));
    ksession.getWorkItemManager().registerWorkItemHandler("Error Handler", new SystemOutWorkItemHandler());
    try {
        ProcessInstance processInstance = ksession.startProcess(ERROR_CODE_EXCEPTION_ID);
        assertProcessInstanceNotActive(processInstance.getId(), ksession);
        Assertions.assertThat(((WorkflowProcessInstance) processInstance).getOutcome()).isEqualTo("90277");
    } catch (WorkflowRuntimeException e) {
        fail("Error code exceptions in subprocess does not work.");
    }
}
Also used : SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 25 with Error

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

the class ServiceTaskHandler method getWSClient.

@SuppressWarnings("unchecked")
protected synchronized Client getWSClient(WorkItem workItem, String interfaceRef) {
    if (clients.containsKey(interfaceRef)) {
        return clients.get(interfaceRef);
    }
    long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
    WorkflowProcessImpl process = ((WorkflowProcessImpl) ksession.getProcessInstance(processInstanceId).getProcess());
    List<Bpmn2Import> typedImports = (List<Bpmn2Import>) process.getMetaData("Bpmn2Imports");
    if (typedImports != null) {
        Client client = null;
        for (Bpmn2Import importObj : typedImports) {
            if (WSDL_IMPORT_TYPE.equalsIgnoreCase(importObj.getType())) {
                try {
                    client = dcf.createClient(importObj.getLocation(), new QName(importObj.getNamespace(), interfaceRef), getInternalClassLoader(), null);
                    clients.put(interfaceRef, client);
                    logger.info("WS Client is created for {" + importObj.getNamespace() + "}" + interfaceRef);
                    return client;
                } catch (Exception e) {
                    logger.info("Error when creating WS Client. You can ignore this error as long as a client is eventually created", e);
                    continue;
                }
            }
        }
    }
    return null;
}
Also used : Bpmn2Import(org.jbpm.bpmn2.core.Bpmn2Import) QName(javax.xml.namespace.QName) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) List(java.util.List) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Client(org.apache.cxf.endpoint.Client) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Test (org.junit.Test)13 HashMap (java.util.HashMap)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 ArrayList (java.util.ArrayList)10 KieBase (org.kie.api.KieBase)9 List (java.util.List)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)7 Error (org.jbpm.bpmn2.core.Error)6 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)6 WorkItem (org.kie.api.runtime.process.WorkItem)6 Map (java.util.Map)5 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)4 Person (org.jbpm.bpmn2.objects.Person)4 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)4 Collections (java.util.Collections)3 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)3 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)3 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)3 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)3 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)3