Search in sources :

Example 1 with DUMMY_TASK_ASSIGNMENT

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

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 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)1 User (org.kie.kogito.taskassigning.core.model.User)1 RESERVED (org.kie.kogito.taskassigning.service.TaskState.RESERVED)1 AttributesProcessorRegistry (org.kie.kogito.taskassigning.service.processing.AttributesProcessorRegistry)1 IndexedElement (org.kie.kogito.taskassigning.service.util.IndexedElement)1 IndexedElement.addInOrder (org.kie.kogito.taskassigning.service.util.IndexedElement.addInOrder)1 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)1