Search in sources :

Example 1 with RemoveTaskProblemFactChange

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));
}
Also used : Arrays(java.util.Arrays) SET_OF_100TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION) SET_OF_500TASKS_20USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Task(org.kie.kogito.taskassigning.core.model.Task) List(java.util.List) SET_OF_50TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION) TestConstants(org.kie.kogito.taskassigning.core.TestConstants) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) Tag(org.junit.jupiter.api.Tag) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)

Example 2 with RemoveTaskProblemFactChange

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;
}
Also used : RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) User(org.kie.kogito.taskassigning.core.model.User) IndexedElement(org.kie.kogito.taskassigning.service.util.IndexedElement) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)

Example 3 with RemoveTaskProblemFactChange

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());
}
Also used : RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)

Example 4 with RemoveTaskProblemFactChange

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();
}
Also used : RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) RemoveUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)

Aggregations

RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)4 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 User (org.kie.kogito.taskassigning.core.model.User)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Tag (org.junit.jupiter.api.Tag)1 Test (org.junit.jupiter.api.Test)1 TestConstants (org.kie.kogito.taskassigning.core.TestConstants)1 SET_OF_100TASKS_5USERS_SOLUTION (org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION)1 SET_OF_24TASKS_8USERS_SOLUTION (org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION)1 SET_OF_500TASKS_20USERS_SOLUTION (org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION)1 SET_OF_50TASKS_5USERS_SOLUTION (org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION)1 Task (org.kie.kogito.taskassigning.core.model.Task)1