Search in sources :

Example 1 with ReleaseTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange 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 2 with ReleaseTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method assertChange.

private static void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, ReleaseTaskProblemFactChange expected) {
    assertThat(result.get(index)).isInstanceOf(ReleaseTaskProblemFactChange.class);
    ReleaseTaskProblemFactChange change = (ReleaseTaskProblemFactChange) result.get(index);
    assertTaskEquals(expected.getTaskAssignment(), change.getTaskAssignment());
}
Also used : ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)

Example 3 with ReleaseTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilder method addTaskChanges.

private void addTaskChanges(TaskAssignment taskAssignment, TaskData taskData) {
    String taskState = taskData.getState();
    if (READY.value().equals(taskState)) {
        context.setTaskPublished(taskData.getId(), false);
        releasedTasksChanges.add(new ReleaseTaskProblemFactChange(taskAssignment));
    } else if (RESERVED.value().equals(taskState)) {
        context.setTaskPublished(taskData.getId(), true);
        if (!taskData.getActualOwner().equals(taskAssignment.getUser().getId()) || !taskAssignment.isPinned()) {
            final User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
            AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(taskAssignment, user, true);
            addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
        }
    } else if (TaskState.isTerminal(taskState)) {
        removedTasksSet.add(taskAssignment);
    }
    if (!removedTasksSet.contains(taskAssignment)) {
        Task updatedTask = fromTaskData(taskData);
        if (!equalsByTaskInfoProperties(taskAssignment.getTask(), updatedTask)) {
            processorRegistry.applyAttributesProcessor(updatedTask, updatedTask.getAttributes());
        } else {
            updatedTask.setAttributes(taskAssignment.getTask().getAttributes());
        }
        taskPropertyChanges.add(new TaskInfoChangeProblemFactChange(taskAssignment, updatedTask));
    }
}
Also used : Task(org.kie.kogito.taskassigning.core.model.Task) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) 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) TaskInfoChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.TaskInfoChangeProblemFactChange)

Aggregations

ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)3 User (org.kie.kogito.taskassigning.core.model.User)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 Test (org.junit.jupiter.api.Test)1 Task (org.kie.kogito.taskassigning.core.model.Task)1 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)1 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)1 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)1 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)1 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)1 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)1 RemoveUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)1 TaskInfoChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.TaskInfoChangeProblemFactChange)1 UserPropertyChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)1 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)1 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)1 UserUtil.fromExternalUser (org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser)1 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)1