Search in sources :

Example 16 with TaskEntity

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);
}
Also used : TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ActivitiEntityWithVariablesEvent(org.activiti.engine.delegate.event.ActivitiEntityWithVariablesEvent) HashMap(java.util.HashMap)

Example 17 with TaskEntity

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);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) TaskFormHandler(org.activiti.engine.impl.form.TaskFormHandler) TaskFormData(org.activiti.engine.form.TaskFormData) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) FormEngine(org.activiti.engine.impl.form.FormEngine)

Example 18 with TaskEntity

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());
}
Also used : ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity)

Example 19 with TaskEntity

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());
}
Also used : ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) Task(org.activiti.engine.task.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity)

Example 20 with TaskEntity

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);
}
Also used : Task(org.activiti.engine.task.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)21 ActivitiException (org.activiti.engine.ActivitiException)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 ActivitiEntityEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl)4 Date (java.util.Date)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)3 Task (org.activiti.engine.task.Task)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Expression (org.activiti.engine.delegate.Expression)1 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)1 ActivitiEntityWithVariablesEvent (org.activiti.engine.delegate.event.ActivitiEntityWithVariablesEvent)1 TaskFormData (org.activiti.engine.form.TaskFormData)1 BusinessCalendar (org.activiti.engine.impl.calendar.BusinessCalendar)1 DueDateBusinessCalendar (org.activiti.engine.impl.calendar.DueDateBusinessCalendar)1 FormEngine (org.activiti.engine.impl.form.FormEngine)1 TaskFormHandler (org.activiti.engine.impl.form.TaskFormHandler)1 CommentEntity (org.activiti.engine.impl.persistence.entity.CommentEntity)1