Exemplo n.º 1
0
  public void editRoleAssignments(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    Role role = RoleLocalServiceUtil.getRole(roleId);

    if (role.getName().equals(RoleConstants.OWNER)) {
      throw new RoleAssignmentException(role.getName());
    }

    long[] addUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "addUserIds"), 0L);
    long[] removeUserIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "removeUserIds"), 0L);

    if (!ArrayUtil.isEmpty(addUserIds) || !ArrayUtil.isEmpty(removeUserIds)) {

      UserServiceUtil.addRoleUsers(roleId, addUserIds);
      UserServiceUtil.unsetRoleUsers(roleId, removeUserIds);
    }

    long[] addGroupIds = StringUtil.split(ParamUtil.getString(actionRequest, "addGroupIds"), 0L);
    long[] removeGroupIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "removeGroupIds"), 0L);

    if (!ArrayUtil.isEmpty(addGroupIds) || !ArrayUtil.isEmpty(removeGroupIds)) {

      GroupServiceUtil.addRoleGroups(roleId, addGroupIds);
      GroupServiceUtil.unsetRoleGroups(roleId, removeGroupIds);
    }
  }
  public static void unsetRoleGroups(long roleId, long[] groupIds) throws RemoteException {
    try {
      GroupServiceUtil.unsetRoleGroups(roleId, groupIds);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }