Search in sources :

Example 1 with ResponseHolder

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

the class ProcessStatisticsService method taskVariationOverTime.

/**
 * Task variation of user over time i.e. tasks started and completed by the user -- User Performance
 *
 * @param assignee taskAssignee/User selected to view the user performance of task completion over time
 * @return array with the tasks started and completed of the selected user
 */
@GET
@Path("/user-performance/variation/{assignee}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder taskVariationOverTime(@PathParam("assignee") String assignee) throws UserStoreException {
    if (!validateCurrentUser(assignee)) {
        throw new ActivitiObjectNotFoundException("User with user id " + assignee + "not defined in the system");
    }
    ResponseHolder response = new ResponseHolder();
    List list = new ArrayList();
    SimpleDateFormat ft = new SimpleDateFormat("M");
    ProcessInstanceStatInfo[] taskStatPerMonths = new ProcessInstanceStatInfo[12];
    for (int i = 0; i < taskStatPerMonths.length; i++) {
        taskStatPerMonths[i] = new ProcessInstanceStatInfo(MONTHS[i], 0, 0);
    }
    // Get completed tasks
    List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).finished().list();
    for (HistoricTaskInstance instance : taskList) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        int endTime = Integer.parseInt(ft.format(instance.getEndTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
        taskStatPerMonths[endTime - 1].setInstancesCompleted(taskStatPerMonths[endTime - 1].getInstancesCompleted() + 1);
    }
    // Get active/started tasks
    List<Task> taskActive = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).active().list();
    for (Task instance : taskActive) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
    }
    // Get suspended tasks
    List<Task> taskSuspended = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).taskAssignee(assignee).suspended().list();
    for (Task instance : taskSuspended) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
    }
    for (int i = 0; i < taskStatPerMonths.length; i++) {
        list.add(taskStatPerMonths[i]);
    }
    response.setData(list);
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ProcessInstanceStatInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ResponseHolder

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

the class ProcessStatisticsService method getAllProcesses.

/**
 * Get all deployed processes
 *
 * @return list with the processDefinitions of all deployed processes
 */
@GET
@Path("/processes/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getAllProcesses() {
    // Get a list of the deployed processes
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).list();
    List<Object> listOfProcesses = new ArrayList<>();
    ResponseHolder response = new ResponseHolder();
    for (ProcessDefinition processDefinition : processDefinitionList) {
        listOfProcesses.add(processDefinition.getId());
    }
    response.setData(listOfProcesses);
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ResponseHolder

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

the class ProcessStatisticsService method getAvgTimeDurationForCompletedProcesses.

/**
 * Get the average time duration of completed processes
 *
 * @return list with the completed processes and the average time duration taken for each process
 */
@GET
@Path("/process-instances/duration/average")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getAvgTimeDurationForCompletedProcesses() {
    ResponseHolder response = new ResponseHolder();
    List<Object> list = new ArrayList<>();
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    List<ProcessDefinition> deployedProcessList = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).list();
    for (ProcessDefinition instance : deployedProcessList) {
        ProcessInstanceAverageInfo bpmnProcessInstance = new ProcessInstanceAverageInfo();
        bpmnProcessInstance.setProcessDefinitionId(instance.getId());
        double totalTime = 0;
        double averageTime;
        String processDefinitionID = instance.getId();
        HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).processDefinitionId(processDefinitionID).finished();
        long instanceCount = historicProcessInstanceQuery.count();
        if (instanceCount != 0) {
            List<HistoricProcessInstance> instanceList = historicProcessInstanceQuery.list();
            for (HistoricProcessInstance completedProcess : instanceList) {
                double timeDurationOfTask = completedProcess.getDurationInMillis();
                double timeInMins = timeDurationOfTask / (1000 * 60);
                totalTime += timeInMins;
            }
            averageTime = totalTime / instanceCount;
            bpmnProcessInstance.setAverageTimeForCompletion(averageTime);
            list.add(bpmnProcessInstance);
        }
    }
    response.setData(list);
    return response;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ProcessInstanceAverageInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceAverageInfo) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ResponseHolder

use of org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder 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 5 with ResponseHolder

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

the class ProcessStatisticsService method taskVariationOverTime.

/**
 * Task variation over time i.e. tasks started and completed over the months
 *
 * @return array with the no. of tasks started and completed over the months
 */
@GET
@Path("/task-instances/count/variation")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder taskVariationOverTime() {
    ResponseHolder response = new ResponseHolder();
    List list = new ArrayList();
    SimpleDateFormat ft = new SimpleDateFormat("M");
    ProcessInstanceStatInfo[] taskStatPerMonths = new ProcessInstanceStatInfo[12];
    for (int i = 0; i < taskStatPerMonths.length; i++) {
        taskStatPerMonths[i] = new ProcessInstanceStatInfo(MONTHS[i], 0, 0);
    }
    // Get completed tasks
    List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).finished().list();
    for (HistoricTaskInstance instance : taskList) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        int endTime = Integer.parseInt(ft.format(instance.getEndTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
        taskStatPerMonths[endTime - 1].setInstancesCompleted(taskStatPerMonths[endTime - 1].getInstancesCompleted() + 1);
    }
    // Get active/started tasks
    List<Task> taskActive = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).active().list();
    for (Task instance : taskActive) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
    }
    // Get suspended tasks
    List<Task> taskSuspended = BPMNOSGIService.getTaskService().createTaskQuery().taskTenantId(getTenantIdStr()).suspended().list();
    for (Task instance : taskSuspended) {
        int startTime = Integer.parseInt(ft.format(instance.getCreateTime()));
        taskStatPerMonths[startTime - 1].setInstancesStarted(taskStatPerMonths[startTime - 1].getInstancesStarted() + 1);
    }
    Collections.addAll(list, taskStatPerMonths);
    response.setData(list);
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ProcessInstanceStatInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 ResponseHolder (org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder)10 RepositoryService (org.activiti.engine.RepositoryService)4 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 ProcessInstanceStatInfo (org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatInfo)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 HistoryService (org.activiti.engine.HistoryService)2 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)2 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)2 Task (org.activiti.engine.task.Task)2 ProcessInstanceStatusCountInfo (org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatusCountInfo)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1