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);
}
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();
}
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();
}
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();
}
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));
}
Aggregations