/**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static ResourcePermission toModel(ResourcePermissionSoap soapModel) {
    ResourcePermission model = new ResourcePermissionImpl();

    model.setResourcePermissionId(soapModel.getResourcePermissionId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setName(soapModel.getName());
    model.setScope(soapModel.getScope());
    model.setPrimKey(soapModel.getPrimKey());
    model.setRoleId(soapModel.getRoleId());
    model.setOwnerId(soapModel.getOwnerId());
    model.setActionIds(soapModel.getActionIds());

    return model;
  }
  public static ResourcePermission addResourcePermission(
      long actionIds, String name, String primKey, long roleId, int scope) throws Exception {

    long resourcePermissionId =
        CounterLocalServiceUtil.increment(ResourcePermission.class.getName());

    ResourcePermission resourcePermission =
        ResourcePermissionLocalServiceUtil.createResourcePermission(resourcePermissionId);

    resourcePermission.setCompanyId(TestPropsValues.getCompanyId());
    resourcePermission.setName(name);
    resourcePermission.setScope(scope);
    resourcePermission.setPrimKey(primKey);
    resourcePermission.setRoleId(roleId);
    resourcePermission.setActionIds(actionIds);

    return ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
  }
  @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 ResourcePermission addResourcePermission() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    ResourcePermission resourcePermission = _persistence.create(pk);

    resourcePermission.setCompanyId(ServiceTestUtil.nextLong());

    resourcePermission.setName(ServiceTestUtil.randomString());

    resourcePermission.setScope(ServiceTestUtil.nextInt());

    resourcePermission.setPrimKey(ServiceTestUtil.randomString());

    resourcePermission.setRoleId(ServiceTestUtil.nextLong());

    resourcePermission.setOwnerId(ServiceTestUtil.nextLong());

    resourcePermission.setActionIds(ServiceTestUtil.nextLong());

    _persistence.update(resourcePermission, false);

    return resourcePermission;
  }
예제 #5
0
  protected void fixOrganizationRolePermissions() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(ResourcePermission.class);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("name", Organization.class.getName()));

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (ResourcePermission resourcePermission : resourcePermissions) {
      ResourcePermission groupResourcePermission = null;

      try {
        groupResourcePermission =
            ResourcePermissionLocalServiceUtil.getResourcePermission(
                resourcePermission.getCompanyId(),
                Group.class.getName(),
                resourcePermission.getScope(),
                resourcePermission.getPrimKey(),
                resourcePermission.getRoleId());
      } catch (Exception e) {
        ResourcePermissionLocalServiceUtil.setResourcePermissions(
            resourcePermission.getCompanyId(),
            Group.class.getName(),
            resourcePermission.getScope(),
            resourcePermission.getPrimKey(),
            resourcePermission.getRoleId(),
            ResourcePermissionLocalServiceImpl.EMPTY_ACTION_IDS);

        groupResourcePermission =
            ResourcePermissionLocalServiceUtil.getResourcePermission(
                resourcePermission.getCompanyId(),
                Group.class.getName(),
                resourcePermission.getScope(),
                resourcePermission.getPrimKey(),
                resourcePermission.getRoleId());
      }

      long organizationActions = resourcePermission.getActionIds();
      long groupActions = groupResourcePermission.getActionIds();

      for (Object[] actionIdToMask : _ORGANIZATION_ACTION_IDS_TO_MASKS) {
        long organizationActionMask = (Long) actionIdToMask[1];
        long groupActionMask = (Long) actionIdToMask[2];

        if ((organizationActions & organizationActionMask) == organizationActionMask) {

          organizationActions = organizationActions & (~organizationActionMask);
          groupActions = groupActions | groupActionMask;
        }
      }

      try {
        resourcePermission.resetOriginalValues();

        resourcePermission.setActionIds(organizationActions);

        ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);

        groupResourcePermission.resetOriginalValues();
        groupResourcePermission.setActionIds(groupActions);

        ResourcePermissionLocalServiceUtil.updateResourcePermission(groupResourcePermission);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    PermissionCacheUtil.clearCache();
  }