private Map<SharingSetting, Set<User>> createUsersBySharingSettingMap(HttpServletRequest request, ProjectSharingSettings projectSharingSettings, MetaProject metaProject) {
Map<SharingSetting, Set<User>> usersBySharingSetting = createSharingSettingMap();
for (UserSharingSetting userSharingSetting : projectSharingSettings.getSharingSettings()) {
UserId userId = userSharingSetting.getUserId();
if (!userId.isGuest()) {
User user = getUserFromUserId(metaProject, userId);
if (user != null) {
usersBySharingSetting.get(userSharingSetting.getSharingSetting()).add(user);
}
else {
if(userId.getUserName().contains("@")) {
// Assume it's an email invitation
sendEmailInvitation(request, projectSharingSettings, userSharingSetting);
User freshUser = getUserFromUserId(metaProject, userId);
usersBySharingSetting.get(userSharingSetting.getSharingSetting()).add(freshUser);
}