コード例 #1
0
  /** Test getFollowing(). */
  @Test
  public void testGetFollowing() {
    final long followedGroupId = 1L;
    PagedSet<Followable> followedGroups = jpaGroupMapper.getFollowing("mrburns", 0, 9);
    assertEquals(1, followedGroups.getTotal());
    assertEquals(0, followedGroups.getFromIndex());
    assertEquals(0, followedGroups.getToIndex());

    List<Followable> groups = followedGroups.getPagedSet();
    assertEquals(1, groups.size());
    assertEquals(followedGroupId, groups.get(0).getId());
  }
コード例 #2
0
  /**
   * Returns Set of people following a user excluding themselves.
   *
   * @param inActionContext The action context.
   * @return true if the group exists and the user is authorized, false otherwise
   */
  @Override
  public PagedSet<FollowerStatusable> execute(final PrincipalActionContext inActionContext) {
    // get the request
    GetFollowersFollowingRequest inRequest =
        (GetFollowersFollowingRequest) inActionContext.getParams();

    // get the unique entity Id
    final String entityUniqueId = inRequest.getEntityId();

    final long currentUserId = inActionContext.getPrincipal().getId();

    Long entityId = getPersonIdByAccountIdMapper.execute(entityUniqueId);

    List<Long> allIds = idsMapper.execute(entityId);

    // determine the page
    int startIndex = (inRequest.getStartIndex()).intValue();
    int endIndex = (inRequest.getEndIndex()).intValue();

    PagedSet<FollowerStatusable> pagedSet;
    if (allIds.isEmpty()) {
      pagedSet = new PagedSet<FollowerStatusable>();
    } else if (startIndex >= allIds.size()) {
      // if asking for a range beyond the end of the list return an empty set
      pagedSet = new PagedSet<FollowerStatusable>();
      pagedSet.setTotal(allIds.size());
    } else {
      if (endIndex >= allIds.size()) {
        endIndex = allIds.size() - 1;
      }
      List<Long> pageIds = allIds.subList(startIndex, endIndex + 1);

      List<FollowerStatusable> list = bulkModelViewMapper.execute(pageIds);
      followerStatusPopulator.execute(currentUserId, list, FollowerStatus.NOTSPECIFIED);

      pagedSet = new PagedSet<FollowerStatusable>(startIndex, endIndex, allIds.size(), list);
    }

    if (log.isTraceEnabled()) {
      log.trace(
          "Retrieved "
              + pagedSet.getFromIndex()
              + " to "
              + pagedSet.getToIndex()
              + " of "
              + pagedSet.getTotal()
              + " following for person "
              + entityUniqueId);
    }

    return pagedSet;
  }