Search in sources :

Example 16 with Task

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

the class TaskUtil method fromTaskData.

public static Task fromTaskData(TaskData taskData) {
    final Task task = new Task(taskData.getTaskId(), taskData.getProcessInstanceId(), taskData.getProcessId(), taskData.getContainerId(), taskData.getName(), taskData.getPriority(), taskData.getStatus(), taskData.getInputData());
    if (taskData.getPotentialOwners() != null) {
        taskData.getPotentialOwners().forEach(potentialOwner -> {
            if (isUser(potentialOwner.getType())) {
                task.getPotentialOwners().add(new User(potentialOwner.getName().hashCode(), potentialOwner.getName()));
            } else {
                task.getPotentialOwners().add(new Group(potentialOwner.getName().hashCode(), potentialOwner.getName()));
            }
        });
    }
    LabelValueExtractorRegistry.getInstance().applyLabelValueExtractors(TaskData.class, taskData, task::setLabelValues);
    return task;
}
Also used : Group(org.kie.server.services.taskassigning.core.model.Group) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) UserUtil.isUser(org.kie.server.services.taskassigning.planning.util.UserUtil.isUser)

Example 17 with Task

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

the class PlanningBuilderTest method mockTask.

private Task mockTask(long taskId, boolean pinned, String containerId, long processInstanceId) {
    Task result = new Task(taskId, "Task_" + taskId, 0);
    result.setContainerId(containerId);
    result.setProcessInstanceId(processInstanceId);
    result.setPinned(pinned);
    return result;
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task)

Example 18 with Task

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

the class PlanningBuilderTest method assertTasksArePlanned.

private void assertTasksArePlanned(List<Task> tasks, List<PlanningItem> planningItems) {
    for (Task task : tasks) {
        PlanningItem peerItem = planningItems.stream().filter(item -> item.getTaskId().equals(task.getId())).findFirst().orElse(null);
        if (peerItem == null) {
            fail("Task: " + task.getId() + " for user: " + task.getUser().getId() + " must be part of the generated planning");
        }
        assertEquals("PlanningItem containerId for task: " + task.getId() + " and user: " + task.getUser().getId() + " don't have the expected value.", task.getContainerId(), peerItem.getContainerId());
        assertEquals("PlanningItem processInstanceId for task: " + task.getId() + " and user: " + task.getUser().getId() + " don't have the expected value.", task.getProcessInstanceId(), task.getProcessInstanceId());
        assertEquals("PlanningItem assignedUser for task: " + task.getId() + " and user: " + task.getUser().getId() + " don't have the expected value.", task.getUser().getEntityId(), peerItem.getPlanningTask().getAssignedUser());
    }
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem)

Example 19 with Task

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

the class PlanningBuilderTest method build.

@Test
public void build() {
    List<Task> user1Tasks = mockTasks(USER1_TOTAL_TASKS, USER1_PINNED_TASKS, "container1", 1L);
    User user1 = mockUser(1, user1Tasks);
    List<Task> user2Tasks = mockTasks(USER2_TOTAL_TASKS, USER2_PINNED_TASKS, "container2", 2L);
    User user2 = mockUser(2, user2Tasks);
    List<Task> user3Tasks = mockTasks(USER3_TOTAL_TASKS, USER3_PINNED_TASKS, "container3", 3L);
    User user3 = mockUser(3, user3Tasks);
    List<Task> user4Tasks = mockTasks(USER4_TOTAL_TASKS, USER4_PINNED_TASKS, "container4", 4L);
    User user4 = mockUser(4, user4Tasks);
    List<Task> user5Tasks = mockTasks(USER5_TOTAL_TASKS, USER5_PINNED_TASKS, "container5", 5L);
    User user5 = mockUser(5, user5Tasks);
    List<Task> user6Tasks = mockTasks(USER6_TOTAL_TASKS, USER6_PINNED_TASKS, "container6", 6L);
    User user6 = mockUser(6, user6Tasks);
    List<Task> planningUserTasks = mockTasks(PLANNING_USER_TASKS, 0, "container7", 7L);
    User planningUser = initializeUser(new User(-1, PLANNING_USER_ID), planningUserTasks);
    List<Task> totalTasks = new ArrayList<>();
    totalTasks.addAll(user1Tasks);
    totalTasks.addAll(user2Tasks);
    totalTasks.addAll(user3Tasks);
    totalTasks.addAll(user4Tasks);
    totalTasks.addAll(user5Tasks);
    totalTasks.addAll(user6Tasks);
    totalTasks.addAll(planningUserTasks);
    List<User> totalUsers = Arrays.asList(user1, user2, user3, user4, user5, user6, planningUser);
    TaskAssigningSolution solution = new TaskAssigningSolution(1, totalUsers, totalTasks);
    List<PlanningItem> planningItems = PlanningBuilder.create().withPublishWindowSize(publishWindowSize).withSolution(solution).build();
    assertPlanningItems(user1, publishWindowSize, planningItems);
    assertPlanningItems(user2, publishWindowSize, planningItems);
    assertPlanningItems(user3, publishWindowSize, planningItems);
    assertPlanningItems(user4, publishWindowSize, planningItems);
    assertPlanningItems(user5, publishWindowSize, planningItems);
    assertPlanningItems(user6, publishWindowSize, planningItems);
    assertPlanningUserPlanningItems(planningUser, publishWindowSize, planningItems);
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) TestUtil.mockUser(org.kie.server.services.taskassigning.planning.TestUtil.mockUser) User(org.kie.server.services.taskassigning.core.model.User) TestUtil.initializeUser(org.kie.server.services.taskassigning.planning.TestUtil.initializeUser) ArrayList(java.util.ArrayList) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) Test(org.junit.Test)

Example 20 with Task

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

the class SolutionBuilderTest method assertContainsAssignedTask.

private void assertContainsAssignedTask(TaskData taskData, String userId, boolean pinned, TaskAssigningSolution solution) {
    Task task = solution.getTaskList().stream().filter(t -> taskData.getTaskId().equals(t.getId())).findFirst().orElse(null);
    User user = solution.getUserList().stream().filter(u -> userId.equals(u.getEntityId())).findFirst().orElse(null);
    assertNotNull("Task: " + taskData.getTaskId() + " must be present in the solution.", task);
    assertNotNull("Task: " + taskData.getTaskId() + " must assigned to user: " + userId + " but user is not be present in the solution.", user);
    assertNotNull("Task: " + taskData.getTaskId() + " must be assigned to user: " + userId + " but has no assigned user.", task.getUser());
    assertEquals("Task: " + taskData.getTaskId() + " must be assigned to user: " + userId, userId, task.getUser().getEntityId());
    assertEquals("Task: " + taskData.getTaskId() + " must have pinned = " + pinned, pinned, task.isPinned());
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) User(org.kie.server.services.taskassigning.core.model.User) TestUtil.mockExternalUser(org.kie.server.services.taskassigning.planning.TestUtil.mockExternalUser)

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