use of org.kie.kogito.taskassigning.service.util.IndexedElement in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method build.
public List<ProblemFactChange<TaskAssigningSolution>> build() {
usersById = solution.getUserList().stream().collect(Collectors.toMap(User::getId, Function.identity()));
Map<String, TaskAssignment> taskAssignmentById = filterNonDummyAssignments(solution.getTaskAssignmentList()).stream().collect(Collectors.toMap(TaskAssignment::getId, Function.identity()));
TaskAssignment taskAssignment;
for (TaskData taskData : taskDataList) {
taskAssignment = taskAssignmentById.remove(taskData.getId());
if (taskAssignment == null) {
addNewTaskChanges(taskData);
} else {
addTaskChanges(taskAssignment, taskData);
}
}
for (TaskAssignment removedTask : removedTasksSet) {
removedTaskChanges.add(new RemoveTaskProblemFactChange(removedTask));
}
if (userDataEvent != null) {
addFullSyncUserChanges(userDataEvent.getData());
} else {
addRemovableUserChanges();
}
totalChanges.addAll(newUserChanges);
totalChanges.addAll(removedTaskChanges);
totalChanges.addAll(releasedTasksChanges);
for (List<IndexedElement<AssignTaskProblemFactChange>> assignTaskToUserChanges : assignToUserChangesByUserId.values()) {
List<AssignTaskProblemFactChange> assignTaskChanges = assignTaskToUserChanges.stream().map(IndexedElement::getElement).collect(Collectors.toList());
totalChanges.addAll(assignTaskChanges);
}
totalChanges.addAll(taskPropertyChanges);
totalChanges.addAll(updateUserChanges);
totalChanges.addAll(newTasksChanges);
totalChanges.addAll(removableUserChanges);
traceChanges();
if (!totalChanges.isEmpty()) {
totalChanges.add(0, scoreDirector -> context.setCurrentChangeSetId(context.nextChangeSetId()));
}
return totalChanges;
}
use of org.kie.kogito.taskassigning.service.util.IndexedElement 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