use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeys.
@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeys() {
JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
Collection<String> processDefinitionKeys = new ArrayList<>();
DateTime startTime = new DateTime();
DateTime endTime = new DateTime();
HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys))).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.unfinished()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.startedAfter(startTime.toDate())).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.finishedBefore(endTime.toDate())).thenReturn(historicProcessInstanceQuery);
List<HistoricProcessInstance> expectedHistoricProcessInstances = new ArrayList<>();
when(historicProcessInstanceQuery.list()).thenReturn(expectedHistoricProcessInstances);
List<HistoricProcessInstance> actualHistoricProcessInstance = activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
assertSame(expectedHistoricProcessInstances, actualHistoricProcessInstance);
InOrder inOrder = inOrder(historicProcessInstanceQuery);
inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
inOrder.verify(historicProcessInstanceQuery).unfinished();
inOrder.verify(historicProcessInstanceQuery).startedAfter(startTime.toDate());
inOrder.verify(historicProcessInstanceQuery).finishedBefore(endTime.toDate());
inOrder.verify(historicProcessInstanceQuery).list();
inOrder.verifyNoMoreInteractions();
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStartTimeNotSpecified.
@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStartTimeNotSpecified() {
JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
Collection<String> processDefinitionKeys = new ArrayList<>();
DateTime startTime = null;
DateTime endTime = new DateTime();
HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys))).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.unfinished()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.finishedBefore(endTime.toDate())).thenReturn(historicProcessInstanceQuery);
List<HistoricProcessInstance> expectedHistoricProcessInstances = new ArrayList<>();
when(historicProcessInstanceQuery.list()).thenReturn(expectedHistoricProcessInstances);
List<HistoricProcessInstance> actualHistoricProcessInstance = activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
assertSame(expectedHistoricProcessInstances, actualHistoricProcessInstance);
InOrder inOrder = inOrder(historicProcessInstanceQuery);
inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
inOrder.verify(historicProcessInstanceQuery).unfinished();
inOrder.verify(historicProcessInstanceQuery).finishedBefore(endTime.toDate());
inOrder.verify(historicProcessInstanceQuery).list();
inOrder.verifyNoMoreInteractions();
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class AbstractServiceTest method deleteAllHistoricJobs.
/**
* Deletes all Activiti jobs from the history table.
*/
protected void deleteAllHistoricJobs() {
HistoricProcessInstanceQuery query = activitiHistoryService.createHistoricProcessInstanceQuery();
List<HistoricProcessInstance> historicProcessInstances = query.list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
activitiHistoryService.deleteHistoricProcessInstance(historicProcessInstance.getId());
}
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project carbon-business-process by wso2.
the class ProcessStatisticsService method avgTaskTimeDurationForCompletedProcesses.
/**
* Average task duration for completed processes
*
* @param pId processDefintionId of the process selected to view the average time duration for each task
* @return list of completed tasks with the average time duration for the selected process
*/
@GET
@Path("/task-instances/duration/avarage/{pid}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder avgTaskTimeDurationForCompletedProcesses(@PathParam("pid") String pId) {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
HistoryService historyService = BPMNOSGIService.getHistoryService();
long processCount = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).processDefinitionId(pId).count();
if (processCount == 0) {
throw new ActivitiObjectNotFoundException("Count not find a matching process with PID '" + pId + "'.");
}
ResponseHolder response = new ResponseHolder();
List<Object> taskListForProcess = new ArrayList<>();
HashMap<String, Long> map = new HashMap<>();
// Get the number of completed/finished process instance for each process definition
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).processDefinitionId(pId).finished();
// Get the count of the complete process instances
long noOfHistoricInstances = historicProcessInstanceQuery.count();
// If the deployed process does not have any completed process instances --> Ignore
if (noOfHistoricInstances == 0) {
response.setData(taskListForProcess);
} else // If the deployed process has completed process instances --> then
{
TaskInstanceAverageInfo tInstance;
// Get the list of completed tasks/activities in the completed process instance by passing the
// process definition id of the process
List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).processDefinitionId(pId).processFinished().list();
// Iterate through each completed task/activity and get the task name and duration
for (HistoricTaskInstance taskInstance : taskList) {
// Get the task name
String taskKey = taskInstance.getTaskDefinitionKey();
// Get the time duration taken for the task to be completed
long taskDuration = taskInstance.getDurationInMillis();
if (map.containsKey(taskKey)) {
long tt = map.get(taskKey);
map.put(taskKey, taskDuration + tt);
} else {
map.put(taskKey, taskDuration);
}
// Iterating Task List finished
}
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
double value = map.get(key) / noOfHistoricInstances;
tInstance = new TaskInstanceAverageInfo();
tInstance.setTaskDefinitionKey(key);
tInstance.setAverageTimeForCompletion(value);
taskListForProcess.add(tInstance);
}
response.setData(taskListForProcess);
}
return response;
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project carbon-business-process by wso2.
the class BPMNInstanceService method deleteAllCompletedInstances.
/**
* Delete all completed instances
*/
public void deleteAllCompletedInstances() {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).finished();
for (HistoricProcessInstance instance : query.list()) {
historyService.deleteHistoricProcessInstance(instance.getId());
}
}
Aggregations