Search in sources :

Example 21 with TaskAssigningSolution

use of org.kie.kogito.taskassigning.core.model.TaskAssigningSolution in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method addNewUserChange.

@Test
void addNewUserChange() {
    org.kie.kogito.taskassigning.user.service.User newExternalUser = mockExternalUser(USER_1);
    User newUser = mockUser(USER_1);
    TaskAssigningSolution solution = mockSolution(Collections.emptyList(), Collections.emptyList());
    UserDataEvent event = new UserDataEvent(Collections.singletonList(newExternalUser), ZonedDateTime.now());
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
    AddUserProblemFactChange expected = new AddUserProblemFactChange(newUser);
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, expected);
    assertThatUserProcessorsWereApplied(newExternalUser);
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) 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) Test(org.junit.jupiter.api.Test)

Example 22 with TaskAssigningSolution

use of org.kie.kogito.taskassigning.core.model.TaskAssigningSolution in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method addReleasedTaskChange.

@Test
void addReleasedTaskChange() {
    TaskAssignment user1Assignment = new TaskAssignment(mockTask(TASK_1_ID, RESERVED.value()));
    User user1 = TestUtil.mockUser(USER_1, Collections.singletonList(user1Assignment));
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(user1), Collections.singletonList(user1Assignment));
    TaskData taskData = mockTaskData(TASK_1_ID, READY.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 ReleaseTaskProblemFactChange(new TaskAssignment(fromTaskData(taskData))));
    assertTaskPublishStatus(TASK_1_ID, false);
    assertThatTaskProcessorsWhereNotApplied();
    assertThatUserProcessorsWereNotApplied();
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) 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) Test(org.junit.jupiter.api.Test)

Example 23 with TaskAssigningSolution

use of org.kie.kogito.taskassigning.core.model.TaskAssigningSolution in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method addReservedTaskChangeForAnotherUserInSolution.

@Test
void addReservedTaskChangeForAnotherUserInSolution() {
    TaskAssignment user1Assignment = new TaskAssignment(mockTask(TASK_1_ID));
    User user1 = TestUtil.mockUser(USER_1, Collections.singletonList(user1Assignment));
    User user2 = mockUser(USER_2);
    TaskAssigningSolution solution = mockSolution(Arrays.asList(user1, user2), Collections.singletonList(user1Assignment));
    TaskData taskData = mockTaskData(TASK_1_ID, RESERVED.value(), USER_2, TASK_1_LAST_UPDATE);
    addReservedTaskChangeForAnotherUser(solution, taskData, user2);
    assertThatUserProcessorsWereNotApplied();
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) 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) Test(org.junit.jupiter.api.Test)

Example 24 with TaskAssigningSolution

use of org.kie.kogito.taskassigning.core.model.TaskAssigningSolution in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method addDisableUserChange.

@Test
void addDisableUserChange() {
    User user = mockUser(USER_1);
    user.setEnabled(true);
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(user), Collections.emptyList());
    UserDataEvent event = new UserDataEvent(Collections.emptyList(), ZonedDateTime.now());
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
    DisableUserProblemFactChange expected = new DisableUserProblemFactChange(user);
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, expected);
    assertThatUserProcessorsWereNotApplied();
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) 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) Test(org.junit.jupiter.api.Test)

Example 25 with TaskAssigningSolution

use of org.kie.kogito.taskassigning.core.model.TaskAssigningSolution in project kogito-apps by kiegroup.

the class TaskAssigningService method executeSolutionChange.

private void executeSolutionChange(TaskAssigningSolution chBestSolution, Supplier<TaskAssigningSolution> solutionSupplier) {
    TaskAssigningSolution currentLastBestSolution = solutionSupplier.get();
    LOGGER.debug("Executing delayed solution change for currentChangeSetId: {}, the first CH generated solution after the changes is chBestSolution: {}, lastBestSolution: {}", context.getCurrentChangeSetId(), chBestSolution, currentLastBestSolution);
    if (chBestSolution == currentLastBestSolution) {
        LOGGER.debug("SAME SOLUTION: lastBestSolution is the same as the chBestSolution");
    } else {
        if (chBestSolution.getScore().compareTo(currentLastBestSolution.getScore()) < 0) {
            LOGGER.debug("SCORE IMPROVEMENT: lastBestSolution has a better score than the chBestSolution: " + "currentChangeSetId: {}, chBestSolution.score: {}, lastBestSolution.score: {}", context.getCurrentChangeSetId(), chBestSolution.getScore(), currentLastBestSolution.getScore());
        } else {
            LOGGER.debug("SAME SCORE: lastBestSolution is not the same as the chBestSolution BUT the score has not improved" + ", currentChangeSetId: {}, chBestSolution.score: {}, lastBestSolution.score: {}", context.getCurrentChangeSetId(), chBestSolution.getScore(), currentLastBestSolution.getScore());
        }
    }
    context.setProcessedChangeSet(context.getCurrentChangeSetId());
    managedExecutor.runAsync(() -> executeSolutionChange(currentLastBestSolution));
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)

Aggregations

TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)65 Test (org.junit.jupiter.api.Test)30 User (org.kie.kogito.taskassigning.core.model.User)24 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)23 ArrayList (java.util.ArrayList)15 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)12 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)12 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)11 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)11 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)11 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)10 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)9 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)7 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)7 RemoveUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)7 UserPropertyChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)7 List (java.util.List)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Task (org.kie.kogito.taskassigning.core.model.Task)5 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)5