use of org.kie.kogito.taskassigning.core.model.ModelConstants.DUMMY_TASK_ASSIGNMENT in project kogito-apps by kiegroup.
the class SolutionBuilder method build.
public TaskAssigningSolution build() {
final List<TaskAssignment> taskAssignments = new ArrayList<>();
final Map<String, List<IndexedElement<TaskAssignment>>> assignmentsByUserId = new HashMap<>();
final Map<String, User> usersById = filterDuplicates(externalUsers).filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(externalUser -> fromExternalUser(externalUser, processorRegistry)).collect(Collectors.toMap(User::getId, Function.identity()));
usersById.put(PLANNING_USER.getId(), PLANNING_USER);
taskDataList.forEach(taskData -> {
Task task = fromTaskData(taskData);
processorRegistry.applyAttributesProcessor(task, task.getAttributes());
TaskAssignment taskAssignment = new TaskAssignment(task);
String state = task.getState();
taskAssignments.add(taskAssignment);
if (RESERVED.value().equals(state)) {
addTaskAssignmentToUser(assignmentsByUserId, taskAssignment, taskData.getActualOwner(), -1, true);
}
});
assignmentsByUserId.forEach((key, assignedTasks) -> {
User user = usersById.get(key);
if (user == null) {
// create the user by convention.
user = new User(key);
usersById.put(key, user);
}
final List<TaskAssignment> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList());
addAssignmentsToUser(user, userTasks);
});
// Add the DUMMY_TASKs to avoid running into scenarios where the solution remains with no tasks or only one task
// for selection. (https://issues.redhat.com/browse/PLANNER-1738)
taskAssignments.add(DUMMY_TASK_ASSIGNMENT);
taskAssignments.add(DUMMY_TASK_ASSIGNMENT_PLANNER_1738);
final List<User> users = new ArrayList<>(usersById.values());
return new TaskAssigningSolution("-1", users, taskAssignments);
}
Aggregations