コード例 #1
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Team newTeam = _persistence.create(pk);

    newTeam.setMvccVersion(RandomTestUtil.nextLong());

    newTeam.setCompanyId(RandomTestUtil.nextLong());

    newTeam.setUserId(RandomTestUtil.nextLong());

    newTeam.setUserName(RandomTestUtil.randomString());

    newTeam.setCreateDate(RandomTestUtil.nextDate());

    newTeam.setModifiedDate(RandomTestUtil.nextDate());

    newTeam.setGroupId(RandomTestUtil.nextLong());

    newTeam.setName(RandomTestUtil.randomString());

    newTeam.setDescription(RandomTestUtil.randomString());

    _teams.add(_persistence.update(newTeam));

    Team existingTeam = _persistence.findByPrimaryKey(newTeam.getPrimaryKey());

    Assert.assertEquals(existingTeam.getMvccVersion(), newTeam.getMvccVersion());
    Assert.assertEquals(existingTeam.getTeamId(), newTeam.getTeamId());
    Assert.assertEquals(existingTeam.getCompanyId(), newTeam.getCompanyId());
    Assert.assertEquals(existingTeam.getUserId(), newTeam.getUserId());
    Assert.assertEquals(existingTeam.getUserName(), newTeam.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingTeam.getCreateDate()),
        Time.getShortTimestamp(newTeam.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingTeam.getModifiedDate()),
        Time.getShortTimestamp(newTeam.getModifiedDate()));
    Assert.assertEquals(existingTeam.getGroupId(), newTeam.getGroupId());
    Assert.assertEquals(existingTeam.getName(), newTeam.getName());
    Assert.assertEquals(existingTeam.getDescription(), newTeam.getDescription());
  }
コード例 #2
0
  public long[] getTeamIds() throws SystemException {
    List<Team> teams = getTeams();

    long[] teamIds = new long[teams.size()];

    for (int i = 0; i < teams.size(); i++) {
      Team team = teams.get(i);

      teamIds[i] = team.getTeamId();
    }

    return teamIds;
  }
コード例 #3
0
  /**
   * Removes the user groups from the group.
   *
   * @param groupId the primary key of the group
   * @param userGroupIds the primary keys of the user groups
   */
  @Override
  public void unsetGroupUserGroups(long groupId, long[] userGroupIds) {
    List<Team> teams = teamPersistence.findByGroupId(groupId);

    for (Team team : teams) {
      teamPersistence.removeUserGroups(team.getTeamId(), userGroupIds);
    }

    userGroupGroupRoleLocalService.deleteUserGroupGroupRoles(userGroupIds, groupId);

    groupPersistence.removeUserGroups(groupId, userGroupIds);

    PermissionCacheUtil.clearCache();
  }
コード例 #4
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Team newTeam = addTeam();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Team.class, Team.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("teamId", newTeam.getTeamId()));

    List<Team> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Team existingTeam = result.get(0);

    Assert.assertEquals(existingTeam, newTeam);
  }
