use of org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER in project kogito-apps by kiegroup.
the class SolverTest method assertAssignment.
private void assertAssignment(User user, TaskAssignment taskAssignment, List<User> availableUsers) {
assertThat(taskAssignment.getUser()).isNotNull();
assertThat(taskAssignment.getUser().getId()).as("TaskAssignment: %s is not assigned to expected user: %s ", taskAssignment, user).isEqualTo(user.getId());
Task task = taskAssignment.getTask();
if (task.getPotentialUsers().isEmpty() && task.getPotentialGroups().isEmpty()) {
assertThat(user.getId()).as("TaskAssignment: %s without potentialOwners can only be assigned to the PLANNING_USER", taskAssignment).isEqualTo(PLANNING_USER.getId());
} else if (PLANNING_USER.getId().equals(user.getId())) {
availableUsers.forEach(availableUser -> assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("PLANNING_USER user was assigned but another potential owner was found, user: %s taskAssignment: %s", user, taskAssignment)).isFalse());
} else {
assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("User: %s is not a potential owner for the taskAssignment: %s", user, taskAssignment)).isTrue();
}
}
use of org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER 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);
}
use of org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER in project kogito-apps by kiegroup.
the class AddTaskExecutableProblemFactChangeTest method addTaskProblemFactChange.
private void addTaskProblemFactChange(TaskAssigningSolution solution, List<String> taskIds) {
solution.getUserList().add(PLANNING_USER);
List<ProgrammedProblemFactChange<AddTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> new ProgrammedProblemFactChange<>(new AddTaskProblemFactChange(new TaskAssignment(Task.newBuilder().id(id).name("NewTask_" + id).build())))).collect(Collectors.toList());
// each partial solution must have the change that was applied on it.
executeSequentialChanges(solution, programmedChanges);
programmedChanges.forEach(change -> assertAddTaskProblemFactChangeWasProduced(change.getChange(), change.getSolutionAfterChange()));
// finally the last solution must have the result of all the changes.
TaskAssigningSolution lastSolution = programmedChanges.get(programmedChanges.size() - 1).getSolutionAfterChange();
programmedChanges.forEach(change -> assertAddTaskProblemFactChangeWasProduced(change.getChange(), lastSolution));
}
Aggregations