use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class RemoveTaskProblemFactChange method doChange.
@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
TaskAssigningSolution solution = scoreDirector.getWorkingSolution();
TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
if (workingTaskAssignment != null) {
ChainElement previousElement = workingTaskAssignment.getPreviousElement();
unlinkTaskAssignment(workingTaskAssignment, previousElement, scoreDirector);
scoreDirector.beforeEntityRemoved(workingTaskAssignment);
// Planning entity lists are already cloned by the SolutionCloner, no need to clone.
solution.getTaskAssignmentList().remove(workingTaskAssignment);
scoreDirector.afterEntityRemoved(workingTaskAssignment);
scoreDirector.triggerVariableListeners();
}
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class TaskHelperTest method hasPinnedTasks.
@Test
void hasPinnedTasks() {
ChainElement chainElement = buildChainElement();
assertThat(TaskHelper.hasPinnedTasks(chainElement)).isTrue();
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChangeTest method doChangeForExistingUserAndTaskAssignmentThatBelongsToAnotherUser.
@Test
void doChangeForExistingUserAndTaskAssignmentThatBelongsToAnotherUser() {
// Initial assignments:
// User1 <- TASK_0 <- TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
// User2 <- USER2_TASK_0 <- USER2_TASK_1 <- USER2_TASK_2
List<TaskAssignment> user1Tasks = buildUserTasks();
User user1 = buildUser(user1Tasks);
List<TaskAssignment> user2Tasks = Arrays.asList(mockTaskAssignment(USER2_TASK_0, false), mockTaskAssignment(USER2_TASK_1, false), mockTaskAssignment(USER2_TASK_2, false));
User user2 = mockUser("USER_2", user2Tasks);
TaskAssignment taskAssignment = mockTaskAssignment(USER2_TASK_1, false);
TaskAssignment workingTaskAssignment = user2Tasks.get(1);
ChainElement originalPreviousElement = workingTaskAssignment.getPreviousElement();
TaskAssignment expectedPreviousElement = user1Tasks.get(1);
when(scoreDirector.lookUpWorkingObjectOrReturnNull(user1)).thenReturn(user1);
when(scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment)).thenReturn(workingTaskAssignment);
change = new AssignTaskProblemFactChange(taskAssignment, user1);
change.doChange(scoreDirector);
assertPinning(workingTaskAssignment);
assertThat(workingTaskAssignment.getPreviousElement()).isSameAs(expectedPreviousElement);
assertThat(user2Tasks.get(2).getPreviousElement()).isSameAs(originalPreviousElement);
verify(scoreDirector, never()).beforeEntityAdded(any());
verify(scoreDirector, never()).afterEntityAdded(any());
verify(scoreDirector).triggerVariableListeners();
// Expected assignments:
// User1 <- TASK_0 <- TASK_1 <- USER2_TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
// User2 <- USER2_TASK_0 <- USER2_TASK_2
assertTaskPositions(user1, user1Tasks.get(0), user1Tasks.get(1), workingTaskAssignment, user1Tasks.get(2), user1Tasks.get(3), user1Tasks.get(4));
assertTaskPositions(user2, user2Tasks.get(0), user2Tasks.get(2));
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class AssignTaskExecutableProblemFactChangeTest method assertAssignTaskProblemFactChangeWasProduced.
/**
* Given an AssignTaskProblemFactChange and a solution that was produced as the result of applying the change,
* asserts that the assignment defined by the change is not violated (exists in) by the solution.
* The assignment defined in the change must also be pinned in the produced solution as well as any other
* previous assignment for the given user.
*
* @param change The change that was executed for producing the solution.
* @param solution The produced solution.
*/
private void assertAssignTaskProblemFactChangeWasProduced(AssignTaskProblemFactChange change, TaskAssigningSolution solution) throws Exception {
User internalUser = solution.getUserList().stream().filter(user -> Objects.equals(user.getId(), change.getUser().getId())).findFirst().orElseThrow(() -> new Exception("User: " + change.getUser() + " was not found in solution."));
TaskAssignment internalTaskAssignment = solution.getTaskAssignmentList().stream().filter(taskAssignment -> Objects.equals(taskAssignment.getId(), change.getTaskAssignment().getId())).findFirst().orElseThrow(() -> new Exception("TaskAssignment: " + change + " was not found in solution."));
assertThat(internalTaskAssignment.getUser()).isEqualTo(internalUser);
assertThat(internalTaskAssignment.isPinned()).isTrue();
// all the previous tasks must be pinned by construction and be assigned to the user
ChainElement previousElement = internalTaskAssignment.getPreviousElement();
while (previousElement != null) {
if (previousElement.isTaskAssignment()) {
TaskAssignment previousTaskAssignment = (TaskAssignment) previousElement;
assertThat(previousTaskAssignment.isPinned()).isTrue();
assertThat(previousTaskAssignment.getUser()).isEqualTo(internalUser);
previousElement = previousTaskAssignment.getPreviousElement();
} else {
assertThat(previousElement).isEqualTo(internalUser);
previousElement = null;
}
}
// all the next tasks must to the user.
TaskAssignment nextTaskAssignment = internalTaskAssignment.getNextElement();
while (nextTaskAssignment != null) {
assertThat(nextTaskAssignment.getUser()).isEqualTo(internalUser);
nextTaskAssignment = nextTaskAssignment.getNextElement();
}
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class SolutionBuilder method addAssignmentsToUser.
/**
* Link the list of tasks to the given user. The tasks comes in the expected order.
*
* @param user the user that will "own" the tasks in the chained graph.
* @param taskAssignments the tasks to link.
*/
private static void addAssignmentsToUser(User user, List<TaskAssignment> taskAssignments) {
ChainElement previousElement = user;
int previousEndTimeInMinutes = 0;
TaskAssignment nextElement;
// they are initialized as part of the solution restoring.
for (TaskAssignment taskAssignment : taskAssignments) {
nextElement = taskAssignment;
previousElement.setNextElement(nextElement);
nextElement.setStartTimeInMinutes(previousEndTimeInMinutes);
nextElement.setEndTimeInMinutes(nextElement.getStartTimeInMinutes() + nextElement.getDurationInMinutes());
nextElement.setPreviousElement(previousElement);
nextElement.setUser(user);
previousEndTimeInMinutes = nextElement.getEndTimeInMinutes();
previousElement = nextElement;
}
}
Aggregations