Search in sources :

Example 1 with ChainElement

use of org.kie.kogito.taskassigning.core.model.ChainElement 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 ChainElement

use of org.kie.kogito.taskassigning.core.model.ChainElement 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 ChainElement

use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.

the class AssignTaskProblemFactChange method processExistingTaskAssignment.

private void processExistingTaskAssignment(TaskAssignment existingTaskAssignment, ChainElement insertPosition, TaskAssignment insertPositionNextTask, ScoreDirector<TaskAssigningSolution> scoreDirector) {
    if (insertPosition.getNextElement() != existingTaskAssignment) {
        // relocate the existingTaskAssignment at the desired position
        ChainElement previousElement = existingTaskAssignment.getPreviousElement();
        if (previousElement != null) {
            // unlink from the current chain position.
            unlinkTaskAssignment(existingTaskAssignment, previousElement, scoreDirector);
        }
        scoreDirector.beforeVariableChanged(existingTaskAssignment, PREVIOUS_ELEMENT);
        existingTaskAssignment.setPreviousElement(insertPosition);
        scoreDirector.afterVariableChanged(existingTaskAssignment, PREVIOUS_ELEMENT);
        setPreviousElementIfApply(insertPositionNextTask, existingTaskAssignment, scoreDirector);
    }
    setPinned(existingTaskAssignment, scoreDirector);
    scoreDirector.triggerVariableListeners();
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement)

Example 4 with ChainElement

use of org.kie.kogito.taskassigning.core.model.ChainElement 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)

Example 5 with ChainElement

use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.

the class ReleaseTaskProblemFactChange method doChange.

@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
    TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
    if (workingTaskAssignment == null || workingTaskAssignment.getPreviousElement() == null) {
        // or it's simply not yet assigned.
        return;
    }
    // unlink the workingTaskAssignment from the chain.
    ChainElement previousElement = workingTaskAssignment.getPreviousElement();
    unlinkTaskAssignment(workingTaskAssignment, previousElement, scoreDirector);
    scoreDirector.beforeVariableChanged(workingTaskAssignment, PREVIOUS_ELEMENT);
    workingTaskAssignment.setPreviousElement(null);
    scoreDirector.afterVariableChanged(workingTaskAssignment, PREVIOUS_ELEMENT);
    if (workingTaskAssignment.isPinned()) {
        scoreDirector.beforeProblemPropertyChanged(workingTaskAssignment);
        workingTaskAssignment.setPinned(false);
        scoreDirector.afterProblemPropertyChanged(workingTaskAssignment);
    }
    scoreDirector.triggerVariableListeners();
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) ProblemFactChangeUtil.unlinkTaskAssignment(org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

ChainElement (org.kie.kogito.taskassigning.core.model.ChainElement)15 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)13 User (org.kie.kogito.taskassigning.core.model.User)5 Test (org.junit.jupiter.api.Test)4 ProblemFactChangeUtil.unlinkTaskAssignment (org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)1 TestUtil.mockTaskAssignment (org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment)1 TestUtil.mockUser (org.kie.kogito.taskassigning.core.model.TestUtil.mockUser)1