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