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);
}
}
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();
}
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);
});
}
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())));
}
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;
}
Aggregations