How to programmatically add permissions for a role for a document folder?

Alla Sapozhnikova, modified 1 Year ago. Junior Member Posts: 82 Join Date: 3/2/12 Recent Posts

Hi there,

 

I have a folder in Liferay 7.4 document library, and I have to add a number of permissions for this folder to a certain role. 

I tried using different functions from ResourcePermissionLocalServiceUtil  for example: setResourcePermissions, addResourcePermission, updateResourcePermission. None of them work when my role does not have any permissions for the folder. All of them return an error : 

No ResourcePermission exists with the key {companyId=20096, name=com.liferay.document.library.kernel.model.DLFolder, scope=4, primKey=56877, roleId=20106}

even though Liferay documentation says.: "

updateResourcePermission(ResourcePermission resourcePermission)

Updates the resource permission in the database or adds it if it does not yet exist"

Any help is greatly appreciated.

Thank you.

Alla