@Override public void moveUsers(UserGroup fromGroup, UserGroup toGroup) { try { List<User> users = userLocalService.getUserGroupUsers(fromGroup.getUserGroupId()); long[] userIds = toIdArray(users.toArray(new User[]{})); userLocalService.addUserGroupUsers(toGroup.getUserGroupId(), userIds); userLocalService.unsetUserGroupUsers(fromGroup.getUserGroupId(), userIds); } catch (Exception e) { String msg = String.format("Failed to users from [%s] to [%s]", fromGroup.getName(), toGroup.getName()); log(msg, e); throw new RuntimeException(msg, e); } }
@Override public void delete(UserGroup userGroup) { try { List<User> users = userLocalService.getUserGroupUsers(userGroup.getUserGroupId()); long[] userIds = toIdArray(users.toArray(new User[]{})); userLocalService.unsetUserGroupUsers(userGroup.getUserGroupId(), userIds); userGroupLocalService.deleteUserGroup(userGroup); } catch (Exception e) { String msg = String.format("Failed to delete UserGroup [%s]", userGroup.getName()); log(msg, e); throw new RuntimeException(msg, e); } }
@Override public boolean isMember(UserGroup userGroup, User user) { try { return userLocalService.hasUserGroupUser(userGroup.getUserGroupId(), user.getUserId()); } catch (Exception e) { String msg = String.format("Failed to lookup if user belongs to group [%s, %s]", user.getScreenName(), userGroup.getName()); log(msg, e); } return false; }
@Override public void addUser(UserGroup userGroup, User... users) { if (isInvalid(users)) return; if (userGroup != null) { try { userLocalService.addUserGroupUsers(userGroup.getUserGroupId(), toIdArray(users)); } catch (Exception e) { String msg = String.format("Failed to add users [%s] to UserGroup [%s]", toScreenNames(users), userGroup.getName()); log(msg, e); } } }
@Override public void removeUser(UserGroup userGroup, User... users) { if (isInvalid(users)) return; if (userGroup != null) { try { userLocalService.unsetUserGroupUsers(userGroup.getUserGroupId(), toIdArray(users)); } catch (Exception e) { String msg = String.format("Failed to remove users [%s] from UserGroup [%s]", toScreenNames(users), userGroup.getName()); log(msg, e); } } }