use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method addNewReadyTaskChange.
@Test
public void addNewReadyTaskChange() {
TaskData taskData = mockTaskData(TASK_ID, NAME, Ready, null);
List<TaskData> taskDataList = mockTaskDataList(taskData);
TaskAssigningSolution solution = mockSolution(Collections.emptyList(), Collections.emptyList());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(taskDataList).withUserSystem(userSystemService).withContext(context).build();
AddTaskProblemFactChange expected = new AddTaskProblemFactChange(fromTaskData(taskData));
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method assertChange.
private void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, AddTaskProblemFactChange expected) {
AddTaskProblemFactChange change = (AddTaskProblemFactChange) result.get(index);
assertTaskEquals(expected.getTask(), change.getTask());
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilder method addNewTaskChanges.
private void addNewTaskChanges(final TaskData taskData, final Map<String, User> usersById, final List<AddTaskProblemFactChange> newTaskChanges, final Map<String, List<IndexedElement<AssignTaskProblemFactChange>>> changesByUserId) {
Task newTask;
final Status taskDataStatus = convertFromString(taskData.getStatus());
switch(taskDataStatus) {
case Ready:
newTask = fromTaskData(taskData);
newTaskChanges.add(new AddTaskProblemFactChange(newTask));
break;
case Reserved:
case InProgress:
case Suspended:
if (taskData.getActualOwner() != null) {
newTask = fromTaskData(taskData);
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(newTask, user, true);
addChangeToUser(changesByUserId, change, user, -1, true);
}
break;
default:
// out of the refresh interval, so there's nothing to do with them.
break;
}
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange 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;
}
Aggregations