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());
}
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;
}
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);
}
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);
}
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());
}
Aggregations