use of org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method assertChange.
private static void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, UserPropertyChangeProblemFactChange expected) {
assertThat(result.get(index)).isInstanceOf(UserPropertyChangeProblemFactChange.class);
UserPropertyChangeProblemFactChange change = (UserPropertyChangeProblemFactChange) result.get(index);
assertUserEquals(change.getUser(), expected.getUser());
assertThat(change.getNewAttributes()).isEqualTo(expected.getNewAttributes());
assertThat(change.getNewGroups()).isEqualTo(expected.getNewGroups());
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method addFullSyncUserChanges.
private void addFullSyncUserChanges(List<org.kie.kogito.taskassigning.user.service.User> externalUserList) {
final Set<String> updatedUserIds = new HashSet<>();
externalUserList.stream().filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(externalUser -> fromExternalUser(externalUser, processorRegistry)).forEach(synchedUser -> {
final User previousUser = usersById.get(synchedUser.getId());
updatedUserIds.add(synchedUser.getId());
if (previousUser == null) {
// add brand new users
newUserChanges.add(new AddUserProblemFactChange(synchedUser));
} else if (!equalsByProperties(previousUser, synchedUser)) {
// update the users that has changes.
updateUserChanges.add(new UserPropertyChangeProblemFactChange(previousUser, true, synchedUser.getAttributes(), synchedUser.getGroups()));
}
});
// current users not present in the synchronization data set are marked for disabling.
usersById.values().stream().filter(previousUser -> !IS_PLANNING_USER.test(previousUser.getId())).filter(previousUser -> !updatedUserIds.contains(previousUser.getId())).filter(User::isEnabled).forEach(previousUser -> updateUserChanges.add(new DisableUserProblemFactChange(previousUser)));
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addUpdateUserChange.
private void addUpdateUserChange(User user, org.kie.kogito.taskassigning.user.service.User updatedExternalUser) {
TaskAssigningSolution solution = mockSolution(Collections.singletonList(user), Collections.emptyList());
UserDataEvent event = new UserDataEvent(Collections.singletonList(updatedExternalUser), ZonedDateTime.now());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
Set<Group> expectedGroups = updatedExternalUser.getGroups().stream().map(externalGroup -> new Group(externalGroup.getId())).collect(Collectors.toSet());
UserPropertyChangeProblemFactChange expected = new UserPropertyChangeProblemFactChange(user, true, updatedExternalUser.getAttributes(), expectedGroups);
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertThatUserProcessorsWereApplied(updatedExternalUser);
}
Aggregations