Search in sources :

Example 6 with AssignTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilder method addTaskChanges.

private void addTaskChanges(TaskAssignment taskAssignment, TaskData taskData) {
    String taskState = taskData.getState();
    if (READY.value().equals(taskState)) {
        context.setTaskPublished(taskData.getId(), false);
        releasedTasksChanges.add(new ReleaseTaskProblemFactChange(taskAssignment));
    } else if (RESERVED.value().equals(taskState)) {
        context.setTaskPublished(taskData.getId(), true);
        if (!taskData.getActualOwner().equals(taskAssignment.getUser().getId()) || !taskAssignment.isPinned()) {
            final User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
            AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(taskAssignment, user, true);
            addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
        }
    } else if (TaskState.isTerminal(taskState)) {
        removedTasksSet.add(taskAssignment);
    }
    if (!removedTasksSet.contains(taskAssignment)) {
        Task updatedTask = fromTaskData(taskData);
        if (!equalsByTaskInfoProperties(taskAssignment.getTask(), updatedTask)) {
            processorRegistry.applyAttributesProcessor(updatedTask, updatedTask.getAttributes());
        } else {
            updatedTask.setAttributes(taskAssignment.getTask().getAttributes());
        }
        taskPropertyChanges.add(new TaskInfoChangeProblemFactChange(taskAssignment, updatedTask));
    }
}
Also used : Task(org.kie.kogito.taskassigning.core.model.Task) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) User(org.kie.kogito.taskassigning.core.model.User) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) TaskInfoChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.TaskInfoChangeProblemFactChange)

Example 7 with AssignTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange 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 8 with AssignTaskProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilder method addNewTaskChanges.

private void addNewTaskChanges(TaskData taskData) {
    Task newTask;
    if (READY.value().equals(taskData.getState())) {
        newTask = fromTaskData(taskData);
        processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
        newTasksChanges.add(new AddTaskProblemFactChange(new TaskAssignment(newTask)));
        context.setTaskPublished(taskData.getId(), false);
    } else if (RESERVED.value().equals(taskData.getState())) {
        newTask = fromTaskData(taskData);
        processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
        User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
        AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(new TaskAssignment(newTask), user, true);
        context.setTaskPublished(taskData.getId(), true);
        addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
    }
}
Also used : 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) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)8 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)5 User (org.kie.kogito.taskassigning.core.model.User)4 Task (org.kie.kogito.taskassigning.core.model.Task)3 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)3 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)3 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)3 UserUtil.fromExternalUser (org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser)3 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)2 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)2 RemoveUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)2 UserPropertyChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)2 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TaskInfoChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.TaskInfoChangeProblemFactChange)1 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)1