protected void convertResourcePermissions(String name, String tableName, String pkColumnName) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); ps = con.prepareStatement("select " + pkColumnName + ", companyId from " + tableName); rs = ps.executeQuery(); while (rs.next()) { long primKey = rs.getLong(pkColumnName); long companyId = rs.getLong("companyId"); ResourceBlock resourceBlock = convertResourcePermissions(companyId, name, primKey); if (_log.isInfoEnabled() && ((resourceBlock.getResourceBlockId() % 100) == 0)) { _log.info("Processed 100 resource blocks for " + name); } } } finally { DataAccess.cleanUp(con, ps, rs); } List<ResourcePermission> resourcePermissions = ResourcePermissionLocalServiceUtil.getScopeResourcePermissions(_SCOPES); for (ResourcePermission resourcePermission : resourcePermissions) { int scope = resourcePermission.getScope(); if (!name.equals(resourcePermission.getName())) { continue; } if ((scope == ResourceConstants.SCOPE_COMPANY) || (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE)) { ResourceBlockLocalServiceUtil.setCompanyScopePermissions( resourcePermission.getCompanyId(), name, resourcePermission.getRoleId(), resourcePermission.getActionIds()); } else if (scope == ResourceConstants.SCOPE_GROUP) { ResourceBlockLocalServiceUtil.setGroupScopePermissions( resourcePermission.getCompanyId(), GetterUtil.getLong(resourcePermission.getPrimaryKey()), name, resourcePermission.getRoleId(), resourcePermission.getActionIds()); } } }
@Test public void testUpdateExisting() throws Exception { long pk = ServiceTestUtil.nextLong(); ResourcePermission newResourcePermission = _persistence.create(pk); newResourcePermission.setCompanyId(ServiceTestUtil.nextLong()); newResourcePermission.setName(ServiceTestUtil.randomString()); newResourcePermission.setScope(ServiceTestUtil.nextInt()); newResourcePermission.setPrimKey(ServiceTestUtil.randomString()); newResourcePermission.setRoleId(ServiceTestUtil.nextLong()); newResourcePermission.setOwnerId(ServiceTestUtil.nextLong()); newResourcePermission.setActionIds(ServiceTestUtil.nextLong()); _persistence.update(newResourcePermission, false); ResourcePermission existingResourcePermission = _persistence.findByPrimaryKey(newResourcePermission.getPrimaryKey()); Assert.assertEquals( existingResourcePermission.getResourcePermissionId(), newResourcePermission.getResourcePermissionId()); Assert.assertEquals( existingResourcePermission.getCompanyId(), newResourcePermission.getCompanyId()); Assert.assertEquals(existingResourcePermission.getName(), newResourcePermission.getName()); Assert.assertEquals(existingResourcePermission.getScope(), newResourcePermission.getScope()); Assert.assertEquals( existingResourcePermission.getPrimKey(), newResourcePermission.getPrimKey()); Assert.assertEquals(existingResourcePermission.getRoleId(), newResourcePermission.getRoleId()); Assert.assertEquals( existingResourcePermission.getOwnerId(), newResourcePermission.getOwnerId()); Assert.assertEquals( existingResourcePermission.getActionIds(), newResourcePermission.getActionIds()); }
protected void deletePermissions_6(long companyId) throws Exception { Group group = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.CONTROL_PANEL); long plid = LayoutLocalServiceUtil.getDefaultPlid(group.getGroupId(), true); Role role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST); List<ResourcePermission> resourcePermissions = ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(role.getRoleId()); for (ResourcePermission resourcePermission : resourcePermissions) { if (isControlPanelLayout(plid, resourcePermission.getPrimKey()) || isPrivateLayout(resourcePermission.getName(), resourcePermission.getPrimKey())) { ResourcePermissionLocalServiceUtil.deleteResourcePermission( resourcePermission.getResourcePermissionId()); } } }