use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilder method addUserChanges.
private void addUserChanges(final Map<String, User> usersById, final List<AddUserProblemFactChange> newUserChanges, final List<ProblemFactChange<TaskAssigningSolution>> updateUserChanges) {
final Set<String> updatedUserIds = new HashSet<>();
filterDuplicates(externalUserList).filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(UserUtil::fromExternalUser).forEach(user -> {
final User previousUser = usersById.get(user.getEntityId());
updatedUserIds.add(user.getEntityId());
if (previousUser == null) {
newUserChanges.add(new AddUserProblemFactChange(user));
} else if (!equalsByProperties(previousUser, user)) {
updateUserChanges.add(new UserPropertyChangeProblemFactChange(previousUser, true, user.getAttributes(), user.getAllLabelValues(), user.getGroups()));
}
});
usersById.values().stream().filter(user -> !IS_PLANNING_USER.test(user.getEntityId())).filter(user -> !updatedUserIds.contains(user.getEntityId())).filter(User::isEnabled).forEach(user -> updateUserChanges.add(new DisableUserProblemFactChange(user)));
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method addNewUserChange.
@Test
public void addNewUserChange() {
List<User> userList = mockUserList(mockUser(USER1_ID), mockUser(USER2_ID));
org.kie.server.services.taskassigning.user.system.api.User newExternalUser = mockExternalUser(USER3_ID);
org.kie.server.services.taskassigning.user.system.api.User newExternalUserRepeated1 = mockExternalUser(USER3_ID);
org.kie.server.services.taskassigning.user.system.api.User newExternalUserRepeated2 = mockExternalUser(USER3_ID);
List<org.kie.server.services.taskassigning.user.system.api.User> externalUserList = mockExternalUserList(newExternalUser, newExternalUserRepeated1, newExternalUserRepeated2);
TaskAssigningSolution solution = mockSolution(Collections.emptyList(), userList);
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(Collections.emptyList()).withUserSystem(userSystemService).withUsersUpdate(externalUserList).withContext(context).build();
AddUserProblemFactChange expected = new AddUserProblemFactChange(fromExternalUser(newExternalUser));
assertChangeIsTheChangeSetId(result, 0);
assertOneChange(result, 1, expected);
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange 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;
}
use of org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method assertOneChange.
private void assertOneChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, AddUserProblemFactChange expected) {
AddUserProblemFactChange change = (AddUserProblemFactChange) result.get(index);
assertUserEquals(expected.getUser(), change.getUser());
assertEquals(1, result.stream().filter(calculated -> calculated instanceof AddUserProblemFactChange).count());
}
Aggregations