Search in sources :

Example 1 with ProcessInstanceStatusCountInfo

use of org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo in project carbon-business-process by wso2.

the class ProcessStatisticsService method getCountOfProcessInstanceStatus.

/**
 * Get the number of  processInstances with various States
 * States: Completed , Active, Suspended, Failed
 *
 * @return list with the states and the count of process instances in each state
 */
@GET
@Path("/process-instances/state/all/count/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getCountOfProcessInstanceStatus() {
    List<Object> processCountList = new ArrayList<>();
    ResponseHolder response = new ResponseHolder();
    long completedInstanceCount = BPMNOSGIService.getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).finished().count();
    long activeInstanceCount = BPMNOSGIService.getRuntimeService().createProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).active().count();
    long suspendedInstanceCount = BPMNOSGIService.getRuntimeService().createProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).suspended().count();
    long failedInstanceCont = BPMNOSGIService.getManagementService().createJobQuery().jobTenantId(getTenantIdStr()).withException().count();
    if (completedInstanceCount == 0 && activeInstanceCount == 0 && suspendedInstanceCount == 0 && failedInstanceCont == 0) {
        response.setData(processCountList);
    } else {
        processCountList.add(new ProcessInstanceStatusCountInfo("Completed", completedInstanceCount));
        processCountList.add(new ProcessInstanceStatusCountInfo("Active", activeInstanceCount));
        processCountList.add(new ProcessInstanceStatusCountInfo("Suspended", suspendedInstanceCount));
        processCountList.add(new ProcessInstanceStatusCountInfo("Failed", failedInstanceCont));
        response.setData(processCountList);
    }
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ProcessInstanceStatusCountInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ProcessInstanceStatusCountInfo

use of org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo in project carbon-business-process by wso2.

the class ProcessStatisticsService method getCountOfTaskInstanceStatus.

/**
 * Get the number of  Task Instances with various states
 * States: Completed , Active, Suspended, Failed
 *
 * @return list with the states and the count of task instances in each state
 */
@GET
@Path("/task-instances/status/all/count")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getCountOfTaskInstanceStatus() {
    List<Object> taskCountList = new ArrayList<>();
    ResponseHolder response = new ResponseHolder();
    ProcessInstanceStatusCountInfo completedTaskInstances, activeTaskInstances, suspendedTaskInstances, failedTaskInstances;
    TaskQuery taskQuery = BPMNOSGIService.getTaskService().createTaskQuery();
    long completedTaskInstanceCount = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).finished().count();
    long activeTaskInstanceCount = taskQuery.taskTenantId(getTenantIdStr()).active().count();
    long suspendedTaskInstanceCount = taskQuery.taskTenantId(getTenantIdStr()).suspended().count();
    // Check on this
    long failedTaskInstanceCount = BPMNOSGIService.getManagementService().createJobQuery().jobTenantId(getTenantIdStr()).withException().count();
    if (completedTaskInstanceCount == 0 && activeTaskInstanceCount == 0 && suspendedTaskInstanceCount == 0 && failedTaskInstanceCount == 0) {
        response.setData(taskCountList);
    } else {
        taskCountList.add(new ProcessInstanceStatusCountInfo("Completed", completedTaskInstanceCount));
        taskCountList.add(new ProcessInstanceStatusCountInfo("Active", activeTaskInstanceCount));
        taskCountList.add(new ProcessInstanceStatusCountInfo("Suspended", suspendedTaskInstanceCount));
        taskCountList.add(new ProcessInstanceStatusCountInfo("Failed", failedTaskInstanceCount));
        response.setData(taskCountList);
    }
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ProcessInstanceStatusCountInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo) TaskQuery(org.activiti.engine.task.TaskQuery) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ProcessInstanceStatusCountInfo (org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo)2 ResponseHolder (org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder)2 TaskQuery (org.activiti.engine.task.TaskQuery)1