public TaskDef getTaskDefById(String name) { //TODO: FIX LOGIC List<TaskDef> resultList = persistenceContext.queryStringWithParametersInTransaction("select td from TaskDef td where td.name = :name", persistenceContext.addParametersToMap("name", name), ClassUtil.<List<TaskDef>>castClass(List.class)); if(resultList.size() > 0){ return resultList.get(0); } return null; }
/** * Retrieves a list of tasks that the users are currently assigned to, and which * are waiting to be worked on or are being worked on * @param users The list of users that we are interested in * @param context The TaskContext which is associated with the new task * @return A list of TaskInfo objects */ private synchronized List<TaskInfo> getUserActiveTaskLists(List<User> users, TaskContext context) { TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("owners", users); return taskContext.queryStringWithParametersInTransaction(TASK_LIST_QUERY, params, ClassUtil.<List<TaskInfo>>castClass(List.class)); }
public List<TaskEvent> getTaskEventsById(long taskId) { return persistenceContext.queryStringWithParametersInTransaction("select te from TaskEvent te where te.taskId =:taskId ", persistenceContext.addParametersToMap("taskId", taskId), ClassUtil.<List<TaskEvent>>castClass(List.class)); }
/** * Calculates the average duration for a target task, using a query * against the BAMTaskSummary table * @param context Used to retrieve a PersistenceContext * @param processId The identifier for the process definition containing the target task * @param deploymentId The identifier for the deployment which contains the target task * @param name The name of the target task * @return */ private Double calculateAverageDuration(TaskContext context, String processId, String deploymentId, String name) { Double avgDur = new Double(1); TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("procid",processId); params.put("depid", deploymentId); params.put("taskname", name); List<TaskAverageDuration> durations = taskContext.queryStringWithParametersInTransaction(TASK_AVG_DURATION, params, ClassUtil.<List<TaskAverageDuration>>castClass(List.class)); if (durations != null && !durations.isEmpty()) { avgDur = durations.get(0).getAverageDuration(); logger.debug("Retrieved duration is {}",avgDur); } return avgDur; }
@Override public Collection<UserTaskLoad> getUserTaskLoads(List<User> users, TaskContext context) { Collection<UserTaskLoad> userTaskLoads = new ArrayList<>(); List<String> userIds = users.stream().map(user -> {return user.getId();}).collect(Collectors.toList()); TaskPersistenceContext persistenceContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("owners", userIds); logger.debug("DB query to be used for finding assignments :: '{}'", getMultiUserQuery()); List<AssignmentImpl> assignments = persistenceContext.queryStringWithParametersInTransaction(getMultiUserQuery(), params, ClassUtil.<List<AssignmentImpl>>castClass(List.class)); Map<String,AssignmentImpl> assignmentMap = assignments.stream().collect(Collectors.toMap(assignKey,(assign)->assign)); if (assignments != null && !assignments.isEmpty()) { users.forEach(usr -> { String uid = usr.getId(); if (assignmentMap.containsKey(uid)) { Long loadValue = assignmentMap.get(uid).getCurrentlyAssigned(); userTaskLoads.add(new UserTaskLoad(getIdentifier(), usr, new Double(loadValue != null ? loadValue:0))); } else { userTaskLoads.add(new UserTaskLoad(getIdentifier(), usr, new Double(0))); } }); } else { users.forEach(u -> { userTaskLoads.add(new UserTaskLoad(getIdentifier(),u,new Double(0))); }); } return userTaskLoads; }
@Override public UserTaskLoad getUserTaskLoad(User user, TaskContext context) { UserTaskLoad load = new UserTaskLoad(getIdentifier(), user); TaskPersistenceContext persistenceContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("owner", user.getId()); logger.debug("DB query to be used for finding assignments :: '{}'", getSingleUserQuery()); List<Integer> assignmentCounts = persistenceContext.queryStringWithParametersInTransaction(getSingleUserQuery(), params, ClassUtil.<List<Integer>>castClass(List.class)); if (assignmentCounts != null && !assignmentCounts.isEmpty()) { load.setCalculatedLoad(new Double(assignmentCounts.get(0))); } else { load.setCalculatedLoad(new Double(0)); } return load; }
List<Assignment> assignments = persistenceContext.queryStringWithParametersInTransaction(getQuery(), params, ClassUtil.<List<Assignment>>castClass(List.class));
@Override public List<TaskEvent> execute(Context context) { TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext(); if( this.taskId != null ) { return persistenceContext.queryWithParametersInTransaction("getAllTasksEvents", persistenceContext.addParametersToMap("taskId", taskId, "firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<TaskEvent>>castClass(List.class)); } else { return persistenceContext.queryStringWithParametersInTransaction("FROM TaskEventImpl",persistenceContext.addParametersToMap("firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<TaskEvent>>castClass(List.class)); } }
result = persistenceContext.queryStringWithParametersInTransaction("select bts from BAMTaskSummaryImpl bts where bts.taskId=:taskId", true, persistenceContext.addParametersToMap("taskId", ti.getId()), BAMTaskSummaryImpl.class);
/** * Retrieves a list of tasks that the users are currently assigned to, and which * are waiting to be worked on or are being worked on * @param users The list of users that we are interested in * @param context The TaskContext which is associated with the new task * @return A list of TaskInfo objects */ private synchronized List<TaskInfo> getUserActiveTaskLists(List<User> users, TaskContext context) { TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("owners", users); return taskContext.queryStringWithParametersInTransaction(TASK_LIST_QUERY, params, ClassUtil.<List<TaskInfo>>castClass(List.class)); }
/** * Calculates the average duration for a target task, using a query * against the BAMTaskSummary table * @param context Used to retrieve a PersistenceContext * @param processId The identifier for the process definition containing the target task * @param deploymentId The identifier for the deployment which contains the target task * @param name The name of the target task * @return */ private Double calculateAverageDuration(TaskContext context, String processId, String deploymentId, String name) { Double avgDur = new Double(1); TaskPersistenceContext taskContext = ((org.jbpm.services.task.commands.TaskContext)context).getPersistenceContext(); Map<String, Object> params = new HashMap<>(); params.put("procid",processId); params.put("depid", deploymentId); params.put("taskname", name); List<TaskAverageDuration> durations = taskContext.queryStringWithParametersInTransaction(TASK_AVG_DURATION, params, ClassUtil.<List<TaskAverageDuration>>castClass(List.class)); if (durations != null && !durations.isEmpty()) { avgDur = durations.get(0).getAverageDuration(); logger.debug("Retrieved duration is {}",avgDur); } return avgDur; }
@Override public List<TaskEvent> execute(Context context) { TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext(); if( this.taskId != null ) { return persistenceContext.queryWithParametersInTransaction("getAllTasksEvents", persistenceContext.addParametersToMap("taskId", taskId, "firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<TaskEvent>>castClass(List.class)); } else { return persistenceContext.queryStringWithParametersInTransaction("FROM TaskEventImpl",persistenceContext.addParametersToMap("firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<TaskEvent>>castClass(List.class)); } }
result = persistenceContext.queryStringWithParametersInTransaction("select bts from BAMTaskSummaryImpl bts where bts.taskId=:taskId", true, persistenceContext.addParametersToMap("taskId", ti.getId()), BAMTaskSummaryImpl.class);