Search in sources :

Example 1 with HistoricTaskInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity in project camunda-bpm-platform by camunda.

the class DeleteHistoricTaskInstanceCmd method execute.

public Object execute(CommandContext commandContext) {
    ensureNotNull("taskId", taskId);
    HistoricTaskInstanceEntity task = commandContext.getHistoricTaskInstanceManager().findHistoricTaskInstanceById(taskId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkDeleteHistoricTaskInstance(task);
    }
    commandContext.getHistoricTaskInstanceManager().deleteHistoricTaskInstanceById(taskId);
    return null;
}
Also used : CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) HistoricTaskInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity)

Example 2 with HistoricTaskInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceTest method testHistoricTaskInstance.

@Deployment
public void testHistoricTaskInstance() throws Exception {
    String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    // Set priority to non-default value
    Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    runtimeTask.setPriority(1234);
    // Set due-date
    Date dueDate = sdf.parse("01/02/2003 04:05:06");
    runtimeTask.setDueDate(dueDate);
    taskService.saveTask(runtimeTask);
    String taskId = runtimeTask.getId();
    String taskDefinitionKey = runtimeTask.getTaskDefinitionKey();
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId, historicTaskInstance.getId());
    assertEquals(1234, historicTaskInstance.getPriority());
    assertEquals("Clean up", historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
    assertEquals(dueDate, historicTaskInstance.getDueDate());
    assertEquals("kermit", historicTaskInstance.getAssignee());
    assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
    assertNull(historicTaskInstance.getEndTime());
    assertNull(historicTaskInstance.getDurationInMillis());
    assertNull(historicTaskInstance.getCaseDefinitionId());
    assertNull(historicTaskInstance.getCaseInstanceId());
    assertNull(historicTaskInstance.getCaseExecutionId());
    // the activity instance id is set
    assertEquals(((TaskEntity) runtimeTask).getExecution().getActivityInstanceId(), historicTaskInstance.getActivityInstanceId());
    runtimeService.setVariable(processInstanceId, "deadline", "yesterday");
    // move clock by 1 second
    Date now = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(new Date(now.getTime() + 1000));
    taskService.complete(taskId);
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals(taskId, historicTaskInstance.getId());
    assertEquals(1234, historicTaskInstance.getPriority());
    assertEquals("Clean up", historicTaskInstance.getName());
    assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
    assertEquals(dueDate, historicTaskInstance.getDueDate());
    assertEquals("kermit", historicTaskInstance.getAssignee());
    assertEquals(TaskEntity.DELETE_REASON_COMPLETED, historicTaskInstance.getDeleteReason());
    assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
    assertNotNull(historicTaskInstance.getEndTime());
    assertNotNull(historicTaskInstance.getDurationInMillis());
    assertTrue(historicTaskInstance.getDurationInMillis() >= 1000);
    assertTrue(((HistoricTaskInstanceEntity) historicTaskInstance).getDurationRaw() >= 1000);
    assertNull(historicTaskInstance.getCaseDefinitionId());
    assertNull(historicTaskInstance.getCaseInstanceId());
    assertNull(historicTaskInstance.getCaseExecutionId());
    historyService.deleteHistoricTaskInstance(taskId);
    assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
}
Also used : Task(org.camunda.bpm.engine.task.Task) HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) HistoricTaskInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricTaskInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricTaskInstanceEntity)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HistoricTaskInstance (org.camunda.bpm.engine.history.HistoricTaskInstance)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)1 Task (org.camunda.bpm.engine.task.Task)1 Deployment (org.camunda.bpm.engine.test.Deployment)1