Class ResourceLocalServiceImpl

Object
com.liferay.portal.kernel.service.BaseLocalServiceImpl
com.liferay.portal.service.base.ResourceLocalServiceBaseImpl
com.liferay.portal.service.impl.ResourceLocalServiceImpl
All Implemented Interfaces:
com.liferay.portal.kernel.module.framework.service.IdentifiableOSGiService, com.liferay.portal.kernel.service.BaseLocalService, com.liferay.portal.kernel.service.ResourceLocalService

@Transactional(enabled=false) public class ResourceLocalServiceImpl extends ResourceLocalServiceBaseImpl
Provides the local service for accessing, adding, and updating resources.

Permissions in Liferay are defined for resource/action pairs. Some resources, known as portlet resources, define actions that the end-user can perform with respect to a portlet window. Other resources, known as model resources, define actions that the end-user can perform with respect to the service/persistence layer.

On creating an entity instance, you should create resources for it. The following example demonstrates adding resources for an instance of a model entity named SomeWidget. The IDs of the actions permitted for the group and guests are passed in from the service context.

 
 resourceLocalService.addModelResources(
                SomeWidget.getCompanyId(), SomeWidget.getGroupId(), userId,
                SomeWidget.class.getName(), SomeWidget.getPrimaryKey(),
                serviceContext.getGroupPermissions, serviceContext.getGuestPermissions);
 
 

Just prior to deleting an entity instance, you should delete its resource at the individual scope. The following example demonstrates deleting a resource associated with the SomeWidget model entity at the scope individual scope.

 
 resourceLocalService.deleteResource(
                SomeWidget.getCompanyId(), SomeWidget.class.getName(),
                ResourceConstants.SCOPE_INDIVIDUAL, SomeWidget.getPrimaryKey());
 
 

