Class RoleServiceImpl

Object
com.liferay.portal.kernel.service.BaseServiceImpl
com.liferay.portal.service.base.RoleServiceBaseImpl
com.liferay.portal.service.impl.RoleServiceImpl
All Implemented Interfaces:
com.liferay.portal.kernel.module.framework.service.IdentifiableOSGiService, com.liferay.portal.kernel.service.BaseService, com.liferay.portal.kernel.service.RoleService

public class RoleServiceImpl extends RoleServiceBaseImpl
Provides the remote service for accessing, adding, unassigning, checking, deleting, and updating roles. Its methods include permission checks.
Author:
Brian Wing Shun Chan
  • Constructor Details

    • RoleServiceImpl

      public RoleServiceImpl()
  • Method Details

    • addRole

      public com.liferay.portal.kernel.model.Role addRole(String externalReferenceCode, String className, long classPK, String name, Map<Locale,String> titleMap, Map<Locale,String> descriptionMap, int type, String subtype, com.liferay.portal.kernel.service.ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addUserRoles

      public void addUserRoles(long userId, long[] roleIds) throws com.liferay.portal.kernel.exception.PortalException
      Adds the roles to the user. The user is reindexed after the roles are added.
      Parameters:
      userId - the primary key of the user
      roleIds - the primary keys of the roles
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • deleteRole

      public void deleteRole(long roleId) throws com.liferay.portal.kernel.exception.PortalException
      Deletes the role with the primary key and its associated permissions.
      Parameters:
      roleId - the primary key of the role
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • fetchRole

      public com.liferay.portal.kernel.model.Role fetchRole(long roleId) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • fetchRole

      public com.liferay.portal.kernel.model.Role fetchRole(long companyId, String name) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • fetchRoleByExternalReferenceCode

      public com.liferay.portal.kernel.model.Role fetchRoleByExternalReferenceCode(String externalReferenceCode, long companyId) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getGroupRoles

      public List<com.liferay.portal.kernel.model.Role> getGroupRoles(long groupId) throws com.liferay.portal.kernel.exception.PortalException
      Returns all the roles associated with the group.
      Parameters:
      groupId - the primary key of the group
      Returns:
      the roles associated with the group
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getGroupRolesAndTeamRoles

      public List<com.liferay.portal.kernel.model.Role> getGroupRolesAndTeamRoles(long companyId, String name, List<String> excludedNames, String title, String description, int[] types, long excludedTeamRoleId, long teamGroupId, int start, int end)
    • getGroupRolesAndTeamRolesCount

      public int getGroupRolesAndTeamRolesCount(long companyId, String name, List<String> excludedNames, String title, String description, int[] types, long excludedTeamRoleId, long teamGroupId)
    • getRole

      public com.liferay.portal.kernel.model.Role getRole(long roleId) throws com.liferay.portal.kernel.exception.PortalException
      Returns the role with the primary key.
      Parameters:
      roleId - the primary key of the role
      Returns:
      the role with the primary key
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getRole

      public com.liferay.portal.kernel.model.Role getRole(long companyId, String name) throws com.liferay.portal.kernel.exception.PortalException
      Returns the role with the name in the company.

      The method searches the system roles map first for default roles. If a role with the name is not found, then the method will query the database.

      Parameters:
      companyId - the primary key of the company
      name - the role's name
      Returns:
      the role with the name
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getRoleByExternalReferenceCode

      public com.liferay.portal.kernel.model.Role getRoleByExternalReferenceCode(String externalReferenceCode, long companyId) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getRoles

      public List<com.liferay.portal.kernel.model.Role> getRoles(int type, String subtype) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getRoles

      public List<com.liferay.portal.kernel.model.Role> getRoles(long companyId, int[] types) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getUserGroupGroupRoles

      public List<com.liferay.portal.kernel.model.Role> getUserGroupGroupRoles(long userId, long groupId) throws com.liferay.portal.kernel.exception.PortalException
      Returns all the user's roles within the user group.
      Parameters:
      userId - the primary key of the user
      groupId - the primary key of the group
      Returns:
      the user's roles within the user group
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getUserGroupRoles

      public List<com.liferay.portal.kernel.model.Role> getUserGroupRoles(long userId, long groupId) throws com.liferay.portal.kernel.exception.PortalException
      Returns all the user's roles within the user group.
      Parameters:
      userId - the primary key of the user
      groupId - the primary key of the group
      Returns:
      the user's roles within the user group
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getUserRelatedRoles

      public List<com.liferay.portal.kernel.model.Role> getUserRelatedRoles(long userId, List<com.liferay.portal.kernel.model.Group> groups) throws com.liferay.portal.kernel.exception.PortalException
      Returns the union of all the user's roles within the groups. If no groups are provided, only the user's directly assigned roles are returned.
      Parameters:
      userId - the primary key of the user
      groups - the groups (optionally null)
      Returns:
      the union of all the user's roles within the groups
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getUserRoles

      public List<com.liferay.portal.kernel.model.Role> getUserRoles(long userId) throws com.liferay.portal.kernel.exception.PortalException
      Returns all the roles associated with the user.
      Parameters:
      userId - the primary key of the user
      Returns:
      the roles associated with the user
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • hasUserRole

      public boolean hasUserRole(long userId, long companyId, String name, boolean inherited) throws com.liferay.portal.kernel.exception.PortalException
      Returns true if the user is associated with the named regular role.
      Parameters:
      userId - the primary key of the user
      companyId - the primary key of the company
      name - the name of the role
      inherited - whether to include the user's inherited roles in the search
      Returns:
      true if the user is associated with the regular role; false otherwise
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • hasUserRoles

      public boolean hasUserRoles(long userId, long companyId, String[] names, boolean inherited) throws com.liferay.portal.kernel.exception.PortalException
      Returns true if the user has any one of the named regular roles.
      Parameters:
      userId - the primary key of the user
      companyId - the primary key of the company
      names - the names of the roles
      inherited - whether to include the user's inherited roles in the search
      Returns:
      true if the user has any one of the regular roles; false otherwise
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • search

      public List<com.liferay.portal.kernel.model.Role> search(long companyId, String keywords, Integer[] types, LinkedHashMap<String,Object> params, int start, int end, com.liferay.portal.kernel.util.OrderByComparator<com.liferay.portal.kernel.model.Role> orderByComparator)
    • searchCount

      public int searchCount(long companyId, String keywords, Integer[] types, LinkedHashMap<String,Object> params)
    • unsetUserRoles

      public void unsetUserRoles(long userId, long[] roleIds) throws com.liferay.portal.kernel.exception.PortalException
      Removes the matching roles associated with the user. The user is reindexed after the roles are removed.
      Parameters:
      userId - the primary key of the user
      roleIds - the primary keys of the roles
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateExternalReferenceCode

      public com.liferay.portal.kernel.model.Role updateExternalReferenceCode(long roleId, String externalReferenceCode) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateExternalReferenceCode

      public com.liferay.portal.kernel.model.Role updateExternalReferenceCode(com.liferay.portal.kernel.model.Role role, String externalReferenceCode) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateRole

      public com.liferay.portal.kernel.model.Role updateRole(long roleId, String name, Map<Locale,String> titleMap, Map<Locale,String> descriptionMap, String subtype, com.liferay.portal.kernel.service.ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException
      Updates the role with the primary key.
      Parameters:
      roleId - the primary key of the role
      name - the role's new name
      titleMap - the new localized titles (optionally null) to replace those existing for the role
      descriptionMap - the new localized descriptions (optionally null) to replace those existing for the role
      subtype - the role's new subtype (optionally null)
      serviceContext - the service context to be applied (optionally null). Can set the expando bridge attributes for the role.
      Returns:
      the role with the primary key
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • checkUserRolesPermission

      protected void checkUserRolesPermission(long userId, long[] roleIds) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • filterRoles

      protected List<com.liferay.portal.kernel.model.Role> filterRoles(List<com.liferay.portal.kernel.model.Role> roles) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException