Search in sources :

Example 1 with TaskAssignment

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);
    }
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 2 with TaskAssignment

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())));
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) User(org.kie.kogito.taskassigning.core.model.User) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 3 with TaskAssignment

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();
}
Also used : TaskAssigningRuntimeException(org.kie.kogito.taskassigning.core.TaskAssigningRuntimeException) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 4 with TaskAssignment

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;
    }
}
Also used : ProblemFactChangeUtil.unlinkTaskAssignment(org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 5 with 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);
    }
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) User(org.kie.kogito.taskassigning.core.model.User) ProblemFactChangeUtil.unlinkTaskAssignment(org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)72 User (org.kie.kogito.taskassigning.core.model.User)39 Test (org.junit.jupiter.api.Test)27 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)23 ChainElement (org.kie.kogito.taskassigning.core.model.ChainElement)14 ArrayList (java.util.ArrayList)12 TestUtil.mockTaskAssignment (org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment)12 TestUtil.mockUser (org.kie.kogito.taskassigning.core.model.TestUtil.mockUser)11 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)10 Task (org.kie.kogito.taskassigning.core.model.Task)8 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)8 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)8 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)8 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)6 List (java.util.List)5 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)5 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)5 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)4 ProblemFactChangeUtil.unlinkTaskAssignment (org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment)4 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)4