コード例 #5
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Team newTeam = addTeam();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Team.class, Team.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("teamId"));

    Object newTeamId = newTeam.getTeamId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("teamId", new Object[] {newTeamId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingTeamId = result.get(0);

    Assert.assertEquals(existingTeamId, newTeamId);
  }
コード例 #6
0
  public void importPermissions(String resourceName, long resourcePK, long newResourcePK)
      throws PortalException, SystemException {

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

      return;
    }

    List<KeyValuePair> permissions =
        _permissionsMap.get(getPrimaryKeyString(resourceName, resourcePK));

    if (permissions == null) {
      return;
    }

    Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>();

    for (KeyValuePair permission : permissions) {
      String roleName = permission.getKey();

      Role role = null;

      Team team = null;

      if (roleName.startsWith(PermissionExporter.ROLE_TEAM_PREFIX)) {
        roleName = roleName.substring(PermissionExporter.ROLE_TEAM_PREFIX.length());

        try {
          team = TeamLocalServiceUtil.getTeam(_groupId, roleName);
        } catch (NoSuchTeamException nste) {
          if (_log.isWarnEnabled()) {
            _log.warn("Team " + roleName + " does not exist");
          }

          continue;
        }
      }

      try {
        if (team != null) {
          role = RoleLocalServiceUtil.getTeamRole(_companyId, team.getTeamId());
        } else {
          role = RoleLocalServiceUtil.getRole(_companyId, roleName);
        }
      } catch (NoSuchRoleException nsre) {
        if (_log.isWarnEnabled()) {
          _log.warn("Role " + roleName + " does not exist");
        }

        continue;
      }

      String[] actionIds = StringUtil.split(permission.getValue());

      roleIdsToActionIds.put(role.getRoleId(), actionIds);
    }

    if (roleIdsToActionIds.isEmpty()) {
      return;
    }

    if (ResourceBlockLocalServiceUtil.isSupported(resourceName)) {
      ResourceBlockLocalServiceUtil.setIndividualScopePermissions(
          _companyId, _groupId, resourceName, newResourcePK, roleIdsToActionIds);
    } else {
      ResourcePermissionLocalServiceUtil.setResourcePermissions(
          _companyId,
          resourceName,
          ResourceConstants.SCOPE_INDIVIDUAL,
          String.valueOf(newResourcePK),
          roleIdsToActionIds);
    }
  }
コード例 #7
0
ファイル: Team.java プロジェクト: evliu/liferay-portal
 @Override
 public Long get(Team team) {
   return team.getTeamId();
 }
コード例 #8
0
  protected void doAddPermissionFields_6(
      long companyId, long groupId, String className, String classPK, Document doc)
      throws Exception {

    Group group = null;

    if (groupId > 0) {
      group = GroupLocalServiceUtil.getGroup(groupId);
    }

    List<Role> roles = ResourceActionsUtil.getRoles(companyId, group, className, null);

    if (groupId > 0) {
      List<Team> teams = TeamLocalServiceUtil.getGroupTeams(groupId);

      for (Team team : teams) {
        Role role = RoleLocalServiceUtil.getTeamRole(team.getCompanyId(), team.getTeamId());

        roles.add(role);
      }
    }

    long[] roleIdsArray = new long[roles.size()];

    for (int i = 0; i < roleIdsArray.length; i++) {
      Role role = roles.get(i);

      roleIdsArray[i] = role.getRoleId();
    }

    boolean[] hasResourcePermissions = null;

    if (ResourceBlockLocalServiceUtil.isSupported(className)) {
      ResourceBlockIdsBag resourceBlockIdsBag =
          ResourceBlockLocalServiceUtil.getResourceBlockIdsBag(
              companyId, groupId, className, roleIdsArray);

      long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW);

      List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId);

      hasResourcePermissions = new boolean[roleIdsArray.length];

      for (long resourceBlockId : resourceBlockIds) {
        for (int i = 0; i < roleIdsArray.length; i++) {
          int count =
              ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount(
                  resourceBlockId, roleIdsArray[i]);

          hasResourcePermissions[i] = (count > 0);
        }
      }
    } else {
      hasResourcePermissions =
          ResourcePermissionLocalServiceUtil.hasResourcePermissions(
              companyId,
              className,
              ResourceConstants.SCOPE_INDIVIDUAL,
              classPK,
              roleIdsArray,
              ActionKeys.VIEW);
    }

    List<Long> roleIds = new ArrayList<Long>();
    List<String> groupRoleIds = new ArrayList<String>();

    for (int i = 0; i < hasResourcePermissions.length; i++) {
      if (!hasResourcePermissions[i]) {
        continue;
      }

      Role role = roles.get(i);

      if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
          || (role.getType() == RoleConstants.TYPE_SITE)) {

        groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId());
      } else {
        roleIds.add(role.getRoleId());
      }
    }

    doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()]));
    doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()]));
  }