use of org.camunda.bpm.engine.management.ActivityStatistics in project camunda-bpm-platform by camunda.
the class MockProvider method createMockActivityStatistics.
public static List<ActivityStatistics> createMockActivityStatistics() {
ActivityStatistics statistics = mock(ActivityStatistics.class);
when(statistics.getFailedJobs()).thenReturn(EXAMPLE_FAILED_JOBS);
when(statistics.getInstances()).thenReturn(EXAMPLE_INSTANCES);
when(statistics.getId()).thenReturn(EXAMPLE_ACTIVITY_ID);
IncidentStatistics incidentStaticits = mock(IncidentStatistics.class);
when(incidentStaticits.getIncidentType()).thenReturn(EXAMPLE_INCIDENT_TYPE);
when(incidentStaticits.getIncidentCount()).thenReturn(EXAMPLE_INCIDENT_COUNT);
List<IncidentStatistics> exampleIncidentList = new ArrayList<IncidentStatistics>();
exampleIncidentList.add(incidentStaticits);
when(statistics.getIncidentStatistics()).thenReturn(exampleIncidentList);
ActivityStatistics anotherStatistics = mock(ActivityStatistics.class);
when(anotherStatistics.getFailedJobs()).thenReturn(ANOTHER_EXAMPLE_FAILED_JOBS);
when(anotherStatistics.getInstances()).thenReturn(ANOTHER_EXAMPLE_INSTANCES);
when(anotherStatistics.getId()).thenReturn(ANOTHER_EXAMPLE_ACTIVITY_ID);
IncidentStatistics anotherIncidentStaticits = mock(IncidentStatistics.class);
when(anotherIncidentStaticits.getIncidentType()).thenReturn(ANOTHER_EXAMPLE_INCIDENT_TYPE);
when(anotherIncidentStaticits.getIncidentCount()).thenReturn(ANOTHER_EXAMPLE_INCIDENT_COUNT);
List<IncidentStatistics> anotherExampleIncidentList = new ArrayList<IncidentStatistics>();
anotherExampleIncidentList.add(anotherIncidentStaticits);
when(anotherStatistics.getIncidentStatistics()).thenReturn(anotherExampleIncidentList);
List<ActivityStatistics> activityResults = new ArrayList<ActivityStatistics>();
activityResults.add(statistics);
activityResults.add(anotherStatistics);
return activityResults;
}
use of org.camunda.bpm.engine.management.ActivityStatistics in project camunda-bpm-platform by camunda.
the class ProcessDefinitionResourceImpl method getActivityStatistics.
@Override
public List<StatisticsResultDto> getActivityStatistics(Boolean includeFailedJobs, Boolean includeIncidents, String includeIncidentsForType) {
if (includeIncidents != null && includeIncidentsForType != null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeIncidentsForType can be set.");
}
ManagementService mgmtService = engine.getManagementService();
ActivityStatisticsQuery query = mgmtService.createActivityStatisticsQuery(processDefinitionId);
if (includeFailedJobs != null && includeFailedJobs) {
query.includeFailedJobs();
}
if (includeIncidents != null && includeIncidents) {
query.includeIncidents();
} else if (includeIncidentsForType != null) {
query.includeIncidentsForType(includeIncidentsForType);
}
List<ActivityStatistics> queryResults = query.list();
List<StatisticsResultDto> results = new ArrayList<StatisticsResultDto>();
for (ActivityStatistics queryResult : queryResults) {
StatisticsResultDto dto = ActivityStatisticsResultDto.fromActivityStatistics(queryResult);
results.add(dto);
}
return results;
}
use of org.camunda.bpm.engine.management.ActivityStatistics in project camunda-bpm-platform by camunda.
the class ActivityStatisticsAuthorizationTest method testQueryIncludingIncidentsWithReadInstancePermissionOnProcessDefinition.
public void testQueryIncludingIncidentsWithReadInstancePermissionOnProcessDefinition() {
// given
String processDefinitionId = selectProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_DEFINITION, ONE_INCIDENT_PROCESS_KEY, userId, READ, READ_INSTANCE);
// when
ActivityStatistics statistics = managementService.createActivityStatisticsQuery(processDefinitionId).includeIncidents().singleResult();
// then
assertNotNull(statistics);
assertEquals("scriptTask", statistics.getId());
assertEquals(3, statistics.getInstances());
assertEquals(0, statistics.getFailedJobs());
assertFalse(statistics.getIncidentStatistics().isEmpty());
IncidentStatistics incidentStatistics = statistics.getIncidentStatistics().get(0);
assertEquals(3, incidentStatistics.getIncidentCount());
}
use of org.camunda.bpm.engine.management.ActivityStatistics in project camunda-bpm-platform by camunda.
the class ActivityStatisticsAuthorizationTest method testQueryIncludingInstancesWithReadInstancePermissionOnProcessDefinition.
public void testQueryIncludingInstancesWithReadInstancePermissionOnProcessDefinition() {
// given
String processDefinitionId = selectProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_DEFINITION, ONE_INCIDENT_PROCESS_KEY, userId, READ, READ_INSTANCE);
// when
ActivityStatistics statistics = managementService.createActivityStatisticsQuery(processDefinitionId).singleResult();
// then
assertNotNull(statistics);
assertEquals("scriptTask", statistics.getId());
assertEquals(3, statistics.getInstances());
assertEquals(0, statistics.getFailedJobs());
assertTrue(statistics.getIncidentStatistics().isEmpty());
}
use of org.camunda.bpm.engine.management.ActivityStatistics in project camunda-bpm-platform by camunda.
the class ActivityStatisticsAuthorizationTest method testQueryIncludingInstancesWithReadPermissionOnOneProcessInstance.
public void testQueryIncludingInstancesWithReadPermissionOnOneProcessInstance() {
// given
String processDefinitionId = selectProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY).getId();
disableAuthorization();
String processInstanceId = runtimeService.createProcessInstanceQuery().list().get(0).getId();
enableAuthorization();
createGrantAuthorization(PROCESS_DEFINITION, ONE_INCIDENT_PROCESS_KEY, userId, READ);
createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
// when
ActivityStatistics statistics = managementService.createActivityStatisticsQuery(processDefinitionId).singleResult();
// then
assertNotNull(statistics);
assertEquals("scriptTask", statistics.getId());
assertEquals(1, statistics.getInstances());
assertEquals(0, statistics.getFailedJobs());
assertTrue(statistics.getIncidentStatistics().isEmpty());
}
Aggregations