Search in sources :

Example 96 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task 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 97 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task 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 98 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method completeTask.

protected void completeTask(Task task, TaskActionRequest actionRequest, TaskService taskService) {
    if (actionRequest.getVariables() != null) {
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        for (RestVariable var : actionRequest.getVariables()) {
            if (var.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required");
            }
            Object actualVariableValue = restResponseFactory.getVariableValue(var);
            variablesToSet.put(var.getName(), actualVariableValue);
        }
        taskService.complete(task.getId(), variablesToSet);
    } else {
        taskService.complete(task.getId());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

Example 99 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method deleteAttachment.

@DELETE
@Path("/{taskId}/attachments/{attachmentId}")
public Response deleteAttachment(@PathParam("taskId") String taskId, @PathParam("attachmentId") String attachmentId) {
    Task task = getTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    Attachment attachment = taskService.getAttachment(attachmentId);
    if (attachment == null) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
    }
    taskService.deleteAttachment(attachmentId);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 100 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method getEvents.

@GET
@Path("/{taskId}/events")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getEvents(@PathParam("taskId") String taskId) {
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    List<EventResponse> eventResponseList = new RestResponseFactory().createEventResponseList(taskService.getTaskEvents(task.getId()), uriInfo.getBaseUri().toString());
    EventResponseCollection eventResponseCollection = new EventResponseCollection();
    eventResponseCollection.setEventResponseList(eventResponseList);
    return Response.ok().entity(eventResponseCollection).build();
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Aggregations

HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)41 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)35 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)28 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)28 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)25 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)25 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)25 ArrayList (java.util.ArrayList)14 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)13 Element (org.w3c.dom.Element)12 QName (javax.xml.namespace.QName)11 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)11 IOException (java.io.IOException)9 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)9 AxisFault (org.apache.axis2.AxisFault)8 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)8