Search in sources :

Example 11 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilderTest method addPinReservedOrInProgressOrSuspendedTaskWhenPublishedAndNotYetPinned.

private void addPinReservedOrInProgressOrSuspendedTaskWhenPublishedAndNotYetPinned(Status status, boolean addActualOwnerToSolution) {
    TaskData taskData = mockTaskData(TASK_ID, NAME, status, ACTUAL_OWNER_ENTITY_ID);
    PlanningTask planningTask = mockPlanningTask(taskData.getTaskId(), true);
    planningTask.setIndex(0);
    taskData.setPlanningTask(planningTask);
    Task task = fromTaskData(taskData);
    task.setPinned(false);
    User actualOwner = mockUser(ACTUAL_OWNER_ENTITY_ID);
    task.setUser(actualOwner);
    List<User> userList = new ArrayList<>();
    if (addActualOwnerToSolution) {
        userList.add(actualOwner);
    }
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(task), userList);
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(mockTaskDataList(taskData)).withUserSystem(userSystemService).withContext(context).build();
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, new AssignTaskProblemFactChange(task, mockUser(ACTUAL_OWNER_ENTITY_ID), true));
    assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) Task(org.kie.server.services.taskassigning.core.model.Task) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) User(org.kie.server.services.taskassigning.core.model.User) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) ArrayList(java.util.ArrayList) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) TaskData(org.kie.server.api.model.taskassigning.TaskData) TaskUtil.fromTaskData(org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)

Example 12 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class AddTaskProblemFactChangeTest method addTaskProblemFactChange.

private void addTaskProblemFactChange(TaskAssigningSolution solution, List<Long> taskIds) throws Exception {
    solution.getUserList().add(PLANNING_USER);
    List<ProgrammedProblemFactChange<AddTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> new ProgrammedProblemFactChange<>(new AddTaskProblemFactChange(new Task(id, "NewTask_" + id, 1)))).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) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PLANNING_USER(org.kie.server.services.taskassigning.core.model.ModelConstants.PLANNING_USER) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SET_OF_50TASKS_5USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION) List(java.util.List) SET_OF_100TASKS_5USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) Assertions(org.assertj.core.api.Assertions) SET_OF_500TASKS_20USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION) Collections(java.util.Collections) Task(org.kie.server.services.taskassigning.core.model.Task) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) Task(org.kie.server.services.taskassigning.core.model.Task) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)

Example 13 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class AssignTaskProblemFactChangeTest method assertAssignTaskProblemFactChangeWasProduced.

/**
 * Given an AssignTaskProblemFactChange and a solution that was produced as the result of applying the change,
 * asserts that the assignment defined by the change is not violated (exists in) by the solution.
 * The assignment defined in the change must also be pinned in the produced solution as well as any other
 * previous assignment for the given user.
 * @param change The change that was executed for producing the solution.
 * @param solution The produced solution.
 */
private void assertAssignTaskProblemFactChangeWasProduced(AssignTaskProblemFactChange change, TaskAssigningSolution solution) throws Exception {
    User internalUser = solution.getUserList().stream().filter(user -> Objects.equals(user.getId(), change.getUser().getId())).findFirst().orElseThrow(() -> new Exception("User: " + change.getUser() + " was not found in solution."));
    Task internalTask = solution.getTaskList().stream().filter(task -> Objects.equals(task.getId(), change.getTask().getId())).findFirst().orElseThrow(() -> new Exception("Task: " + change + " was not found in solution."));
    assertEquals(internalUser, internalTask.getUser());
    assertTrue(internalTask.isPinned());
    // all the previous tasks must be pinned by construction and be assigned to the user
    TaskOrUser previousTaskOrUser = internalTask.getPreviousTaskOrUser();
    while (previousTaskOrUser != null) {
        if (previousTaskOrUser instanceof Task) {
            Task previousTask = (Task) previousTaskOrUser;
            assertTrue(previousTask.isPinned());
            assertEquals(internalUser, previousTask.getUser());
            previousTaskOrUser = previousTask.getPreviousTaskOrUser();
        } else {
            assertEquals(internalUser, previousTaskOrUser);
            previousTaskOrUser = null;
        }
    }
    // all the next tasks must to the user.
    Task nextTask = internalTask.getNextTask();
    while (nextTask != null) {
        assertEquals(internalUser, nextTask.getUser());
        nextTask = nextTask.getNextTask();
    }
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser) User(org.kie.server.services.taskassigning.core.model.User) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser)

Example 14 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class ReleaseTaskProblemFactChangeTest method setUp.

@Before
public void setUp() {
    task = new Task();
    previousTaskOrUser = spy(new Task());
    workingTask = spy(new Task());
    nextTask = spy(new Task());
    change = new ReleaseTaskProblemFactChange(task);
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) Before(org.junit.Before)

Example 15 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class RemoveTaskProblemFactChangeTest method removeTaskProblemFactChange.

private void removeTaskProblemFactChange(TaskAssigningSolution solution, List<Long> taskIds) throws Exception {
    List<ProgrammedProblemFactChange<RemoveTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> findTaskOrCreate(solution, id)).map(task -> new ProgrammedProblemFactChange<>(new RemoveTaskProblemFactChange(task))).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) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SET_OF_50TASKS_5USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION) List(java.util.List) SET_OF_100TASKS_5USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION) Assert.assertFalse(org.junit.Assert.assertFalse) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) SET_OF_500TASKS_20USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION) Task(org.kie.server.services.taskassigning.core.model.Task) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.server.services.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)

Aggregations

Task (org.kie.server.services.taskassigning.core.model.Task)63 User (org.kie.server.services.taskassigning.core.model.User)32 Test (org.junit.Test)26 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)23 TaskOrUser (org.kie.server.services.taskassigning.core.model.TaskOrUser)21 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)15 ArrayList (java.util.ArrayList)14 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)12 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)12 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)11 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)11 TaskData (org.kie.server.api.model.taskassigning.TaskData)10 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)10 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)10 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)10 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)10 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)10 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)10 TaskUtil.fromTaskData (org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)8 UserUtil.fromExternalUser (org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser)8