Search in sources :

Example 21 with HistoricActivityStatistics

use of org.camunda.bpm.engine.history.HistoricActivityStatistics 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 22 with HistoricActivityStatistics

use of org.camunda.bpm.engine.history.HistoricActivityStatistics 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)

Example 23 with HistoricActivityStatistics

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

the class HistoricActivityStatisticsAuthorizationTest method testQueryIncludingFinishedWithReadHistoryPermissionOnAnyProcessDefinition.

public void testQueryIncludingFinishedWithReadHistoryPermissionOnAnyProcessDefinition() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(PROCESS_KEY).getId();
    startProcessInstanceByKey(PROCESS_KEY);
    startProcessInstanceByKey(PROCESS_KEY);
    startProcessInstanceByKey(PROCESS_KEY);
    String taskId = selectAnyTask().getId();
    disableAuthorization();
    taskService.complete(taskId);
    enableAuthorization();
    createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY);
    // when
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeFinished();
    // then
    verifyQueryResults(query, 3);
    List<HistoricActivityStatistics> statistics = query.list();
    HistoricActivityStatistics start = getStatisticsByKey(statistics, "theStart");
    verifyStatisticsResult(start, 0, 3, 0, 0);
    HistoricActivityStatistics task = getStatisticsByKey(statistics, "theTask");
    verifyStatisticsResult(task, 2, 1, 0, 0);
    HistoricActivityStatistics end = getStatisticsByKey(statistics, "theEnd");
    verifyStatisticsResult(end, 0, 1, 0, 0);
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics)

Example 24 with HistoricActivityStatistics

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

the class HistoricActivityStatisticsAuthorizationTest method testQueryIncludingCompleteScopeWithReadHistoryPermissionOnProcessDefinition.

public void testQueryIncludingCompleteScopeWithReadHistoryPermissionOnProcessDefinition() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(PROCESS_KEY).getId();
    startProcessInstanceByKey(PROCESS_KEY);
    startProcessInstanceByKey(PROCESS_KEY);
    startProcessInstanceByKey(PROCESS_KEY);
    String taskId = selectAnyTask().getId();
    disableAuthorization();
    taskService.complete(taskId);
    enableAuthorization();
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);
    // when
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId).includeCompleteScope();
    // then
    verifyQueryResults(query, 2);
    List<HistoricActivityStatistics> statistics = query.list();
    HistoricActivityStatistics task = getStatisticsByKey(statistics, "theTask");
    verifyStatisticsResult(task, 2, 0, 0, 0);
    HistoricActivityStatistics end = getStatisticsByKey(statistics, "theEnd");
    verifyStatisticsResult(end, 0, 0, 0, 1);
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics)

Example 25 with HistoricActivityStatistics

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

the class HistoricActivityStatisticsQueryTest method testQueryByFinishedAndCompleteScopeAndCanceled.

@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityStatisticsQueryTest.testSingleTask.bpmn20.xml")
public void testQueryByFinishedAndCompleteScopeAndCanceled() {
    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().includeCanceled().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(0, end.getCanceled());
    assertEquals(2, end.getFinished());
    assertEquals(2, end.getCompleteScope());
    // start
    HistoricActivityStatistics start = statistics.get(1);
    assertEquals("start", start.getId());
    assertEquals(0, start.getInstances());
    assertEquals(0, start.getCanceled());
    assertEquals(6, start.getFinished());
    assertEquals(0, start.getCompleteScope());
    // task
    HistoricActivityStatistics task = statistics.get(2);
    assertEquals("task", task.getId());
    assertEquals(2, task.getInstances());
    assertEquals(2, task.getCanceled());
    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)

Aggregations

HistoricActivityStatistics (org.camunda.bpm.engine.history.HistoricActivityStatistics)30 HistoricActivityStatisticsQuery (org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery)29 Deployment (org.camunda.bpm.engine.test.Deployment)19 Task (org.camunda.bpm.engine.task.Task)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)6 ArrayList (java.util.ArrayList)2 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