<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay 7.2, programmatically add new ResourcePermission for DLFolder</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121370626" />
  <subtitle>Liferay 7.2, programmatically add new ResourcePermission for DLFolder</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121370626</id>
  <updated>2026-04-06T11:49:38Z</updated>
  <dc:date>2026-04-06T11:49:38Z</dc:date>
  <entry>
    <title>Liferay 7.2, programmatically add new ResourcePermission for DLFolder</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121370625" />
    <author>
      <name>Steve Weiss</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121370625</id>
    <updated>2022-03-02T16:15:02Z</updated>
    <published>2022-03-02T16:09:03Z</published>
    <summary type="html">&lt;p&gt;We have a requirement to allow a user to propagate folder permissions
  in the document library. I have it partly working but I'm running into
  a problem that I don't understand. From what understand, each
  ResourcePermission is associated with a role. I can propagate
  permissions for some roles (e.g., Site Member) but not others, for
  example &amp;quot;Site Content Reviewer&amp;quot;. Basically my code checks
  the roles for child folder permissions to look for the matching roles
  in the parent. If a parent ResourcePermission is for a role that
  doesn't match any child role, the code attempts to add a new
  ResourcePermission for that child role and child folder. This is the code:&lt;/p&gt;
&lt;p&gt;                        // Create a new resource permission&lt;br /&gt;    
                      ResourcePermission newResPerm = null;&lt;br /&gt;      
                    long respermId =
  CounterLocalServiceUtil.increment();&lt;br /&gt;                        
  newResPerm =
  ResourcePermissionLocalServiceUtil.createResourcePermission(respermId);&lt;br /&gt;
                          respermId =
  newResPerm.getResourcePermissionId();&lt;br /&gt;                        
  _log.info(ID + &amp;quot;New ResourcePermission, ID = &amp;quot; +
  newResPerm.getResourcePermissionId());&lt;br /&gt;                        
  _log.info(ID + &amp;quot;Folder ID = &amp;quot; + childFolderId);&lt;/p&gt;
&lt;p&gt;                        newResPerm.setScope(scope);&lt;br /&gt;            
              newResPerm.setCompanyId(companyId);&lt;br /&gt;                
          newResPerm.setName(resourceName);&lt;br /&gt;                      
    newResPerm.setRoleId(roleId);&lt;br /&gt;                         newResPerm.setPrimaryKey(childFolderId);&lt;/p&gt;
&lt;p&gt;                        for (ResourceAction action : actions) {&lt;br /&gt;
                              String actionId =
  action.getActionId();&lt;br /&gt;                             try {&lt;br /&gt;  
                               
  newResPerm.addResourceAction(actionId);&lt;br /&gt;                        
      } catch (PortalException e) {&lt;br /&gt;                              
    e.printStackTrace();&lt;br /&gt;                             }&lt;br /&gt;      
                    }&lt;/p&gt;
&lt;p&gt;                        try {&lt;br /&gt;                            
  ResourcePermission rp = ResourcePermissionLocalServiceUtil&lt;br /&gt;      
                               
  .updateResourcePermission(newResPerm);&lt;br /&gt;                          
    _log.info(ID + &amp;quot;New ResourcePermission, ID = &amp;quot; +
  rp.getResourcePermissionId());&lt;br /&gt;                         } catch
  (Exception ex) {&lt;br /&gt;                            
  //ex.printStackTrace();&lt;br /&gt;                            
  _log.error(ex.getMessage());&lt;br /&gt;                         }&lt;br /&gt;  &lt;/p&gt;
&lt;p&gt;And this is the error I get:&lt;/p&gt;
&lt;p&gt;2022-03-02 15:41:46.164 ERROR
  [http-nio-8080-exec-6][JDBCExceptionReporter:234] ORA-00001: unique
  constraint (LIFERAY72_10_4.SYS_C0038538) violated_ [Sanitized]&lt;br /&gt;
  2022-03-02 15:41:46.164 ERROR
  [http-nio-8080-exec-6][JDBCExceptionReporter:234] ORA-00001: unique
  constraint (LIFERAY72_10_4.SYS_C0038538) violated_ [Sanitized]&lt;br /&gt;
  2022-03-02 15:41:46.168 ERROR
  [http-nio-8080-exec-6][CustomEditFolderMVCActionCommand:326] Could not
  execute JDBC batch update; SQL [insert into ResourcePermission
  (mvccVersion, companyId, name, scope, primKey, primKeyId, roleId,
  ownerId, actionIds, viewActionId, resourcePermissionId) values (?, ?,
  ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [LIFERAY72_10_4.SYS_C0038538];
  nested exception is
  org.hibernate.exception.ConstraintViolationException: Could not
  execute JDBC batch update&lt;br /&gt;  &lt;/p&gt;
&lt;p&gt;There is no corresponding record in the ResourcePermission table, and
  additionally, I'm calling update (which is supposed to update if the
  record exists and add if it doesn't).&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;If however, I manually add just one permission (say, VIEW) to a role
  that previously had no permissions associated with the child folder,
  and THEN propagate permissions from parent, all the parent permissions
  are propagated to that child folder.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Steve Weiss</dc:creator>
    <dc:date>2022-03-02T16:09:03Z</dc:date>
  </entry>
</feed>
