Search in sources :

Example 1 with IndexedElement

use of org.kie.kogito.taskassigning.service.util.IndexedElement in project kogito-apps by kiegroup.

the class SolutionChangesBuilder method build.

public List<ProblemFactChange<TaskAssigningSolution>> build() {
    usersById = solution.getUserList().stream().collect(Collectors.toMap(User::getId, Function.identity()));
    Map<String, TaskAssignment> taskAssignmentById = filterNonDummyAssignments(solution.getTaskAssignmentList()).stream().collect(Collectors.toMap(TaskAssignment::getId, Function.identity()));
    TaskAssignment taskAssignment;
    for (TaskData taskData : taskDataList) {
        taskAssignment = taskAssignmentById.remove(taskData.getId());
        if (taskAssignment == null) {
            addNewTaskChanges(taskData);
        } else {
            addTaskChanges(taskAssignment, taskData);
        }
    }
    for (TaskAssignment removedTask : removedTasksSet) {
        removedTaskChanges.add(new RemoveTaskProblemFactChange(removedTask));
    }
    if (userDataEvent != null) {
        addFullSyncUserChanges(userDataEvent.getData());
    } else {
        addRemovableUserChanges();
    }
    totalChanges.addAll(newUserChanges);
    totalChanges.addAll(removedTaskChanges);
    totalChanges.addAll(releasedTasksChanges);
    for (List<IndexedElement<AssignTaskProblemFactChange>> assignTaskToUserChanges : assignToUserChangesByUserId.values()) {
        List<AssignTaskProblemFactChange> assignTaskChanges = assignTaskToUserChanges.stream().map(IndexedElement::getElement).collect(Collectors.toList());
        totalChanges.addAll(assignTaskChanges);
    }
    totalChanges.addAll(taskPropertyChanges);
    totalChanges.addAll(updateUserChanges);
    totalChanges.addAll(newTasksChanges);
    totalChanges.addAll(removableUserChanges);
    traceChanges();
    if (!totalChanges.isEmpty()) {
        totalChanges.add(0, scoreDirector -> context.setCurrentChangeSetId(context.nextChangeSetId()));
    }
    return totalChanges;
}
Also used : RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) User(org.kie.kogito.taskassigning.core.model.User) IndexedElement(org.kie.kogito.taskassigning.service.util.IndexedElement) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)

Example 2 with IndexedElement

use of org.kie.kogito.taskassigning.service.util.IndexedElement 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)

Aggregations

TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)2 User (org.kie.kogito.taskassigning.core.model.User)2 IndexedElement (org.kie.kogito.taskassigning.service.util.IndexedElement)2 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)2 UserUtil.fromExternalUser (org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ChainElement (org.kie.kogito.taskassigning.core.model.ChainElement)1 DUMMY_TASK_ASSIGNMENT (org.kie.kogito.taskassigning.core.model.ModelConstants.DUMMY_TASK_ASSIGNMENT)1 DUMMY_TASK_ASSIGNMENT_PLANNER_1738 (org.kie.kogito.taskassigning.core.model.ModelConstants.DUMMY_TASK_ASSIGNMENT_PLANNER_1738)1 IS_PLANNING_USER (org.kie.kogito.taskassigning.core.model.ModelConstants.IS_PLANNING_USER)1 PLANNING_USER (org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER)1 Task (org.kie.kogito.taskassigning.core.model.Task)1 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)1 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)1 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)1