Search in sources :

Example 1 with TaskPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolverHandlerTest method onUpdateSolutionSolverNotStarted.

@Test
public void onUpdateSolutionSolverNotStarted() {
    prepareStart();
    List<ProblemFactChange<TaskAssigningSolution>> changes = new ArrayList<>();
    changes.add(new TaskPropertyChangeProblemFactChange(new Task()));
    SolutionSynchronizer.Result result = SolutionSynchronizer.Result.forChanges(changes);
    doReturn(false).when(solverExecutor).isStarted();
    synchronizerConsumerCaptor.getValue().accept(result);
    verify(solverExecutor, never()).addProblemFactChanges(changes);
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) ArrayList(java.util.ArrayList) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) Test(org.junit.Test)

Example 2 with TaskPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilder method addTaskChanges.

private void addTaskChanges(final Task task, final TaskData taskData, final Map<String, User> usersById, final List<ReleaseTaskProblemFactChange> releasedTasksChanges, final Set<Task> removedTasksSet, final List<TaskPropertyChangeProblemFactChange> propertyChanges, final Map<String, List<IndexedElement<AssignTaskProblemFactChange>>> changesByUserId) {
    final Status taskDataStatus = convertFromString(taskData.getStatus());
    switch(taskDataStatus) {
        case Ready:
            if (!convertToString(Status.Ready).equals(task.getStatus())) {
                // task was probably assigned to someone else in the past and released from the task
                // list administration
                releasedTasksChanges.add(new ReleaseTaskProblemFactChange(task));
            }
            break;
        case Reserved:
        case InProgress:
        case Suspended:
            if (taskData.getActualOwner() == null) {
                // Task was necessary in Ready status prior going into Suspension. Remove it from solution
                // and let it be added again if it comes into Ready or Reserved status in a later moment.
                removedTasksSet.add(task);
            } else if (!taskData.getActualOwner().equals(task.getUser().getEntityId())) {
                // if Reserved:
                // the task was probably manually re-assigned from the task list to another user.
                // We must respect this assignment.
                // if InProgress:
                // the task was probably re-assigned to another user from the task list prior to start.
                // We must correct this assignment so it's reflected in the plan and also respect it.
                // if Suspended:
                // the task was assigned to someone else from the task list prior to the suspension,
                // we must reflect that change in the plan.
                final User user = getUser(usersById, taskData.getActualOwner());
                // assign and ensure the task is published since the task was already seen by the public audience.
                AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(task, user, true);
                addChangeToUser(changesByUserId, change, user, -1, true);
            } else if ((taskData.getPlanningTask() == null || taskData.getPlanningTask().getPublished()) && !task.isPinned()) {
                // The task was published and not yet pinned
                final User user = getUser(usersById, taskData.getActualOwner());
                AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(task, user, true);
                int index = taskData.getPlanningTask() != null ? taskData.getPlanningTask().getIndex() : -1;
                addChangeToUser(changesByUserId, change, user, index, true);
            }
            break;
        case Completed:
        case Exited:
        case Failed:
        case Error:
        case Obsolete:
            removedTasksSet.add(task);
            break;
        default:
            // sonar required. No other cases exist.
            break;
    }
    if (!removedTasksSet.contains(task) && (taskData.getPriority() != task.getPriority() || !taskData.getStatus().equals(task.getStatus()))) {
        TaskPropertyChangeProblemFactChange propertyChange = new TaskPropertyChangeProblemFactChange(task);
        if (taskData.getPriority() != task.getPriority()) {
            propertyChange.setPriority(taskData.getPriority());
        }
        if (!taskData.getStatus().equals(task.getStatus())) {
            propertyChange.setStatus(taskData.getStatus());
        }
        propertyChanges.add(propertyChange);
    }
}
Also used : Status(org.kie.api.task.model.Status) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) User(org.kie.server.services.taskassigning.core.model.User) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)

