use of org.jbpm.services.task.assignment.UserTaskLoad in project jbpm by kiegroup.
the class TotalCompletionTimeLoadCalculator method getUserTaskLoads.
@Override
public Collection<UserTaskLoad> getUserTaskLoads(List<User> users, TaskContext context) {
Collection<UserTaskLoad> loads = new ArrayList<>();
List<TaskInfo> usersTasks = getUserActiveTaskLists(users, context);
// If there are no user tasks then everyone gets a score of 0 (zero)
if (usersTasks == null || usersTasks.isEmpty()) {
users.forEach(u -> {
loads.add(new UserTaskLoad(IDENTIFIER, u, new Double(0)));
});
} else {
users.forEach(u -> {
Double loadForUser = new Double(0.0);
//
// Get the list of tasks for the user
//
List<TaskInfo> tasksForUser = usersTasks.stream().filter(ut -> ut.getOwnerId().equals(u.getId())).collect(Collectors.toList());
//
for (TaskInfo ti : tasksForUser) {
loadForUser += getTaskDuration(ti, context) * ti.getCount();
}
UserTaskLoad load = new UserTaskLoad(IDENTIFIER, u, loadForUser);
logger.debug("User load: {}", load);
loads.add(load);
});
}
return loads;
}
use of org.jbpm.services.task.assignment.UserTaskLoad in project jbpm by kiegroup.
the class TotalCompletionTimeLoadCalculator method getUserTaskLoad.
@Override
public UserTaskLoad getUserTaskLoad(User user, TaskContext context) {
UserTaskLoad load = new UserTaskLoad(IDENTIFIER, user);
List<User> users = Arrays.asList(user);
List<TaskInfo> userTasks = getUserActiveTaskLists(users, context);
if (userTasks == null || userTasks.isEmpty()) {
load.setCalculatedLoad(new Double(0));
} else {
Double loadForUser = new Double(0.0);
for (TaskInfo ti : userTasks) {
loadForUser += getTaskDuration(ti, context);
}
load.setCalculatedLoad(loadForUser);
}
return load;
}
use of org.jbpm.services.task.assignment.UserTaskLoad in project jbpm by kiegroup.
the class TaskCountLoadCalculator method getUserTaskLoads.
@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;
}
use of org.jbpm.services.task.assignment.UserTaskLoad in project jbpm by kiegroup.
the class LoadBalanceAssignmentStrategy method apply.
@Override
public Assignment apply(Task task, TaskContext taskContext, String excludedUser) {
UserInfo userInfo = (UserInfo) ((org.jbpm.services.task.commands.TaskContext) taskContext).get(EnvironmentName.TASK_USER_INFO);
List<OrganizationalEntity> excluded = (getExcludedEntities(task, userInfo));
// Get the the users from the task's the potential owners, making sure that excluded users are not included
List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners().stream().filter(oe -> oe instanceof User && !excluded.contains(oe) && !oe.getId().equals(excludedUser)).collect(Collectors.toList());
// Get the users belonging to groups that are potential owners
task.getPeopleAssignments().getPotentialOwners().stream().filter(oe -> oe instanceof Group).forEach(oe -> {
Iterator<OrganizationalEntity> groupUsers = userInfo.getMembersForGroup((Group) oe);
if (groupUsers != null) {
groupUsers.forEachRemaining(user -> {
if (user != null && !excluded.contains(user) && !potentialOwners.contains(user) && !user.getId().equals(excludedUser)) {
potentialOwners.add(user);
}
});
}
});
logger.debug("Asking the load calculator [{}] for task loads for the users {}", calculator.getIdentifier(), potentialOwners);
List<User> users = potentialOwners.stream().map(entityToUser).collect(Collectors.toList());
Collection<UserTaskLoad> loads = calculator.getUserTaskLoads(users, taskContext);
UserTaskLoad lightestLoad = loads.stream().min(UserTaskLoad::compareTo).orElse(null);
return lightestLoad != null ? new Assignment(lightestLoad.getUser().getId()) : null;
}
use of org.jbpm.services.task.assignment.UserTaskLoad in project jbpm by kiegroup.
the class TaskCountLoadCalculator method getUserTaskLoad.
@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;
}
Aggregations