@Override public void rename(String newUserGroupName, UserGroup userGroup) { try { String description = liferayAutomation.autoRenameDescription(userGroup.getName(), newUserGroupName); userGroup.setName(newUserGroupName); userGroup.setDescription(userGroup.getDescription() + description); userGroupLocalService.updateUserGroup(userGroup); } catch (Exception e) { String msg = String.format("Failed to rename UserGroup from [%s] to [%s]", userGroup.getName(), newUserGroupName); log(msg, e); throw new RuntimeException(msg, e); } }
@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); } }
public static List<String[]> getUserGroupsWithNames(String user) { if (debug) { log("getting user groups with names " + user); } if (user == null || user.isEmpty()) { if (debug) { log("returning empty groups"); } return Collections.EMPTY_LIST; } ArrayList<String[]> result = new ArrayList<String[]>(); try { List<UserGroup> groups = UserGroupLocalServiceUtil.getUserUserGroups(Long.valueOf(user,10)); for(UserGroup g: groups) { result.add(new String[] {g.getName(),g.getDescription()}); } } catch (Exception ex) { throw new RuntimeException(ex); } if (debug) { log("returning groups with names " + result); } return result; }
private static void setGroupRoles(UserData ud, User user) { try { for (UserGroup userGroup : user.getUserGroups()) { List<Role> roles = RoleLocalServiceUtil.getGroupRoles(userGroup.getGroup().getGroupId()); for (Role role : roles) { ud.addRoleName(role.getName()); } } } catch (Exception e) { throw new LiferayBridgeException(e); } }
private static void setGroupRoles(UserDataBean ud, User user) { try { for (UserGroup userGroup : user.getUserGroups()) { List<Role> roles = RoleLocalServiceUtil.getGroupRoles(userGroup.getGroup().getGroupId()); for (Role role : roles) { ud.addRole(role.getName()); } } } catch (Exception e) { throw new UserSourceException(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); } }
private List<UserGroup> internalOnlyGroups(List<UserGroup> allUserGroups) { List<UserGroup> result = new ArrayList<UserGroup>(); for (UserGroup group : allUserGroups) { if (group.getName().endsWith(POSTFIX_INTERNAL_ONLY)) { result.add(group); } } return result; }
@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; }
private List<UserGroup> externallySithsOnlyGroups(List<UserGroup> allUserGroups) { List<UserGroup> result = new ArrayList<UserGroup>(); for (UserGroup group : allUserGroups) { if (group.getName().endsWith(POSTFIX_EXTERNALLY_SITHS_ONLY)) { result.add(group); } } return result; }
@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); } } }
public static String[] getUserGroups(String userId) { if (debug) { log("getting user groups " + userId); } if (userId == null || userId.isEmpty()) { if (debug) { log("returning empty user groups"); } return new String[0]; } ArrayList<String> result = new ArrayList<String>(); try { List<UserGroup> groups = UserGroupLocalServiceUtil.getUserUserGroups(Long.valueOf(userId,10)); for(UserGroup g: groups) { result.add(g.getName()); } } catch (Exception ex) { Logger.getLogger(SecurityHelper.class.getName()).log(Level.SEVERE, null, ex); } if (debug) { log("returning user groups " + result); } return result.toArray(new String[0]); }
@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); } } }
userGroupNames.add(userGroup.getName());
userGroupNames.add(userGroup.getName());