use of org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange in project kogito-apps by kiegroup.
the class RemoveTaskExecutableProblemFactChangeTest method removeTaskProblemFactChange.
private void removeTaskProblemFactChange(TaskAssigningSolution solution, List<String> taskIds) {
List<ProgrammedProblemFactChange<RemoveTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> findTaskAssignmentOrCreate(solution, id)).map(taskAssignment -> new ProgrammedProblemFactChange<>(new RemoveTaskProblemFactChange(taskAssignment))).collect(Collectors.toList());
// each partial solution must have the change that was applied on it.
executeSequentialChanges(solution, programmedChanges);
programmedChanges.forEach(change -> assertRemoveTaskProblemFactChangeWasProduced(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 -> assertRemoveTaskProblemFactChangeWasProduced(change.getChange(), lastSolution));
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange 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.core.model.solver.realtime.RemoveTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method assertChange.
private static void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, RemoveTaskProblemFactChange expected) {
assertThat(result.get(index)).isInstanceOf(RemoveTaskProblemFactChange.class);
RemoveTaskProblemFactChange change = (RemoveTaskProblemFactChange) result.get(index);
assertTaskEquals(expected.getTaskAssignment(), change.getTaskAssignment());
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addRemoveTaskInTerminalStatus.
void addRemoveTaskInTerminalStatus(TaskState terminalState) {
TaskAssignment user1Assignment = new TaskAssignment(mockTask(TASK_1_ID));
User user1 = TestUtil.mockUser(USER_1, Collections.singletonList(user1Assignment));
TaskAssigningSolution solution = mockSolution(Collections.singletonList(user1), Collections.singletonList(user1Assignment));
TaskData taskData = mockTaskData(TASK_1_ID, terminalState.value(), TASK_1_LAST_UPDATE);
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(mockTaskDataList(taskData)).forSolution(solution).build();
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, new RemoveTaskProblemFactChange(new TaskAssignment(fromTaskData(taskData))));
assertThatTaskProcessorsWhereNotApplied();
assertThatUserProcessorsWereNotApplied();
}
Aggregations