Author:
Brian Wing Shun Chan, Wilson S. Man, Raymond Augé, Julio Camarero, Connor McKay
  • Field Summary

    Fields inherited from class com.liferay.portal.service.base.ResourceLocalServiceBaseImpl

    counterLocalService, resourceLocalService
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addModelResources(long companyId, long groupId, long userId, String name, long primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions)
     
    void
    addModelResources(long companyId, long groupId, long userId, String name, long primKey, String[] groupPermissions, String[] guestPermissions)
    Adds resources for the model with the name and primary key, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
    void
    addModelResources(long companyId, long groupId, long userId, String name, String primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions)
     
    void
    addModelResources(long companyId, long groupId, long userId, String name, String primKey, String[] groupPermissions, String[] guestPermissions)
    Adds resources for the model with the name and primary key string, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
    void
    addModelResources(com.liferay.portal.kernel.model.AuditedModel auditedModel, com.liferay.portal.kernel.service.ServiceContext serviceContext)
    Adds resources for the model, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
    void
    addResources(long companyId, long groupId, long userId, String name, long primKey, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions)
    Adds resources for the entity with the name and primary key, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
    void
    addResources(long companyId, long groupId, long userId, String name, long primKey, boolean portletActions, com.liferay.portal.kernel.service.ServiceContext serviceContext)
     
    void
    addResources(long companyId, long groupId, long userId, String name, String[] primKeys, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions)
     
    void
    addResources(long companyId, long groupId, long userId, String name, String primKey, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions)
    Adds resources for the entity with the name and primary key string, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
    void
    addResources(long companyId, long groupId, String name, boolean portletActions)
    Adds resources for the entity with the name.
    void
    copyModelResources(long companyId, String name, long sourcePrimKey, long targetPrimKey)
     
    void
    deleteResource(long companyId, String name, int scope, long primKey)
    Deletes the resource matching the primary key at the scope.
    void
    deleteResource(long companyId, String name, int scope, String primKey)
    Deletes the resource matching the primary key at the scope.
    void
    deleteResource(com.liferay.portal.kernel.model.AuditedModel auditedModel, int scope)
    Deletes the resource associated with the model at the scope.
    com.liferay.portal.kernel.model.Resource
    getResource(long companyId, String name, int scope, String primKey)
    Returns a new resource with the name and primary key at the scope.
    boolean
    hasUserPermissions(long userId, long resourceId, List<com.liferay.portal.kernel.model.Resource> resources, String actionId, long[] roleIds)
    Returns true if the roles have permission to perform the action on the resources.
    void
    removeResource(long companyId, String name, int scope, String primKey, long roleId, String actionId)
     
    void
    updateModelResources(com.liferay.portal.kernel.model.AuditedModel auditedModel, com.liferay.portal.kernel.service.ServiceContext serviceContext)
    Updates the resources for the model, replacing their group and guest permissions with new ones from the service context.
    void
    updateResources(long companyId, long groupId, String name, long primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions)
    Updates resources matching the group, name, and primary key at the individual scope, setting new permissions.
    void
    updateResources(long companyId, long groupId, String name, long primKey, String[] groupPermissions, String[] guestPermissions)
    Updates resources matching the group, name, and primary key at the individual scope, setting new group and guest permissions.
    void
    updateResources(long companyId, long groupId, String name, String primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions)
    Updates resources matching the group, name, and primary key string at the individual scope, setting new permissions.
    void
    updateResources(long companyId, long groupId, String name, String primKey, String[] groupPermissions, String[] guestPermissions)
    Updates resources matching the group, name, and primary key string at the individual scope, setting new group and guest permissions.
    void
    updateResources(long companyId, String name, int scope, String primKey, String newPrimKey)
    Updates resources matching the name, primary key string and scope, replacing the primary key of their resource permissions with the new primary key.

    Methods inherited from class com.liferay.portal.kernel.service.BaseLocalServiceImpl

    getClassLoader, getLocalizationMap

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ResourceLocalServiceImpl

      public ResourceLocalServiceImpl()
  • Method Details

    • addModelResources

      public void addModelResources(com.liferay.portal.kernel.model.AuditedModel auditedModel, com.liferay.portal.kernel.service.ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the model, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
      1. If the service context specifies that default group or default guest permissions are to be added, then only default permissions are added. See ServiceContext.setAddGroupPermissions(boolean) and ServiceContext.setAddGuestPermissions(boolean).
      2. Else ...
        1. If the service context specifies to derive default permissions, then default group and guest permissions are derived from the model and added. See ServiceContext.setDeriveDefaultPermissions(boolean).
        2. Lastly group and guest permissions from the service context are applied. See ServiceContext#setGroupPermissions(String[]) and ServiceContext#setGuestPermissions(String[]).
      Parameters:
      auditedModel - the model to associate with the resources
      serviceContext - the service context to apply. Can set whether to add the model's default group and guest permissions, set whether to derive default group and guest permissions from the model, set group permissions to apply, and set guest permissions to apply.
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addModelResources

      public void addModelResources(long companyId, long groupId, long userId, String name, long primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addModelResources

      public void addModelResources(long companyId, long groupId, long userId, String name, long primKey, String[] groupPermissions, String[] guestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the model with the name and primary key, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      userId - the primary key of the user adding the resources
      name - a name for the resource, typically the model's class name
      primKey - the primary key of the model instance, optionally 0 if no instance exists
      groupPermissions - the group permissions to be applied
      guestPermissions - the guest permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addModelResources

      public void addModelResources(long companyId, long groupId, long userId, String name, String primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addModelResources

      public void addModelResources(long companyId, long groupId, long userId, String name, String primKey, String[] groupPermissions, String[] guestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the model with the name and primary key string, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      userId - the primary key of the user adding the resources
      name - a name for the resource, typically the model's class name
      primKey - the primary key string of the model instance, optionally an empty string if no instance exists
      groupPermissions - the group permissions to be applied
      guestPermissions - the guest permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addResources

      public void addResources(long companyId, long groupId, long userId, String name, long primKey, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the entity with the name and primary key, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      userId - the primary key of the user adding the resources
      name - a name for the resource, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key of the resource instance, optionally 0 if no instance exists
      portletActions - whether to associate portlet actions with the resource
      addGroupPermissions - whether to add group permissions
      addGuestPermissions - whether to add guest permissions
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addResources

      public void addResources(long companyId, long groupId, long userId, String name, long primKey, boolean portletActions, com.liferay.portal.kernel.service.ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addResources

      public void addResources(long companyId, long groupId, long userId, String name, String primKey, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the entity with the name and primary key string, always creating a resource at the individual scope and only creating resources at the group, group template, and company scope if such resources don't already exist.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      userId - the primary key of the user adding the resources
      name - a name for the resource, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key string of the resource instance, optionally an empty string if no instance exists
      portletActions - whether to associate portlet actions with the resource
      addGroupPermissions - whether to add group permissions
      addGuestPermissions - whether to add guest permissions
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addResources

      public void addResources(long companyId, long groupId, long userId, String name, String[] primKeys, boolean portletActions, boolean addGroupPermissions, boolean addGuestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • addResources

      public void addResources(long companyId, long groupId, String name, boolean portletActions) throws com.liferay.portal.kernel.exception.PortalException
      Adds resources for the entity with the name. Use this method if the user is unknown or irrelevant and there is no current entity instance.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      name - a name for the resource, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      portletActions - whether to associate portlet actions with the resource
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • copyModelResources

      public void copyModelResources(long companyId, String name, long sourcePrimKey, long targetPrimKey) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • deleteResource

      public void deleteResource(com.liferay.portal.kernel.model.AuditedModel auditedModel, int scope) throws com.liferay.portal.kernel.exception.PortalException
      Deletes the resource associated with the model at the scope.
      Parameters:
      auditedModel - the model associated with the resource
      scope - the scope of the resource. For more information see ResourceConstants.
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • deleteResource

      public void deleteResource(long companyId, String name, int scope, long primKey) throws com.liferay.portal.kernel.exception.PortalException
      Deletes the resource matching the primary key at the scope.
      Parameters:
      companyId - the primary key of the portal instance
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      scope - the scope of the resource. For more information see ResourceConstants.
      primKey - the primary key of the resource instance
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • deleteResource

      public void deleteResource(long companyId, String name, int scope, String primKey) throws com.liferay.portal.kernel.exception.PortalException
      Deletes the resource matching the primary key at the scope.
      Parameters:
      companyId - the primary key of the portal instance
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      scope - the scope of the resource. For more information see ResourceConstants.
      primKey - the primary key string of the resource instance
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • getResource

      public com.liferay.portal.kernel.model.Resource getResource(long companyId, String name, int scope, String primKey)
      Returns a new resource with the name and primary key at the scope.
      Parameters:
      companyId - the primary key of the portal instance
      name - a name for the resource, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      scope - the scope of the resource. For more information see ResourceConstants.
      primKey - the primary key string of the resource
      Returns:
      the new resource
    • hasUserPermissions

      public boolean hasUserPermissions(long userId, long resourceId, List<com.liferay.portal.kernel.model.Resource> resources, String actionId, long[] roleIds) throws com.liferay.portal.kernel.exception.PortalException
      Returns true if the roles have permission to perform the action on the resources.
      Parameters:
      userId - the primary key of the user performing the permission check
      resourceId - the primary key of the resource, typically the scope group ID representing the scope in which the permission check is being performed
      resources - the resources for which permissions are to be checked
      actionId - the primary key of the action to be performed on the resources
      roleIds - the primary keys of the roles
      Returns:
      true if the roles have permission to perform the action on the resources;false otherwise
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • removeResource

      public void removeResource(long companyId, String name, int scope, String primKey, long roleId, String actionId) throws com.liferay.portal.kernel.exception.PortalException
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateModelResources

      public void updateModelResources(com.liferay.portal.kernel.model.AuditedModel auditedModel, com.liferay.portal.kernel.service.ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException
      Updates the resources for the model, replacing their group and guest permissions with new ones from the service context.
      Parameters:
      auditedModel - the model associated with the resources
      serviceContext - the service context to be applied. Can set group and guest permissions.
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateResources

      public void updateResources(long companyId, long groupId, String name, long primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Updates resources matching the group, name, and primary key at the individual scope, setting new permissions.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key of the resource instance
      modelPermissions - the model permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateResources

      public void updateResources(long companyId, long groupId, String name, long primKey, String[] groupPermissions, String[] guestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Updates resources matching the group, name, and primary key at the individual scope, setting new group and guest permissions.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key of the resource instance
      groupPermissions - the group permissions to be applied
      guestPermissions - the guest permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateResources

      public void updateResources(long companyId, long groupId, String name, String primKey, com.liferay.portal.kernel.service.permission.ModelPermissions modelPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Updates resources matching the group, name, and primary key string at the individual scope, setting new permissions.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key string of the resource instance
      modelPermissions - the model permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateResources

      public void updateResources(long companyId, long groupId, String name, String primKey, String[] groupPermissions, String[] guestPermissions) throws com.liferay.portal.kernel.exception.PortalException
      Updates resources matching the group, name, and primary key string at the individual scope, setting new group and guest permissions.
      Parameters:
      companyId - the primary key of the portal instance
      groupId - the primary key of the group
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      primKey - the primary key string of the resource instance
      groupPermissions - the group permissions to be applied
      guestPermissions - the guest permissions to be applied
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • updateResources

      public void updateResources(long companyId, String name, int scope, String primKey, String newPrimKey)
      Updates resources matching the name, primary key string and scope, replacing the primary key of their resource permissions with the new primary key.
      Parameters:
      companyId - the primary key of the portal instance
      name - the resource's name, which should be a portlet ID if the resource is a portlet or the resource's class name otherwise
      scope - the scope of the resource. For more information see ResourceConstants.
      primKey - the primary key string of the resource instance
      newPrimKey - the new primary key string of the resource