use of org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method assertChange.
private static void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, AddTaskProblemFactChange expected) {
assertThat(result.get(index)).isInstanceOf(AddTaskProblemFactChange.class);
AddTaskProblemFactChange change = (AddTaskProblemFactChange) result.get(index);
assertTaskEquals(expected.getTaskAssignment(), change.getTaskAssignment());
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addNewReadyTaskChange.
@Test
void addNewReadyTaskChange() {
TaskData taskData = mockTaskData(TASK_1_ID, READY.value(), TASK_1_LAST_UPDATE);
List<TaskData> taskDataList = mockTaskDataList(taskData);
TaskAssigningSolution solution = mockSolution(Collections.emptyList(), Collections.emptyList());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(taskDataList).forSolution(solution).build();
AddTaskProblemFactChange expected = new AddTaskProblemFactChange(new TaskAssignment(fromTaskData(taskData)));
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertTaskPublishStatus(taskData.getId(), false);
assertThatTaskProcessorsWereApplied(TASK_1_ID);
assertThatUserProcessorsWereNotApplied();
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method addNewTaskChanges.
private void addNewTaskChanges(TaskData taskData) {
Task newTask;
if (READY.value().equals(taskData.getState())) {
newTask = fromTaskData(taskData);
processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
newTasksChanges.add(new AddTaskProblemFactChange(new TaskAssignment(newTask)));
context.setTaskPublished(taskData.getId(), false);
} else if (RESERVED.value().equals(taskData.getState())) {
newTask = fromTaskData(taskData);
processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(new TaskAssignment(newTask), user, true);
context.setTaskPublished(taskData.getId(), true);
addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
}
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange 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));
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project kogito-apps by kiegroup.
the class AddTaskExecutableProblemFactChangeTest method addTaskProblemFactChangeTaskAlreadyExists.
@Test
void addTaskProblemFactChangeTaskAlreadyExists() {
TaskAssigningSolution solution = readTaskAssigningSolution(SET_OF_24TASKS_8USERS_SOLUTION.resource());
// randomly selected task.
String taskId = "20";
TaskAssignment taskAssignment = new TaskAssignment(Task.newBuilder().id(taskId).build());
Assertions.assertThatThrownBy(() -> executeSequentialChanges(solution, Collections.singletonList(new ProgrammedProblemFactChange<>(new AddTaskProblemFactChange(taskAssignment))))).hasMessage("A task assignment with the given identifier id: %s already exists", taskId);
}
Aggregations