Search in sources :

Example 21 with HistoricActivityStatisticsQuery

use of org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery in project camunda-bpm-platform by camunda.

the class HistoricActivityStatisticsQueryTest method testNoRunningProcessInstances.

@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityStatisticsQueryTest.testSingleTask.bpmn20.xml")
public void testNoRunningProcessInstances() {
    String processDefinitionId = getProcessDefinitionId();
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId);
    List<HistoricActivityStatistics> statistics = query.list();
    assertEquals(0, query.count());
    assertEquals(0, statistics.size());
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 22 with HistoricActivityStatisticsQuery

use of org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery in project camunda-bpm-platform by camunda.

the class HistoricActivityStatisticsQueryTest method testQueryByCanceledAndFinishedByPeriods.

@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityStatisticsQueryTest.testSingleTask.bpmn20.xml")
public void testQueryByCanceledAndFinishedByPeriods() throws ParseException {
    try {
        // start two process instances
        ClockUtil.setCurrentTime(sdf.parse("15.01.2016 12:00:00"));
        startProcesses(2);
        // cancel running process instances
        ClockUtil.setCurrentTime(sdf.parse("15.02.2016 12:00:00"));
        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
        for (ProcessInstance processInstance : processInstances) {
            runtimeService.deleteProcessInstance(processInstance.getId(), "test");
        }
        // start two process instances
        ClockUtil.setCurrentTime(sdf.parse("01.02.2016 12:00:00"));
        startProcesses(2);
        // complete running tasks
        ClockUtil.setCurrentTime(sdf.parse("25.02.2016 12:00:00"));
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.complete(task.getId());
        }
        // starte two more process instances
        ClockUtil.setCurrentTime(sdf.parse("15.03.2016 12:00:00"));
        startProcesses(2);
        // NOW
        ClockUtil.setCurrentTime(sdf.parse("25.03.2016 12:00:00"));
        String processDefinitionId = getProcessDefinitionId();
        // check January by started dates
        HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().startedAfter(sdf.parse("01.01.2016 00:00:00")).startedBefore(sdf.parse("31.01.2016 23:59:59")).orderByActivityId().asc();
        List<HistoricActivityStatistics> statistics = query.list();
        assertEquals(2, query.count());
        assertEquals(2, statistics.size());
        // start
        assertActivityStatistics(statistics.get(0), "start", 0, 0, 2);
        // task
        assertActivityStatistics(statistics.get(1), "task", 0, 2, 2);
        // check January by finished dates
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().finishedAfter(sdf.parse("01.01.2016 00:00:00")).finishedBefore(sdf.parse("31.01.2016 23:59:59")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(0, query.count());
        assertEquals(0, statistics.size());
        // check February by started dates
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().startedAfter(sdf.parse("01.02.2016 00:00:00")).startedBefore(sdf.parse("28.02.2016 23:59:59")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(3, query.count());
        assertEquals(3, statistics.size());
        // end
        assertActivityStatistics(statistics.get(0), "end", 0, 0, 2);
        // start
        assertActivityStatistics(statistics.get(1), "start", 0, 0, 2);
        // task
        assertActivityStatistics(statistics.get(2), "task", 0, 0, 2);
        // check February by finished dates
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().finishedAfter(sdf.parse("01.02.2016 00:00:00")).finishedBefore(sdf.parse("28.02.2016 23:59:59")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(3, query.count());
        assertEquals(3, statistics.size());
        // end
        assertActivityStatistics(statistics.get(0), "end", 0, 0, 2);
        // start
        assertActivityStatistics(statistics.get(1), "start", 0, 0, 4);
        // task
        assertActivityStatistics(statistics.get(2), "task", 0, 2, 4);
        // check March by started dates
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().startedAfter(sdf.parse("01.03.2016 00:00:00")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(2, query.count());
        assertEquals(2, statistics.size());
        // start
        assertActivityStatistics(statistics.get(0), "start", 0, 0, 2);
        // task
        assertActivityStatistics(statistics.get(1), "task", 2, 0, 0);
        // check March by finished dates
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().finishedAfter(sdf.parse("01.03.2016 00:00:00")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(0, query.count());
        assertEquals(0, statistics.size());
        // check whole period by started date
        query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCanceled().includeFinished().startedAfter(sdf.parse("01.01.2016 00:00:00")).orderByActivityId().asc();
        statistics = query.list();
        assertEquals(3, query.count());
        assertEquals(3, statistics.size());
        // end
        assertActivityStatistics(statistics.get(0), "end", 0, 0, 2);
        // start
        assertActivityStatistics(statistics.get(1), "start", 0, 0, 6);
        // task
        assertActivityStatistics(statistics.get(2), "task", 2, 2, 4);
    } finally {
        ClockUtil.reset();
    }
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 23 with HistoricActivityStatisticsQuery

use of org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery in project camunda-bpm-platform by camunda.

the class HistoricActivityStatisticsQueryTest method testQueryByFinishedMultipleRunningTasks.

@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityStatisticsQueryTest.testMultipleRunningTasks.bpmn20.xml")
public void testQueryByFinishedMultipleRunningTasks() {
    String processDefinitionId = getProcessDefinitionId();
    startProcesses(5);
    List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("innerTask").list();
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeFinished().orderByActivityId().asc();
    List<HistoricActivityStatistics> statistics = query.list();
    assertEquals(9, query.count());
    assertEquals(9, statistics.size());
    // end1
    HistoricActivityStatistics end1 = statistics.get(0);
    assertEquals("end1", end1.getId());
    assertEquals(0, end1.getInstances());
    assertEquals(5, end1.getFinished());
    // gtw
    HistoricActivityStatistics gtw = statistics.get(1);
    assertEquals("gtw", gtw.getId());
    assertEquals(0, gtw.getInstances());
    assertEquals(5, gtw.getFinished());
    // innerEnd
    HistoricActivityStatistics innerEnd = statistics.get(2);
    assertEquals("innerEnd", innerEnd.getId());
    assertEquals(0, innerEnd.getInstances());
    assertEquals(25, innerEnd.getFinished());
    // innerStart
    HistoricActivityStatistics innerStart = statistics.get(3);
    assertEquals("innerStart", innerStart.getId());
    assertEquals(0, innerStart.getInstances());
    assertEquals(25, innerStart.getFinished());
    // innerTask
    HistoricActivityStatistics innerTask = statistics.get(4);
    assertEquals("innerTask", innerTask.getId());
    assertEquals(0, innerTask.getInstances());
    assertEquals(25, innerTask.getFinished());
    // innerStart
    HistoricActivityStatistics start = statistics.get(5);
    assertEquals("start", start.getId());
    assertEquals(0, start.getInstances());
    assertEquals(5, start.getFinished());
    // subprocess
    HistoricActivityStatistics subProcess = statistics.get(6);
    assertEquals("subprocess", subProcess.getId());
    assertEquals(0, subProcess.getInstances());
    assertEquals(25, subProcess.getFinished());
    // subprocess - multi-instance body
    HistoricActivityStatistics subProcessMiBody = statistics.get(7);
    assertEquals("subprocess#multiInstanceBody", subProcessMiBody.getId());
    assertEquals(0, subProcessMiBody.getInstances());
    assertEquals(5, subProcessMiBody.getFinished());
    // task
    HistoricActivityStatistics task = statistics.get(8);
    assertEquals("task", task.getId());
    assertEquals(5, task.getInstances());
    assertEquals(0, task.getFinished());
    completeProcessInstances();
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) Task(org.camunda.bpm.engine.task.Task) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 24 with HistoricActivityStatisticsQuery

use of org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery in project camunda-bpm-platform by camunda.

the class HistoricActivityStatisticsQueryTest method testQueryByFinishedAndCompleteScope.

@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityStatisticsQueryTest.testSingleTask.bpmn20.xml")
public void testQueryByFinishedAndCompleteScope() {
    String processDefinitionId = getProcessDefinitionId();
    startProcesses(2);
    // cancel running process instances
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    for (ProcessInstance processInstance : processInstances) {
        runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    }
    startProcesses(2);
    // complete running tasks
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    startProcesses(2);
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeFinished().includeCompleteScope().orderByActivityId().asc();
    List<HistoricActivityStatistics> statistics = query.list();
    assertEquals(3, query.count());
    assertEquals(3, statistics.size());
    // end
    HistoricActivityStatistics end = statistics.get(0);
    assertEquals("end", end.getId());
    assertEquals(0, end.getInstances());
    assertEquals(2, end.getFinished());
    assertEquals(2, end.getCompleteScope());
    // start
    HistoricActivityStatistics start = statistics.get(1);
    assertEquals("start", start.getId());
    assertEquals(0, start.getInstances());
    assertEquals(6, start.getFinished());
    assertEquals(0, start.getCompleteScope());
    // task
    HistoricActivityStatistics task = statistics.get(2);
    assertEquals("task", task.getId());
    assertEquals(2, task.getInstances());
    assertEquals(4, task.getFinished());
    assertEquals(0, task.getCompleteScope());
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 25 with HistoricActivityStatisticsQuery

use of org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery in project camunda-bpm-platform by camunda.

the class HistoricProcessDefinitionRestServiceImpl method getHistoricActivityStatistics.

@Override
public List<HistoricActivityStatisticsDto> getHistoricActivityStatistics(UriInfo uriInfo, String processDefinitionId, Boolean includeCanceled, Boolean includeFinished, Boolean includeCompleteScope, String sortBy, String sortOrder) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId);
    if (includeCanceled != null && includeCanceled) {
        query.includeCanceled();
    }
    if (includeFinished != null && includeFinished) {
        query.includeFinished();
    }
    if (includeCompleteScope != null && includeCompleteScope) {
        query.includeCompleteScope();
    }
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    DateConverter dateConverter = new DateConverter();
    dateConverter.setObjectMapper(objectMapper);
    if (queryParameters.getFirst(QUERY_PARAM_STARTED_AFTER) != null) {
        Date startedAfter = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_STARTED_AFTER));
        query.startedAfter(startedAfter);
    }
    if (queryParameters.getFirst(QUERY_PARAM_STARTED_BEFORE) != null) {
        Date startedBefore = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_STARTED_BEFORE));
        query.startedBefore(startedBefore);
    }
    if (queryParameters.getFirst(QUERY_PARAM_FINISHED_AFTER) != null) {
        Date finishedAfter = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_FINISHED_AFTER));
        query.finishedAfter(finishedAfter);
    }
    if (queryParameters.getFirst(QUERY_PARAM_FINISHED_BEFORE) != null) {
        Date finishedBefore = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_FINISHED_BEFORE));
        query.finishedBefore(finishedBefore);
    }
    setSortOptions(query, sortOrder, sortBy);
    List<HistoricActivityStatisticsDto> result = new ArrayList<HistoricActivityStatisticsDto>();
    List<HistoricActivityStatistics> statistics = query.list();
    for (HistoricActivityStatistics currentStatistics : statistics) {
        result.add(HistoricActivityStatisticsDto.fromHistoricActivityStatistics(currentStatistics));
    }
    return result;
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) HistoricActivityStatisticsDto(org.camunda.bpm.engine.rest.dto.history.HistoricActivityStatisticsDto) ArrayList(java.util.ArrayList) HistoryService(org.camunda.bpm.engine.HistoryService) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Date(java.util.Date)

Aggregations

HistoricActivityStatisticsQuery (org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery)38 HistoricActivityStatistics (org.camunda.bpm.engine.history.HistoricActivityStatistics)29 Deployment (org.camunda.bpm.engine.test.Deployment)20 Task (org.camunda.bpm.engine.task.Task)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)6 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HistoryService (org.camunda.bpm.engine.HistoryService)1 DateConverter (org.camunda.bpm.engine.rest.dto.converter.DateConverter)1 HistoricActivityStatisticsDto (org.camunda.bpm.engine.rest.dto.history.HistoricActivityStatisticsDto)1