use of org.activiti.engine.impl.persistence.entity.TaskEntity in project Activiti by Activiti.
the class TaskCompletedEventHandler method generateEventLogEntry.
@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
ActivitiEntityWithVariablesEvent eventWithVariables = (ActivitiEntityWithVariablesEvent) event;
TaskEntity task = (TaskEntity) eventWithVariables.getEntity();
Map<String, Object> data = handleCommonTaskFields(task);
long duration = timeStamp.getTime() - task.getCreateTime().getTime();
putInMapIfNotNull(data, Fields.DURATION, duration);
if (eventWithVariables.getVariables() != null && !eventWithVariables.getVariables().isEmpty()) {
Map<String, Object> variableMap = new HashMap<String, Object>();
for (Object variableName : eventWithVariables.getVariables().keySet()) {
putInMapIfNotNull(variableMap, (String) variableName, eventWithVariables.getVariables().get(variableName));
}
if (eventWithVariables.isLocalScope()) {
putInMapIfNotNull(data, Fields.LOCAL_VARIABLES, variableMap);
} else {
putInMapIfNotNull(data, Fields.VARIABLES, variableMap);
}
}
return createEventLogEntry(task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getExecutionId(), task.getId(), data);
}
use of org.activiti.engine.impl.persistence.entity.TaskEntity in project Activiti by Activiti.
the class GetRenderedTaskFormCmd method execute.
public Object execute(CommandContext commandContext) {
TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
}
if (task.getTaskDefinition() == null) {
throw new ActivitiException("Task form definition for '" + taskId + "' not found");
}
TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
if (taskFormHandler == null) {
return null;
}
FormEngine formEngine = commandContext.getProcessEngineConfiguration().getFormEngines().get(formEngineName);
if (formEngine == null) {
throw new ActivitiException("No formEngine '" + formEngineName + "' defined process engine configuration");
}
TaskFormData taskForm = taskFormHandler.createTaskForm(task);
return formEngine.renderTaskForm(taskForm);
}
use of org.activiti.engine.impl.persistence.entity.TaskEntity in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method addAndRemoveEventListenerAllEvents.
/**
* Test adding a listener and check if events are sent to it. Also checks that
* after removal, no events are received.
*/
public void addAndRemoveEventListenerAllEvents() throws Exception {
// Create a listener that just adds the events to a list
TestActivitiEventListener newListener = new TestActivitiEventListener();
// Add event-listener to dispatcher
dispatcher.addEventListener(newListener);
ActivitiEntityEventImpl event1 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl event2 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
// Dispatch events
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertEquals(2, newListener.getEventsReceived().size());
assertEquals(event1, newListener.getEventsReceived().get(0));
assertEquals(event2, newListener.getEventsReceived().get(1));
// Remove listener and dispatch events again, listener should not be invoked
dispatcher.removeEventListener(newListener);
newListener.clearEventsReceived();
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertTrue(newListener.getEventsReceived().isEmpty());
}
use of org.activiti.engine.impl.persistence.entity.TaskEntity in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method baseEntityEventListener.
/**
* Test the {@link BaseEntityEventListener} shipped with Activiti.
*/
public void baseEntityEventListener() throws Exception {
TestBaseEntityEventListener listener = new TestBaseEntityEventListener();
dispatcher.addEventListener(listener);
ActivitiEntityEventImpl createEvent = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl deleteEvent = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_DELETED);
ActivitiEntityEventImpl updateEvent = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_UPDATED);
ActivitiEntityEventImpl otherEvent = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.CUSTOM);
// Dispatch create event
dispatcher.dispatchEvent(createEvent);
assertTrue(listener.isCreateReceived());
assertFalse(listener.isUpdateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isInitializeReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Dispatch update event
dispatcher.dispatchEvent(updateEvent);
assertTrue(listener.isUpdateReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Dispatch delete event
dispatcher.dispatchEvent(deleteEvent);
assertTrue(listener.isDeleteReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isUpdateReceived());
listener.reset();
// Dispatch other event
dispatcher.dispatchEvent(otherEvent);
assertTrue(listener.isCustomReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isUpdateReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Test typed entity-listener
listener = new TestBaseEntityEventListener(Task.class);
// Dispatch event for a task, should be received
dispatcher.addEventListener(listener);
dispatcher.dispatchEvent(createEvent);
assertTrue(listener.isCreateReceived());
listener.reset();
// Dispatch event for a execution, should NOT be received
ActivitiEntityEventImpl createEventForExecution = new ActivitiEntityEventImpl(new ExecutionEntity(), ActivitiEventType.ENTITY_CREATED);
dispatcher.dispatchEvent(createEventForExecution);
assertFalse(listener.isCreateReceived());
}
use of org.activiti.engine.impl.persistence.entity.TaskEntity in project Activiti by Activiti.
the class TaskEventsTest method testTaskEventsInProcess.
/**
* Check create, update and delete events for a task.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskEventsInProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Check create event
assertEquals(3, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
Task taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertExecutionDetails(event, processInstance);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.TASK_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Update duedate, owner and priority should trigger update-event
taskService.setDueDate(task.getId(), new Date());
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertExecutionDetails(event, processInstance);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
listener.clearEventsReceived();
taskService.setPriority(task.getId(), 12);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
taskService.setOwner(task.getId(), "kermit");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Updating detached task and calling saveTask should trigger a single update-event
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
task.setDueDate(new Date());
task.setOwner("john");
taskService.saveTask(task);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Check delete-event on complete
taskService.complete(task.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TASK_COMPLETED, event.getType());
assertExecutionDetails(event, processInstance);
TaskEntity taskEntity = (TaskEntity) event.getEntity();
assertNotNull(taskEntity.getDueDate());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertExecutionDetails(event, processInstance);
}
Aggregations