/** {@inheritDoc} */ public void render( final Panel renderContainer, final ItemRenderer itemRenderer, final PagedSet<? extends Serializable> items, final String noItemsMessage) { Panel left = new FlowPanel(); left.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionColLeft()); left.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionCol()); Panel right = new FlowPanel(); right.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionColRight()); right.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionCol()); int count = 0; if (items.getTotal() == 0) { Label noItemsMessageLabel = new Label(noItemsMessage); noItemsMessageLabel.addStyleName( StaticResourceBundle.INSTANCE.coreCss().connectionItemEmpty()); renderContainer.add(noItemsMessageLabel); } else { renderContainer.add(left); renderContainer.add(right); } double halfwayPoint = items.getPagedSet().size() / 2.0; for (Serializable item : items.getPagedSet()) { if (count >= halfwayPoint) { right.add(itemRenderer.render(item)); } else { left.add(itemRenderer.render(item)); } count++; } }
/** 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()); }
/** * 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; }
/** * Test get followers. Dataset.xml has one follower for the group, so we should start with 1 and * then see 3. */ @Test public void testGetFollowers() { final int maxFollowers = 10; DomainGroup group = jpaGroupMapper.findByShortName("group1"); Person fordp2 = jpaPersonMapper.findByAccountId("fordp2"); Person csagan = jpaPersonMapper.findByAccountId("csagan"); PagedSet<Person> followers = jpaGroupMapper.getFollowers("group1", 0, maxFollowers); assertEquals(3, followers.getTotal()); jpaGroupMapper.addFollower(fordp2.getId(), group.getId()); jpaGroupMapper.addFollower(csagan.getId(), group.getId()); followers = jpaGroupMapper.getFollowers("group1", 0, maxFollowers); assertEquals(5, followers.getTotal()); }