Example 3 with TaskPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilder method build.

public List<ProblemFactChange<TaskAssigningSolution>> build() {
    final Map<Long, Task> taskById = solution.getTaskList().stream().filter(IS_NOT_DUMMY).collect(Collectors.toMap(Task::getId, Function.identity()));
    final Map<String, User> usersById = solution.getUserList().stream().collect(Collectors.toMap(User::getEntityId, Function.identity()));
    final List<AddTaskProblemFactChange> newTaskChanges = new ArrayList<>();
    final List<ReleaseTaskProblemFactChange> releasedTasksChanges = new ArrayList<>();
    final List<RemoveTaskProblemFactChange> removedTaskChanges = new ArrayList<>();
    final Set<Task> removedTasksSet = new HashSet<>();
    final List<TaskPropertyChangeProblemFactChange> propertyChanges = new ArrayList<>();
    final Map<String, List<IndexedElement<AssignTaskProblemFactChange>>> changesByUserId = new HashMap<>();
    final List<AddUserProblemFactChange> newUserChanges = new ArrayList<>();
    final List<ProblemFactChange<TaskAssigningSolution>> userUpdateChanges = new ArrayList<>();
    final List<RemoveUserProblemFactChange> removableUserChanges = new ArrayList<>();
    final List<TaskData> filteredTaskDataList = taskDataList.stream().filter(taskData -> !context.isProcessedTaskChange(taskData.getTaskId(), taskData.getLastModificationDate())).collect(Collectors.toList());
    Task task;
    for (TaskData taskData : filteredTaskDataList) {
        task = taskById.remove(taskData.getTaskId());
        if (task == null) {
            addNewTaskChanges(taskData, usersById, newTaskChanges, changesByUserId);
        } else {
            addTaskChanges(task, taskData, usersById, releasedTasksChanges, removedTasksSet, propertyChanges, changesByUserId);
        }
    }
    for (Task removedTask : removedTasksSet) {
        removedTaskChanges.add(new RemoveTaskProblemFactChange(removedTask));
    }
    if (executeUsersUpdate) {
        addUserChanges(usersById, newUserChanges, userUpdateChanges);
    } else {
        addRemovableUserChanges(changesByUserId, removableUserChanges);
    }
    List<ProblemFactChange<TaskAssigningSolution>> totalChanges = new ArrayList<>();
    totalChanges.addAll(newUserChanges);
    totalChanges.addAll(removedTaskChanges);
    totalChanges.addAll(releasedTasksChanges);
    changesByUserId.values().forEach(byUserChanges -> byUserChanges.forEach(change -> totalChanges.add(change.getElement())));
    totalChanges.addAll(propertyChanges);
    totalChanges.addAll(userUpdateChanges);
    totalChanges.addAll(newTaskChanges);
    totalChanges.addAll(removableUserChanges);
    if (LOGGER.isTraceEnabled()) {
        if (!totalChanges.isEmpty()) {
            traceProgrammedChanges(LOGGER, removedTaskChanges, releasedTasksChanges, changesByUserId, propertyChanges, newTaskChanges, newUserChanges, userUpdateChanges, removableUserChanges);
        } else {
            LOGGER.trace("No changes has been calculated.");
        }
    }
    applyWorkaroundForPLANNER241(solution, totalChanges);
    if (!totalChanges.isEmpty()) {
        totalChanges.add(0, scoreDirector -> context.setCurrentChangeSetId(context.nextChangeSetId()));
    }
    filteredTaskDataList.forEach(taskData -> context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()));
    return totalChanges;
}
Also used : IndexedElement.addInOrder(org.kie.server.services.taskassigning.planning.util.IndexedElement.addInOrder) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) DUMMY_TASK_PLANNER_241(org.kie.server.services.taskassigning.core.model.ModelConstants.DUMMY_TASK_PLANNER_241) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PLANNING_USER(org.kie.server.services.taskassigning.core.model.ModelConstants.PLANNING_USER) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TaskData(org.kie.server.api.model.taskassigning.TaskData) HashSet(java.util.HashSet) User(org.kie.server.services.taskassigning.core.model.User) Map(java.util.Map) UserUtil.filterDuplicates(org.kie.server.services.taskassigning.planning.util.UserUtil.filterDuplicates) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) Task(org.kie.server.services.taskassigning.core.model.Task) TaskHelper.hasPinnedTasks(org.kie.server.services.taskassigning.core.model.solver.TaskHelper.hasPinnedTasks) TaskUtil.fromTaskData(org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData) Logger(org.slf4j.Logger) IS_PLANNING_USER(org.kie.server.services.taskassigning.core.model.ModelConstants.IS_PLANNING_USER) UserSystemService(org.kie.server.services.taskassigning.user.system.api.UserSystemService) Set(java.util.Set) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) Collectors(java.util.stream.Collectors) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) Objects(java.util.Objects) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) TraceHelper.traceProgrammedChanges(org.kie.server.services.taskassigning.planning.TraceHelper.traceProgrammedChanges) List(java.util.List) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) IS_NOT_DUMMY(org.kie.server.services.taskassigning.core.model.ModelConstants.IS_NOT_DUMMY) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) IndexedElement(org.kie.server.services.taskassigning.planning.util.IndexedElement) UserUtil(org.kie.server.services.taskassigning.planning.util.UserUtil) Status(org.kie.api.task.model.Status) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) TaskData(org.kie.server.api.model.taskassigning.TaskData) TaskUtil.fromTaskData(org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)

