use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class StartAndEndTimeUpdatingVariableListener method updateStartAndEndTime.
private static void updateStartAndEndTime(final ScoreDirector<TaskAssigningSolution> scoreDirector, final TaskAssignment sourceTaskAssignment) {
ChainElement previous = sourceTaskAssignment.getPreviousElement();
TaskAssignment shadowTaskAssignment = sourceTaskAssignment;
Integer previousEndTime = previous == null || !previous.isTaskAssignment() ? 0 : ((TaskAssignment) previous).getEndTimeInMinutes();
Integer startTime = previousEndTime;
Integer endTime = calculateEndTime(shadowTaskAssignment, startTime);
while (shadowTaskAssignment != null && !Objects.equals(shadowTaskAssignment.getStartTimeInMinutes(), startTime)) {
scoreDirector.beforeVariableChanged(shadowTaskAssignment, START_TIME_IN_MINUTES);
shadowTaskAssignment.setStartTimeInMinutes(startTime);
scoreDirector.afterVariableChanged(shadowTaskAssignment, START_TIME_IN_MINUTES);
scoreDirector.beforeVariableChanged(shadowTaskAssignment, END_TIME_IN_MINUTES);
shadowTaskAssignment.setEndTimeInMinutes(endTime);
scoreDirector.afterVariableChanged(shadowTaskAssignment, END_TIME_IN_MINUTES);
previousEndTime = shadowTaskAssignment.getEndTimeInMinutes();
shadowTaskAssignment = shadowTaskAssignment.getNextElement();
startTime = previousEndTime;
endTime = calculateEndTime(shadowTaskAssignment, startTime);
}
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class TaskByGroupAndSkillsChangeMoveFilter method accept.
@Override
public boolean accept(ScoreDirector<TaskAssigningSolution> scoreDirector, ChangeMove<TaskAssigningSolution> changeMove) {
final TaskAssignment assignmentToMove = (TaskAssignment) changeMove.getEntity();
final ChainElement chainElement = (ChainElement) changeMove.getToPlanningValue();
final User user = chainElement.isTaskAssignment() ? ((TaskAssignment) chainElement).getUser() : (User) chainElement;
return user != null && user.isEnabled() && (ModelConstants.IS_PLANNING_USER.test(user.getId()) || (isPotentialOwner(assignmentToMove.getTask(), user) && hasAllLabels(assignmentToMove.getTask(), user, DefaultLabels.SKILLS.name())));
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AddTaskProblemFactChange method doChange.
@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
TaskAssigningSolution solution = scoreDirector.getWorkingSolution();
TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
if (workingTaskAssignment != null) {
throw new TaskAssigningRuntimeException(String.format("A task assignment with the given identifier id: %s already exists", taskAssignment.getId()));
}
scoreDirector.beforeEntityAdded(taskAssignment);
// Planning entity lists are already cloned by the SolutionCloner, no need to clone.
solution.getTaskAssignmentList().add(taskAssignment);
scoreDirector.afterEntityAdded(taskAssignment);
scoreDirector.triggerVariableListeners();
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChange method lookupOrPrepareTaskAssignment.
private static TaskAssignment lookupOrPrepareTaskAssignment(TaskAssignment taskAssignment, ScoreDirector<TaskAssigningSolution> scoreDirector) {
TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
if (workingTaskAssignment != null) {
return workingTaskAssignment;
} else {
// The task assignment will be created by this PFC.
// Ensure that the task assignment to be added doesn't have any out-side manually assigned values for the
// values that are calculated by OptaPlanner
taskAssignment.setPreviousElement(null);
taskAssignment.setUser(null);
taskAssignment.setPinned(false);
taskAssignment.setNextElement(null);
taskAssignment.setStartTimeInMinutes(null);
taskAssignment.setEndTimeInMinutes(null);
return taskAssignment;
}
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChange method doChange.
@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
User workingUser = lookupOrAddWorkingUser(user, scoreDirector, addIfNotExists);
TaskAssignment workingTaskAssignment = lookupOrPrepareTaskAssignment(taskAssignment, scoreDirector);
ChainElement insertPosition = findInsertPosition(workingUser);
TaskAssignment insertPositionNextTask = insertPosition.getNextElement();
if (taskAssignment == workingTaskAssignment) {
processNewTaskAssignment(workingTaskAssignment, insertPosition, insertPositionNextTask, scoreDirector);
} else if (insertPosition != workingTaskAssignment) {
// in cases where insertPosition == workingTaskAssignment there's nothing to do, since the workingTaskAssignment
// is already pinned and belongs to user. (see findInsertPosition)
processExistingTaskAssignment(workingTaskAssignment, insertPosition, insertPositionNextTask, scoreDirector);
}
}
Aggregations