Search in sources :

Example 26 with Task

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

the class ProblemFactChangeUtil method releaseTasks.

/**
 * Release the tasks associated previously associated by OptaPlanner to a user.
 * note: Optimizes the generated graph e.g. User <-> T1 <-> T2 <-> T3 <-> T4 navigation and structure changing
 * by iterating in reverse order.
 * @param workingUser a user instance previously populated by OptaPlanner.
 * @param includePinnedTasks true if the pinned tasks must also be released, false if only non pinned tasks must
 * be released.
 * @param scoreDirector a scored director instance for notifying the changes.
 */
private static void releaseTasks(User workingUser, boolean includePinnedTasks, ScoreDirector<TaskAssigningSolution> scoreDirector) {
    final List<Task> tasks = extractTasks(workingUser, testedTask -> includePinnedTasks || !testedTask.isPinned());
    Task task;
    for (int index = tasks.size() - 1; index >= 0; index--) {
        task = tasks.get(index);
        scoreDirector.beforeProblemPropertyChanged(task);
        task.setPinned(false);
        scoreDirector.afterProblemPropertyChanged(task);
        scoreDirector.beforeVariableChanged(task, PREVIOUS_TASK_OR_USER);
        task.setPreviousTaskOrUser(null);
        scoreDirector.afterVariableChanged(task, PREVIOUS_TASK_OR_USER);
    }
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task)

Example 27 with Task

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

the class ReleaseTaskProblemFactChange method doChange.

@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
    Task workingTask = scoreDirector.lookUpWorkingObjectOrReturnNull(task);
    if (workingTask == null || workingTask.getPreviousTaskOrUser() == null) {
        // or it's simply not yet assigned.
        return;
    }
    // un-link the task from the chain.
    TaskOrUser previousTaskOrUser = workingTask.getPreviousTaskOrUser();
    Task nextTask = workingTask.getNextTask();
    if (nextTask != null) {
        // re-link the chain where the workingTask belonged if any
        scoreDirector.beforeVariableChanged(nextTask, PREVIOUS_TASK_OR_USER);
        nextTask.setPreviousTaskOrUser(previousTaskOrUser);
        scoreDirector.afterVariableChanged(nextTask, PREVIOUS_TASK_OR_USER);
    }
    scoreDirector.beforeVariableChanged(workingTask, PREVIOUS_TASK_OR_USER);
    workingTask.setPreviousTaskOrUser(null);
    scoreDirector.afterVariableChanged(workingTask, PREVIOUS_TASK_OR_USER);
    if (workingTask.isPinned()) {
        scoreDirector.beforeProblemPropertyChanged(workingTask);
        workingTask.setPinned(false);
        scoreDirector.afterProblemPropertyChanged(workingTask);
    }
    scoreDirector.triggerVariableListeners();
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser)

Example 28 with Task

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

the class AbstractTaskAssigningCoreTest method printSolution.

public static void printSolution(TaskAssigningSolution solution, StringBuilder builder) {
    solution.getUserList().forEach(taskOrUser -> {
        appendln(builder, "------------------------------------------");
        appendln(builder, printUser(taskOrUser));
        appendln(builder, "------------------------------------------");
        appendln(builder);
        Task task = taskOrUser.getNextTask();
        while (task != null) {
            builder.append(" -> ");
            appendln(builder, printTask(task));
            task = task.getNextTask();
            if (task != null) {
                appendln(builder);
            }
        }
        appendln(builder);
    });
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task)

Example 29 with Task

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

the class TaskByGroupAndSkillsChangeMoveFilter method accept.

@Override
public boolean accept(ScoreDirector<TaskAssigningSolution> scoreDirector, ChangeMove<TaskAssigningSolution> changeMove) {
    final Task taskToMove = (Task) changeMove.getEntity();
    final TaskOrUser taskOrUser = (TaskOrUser) changeMove.getToPlanningValue();
    final User user = taskOrUser.getUser();
    return user != null && user.isEnabled() && (ModelConstants.IS_PLANNING_USER.test(user.getEntityId()) || (isPotentialOwner(taskToMove, user) && hasAllLabels(taskToMove, user, DefaultLabels.SKILLS.name())));
}
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 30 with Task

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

the class AssignTaskProblemFactChange method findInsertPosition.

/**
 * Find the first available "position" where a task can be added in the tasks chain for a given user.
 * <p>
 * For a chain like:
 * <p>
 * U -> T1 -> T2 -> T3 -> T4 -> null
 * <p>
 * if e.g. T3 is returned, a new task Tn will be later added in the following position.
 * <p>
 * U -> T1 -> T2 -> T3 -> Tn -> T4 -> null
 * Given that we are using a chained structure, to pin a task Tn to a given user, we must be sure that all the
 * previous tasks in the chain are pinned to the same user. For keeping the structure consistency a task Tn is
 * inserted after the last pinned chain. In the example above we have that existing tasks T1, T2 and T3 are pinned.
 * @param user the for adding a task to.
 * @return the proper TaskOrUser object were a task can be added. This method will never return null.
 */
private TaskOrUser findInsertPosition(User user) {
    TaskOrUser result = user;
    Task nextTask = user.getNextTask();
    while (nextTask != null && nextTask.isPinned()) {
        result = nextTask;
        nextTask = nextTask.getNextTask();
    }
    return result;
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser)

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