Search in sources :

Example 1 with AddTaskProblemFactChange

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

Example 2 with AddTaskProblemFactChange

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();
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) 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) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test)

Example 3 with AddTaskProblemFactChange

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

Example 4 with AddTaskProblemFactChange

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));
}
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) PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER) TestConstants(org.kie.kogito.taskassigning.core.TestConstants) Assertions(org.assertj.core.api.Assertions) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) Tag(org.junit.jupiter.api.Tag) Collections(java.util.Collections) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 5 with AddTaskProblemFactChange

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);
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test)

Aggregations

AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)5 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)4 Test (org.junit.jupiter.api.Test)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)3 Task (org.kie.kogito.taskassigning.core.model.Task)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Tag (org.junit.jupiter.api.Tag)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