use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testEscalationBoundaryEventInterruptsTask.
@Test
@Ignore("Escalation does not cancel work items yet.")
public // TODO: make escalation interrupt tasks -- or look more closely at the spec to make sure that's the case?
void testEscalationBoundaryEventInterruptsTask() 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);
// Check for cancellation of task
assertEquals("WorkItem was not cancelled!", WorkItem.ABORTED, handler.getWorkItem().getState());
}
use of org.jbpm.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();
}
}
use of org.jbpm.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();
}
}
use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class BoundaryEventHandler method handleEscalationNode.
@SuppressWarnings("unchecked")
protected void handleEscalationNode(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);
/**
* TODO: because of how we process bpmn2/xml files, we can't tell
* if the cancelActivity attribute is set to false or not
* (because we override with the xsd settings)
* BPMN2 spec, p. 255, Escalation row:
* "In contrast to an Error, an Escalation by default is assumed to not abort
* the Activity to which the boundary Event is attached."
*/
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 ("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);
}
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
String type = escalation.getEscalationCode();
eventFilter.setType("Escalation-" + attachedTo + "-" + type);
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
eventNode.setMetaData("EscalationEvent", type);
} else {
throw new UnsupportedOperationException("General escalation is not yet supported.");
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.bpmn2.core.Escalation in project jbpm by kiegroup.
the class EscalationEventTest method testEventSubprocessEscalation.
@Test
public void testEventSubprocessEscalation() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EventSubprocessEscalation.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-EventSubprocessEscalation");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
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");
assertEquals(1, executednodes.size());
}
Aggregations