Search in sources :

Example 1 with TaskInfo

use of org.activiti.engine.task.TaskInfo in project crnk-framework by crnk-project.

the class ActivitiResourceMapperTest method checkTask.

@Test
public void checkTask() {
    Map<String, Object> variables = mapper.mapToVariables(taskResource);
    Assert.assertEquals(1, variables.size());
    Assert.assertEquals(47, variables.get("someIntValue"));
    TestTask taskCopy = new TestTask();
    mapper.mapFromVariables(taskCopy, variables);
    checkTaskResource(taskCopy);
    TaskInfo task = Mockito.mock(TaskInfo.class);
    Mockito.when(task.getName()).thenReturn("someTask");
    Mockito.when(task.getTaskLocalVariables()).thenReturn(variables);
    TestTask taskResourceCopy = mapper.mapToResource(TestTask.class, task);
    checkTaskResource(taskResourceCopy);
    Assert.assertEquals("someTask", taskResourceCopy.getName());
    Map<String, Object> updatedVariables = Mockito.spy(new HashMap<String, Object>());
    Task updatedTask = Mockito.mock(Task.class);
    Mockito.when(updatedTask.getTaskLocalVariables()).thenReturn(updatedVariables);
    taskResourceCopy.setPriority(12);
    taskResourceCopy.setSomeIntValue(5);
    mapper.mapFromResource(taskResourceCopy, updatedTask);
    Mockito.verify(updatedTask, Mockito.times(1)).setPriority(Mockito.eq(12));
    Mockito.verify(updatedVariables, Mockito.times(1)).put(Mockito.eq("someIntValue"), Mockito.eq(Integer.valueOf(5)));
}
Also used : TaskInfo(org.activiti.engine.task.TaskInfo) Task(org.activiti.engine.task.Task) Test(org.junit.Test)

Example 2 with TaskInfo

use of org.activiti.engine.task.TaskInfo in project Activiti by Activiti.

the class SaveTaskCmd method execute.

public Task execute(CommandContext commandContext) {
    if (task == null) {
        throw new ActivitiIllegalArgumentException("task is null");
    }
    if (task.getRevision() == 0) {
        commandContext.getTaskEntityManager().insert(task, null);
        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_CREATED, task));
            if (task.getAssignee() != null) {
                commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, task));
            }
        }
    } else {
        TaskInfo originalTaskEntity = null;
        if (commandContext.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            originalTaskEntity = commandContext.getHistoricTaskInstanceEntityManager().findById(task.getId());
        }
        if (originalTaskEntity == null) {
            originalTaskEntity = commandContext.getTaskEntityManager().findById(task.getId());
        }
        String originalName = originalTaskEntity.getName();
        String originalAssignee = originalTaskEntity.getAssignee();
        String originalOwner = originalTaskEntity.getOwner();
        String originalDescription = originalTaskEntity.getDescription();
        Date originalDueDate = originalTaskEntity.getDueDate();
        int originalPriority = originalTaskEntity.getPriority();
        String originalCategory = originalTaskEntity.getCategory();
        String originalFormKey = originalTaskEntity.getFormKey();
        String originalParentTaskId = originalTaskEntity.getParentTaskId();
        String originalTaskDefinitionKey = originalTaskEntity.getTaskDefinitionKey();
        // Only update history if history is enabled
        if (commandContext.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            if (!StringUtils.equals(originalName, task.getName())) {
                commandContext.getHistoryManager().recordTaskNameChange(task.getId(), task.getName());
            }
            if (!StringUtils.equals(originalDescription, task.getDescription())) {
                commandContext.getHistoryManager().recordTaskDescriptionChange(task.getId(), task.getDescription());
            }
            if ((originalDueDate == null && task.getDueDate() != null) || (originalDueDate != null && task.getDueDate() == null) || (originalDueDate != null && !originalDueDate.equals(task.getDueDate()))) {
                commandContext.getHistoryManager().recordTaskDueDateChange(task.getId(), task.getDueDate());
            }
            if (originalPriority != task.getPriority()) {
                commandContext.getHistoryManager().recordTaskPriorityChange(task.getId(), task.getPriority());
            }
            if (!StringUtils.equals(originalCategory, task.getCategory())) {
                commandContext.getHistoryManager().recordTaskCategoryChange(task.getId(), task.getCategory());
            }
            if (!StringUtils.equals(originalFormKey, task.getFormKey())) {
                commandContext.getHistoryManager().recordTaskFormKeyChange(task.getId(), task.getFormKey());
            }
            if (!StringUtils.equals(originalParentTaskId, task.getParentTaskId())) {
                commandContext.getHistoryManager().recordTaskParentTaskIdChange(task.getId(), task.getParentTaskId());
            }
            if (!StringUtils.equals(originalTaskDefinitionKey, task.getTaskDefinitionKey())) {
                commandContext.getHistoryManager().recordTaskDefinitionKeyChange(task.getId(), task.getTaskDefinitionKey());
            }
        }
        if (!StringUtils.equals(originalOwner, task.getOwner())) {
            if (task.getProcessInstanceId() != null) {
                commandContext.getIdentityLinkEntityManager().involveUser(task.getProcessInstance(), task.getOwner(), IdentityLinkType.PARTICIPANT);
            }
            commandContext.getHistoryManager().recordTaskOwnerChange(task.getId(), task.getOwner());
        }
        if (!StringUtils.equals(originalAssignee, task.getAssignee())) {
            if (task.getProcessInstanceId() != null) {
                commandContext.getIdentityLinkEntityManager().involveUser(task.getProcessInstance(), task.getAssignee(), IdentityLinkType.PARTICIPANT);
            }
            commandContext.getHistoryManager().recordTaskAssigneeChange(task.getId(), task.getAssignee());
            commandContext.getProcessEngineConfiguration().getListenerNotificationHelper().executeTaskListeners(task, TaskListener.EVENTNAME_ASSIGNMENT);
            commandContext.getHistoryManager().recordTaskAssignment(task);
            if (commandContext.getEventDispatcher().isEnabled()) {
                commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, task));
            }
        }
        return commandContext.getTaskEntityManager().update(task);
    }
    return null;
}
Also used : TaskInfo(org.activiti.engine.task.TaskInfo) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Date(java.util.Date)

Aggregations

TaskInfo (org.activiti.engine.task.TaskInfo)2 Date (java.util.Date)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 Task (org.activiti.engine.task.Task)1 Test (org.junit.Test)1