use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoricProcessInstanceEntityManager method deleteHistoricProcessInstanceById.
@SuppressWarnings("unchecked")
public void deleteHistoricProcessInstanceById(String historicProcessInstanceId) {
if (getHistoryManager().isHistoryEnabled()) {
CommandContext commandContext = Context.getCommandContext();
HistoricProcessInstanceEntity historicProcessInstance = findHistoricProcessInstance(historicProcessInstanceId);
commandContext.getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(historicProcessInstanceId);
commandContext.getHistoricVariableInstanceEntityManager().deleteHistoricVariableInstanceByProcessInstanceId(historicProcessInstanceId);
commandContext.getHistoricActivityInstanceEntityManager().deleteHistoricActivityInstancesByProcessInstanceId(historicProcessInstanceId);
commandContext.getHistoricTaskInstanceEntityManager().deleteHistoricTaskInstancesByProcessInstanceId(historicProcessInstanceId);
commandContext.getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLinksByProcInstance(historicProcessInstanceId);
commandContext.getCommentEntityManager().deleteCommentsByProcessInstanceId(historicProcessInstanceId);
commandContext.getAttachmentEntityManager().deleteAttachmentsByProcessInstanceId(historicProcessInstanceId);
getDbSqlSession().delete(historicProcessInstance);
// Also delete any sub-processes that may be active (ACT-821)
HistoricProcessInstanceQueryImpl subProcessesQueryImpl = new HistoricProcessInstanceQueryImpl();
subProcessesQueryImpl.superProcessInstanceId(historicProcessInstanceId);
List<HistoricProcessInstance> selectList = getDbSqlSession().selectList("selectHistoricProcessInstancesByQueryCriteria", subProcessesQueryImpl);
for (HistoricProcessInstance child : selectList) {
deleteHistoricProcessInstanceById(child.getId());
}
}
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoricProcessInstanceTest method testDeleteReason.
@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public // ACT-1098
void testDeleteReason() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
final String deleteReason = "some delete reason";
ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.deleteProcessInstance(pi.getId(), deleteReason);
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
assertEquals(deleteReason, hpi.getDeleteReason());
}
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoricActivityInstanceTest method testHistoricActivityInstanceCalledProcessId.
@Deployment(resources = { "org/activiti/engine/test/history/calledProcess.bpmn20.xml", "org/activiti/engine/test/history/HistoricActivityInstanceTest.testCallSimpleSubProcess.bpmn20.xml" })
public void testHistoricActivityInstanceCalledProcessId() {
runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("callSubProcess").singleResult();
HistoricProcessInstance oldInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("calledProcess").singleResult();
assertEquals(oldInstance.getId(), historicActivityInstance.getCalledProcessInstanceId());
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoricProcessInstanceTest method testHistoricDataCreatedForProcessExecution.
@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricDataCreatedForProcessExecution() {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, 2010);
calendar.set(Calendar.MONTH, 8);
calendar.set(Calendar.DAY_OF_MONTH, 30);
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date noon = calendar.getTime();
processEngineConfiguration.getClock().setCurrentTime(noon);
final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().count());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getBusinessKey(), historicProcessInstance.getBusinessKey());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertNull(historicProcessInstance.getEndTime());
assertNull(historicProcessInstance.getDurationInMillis());
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(1, tasks.size());
// in this test scenario we assume that 25 seconds after the process start, the
// user completes the task (yes! he must be almost as fast as me)
Date twentyFiveSecsAfterNoon = new Date(noon.getTime() + 25 * 1000);
processEngineConfiguration.getClock().setCurrentTime(twentyFiveSecsAfterNoon);
taskService.complete(tasks.get(0).getId());
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertEquals(twentyFiveSecsAfterNoon, historicProcessInstance.getEndTime());
assertEquals(new Long(25 * 1000), historicProcessInstance.getDurationInMillis());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoricProcessInstanceTest method testHistoricProcessInstanceSorting.
@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricProcessInstanceSorting() {
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().asc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().desc().list().size());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().asc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().desc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().desc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().desc().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().desc().count());
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// First complete process instance 2
for (Task task : taskService.createTaskQuery().processInstanceId(processInstance2.getId()).list()) {
taskService.complete(task.getId());
}
// Then process instance 1
for (Task task : taskService.createTaskQuery().processInstanceId(processInstance1.getId()).list()) {
taskService.complete(task.getId());
}
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().asc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().desc().list().size());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().asc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceId().desc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceDuration().desc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessDefinitionId().desc().count());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceBusinessKey().desc().count());
// Verify orderByProcessInstanceEndTime
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().list();
assertEquals(processInstance1.getId(), historicProcessInstances.get(0).getId());
assertEquals(processInstance2.getId(), historicProcessInstances.get(1).getId());
// Verify again, with variables included (bug reported on that)
historicProcessInstances = historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceEndTime().desc().includeProcessVariables().list();
assertEquals(processInstance1.getId(), historicProcessInstances.get(0).getId());
assertEquals(processInstance2.getId(), historicProcessInstances.get(1).getId());
}
Aggregations