Search in sources :

Example 1 with PLANNING_USER

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

the class SolverTest method assertAssignment.

private void assertAssignment(User user, TaskAssignment taskAssignment, List<User> availableUsers) {
    assertThat(taskAssignment.getUser()).isNotNull();
    assertThat(taskAssignment.getUser().getId()).as("TaskAssignment: %s is not assigned to expected user: %s ", taskAssignment, user).isEqualTo(user.getId());
    Task task = taskAssignment.getTask();
    if (task.getPotentialUsers().isEmpty() && task.getPotentialGroups().isEmpty()) {
        assertThat(user.getId()).as("TaskAssignment: %s without potentialOwners can only be assigned to the PLANNING_USER", taskAssignment).isEqualTo(PLANNING_USER.getId());
    } else if (PLANNING_USER.getId().equals(user.getId())) {
        availableUsers.forEach(availableUser -> assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("PLANNING_USER user was assigned but another potential owner was found, user: %s taskAssignment: %s", user, taskAssignment)).isFalse());
    } else {
        assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("User: %s is not a potential owner for the taskAssignment: %s", user, taskAssignment)).isTrue();
    }
}
Also used : Solver(org.optaplanner.core.api.solver.Solver) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) TaskHelper.isPotentialOwner(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.isPotentialOwner) AbstractTaskAssigningCoreTest(org.kie.kogito.taskassigning.core.AbstractTaskAssigningCoreTest) User(org.kie.kogito.taskassigning.core.model.User) Test(org.junit.jupiter.api.Test) Task(org.kie.kogito.taskassigning.core.model.Task) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER) TaskHelper.extractTaskAssignments(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.extractTaskAssignments) Timeout(org.junit.jupiter.api.Timeout) Task(org.kie.kogito.taskassigning.core.model.Task)

Example 2 with PLANNING_USER

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

the class SolutionBuilder method build.

public TaskAssigningSolution build() {
    final List<TaskAssignment> taskAssignments = new ArrayList<>();
    final Map<String, List<IndexedElement<TaskAssignment>>> assignmentsByUserId = new HashMap<>();
    final Map<String, User> usersById = filterDuplicates(externalUsers).filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(externalUser -> fromExternalUser(externalUser, processorRegistry)).collect(Collectors.toMap(User::getId, Function.identity()));
    usersById.put(PLANNING_USER.getId(), PLANNING_USER);
    taskDataList.forEach(taskData -> {
        Task task = fromTaskData(taskData);
        processorRegistry.applyAttributesProcessor(task, task.getAttributes());
        TaskAssignment taskAssignment = new TaskAssignment(task);
        String state = task.getState();
        taskAssignments.add(taskAssignment);
        if (RESERVED.value().equals(state)) {
            addTaskAssignmentToUser(assignmentsByUserId, taskAssignment, taskData.getActualOwner(), -1, true);
        }
    });
    assignmentsByUserId.forEach((key, assignedTasks) -> {
        User user = usersById.get(key);
        if (user == null) {
            // create the user by convention.
            user = new User(key);
            usersById.put(key, user);
        }
        final List<TaskAssignment> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList());
        addAssignmentsToUser(user, userTasks);
    });
    // Add the DUMMY_TASKs to avoid running into scenarios where the solution remains with no tasks or only one task
    // for selection. (https://issues.redhat.com/browse/PLANNER-1738)
    taskAssignments.add(DUMMY_TASK_ASSIGNMENT);
    taskAssignments.add(DUMMY_TASK_ASSIGNMENT_PLANNER_1738);
    final List<User> users = new ArrayList<>(usersById.values());
    return new TaskAssigningSolution("-1", users, taskAssignments);
}
Also used : IndexedElement.addInOrder(org.kie.kogito.taskassigning.service.util.IndexedElement.addInOrder) ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) HashMap(java.util.HashMap) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) IndexedElement(org.kie.kogito.taskassigning.service.util.IndexedElement) UserUtil.filterDuplicates(org.kie.kogito.taskassigning.service.util.UserUtil.filterDuplicates) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) DUMMY_TASK_ASSIGNMENT(org.kie.kogito.taskassigning.core.model.ModelConstants.DUMMY_TASK_ASSIGNMENT) RESERVED(org.kie.kogito.taskassigning.service.TaskState.RESERVED) User(org.kie.kogito.taskassigning.core.model.User) ArrayList(java.util.ArrayList) Task(org.kie.kogito.taskassigning.core.model.Task) DUMMY_TASK_ASSIGNMENT_PLANNER_1738(org.kie.kogito.taskassigning.core.model.ModelConstants.DUMMY_TASK_ASSIGNMENT_PLANNER_1738) List(java.util.List) PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER) IS_PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.IS_PLANNING_USER) Map(java.util.Map) AttributesProcessorRegistry(org.kie.kogito.taskassigning.service.processing.AttributesProcessorRegistry) Task(org.kie.kogito.taskassigning.core.model.Task) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) User(org.kie.kogito.taskassigning.core.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) ArrayList(java.util.ArrayList) List(java.util.List) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 3 with PLANNING_USER

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

the class AddTaskExecutableProblemFactChangeTest method addTaskProblemFactChange.

private void addTaskProblemFactChange(TaskAssigningSolution solution, List<String> taskIds) {
    solution.getUserList().add(PLANNING_USER);
    List<ProgrammedProblemFactChange<AddTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> new ProgrammedProblemFactChange<>(new AddTaskProblemFactChange(new TaskAssignment(Task.newBuilder().id(id).name("NewTask_" + id).build())))).collect(Collectors.toList());
    // each partial solution must have the change that was applied on it.
    executeSequentialChanges(solution, programmedChanges);
    programmedChanges.forEach(change -> assertAddTaskProblemFactChangeWasProduced(change.getChange(), change.getSolutionAfterChange()));
    // finally the last solution must have the result of all the changes.
    TaskAssigningSolution lastSolution = programmedChanges.get(programmedChanges.size() - 1).getSolutionAfterChange();
    programmedChanges.forEach(change -> assertAddTaskProblemFactChangeWasProduced(change.getChange(), lastSolution));
}
Also used : Arrays(java.util.Arrays) SET_OF_100TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION) SET_OF_500TASKS_20USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Task(org.kie.kogito.taskassigning.core.model.Task) List(java.util.List) SET_OF_50TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION) PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER) TestConstants(org.kie.kogito.taskassigning.core.TestConstants) Assertions(org.assertj.core.api.Assertions) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) Tag(org.junit.jupiter.api.Tag) Collections(java.util.Collections) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

List (java.util.List)3 PLANNING_USER (org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER)3 Task (org.kie.kogito.taskassigning.core.model.Task)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)3 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.jupiter.api.Test)2 SET_OF_24TASKS_8USERS_SOLUTION (org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION)2 User (org.kie.kogito.taskassigning.core.model.User)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 Tag (org.junit.jupiter.api.Tag)1