Search in sources :

Example 6 with Task

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

the class TaskAssigningGenerator method createTaskList.

private void createTaskList(TaskAssigningSolution solution, int taskListSize, List<Group> groupList) {
    List<User> userList = solution.getUserList();
    List<Task> taskList = new ArrayList<>(taskListSize);
    for (int i = 0; i < taskListSize; i++) {
        Task task = new Task();
        task.setId((long) i);
        task.setName("Task_" + task.getId());
        task.setPriority(random.nextInt(TASK_MAX_PRIORITY + 1));
        Set<OrganizationalEntity> potentialOwners = new LinkedHashSet<>();
        int groupListIndex = random.nextInt(groupList.size());
        int groupPotentialOwnersSize = TASK_POTENTIAL_OWNERS_GROUP_SIZE_MINIMUM + random.nextInt(TASK_POTENTIAL_OWNERS_GROUP_SIZE_MAXIMUM - TASK_POTENTIAL_OWNERS_GROUP_SIZE_MINIMUM);
        if (groupPotentialOwnersSize > groupList.size()) {
            groupPotentialOwnersSize = groupList.size();
        }
        for (int j = 0; j < groupPotentialOwnersSize; j++) {
            potentialOwners.add(groupList.get(groupListIndex));
            groupListIndex = (groupListIndex + 1) % groupList.size();
        }
        int userListIndex = random.nextInt(userList.size());
        int userPotentialOwnersSize = TASK_POTENTIAL_OWNERS_USER_SIZE_MINIMUM + random.nextInt(TASK_POTENTIAL_OWNERS_USER_SIZE_MAXIMUM - TASK_POTENTIAL_OWNERS_USER_SIZE_MINIMUM);
        if (userPotentialOwnersSize > userList.size()) {
            userPotentialOwnersSize = userList.size();
        }
        for (int j = 0; j < userPotentialOwnersSize; j++) {
            potentialOwners.add(userList.get(userListIndex));
            userListIndex = (userListIndex + 1) % userList.size();
        }
        task.setPotentialOwners(potentialOwners);
        taskList.add(task);
    }
    solution.setTaskList(taskList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) OrganizationalEntity(org.kie.server.services.taskassigning.core.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Example 7 with Task

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

the class PlanningBuilder method buildPlanningItems.

private List<PlanningItem> buildPlanningItems(User user) {
    int index = 0;
    int publishedCount = 0;
    PlanningItem planningItem;
    // dummy tasks has nothing to with the jBPM runtime, don't process them
    final List<Task> userTasks = extractTasks(user, IS_NOT_DUMMY);
    final List<PlanningItem> userPlanningItems = new ArrayList<>();
    for (Task task : userTasks) {
        planningItem = PlanningItem.builder().containerId(task.getContainerId()).taskId(task.getId()).processInstanceId(task.getProcessInstanceId()).planningTask(PlanningTask.builder().taskId(task.getId()).published(task.isPinned()).assignedUser(user.getUser().getEntityId()).index(index++).build()).build();
        userPlanningItems.add(planningItem);
        publishedCount += planningItem.getPlanningTask().isPublished() ? 1 : 0;
    }
    Iterator<PlanningItem> userPlanningItemsIt = userPlanningItems.iterator();
    while (userPlanningItemsIt.hasNext() && (publishedCount < publishWindowSize || IS_PLANNING_USER.test(user.getEntityId()))) {
        planningItem = userPlanningItemsIt.next();
        if (!planningItem.getPlanningTask().isPublished()) {
            planningItem.getPlanningTask().setPublished(true);
            publishedCount++;
        }
    }
    return userPlanningItems;
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) Task(org.kie.server.services.taskassigning.core.model.Task) ArrayList(java.util.ArrayList) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem)

Example 8 with Task

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

the class SolutionBuilder method build.

public TaskAssigningSolution build() {
    final List<Task> tasks = new ArrayList<>();
    final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>();
    final Map<String, User> usersById = filterDuplicates(externalUsers).filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(UserUtil::fromExternalUser).collect(Collectors.toMap(User::getEntityId, Function.identity()));
    usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER);
    taskDataList.forEach(taskData -> {
        context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate());
        final Task task = fromTaskData(taskData);
        final Status status = convertFromString(task.getStatus());
        switch(status) {
            case Ready:
                tasks.add(task);
                break;
            case Reserved:
            case InProgress:
            case Suspended:
                if (isNoneEmpty(taskData.getActualOwner())) {
                    // If actualOwner is empty the only chance is that the task was in Ready status and changed to
                    // Suspended, since Reserved and InProgress tasks has always an owner in jBPM.
                    // Finally tasks with no actualOwner (Suspended) are skipped, since they'll be properly added to
                    // the solution when they change to Ready status and the proper jBPM event is raised.
                    tasks.add(task);
                    final PlanningTask planningTask = taskData.getPlanningTask();
                    if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) {
                        boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner());
                        addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned);
                    } else {
                        boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status;
                        addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned);
                    }
                }
                break;
            default:
                // no other cases exists, sonar required.
                throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch");
        }
    });
    assignedTasksByUserId.forEach((key, assignedTasks) -> {
        User user = usersById.get(key);
        if (user == null) {
            // create the user by convention.
            user = new User(key.hashCode(), key);
            usersById.put(key, user);
        }
        final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList());
        addTasksToUser(user, userTasks);
    });
    // Add the DUMMY_TASK to avoid running into scenarios where the solution remains with no tasks.
    tasks.add(DUMMY_TASK);
    final List<User> users = new ArrayList<>(usersById.values());
    return new TaskAssigningSolution(-1, users, tasks);
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.server.services.taskassigning.core.model.Task) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser) User(org.kie.server.services.taskassigning.core.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with Task

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

the class SolutionChangesBuilderTest method addReassignReservedOrInProgressOrSuspendedTaskWhenItWasManuallyReassigned.

private void addReassignReservedOrInProgressOrSuspendedTaskWhenItWasManuallyReassigned(Status status, boolean addActualOwnerToSolution) {
    TaskData taskData = mockTaskData(TASK_ID, NAME, status, ACTUAL_OWNER_ENTITY_ID);
    Task task = fromTaskData(taskData);
    User user = mockUser(USER_ENTITY_ID);
    task.setUser(user);
    List<User> userList = new ArrayList<>();
    userList.add(user);
    if (addActualOwnerToSolution) {
        User actualOwner = mockUser(ACTUAL_OWNER_ENTITY_ID);
        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 : 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 10 with Task

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

the class SolutionChangesBuilderTest method addRemoveReservedOrInProgressOrSuspendedTaskChangeWhenActualOwnerNotPresent.

private void addRemoveReservedOrInProgressOrSuspendedTaskChangeWhenActualOwnerNotPresent(Status status) {
    TaskData taskData = mockTaskData(TASK_ID, NAME, status, null);
    Task task = fromTaskData(taskData);
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(task), Collections.emptyList());
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(mockTaskDataList(taskData)).withUserSystem(userSystemService).withContext(context).build();
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, new RemoveTaskProblemFactChange(task));
    assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) 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)

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