[jbpm-commits] JBoss JBPM SVN: r6801 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/parser and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sun Nov 7 04:44:20 EST 2010
Author: rebody
Date: 2010-11-07 04:44:19 -0500 (Sun, 07 Nov 2010)
New Revision: 6801
Added:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryTimerEvent.java
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/timer/BoundaryEventTimerInterruptingTest.java
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/timer/boundary_event_timer_interrupting.bpmn.xml
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
Log:
JBPM-2728 interrupting boundary timer event.
Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryTimerEvent.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryTimerEvent.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryTimerEvent.java 2010-11-07 09:44:19 UTC (rev 6801)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.bpmn.flownodes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.api.model.Transition;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.internal.model.op.AtomicOperation;
+
+/**
+ * boundary timer event.
+ *
+ * @author Huisheng Xu
+ */
+public class BoundaryTimerEvent extends BpmnActivity implements EventListener, BpmnEvent {
+
+ protected String boundaryTimerEventActivityName;
+ protected boolean interrupting;
+
+ @SuppressWarnings("unchecked")
+ public void execute(ExecutionImpl execution) {
+ ProcessDefinitionImpl processDefinitionImpl = execution.getProcessDefinition();
+ ActivityImpl activityImpl = processDefinitionImpl.getActivity(boundaryTimerEventActivityName);
+ if (interrupting) {
+ ExecutionImpl parent = execution.destroyScope(execution.getActivity());
+ parent.moveTo(activityImpl);
+ parent.take(activityImpl.getOutgoingTransitions().get(0));
+ } else {
+ execution.takeDefaultTransition();
+ }
+ }
+
+ public void notify(EventListenerExecution execution) {
+ this.execute((ExecutionImpl) execution);
+ }
+
+ public boolean isInterrupting() {
+ return interrupting;
+ }
+
+ public void setInterrupting(boolean interrupting) {
+ this.interrupting = interrupting;
+ }
+
+ public void setBoundaryTimerEventActivityName(String boundaryTimerEventActivityName) {
+ this.boundaryTimerEventActivityName = boundaryTimerEventActivityName;
+ }
+
+}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-11-07 04:43:17 UTC (rev 6800)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-11-07 09:44:19 UTC (rev 6801)
@@ -35,9 +35,11 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.activity.ActivityBehaviour;
+import org.jbpm.api.listener.EventListener;
import org.jbpm.bpmn.common.Resource;
import org.jbpm.bpmn.common.ResourceParameter;
import org.jbpm.bpmn.flownodes.BpmnActivity;
+import org.jbpm.bpmn.flownodes.BoundaryTimerEvent;
import org.jbpm.bpmn.model.BpmnProcessDefinition;
import org.jbpm.bpmn.model.SequenceflowCondition;
import org.jbpm.internal.log.Log;
@@ -46,6 +48,8 @@
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.CompositeElementImpl;
+import org.jbpm.pvm.internal.model.EventImpl;
+import org.jbpm.pvm.internal.model.EventListenerReference;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.model.ScopeElementImpl;
import org.jbpm.pvm.internal.model.TimerDefinitionImpl;
@@ -135,6 +139,8 @@
// activities
parseActivities(processElement, parse, processDefinition);
+ parseBoundaryEvents(processElement, parse, processDefinition);
+
// bind activities to their destinations
parseSequenceFlow(processElement, parse, processDefinition);
@@ -241,6 +247,69 @@
}
}
+ public void parseBoundaryEvents(Element element, Parse parse, CompositeElementImpl compositeElement) {
+ List<Element> elements = XmlUtil.elements(element, "boundaryEvent");
+ for (Element boundaryEventElement : elements) {
+
+ String attachedToRef = XmlUtil.attribute(boundaryEventElement, "attachedToRef");
+ if (attachedToRef == null || attachedToRef.equals("")) {
+ parse.addProblem("AttachedToRef is required when using a timerEventDefinition : " + boundaryEventElement);
+ }
+
+ String id = XmlUtil.attribute(boundaryEventElement, "id");
+ if (log.isTraceEnabled()) {
+ log.trace("Parsing boundary event " + id);
+ }
+
+ ActivityImpl refActivity = compositeElement.findActivity(attachedToRef);
+ if (refActivity == null) {
+ parse.addProblem("Invalid reference in boundary event. Make sure that the referenced activity is "
+ + "defined in the same scope as the boundary event : " + boundaryEventElement);
+ }
+ ActivityImpl nestedActivity = compositeElement.createActivity(id);
+ nestedActivity.setDescription(parseDocumentation(boundaryEventElement));
+
+ String cancelActivity = XmlUtil.attribute(boundaryEventElement, "cancelActivity", "true");
+ boolean interrupting = cancelActivity.equals("true");
+
+ Element timerEventDefinition = XmlUtil.element(boundaryEventElement, "timerEventDefinition");
+ if (timerEventDefinition != null) {
+ parseBoundaryTimerEventDefinition(timerEventDefinition, interrupting, nestedActivity, refActivity, parse);
+ } else {
+ parse.addProblem("Unsupported boundary event type : " + boundaryEventElement);
+ }
+ }
+ }
+
+ public void parseBoundaryTimerEventDefinition(Element timerEventDefinition,
+ boolean interrupting,
+ ActivityImpl timerActivity,
+ ActivityImpl refActivity,
+ Parse parse) {
+
+ BoundaryTimerEvent boundaryTimerEvent = new BoundaryTimerEvent();
+ boundaryTimerEvent.setInterrupting(interrupting);
+ boundaryTimerEvent.setBoundaryTimerEventActivityName(timerActivity.getName());
+
+ // TimeDate
+
+ // TimeCycle
+
+ // TimeDuration
+ String eventName = refActivity.getName();
+ TimerDefinitionImpl timerDefinitionImpl = this.parseTimerEventDefinition(timerEventDefinition, parse, eventName);
+ timerDefinitionImpl.setEventName(eventName);
+ refActivity.addTimerDefinition(timerDefinitionImpl);
+
+ EventImpl event = refActivity.getEvent(eventName);
+ if (event == null) {
+ event = refActivity.createEvent(eventName);
+ }
+ EventListenerReference eventListenerReference = event.createEventListenerReference(boundaryTimerEvent);
+
+ timerActivity.setActivityBehaviour(boundaryTimerEvent);
+ }
+
public void parseSequenceFlow(Element element, Parse parse, BpmnProcessDefinition processDefinition) {
List<Element> transitionElements = XmlUtil.elements(element, "sequenceFlow");
for (Element transitionElement : transitionElements) {
@@ -257,6 +326,7 @@
// Create new outgoing transition on sourceActivity
ActivityImpl sourceActivity = processDefinition.findActivity(sourceRef);
+
TransitionImpl transition = null;
if (sourceActivity != null) {
transition = sourceActivity.createOutgoingTransition();
@@ -468,4 +538,12 @@
}
+ public String parseDocumentation(Element element) {
+ Element docElement = XmlUtil.element(element, "documentation");
+ if (docElement != null) {
+ return docElement.getTextContent().trim();
+ }
+ return null;
+ }
+
}
Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/timer/BoundaryEventTimerInterruptingTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/timer/BoundaryEventTimerInterruptingTest.java (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/timer/BoundaryEventTimerInterruptingTest.java 2010-11-07 09:44:19 UTC (rev 6801)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.examples.bpmn.event.timer;
+
+import java.util.Date;
+
+import org.jbpm.api.NewDeployment;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.job.Job;
+import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.util.Clock;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * @author Huisheng Xu
+ */
+public class BoundaryEventTimerInterruptingTest extends JbpmTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ NewDeployment deployment = repositoryService.createDeployment();
+ deployment.addResourceFromClasspath("org/jbpm/examples/bpmn/event/timer/boundary_event_timer_interrupting.bpmn.xml");
+ registerDeployment(deployment.deploy());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ Clock.setExplicitTime(null);
+ super.tearDown();
+ }
+
+ public void testIntermediateTimerWithDuration() {
+ Clock.setExplicitTime(new Date(0));
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("boundary_event_timer_interrupting");
+ Job timerJob = managementService.createJobQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(new Date(60 * 60 * 1000).getTime(), timerJob.getDueDate().getTime());
+
+ managementService.executeJob(timerJob.getId());
+ Task task = taskService.createTaskQuery().uniqueResult();
+ taskService.completeTask(task.getId());
+ assertProcessInstanceEnded(processInstance);
+ }
+
+}
Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/timer/boundary_event_timer_interrupting.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/timer/boundary_event_timer_interrupting.bpmn.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/timer/boundary_event_timer_interrupting.bpmn.xml 2010-11-07 09:44:19 UTC (rev 6801)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 ../../../../../../../../../../bpmn/src/main/resources/BPMN20.xsd"
+ xmlns="http://schema.omg.org/spec/BPMN/2.0"
+ typeLanguage="http://www.w3.org/2001/XMLSchema"
+ expressionLanguage="http://www.w3.org/1999/XPath"
+ targetNamespace="http://jbpm.org/example/bpmn2/terminate_end_event"
+ xmlns:jbpm="http://jbpm.org/bpmn2">
+
+ <process id="boundary_event_timer_interrupting" name="Timer escalation example">
+
+ <startEvent id="theStart" />
+
+ <sequenceFlow id="flow1" sourceRef="theStart" targetRef="firstLineSupport" />
+
+ <userTask id="firstLineSupport" name="First line support">
+ <documentation>Fix issue raised by customer</documentation>
+ </userTask>
+
+ <sequenceFlow id="flow2" sourceRef="firstLineSupport" targetRef="normalEnd" />
+
+ <endEvent id="normalEnd" />
+
+ <boundaryEvent id="escalationTimer" cancelActivity="true" attachedToRef="firstLineSupport">
+ <timerEventDefinition>
+ <timeDate xsi:type="tFormalExpression">01/01/1970 09:00:00</timeDate>
+ </timerEventDefinition>
+ </boundaryEvent>
+
+ <sequenceFlow id="flow3" sourceRef="escalationTimer" targetRef="secondLineSupport" />
+
+ <userTask id="secondLineSupport" name="Second line support">
+ <documentation>Escalation: issue was not fixed in time by first level support</documentation>
+ </userTask>
+
+ <sequenceFlow id="flow4" sourceRef="secondLineSupport" targetRef="escalatedEnd" />
+
+ <endEvent id="escalatedEnd" />
+
+ </process>
+
+</definitions>
\ No newline at end of file
More information about the jbpm-commits
mailing list