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());
}
}
}
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);
}
}
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;
}
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);
}
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());
}
}
Aggregations