Example 4 with TaskPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilderTest method addStatusAndPriorityPropertyChange.

@Test
public void addStatusAndPriorityPropertyChange() {
    TaskData taskData = mockTaskData(TASK_ID, NAME, Reserved, ACTUAL_OWNER_ENTITY_ID);
    User actualOwner = mockUser(ACTUAL_OWNER_ENTITY_ID);
    Task task = fromTaskData(taskData);
    task.setUser(actualOwner);
    task.setPinned(true);
    task.setStatus(convertToString(InProgress));
    task.setPriority(taskData.getPriority() + 1);
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(task), Collections.singletonList(actualOwner));
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(mockTaskDataList(taskData)).withUserSystem(userSystemService).withContext(context).build();
    TaskPropertyChangeProblemFactChange change = new TaskPropertyChangeProblemFactChange(task);
    change.setStatus(taskData.getStatus());
    change.setPriority(taskData.getPriority());
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, new TaskPropertyChangeProblemFactChange(task));
    assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) User(org.kie.server.services.taskassigning.core.model.User) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) TaskData(org.kie.server.api.model.taskassigning.TaskData) TaskUtil.fromTaskData(org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData) Test(org.junit.Test)

Example 5 with TaskPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilderTest method assertChange.

private void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, TaskPropertyChangeProblemFactChange expected) {
    TaskPropertyChangeProblemFactChange change = (TaskPropertyChangeProblemFactChange) result.get(index);
    assertTaskEquals(expected.getTask(), change.getTask());
    if (expected.getStatus() != null) {
        assertEquals(expected.getStatus(), change.getStatus());
    }
    if (expected.getPriority() != null) {
        assertEquals(expected.getPriority(), change.getPriority(), 0);
    }
}
Also used : TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)

Aggregations

TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)6 Task (org.kie.server.services.taskassigning.core.model.Task)4 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)3 User (org.kie.server.services.taskassigning.core.model.User)3 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)3 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)3 UserUtil.fromExternalUser (org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser)3 Status (org.kie.api.task.model.Status)2 TaskData (org.kie.server.api.model.taskassigning.TaskData)2 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)2 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)2 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)2 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)2 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)2 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)2 TaskUtil.fromTaskData (org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)2 LocalDateTime (java.time.LocalDateTime)1