提交 f1fe4b73 编写于 作者: T Tijs Rademakers

Merge pull request #441 from martin-grofcik/PROCESS_CANCELLED

PROCESS_CANCELLED event implementation
......@@ -18,11 +18,6 @@ package org.activiti.engine.delegate.event;
*
* @author martin.grofcik
*/
public interface ActivitiActivityCancelledEvent extends ActivitiActivityEvent {
public interface ActivitiActivityCancelledEvent extends ActivitiActivityEvent, ActivitiCancelledEvent{
/**
* @return the cause of the cancel event. Returns null, if no specific cause has been specified.
*/
public Object getCause();
}
package org.activiti.engine.delegate.event;
/**
* An {@link org.activiti.engine.delegate.event.ActivitiEvent} related to cancel event being sent when activiti
* object is cancelled.
*
* @author martin.grofcik
*/
public interface ActivitiCancelledEvent extends ActivitiEvent{
/**
* @return the cause of the cancel event. Returns null, if no specific cause has been specified.
*/
public Object getCause();
}
......@@ -187,6 +187,13 @@ public enum ActivitiEventType {
*/
PROCESS_COMPLETED,
/**
* A process has been cancelled. Dispatched when process instance is deleted by
* @see org.activiti.engine.impl.RuntimeServiceImpl#deleteProcessInstance(java.lang.String, java.lang.String), before
* DB delete.
*/
PROCESS_CANCELLED,
/**
* A new membership has been created.
*/
......
......@@ -172,7 +172,17 @@ public class ActivitiEventBuilder {
return newEvent;
}
public static ActivitiSignalEvent createSignalEvent(ActivitiEventType type, String activityId, String signalName, Object signalData,
public static ActivitiCancelledEvent createCancelledEvent(String executionId, String processInstanceId,
String processDefinitionId, Object cause) {
ActivitiProcessCancelledEventImpl newEvent = new ActivitiProcessCancelledEventImpl();
newEvent.setExecutionId(executionId);
newEvent.setProcessDefinitionId(processDefinitionId);
newEvent.setProcessInstanceId(processInstanceId);
newEvent.setCause(cause);
return newEvent;
}
public static ActivitiSignalEvent createSignalEvent(ActivitiEventType type, String activityId, String signalName, Object signalData,
String executionId, String processInstanceId, String processDefinitionId) {
ActivitiSignalEventImpl newEvent = new ActivitiSignalEventImpl(type);
newEvent.setActivityId(activityId);
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.delegate.event.impl;
import org.activiti.engine.delegate.event.ActivitiCancelledEvent;
import org.activiti.engine.delegate.event.ActivitiEventType;
/**
* An {@link org.activiti.engine.delegate.event.ActivitiCancelledEvent} implementation.
*
* @author martin.grofcik
*/
public class ActivitiProcessCancelledEventImpl extends ActivitiEventImpl implements ActivitiCancelledEvent {
protected Object cause;
public ActivitiProcessCancelledEventImpl() {
super(ActivitiEventType.PROCESS_CANCELLED);
}
public void setCause(Object cause) {
this.cause = cause;
}
public Object getCause() {
return cause;
}
}
......@@ -12,12 +12,12 @@
*/
package org.activiti.engine.impl.cmd;
import java.io.Serializable;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.delegate.event.impl.ActivitiEventBuilder;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import java.io.Serializable;
/**
* @author Joram Barrez
......@@ -42,7 +42,13 @@ public class DeleteProcessInstanceCmd implements Command<Void>, Serializable {
if (deleteReason == null) {
deleteReason = "ACTIVITI_DELETED";
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createCancelledEvent(this.processInstanceId
, this.processInstanceId, null, deleteReason));
}
commandContext
.getExecutionEntityManager()
.deleteProcessInstance(processInstanceId, deleteReason);
......
......@@ -12,19 +12,16 @@
*/
package org.activiti.engine.test.api.event;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.activiti.engine.delegate.event.*;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
import java.util.ArrayList;
import java.util.List;
/**
* Test case for all {@link ActivitiEvent}s related to process instances.
*
......@@ -112,15 +109,15 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), "Testing events");
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
listener.clearEventsReceived();
}
List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
assertEquals(1, processCancelledEvents.size());
ActivitiCancelledEvent cancelledEvent = (ActivitiCancelledEvent) processCancelledEvents.get(0);
assertEquals(ActivitiEventType.PROCESS_CANCELLED, cancelledEvent.getType());
assertEquals(processInstance.getId(), cancelledEvent.getProcessInstanceId());
assertEquals(processInstance.getId(), cancelledEvent.getExecutionId());
listener.clearEventsReceived();
}
/**
* Test create, update and delete events of process instances.
......@@ -185,7 +182,7 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
public void testProcessCompleted_StartEnd() throws Exception {
this.runtimeService.startProcessInstanceByKey("noneTaskProcess");
listener.checkEventCount(1, ActivitiEventType.PROCESS_COMPLETED);
assertEquals("ActivitiEventType.PROCESS_COMPLETED was expected 1 time.", 1, listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED).size());
}
/**
......@@ -197,7 +194,7 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
Task task = taskService.createTaskQuery().processInstanceId(noEndProcess.getId()).singleResult();
taskService.complete(task.getId());
listener.checkEventCount(1, ActivitiEventType.PROCESS_COMPLETED);
assertEquals("ActivitiEventType.PROCESS_COMPLETED was expected 1 time.", 1, listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED).size());
}
/**
......@@ -212,7 +209,7 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
public void testProcessCompleted_ParallelGatewayNoEnd() throws Exception {
this.runtimeService.startProcessInstanceByKey("noEndProcess");
listener.checkEventCount(1, ActivitiEventType.PROCESS_COMPLETED);
assertEquals("ActivitiEventType.PROCESS_COMPLETED was expected 1 time.", 1, listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED).size());
}
/**
......@@ -227,7 +224,36 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
public void testProcessCompleted_ParallelGatewayTwoEnds() throws Exception {
this.runtimeService.startProcessInstanceByKey("noEndProcess");
listener.checkEventCount(1, ActivitiEventType.PROCESS_COMPLETED);
assertEquals("ActivitiEventType.PROCESS_COMPLETED was expected 1 time.", 1, listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED).size());
}
@Deployment(resources = {"org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testProcessInstanceCancelledEvents_cancell() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), "delete_test");
List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
assertEquals("ActivitiEventType.PROCESS_CANCELLED was expected 1 time.", 1, processCancelledEvents.size());
assertTrue("The cause has to be the same as deleteProcessInstance method call", ActivitiCancelledEvent.class.isAssignableFrom(processCancelledEvents.get(0).getClass()));
assertEquals("The process instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), processCancelledEvents.get(0).getProcessInstanceId());
assertEquals("The execution instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), processCancelledEvents.get(0).getExecutionId());
assertEquals("The cause has to be the same as in deleteProcessInstance method call", "delete_test", ((ActivitiCancelledEvent) processCancelledEvents.get(0)).getCause());
listener.clearEventsReceived();
}
@Deployment(resources = {"org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testProcessInstanceCancelledEvents_complete() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
assertEquals("There should be no ActivitiEventType.PROCESS_CANCELLED event after process complete.", 0, processCancelledEvents.size());
}
@Override
......@@ -270,6 +296,8 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
// check whether entity in the event is initialized before adding to the list.
assertNotNull(((ExecutionEntity) ((ActivitiEntityEvent) event).getEntity()).getId());
eventsReceived.add(event);
} else if (ActivitiEventType.PROCESS_CANCELLED.equals(event.getType())) {
eventsReceived.add(event);
}
}
......@@ -278,15 +306,15 @@ public class ProcessInstanceEventsTest extends PluggableActivitiTestCase {
return true;
}
public void checkEventCount(int expectedCount, ActivitiEventType eventType) {// count timer cancelled events
int actualCount = 0;
public List<ActivitiEvent> filterEvents(ActivitiEventType eventType) {// count timer cancelled events
List<ActivitiEvent> filteredEvents = new ArrayList<ActivitiEvent>();
List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
for (ActivitiEvent eventReceived : eventsReceived) {
if (eventType.equals(eventReceived.getType())) {
actualCount++;
filteredEvents.add(eventReceived);
}
}
assertEquals(eventType.name() + " event was expected " + expectedCount + " times.", expectedCount, actualCount);
return filteredEvents;
}
}
......
......@@ -1188,6 +1188,14 @@ in your subclass, BPMN-event throwing can be prevented. The classes involved are
<literal>org.activiti...ActivitiEntityEvent</literal>
</entry>
</row>
<row>
<entry>PROCESS_CANCELLED</entry>
<entry>A process has been cancelled. Dispatched before the process instance is deleted from runtime. Process instance is cancelled by API call <literal>RuntimeService.deleteProcessInstance</entry>literal>.
</entry>
<entry>
<literal>org.activiti...ActivitiCancelledEvent</literal>
</entry>
</row>
<row>
<entry>MEMBERSHIP_CREATED</entry>
<entry>A user has been added to a group. The event contains the id's of the user and group involved.</entry>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册