Search in sources :

Example 6 with ResponseHolder

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

the class ProcessStatisticsService method getTasks.

/**
 * Return all the tasks/activities in a process
 * @param pId process instance id
 * @return all the tasks/activities in a process
 */
@GET
@Path("/task-instances/{pId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getTasks(@PathParam("pId") String pId) {
    ResponseHolder response = new ResponseHolder();
    List<Object> list = new ArrayList();
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(pId);
    if (processDefinition != null) {
        for (ActivityImpl activity : processDefinition.getActivities()) {
            TaskInfo taskInfo = new TaskInfo();
            String taskDefKey = activity.getId();
            String type = (String) activity.getProperty("type");
            String taskName = (String) activity.getProperty("name");
            taskInfo.setTaskDefinitionKey(taskDefKey);
            taskInfo.setType(type);
            taskInfo.setName(taskName);
            list.add(taskInfo);
        }
    }
    response.setData(list);
    return response;
}
Also used : TaskInfo(org.wso2.carbon.bpmn.rest.model.stats.TaskInfo) ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ArrayList(java.util.ArrayList) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with ResponseHolder

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

Example 8 with ResponseHolder

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

the class ProcessStatisticsService method getProcessInstanceCount.

/**
 * Get the deployed processes count
 *
 * @return a list of deployed processes with their instance count
 */
@GET
@Path("/process-instances/count")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getProcessInstanceCount() {
    List<ProcessDefinition> processDefinitionList = BPMNOSGIService.getRepositoryService().createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).list();
    List<Object> bpmnProcessInstancesList = new ArrayList<>();
    ResponseHolder response = new ResponseHolder();
    for (ProcessDefinition processDefinition : processDefinitionList) {
        InstanceCountInfo instanceCountInfo = new InstanceCountInfo();
        instanceCountInfo.setProcessDefinitionId(processDefinition.getId());
        long historicInstanceCount = getCompletedProcessInstanceCount(processDefinition.getId());
        long runningInstanceCount = getActiveProcessInstanceCount(processDefinition.getId());
        long noOfInstances = historicInstanceCount + runningInstanceCount;
        instanceCountInfo.setInstanceCount(noOfInstances);
        bpmnProcessInstancesList.add(instanceCountInfo);
    }
    response.setData(bpmnProcessInstancesList);
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) InstanceCountInfo(org.wso2.carbon.bpmn.rest.model.stats.InstanceCountInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with ResponseHolder

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

the class ProcessStatisticsService method avgTaskTimeDurationForCompletedProcesses.

/**
 * Average task duration for completed processes
 *
 * @param pId processDefintionId of the process selected to view the average time duration for each task
 * @return list of completed tasks with the average time duration for the selected process
 */
@GET
@Path("/task-instances/duration/avarage/{pid}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder avgTaskTimeDurationForCompletedProcesses(@PathParam("pid") String pId) {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    long processCount = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).processDefinitionId(pId).count();
    if (processCount == 0) {
        throw new ActivitiObjectNotFoundException("Count not find a matching process with PID '" + pId + "'.");
    }
    ResponseHolder response = new ResponseHolder();
    List<Object> taskListForProcess = new ArrayList<>();
    HashMap<String, Long> map = new HashMap<>();
    // Get the number of completed/finished process instance for each process definition
    HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).processDefinitionId(pId).finished();
    // Get the count of the complete process instances
    long noOfHistoricInstances = historicProcessInstanceQuery.count();
    // If the deployed process does not have any completed process instances --> Ignore
    if (noOfHistoricInstances == 0) {
        response.setData(taskListForProcess);
    } else // If the deployed process has completed process instances --> then
    {
        TaskInstanceAverageInfo tInstance;
        // Get the list of completed tasks/activities in the completed process instance by passing the
        // process definition id of the process
        List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).processDefinitionId(pId).processFinished().list();
        // Iterate through each completed task/activity and get the task name and duration
        for (HistoricTaskInstance taskInstance : taskList) {
            // Get the task name
            String taskKey = taskInstance.getTaskDefinitionKey();
            // Get the time duration taken for the task to be completed
            long taskDuration = taskInstance.getDurationInMillis();
            if (map.containsKey(taskKey)) {
                long tt = map.get(taskKey);
                map.put(taskKey, taskDuration + tt);
            } else {
                map.put(taskKey, taskDuration);
            }
        // Iterating Task List finished
        }
        Iterator iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next().toString();
            double value = map.get(key) / noOfHistoricInstances;
            tInstance = new TaskInstanceAverageInfo();
            tInstance.setTaskDefinitionKey(key);
            tInstance.setAverageTimeForCompletion(value);
            taskListForProcess.add(tInstance);
        }
        response.setData(taskListForProcess);
    }
    return response;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) Iterator(java.util.Iterator) TaskInstanceAverageInfo(org.wso2.carbon.bpmn.rest.model.stats.TaskInstanceAverageInfo) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with ResponseHolder

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

the class ProcessStatisticsService method processVariationOverTime.

/**
 * Process variation over time i.e. tasks started and completed over the months
 *
 * @return array with the no. of processes started and completed over the months
 */
@GET
@Path("/process-instances/count/variation")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder processVariationOverTime() {
    ResponseHolder response = new ResponseHolder();
    List list = new ArrayList();
    SimpleDateFormat ft = new SimpleDateFormat("M");
    ProcessInstanceStatInfo[] processStatPerMonths = new ProcessInstanceStatInfo[12];
    for (int i = 0; i < processStatPerMonths.length; i++) {
        processStatPerMonths[i] = new ProcessInstanceStatInfo(MONTHS[i], 0, 0);
    }
    // Get completed process instances
    List<HistoricProcessInstance> completedProcesses = BPMNOSGIService.getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).finished().list();
    for (HistoricProcessInstance instance : completedProcesses) {
        int startTime = Integer.parseInt(ft.format(instance.getStartTime()));
        int endTime = Integer.parseInt(ft.format(instance.getEndTime()));
        processStatPerMonths[startTime - 1].setInstancesStarted(processStatPerMonths[startTime - 1].getInstancesStarted() + 1);
        processStatPerMonths[endTime - 1].setInstancesCompleted(processStatPerMonths[endTime - 1].getInstancesCompleted() + 1);
    }
    // Get active process instances
    List<HistoricProcessInstance> activeProcesses = BPMNOSGIService.getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).unfinished().list();
    for (HistoricProcessInstance instance : activeProcesses) {
        int startTime = Integer.parseInt(ft.format(instance.getStartTime()));
        processStatPerMonths[startTime - 1].setInstancesStarted(processStatPerMonths[startTime - 1].getInstancesStarted() + 1);
    }
    Collections.addAll(list, processStatPerMonths);
    response.setData(list);
    return response;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ProcessInstanceStatInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceStatInfo) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) 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