use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testInterruptingEscalationBoundaryEventOnTask.
@Test
public void testInterruptingEscalationBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventOnTaskInterrupting.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(LOGGING_EVENT_LISTENER);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EscalationBoundaryEventOnTask");
List<WorkItem> workItems = handler.getWorkItems();
assertEquals(2, workItems.size());
WorkItem workItem = workItems.get(0);
if (!"john".equalsIgnoreCase((String) workItem.getParameter("ActorId"))) {
workItem = workItems.get(1);
}
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testEscalationBoundaryEventInterrupting.
@Test
public void testEscalationBoundaryEventInterrupting() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventInterrupting.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("MyTask", handler);
ProcessInstance processInstance = ksession.startProcess("EscalationBoundaryEvent");
assertProcessInstanceCompleted(processInstance);
}
use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testGeneralEscalationBoundaryEventWithTask.
@Test
@Ignore("General escalation is not yet supported.")
public // TODO: implement asynchronous escalation
void testGeneralEscalationBoundaryEventWithTask() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "0");
ProcessInstance processInstance = ksession.startProcess("non-interrupting-escalation", params);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(processInstance);
// Did escalation fire?
assertProcessVarValue(processInstance, "x", "1");
}
use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testNonInterruptingEscalationBoundaryEventOnTask.
@Test
@Ignore("Non interrupting escalation has not yet been implemented.")
public // TODO: implement non-interrupting escalation
void testNonInterruptingEscalationBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(LOGGING_EVENT_LISTENER);
ProcessInstance processInstance = ksession.startProcess("non-interrupting-escalation");
List<WorkItem> workItems = handler.getWorkItems();
assertEquals(2, workItems.size());
WorkItem johnsWork = workItems.get(0);
WorkItem marysWork = workItems.get(1);
if (!"john".equalsIgnoreCase((String) johnsWork.getParameter("ActorId"))) {
marysWork = johnsWork;
johnsWork = workItems.get(1);
}
// end event after task triggers escalation
ksession.getWorkItemManager().completeWorkItem(johnsWork.getId(), null);
// escalation should have run..
// should finish process
ksession.getWorkItemManager().completeWorkItem(marysWork.getId(), null);
assertProcessInstanceCompleted(processInstance);
}
use of org.jbpm.bpmn2.core.Escalation 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();
}
}
Aggregations