Search in sources :

Example 46 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class MultiInstanceTest method testParallelUserTasksHistory.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelUserTasks.bpmn20.xml" })
public void testParallelUserTasksHistory() {
    runtimeService.startProcessInstanceByKey("miParallelUserTasks");
    for (Task task : taskService.createTaskQuery().list()) {
        taskService.complete(task.getId());
    }
    // Validate history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().orderByTaskAssignee().asc().list();
        for (int i = 0; i < historicTaskInstances.size(); i++) {
            HistoricTaskInstance hi = historicTaskInstances.get(i);
            assertNotNull(hi.getStartTime());
            assertNotNull(hi.getEndTime());
            assertEquals("kermit_" + i, hi.getAssignee());
        }
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("userTask").list();
        assertEquals(3, historicActivityInstances.size());
        for (HistoricActivityInstance hai : historicActivityInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
            assertNotNull(hai.getAssignee());
            assertEquals("userTask", hai.getActivityType());
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 47 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskInstanceVariableDataResource method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope, HttpServletRequest request) {
    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task variables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return restResponseFactory.createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary);
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 48 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class RestResponseFactory method createHistoricTaskInstanceResponseList.

public List<HistoricTaskInstanceResponse> createHistoricTaskInstanceResponseList(List<HistoricTaskInstance> taskInstances) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<HistoricTaskInstanceResponse> responseList = new ArrayList<HistoricTaskInstanceResponse>();
    for (HistoricTaskInstance instance : taskInstances) {
        responseList.add(createHistoricTaskInstanceResponse(instance, urlBuilder));
    }
    return responseList;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricTaskInstanceResponse(org.activiti.rest.service.api.history.HistoricTaskInstanceResponse) ArrayList(java.util.ArrayList)

Example 49 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class HistoricTaskInstanceTest method testVariableUpdateOrderHistoricTaskInstance.

/**
   * Test to validate fix for ACT-1939: HistoryService loads invalid task local variables for completed task
   */
@Deployment
public void testVariableUpdateOrderHistoricTaskInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("historicTask");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Update task and process-variable 10 times
    for (int i = 0; i < 10; i++) {
        taskService.setVariableLocal(task.getId(), "taskVar", i);
        runtimeService.setVariable(task.getExecutionId(), "procVar", i);
    }
    taskService.complete(task.getId());
    // Check if all variables have the value for the latest revision
    HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().singleResult();
    Object varValue = taskInstance.getProcessVariables().get("procVar");
    assertEquals(9, varValue);
    taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).includeTaskLocalVariables().singleResult();
    varValue = taskInstance.getTaskLocalVariables().get("taskVar");
    assertEquals(9, varValue);
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 50 with HistoricTaskInstance

use of org.activiti.engine.history.HistoricTaskInstance in project Activiti by Activiti.

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersionWithWithTask.

@Deployment(resources = { TEST_PROCESS_USER_TASK_V1 })
public void testSetProcessDefinitionVersionWithWithTask() {
    try {
        // start process instance
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("userTask");
        // check that user task has been reached    
        assertEquals(1, taskService.createTaskQuery().processInstanceId(pi.getId()).count());
        // deploy new version of the process definition
        org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_USER_TASK_V2).deploy();
        assertEquals(2, repositoryService.createProcessDefinitionQuery().processDefinitionKey("userTask").count());
        ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("userTask").processDefinitionVersion(2).singleResult();
        // migrate process instance to new process definition version
        processEngineConfiguration.getCommandExecutor().execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));
        // check UserTask
        Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        assertEquals(newProcessDefinition.getId(), task.getProcessDefinitionId());
        assertEquals("testFormKey", formService.getTaskFormData(task.getId()).getFormKey());
        if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
            HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(pi.getId()).singleResult();
            assertEquals(newProcessDefinition.getId(), historicTask.getProcessDefinitionId());
            assertEquals("testFormKey", formService.getTaskFormData(historicTask.getId()).getFormKey());
        }
        // continue
        taskService.complete(task.getId());
        assertProcessEnded(pi.getId());
        // undeploy "manually" deployed process definition
        repositoryService.deleteDeployment(deployment.getId(), true);
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)65 Task (org.activiti.engine.task.Task)27 Deployment (org.activiti.engine.test.Deployment)26 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)16 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)9 ArrayList (java.util.ArrayList)8 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)7 Date (java.util.Date)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Label (com.vaadin.ui.Label)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Attachment (org.activiti.engine.task.Attachment)4 Button (com.vaadin.ui.Button)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3