@Test public final void testNoGroupFollowed() { final int startIndex = 0; final int endIndex = 9; final List empty = new ArrayList(); context.checking(new Expectations() { { oneOf(ac).getPrincipal(); will(returnValue(principal)); oneOf(principal).getId(); will(returnValue(currentUserId)); oneOf(ac).getParams(); will(returnValue(request)); oneOf(request).getAccountId(); will(returnValue(userAccountId)); oneOf(getPersonIdByAccountIdMapper).execute(userAccountId); will(returnValue(userId)); oneOf(personIdsUserIsFollowingMapper).execute(userId); will(returnValue(mvIds)); oneOf(personModelViewsMapper).execute(mvIds); will(returnValue(pmvList)); oneOf(groupIdsUserIsFollowingMapper).execute(userId); will(returnValue(empty)); oneOf(groupModelViewsMapper).execute(empty); will(returnValue(empty)); oneOf(followerStatusPopulator).execute(with(any(Long.class)), with(any(List.class)), with(any(FollowerStatus.class))); oneOf(request).getStartIndex(); will(returnValue(startIndex)); allowing(request).getEndIndex(); will(returnValue(endIndex)); } }); PagedSet<StreamDTO> pageResults = sut.execute(ac); List<StreamDTO> results = pageResults.getPagedSet(); assertEquals(3, pageResults.getTotal()); assertEquals(3, results.size()); assertEquals("a", results.get(0).getDisplayName()); assertEquals("c", results.get(1).getDisplayName()); assertEquals("e", results.get(2).getDisplayName()); context.assertIsSatisfied(); }
@Override public PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetStreamsUserIsFollowingRequest request = (GetStreamsUserIsFollowingRequest) inActionContext.getParams(); Long start = System.currentTimeMillis(); Long userId = getPersonIdByAccountIdMapper.execute(request.getAccountId()); log.debug("Lookup requested user id time: " + (System.currentTimeMillis() - start) + "(ms)."); Long currentUserId = inActionContext.getPrincipal().getId(); ArrayList<StreamDTO> results = new ArrayList<StreamDTO>(); PagedSet<StreamDTO> pagedResults = new PagedSet<StreamDTO>(); start = System.currentTimeMillis(); results.addAll(personModelViewsMapper.execute(personIdsUserIsFollowingMapper.execute(userId))); results.addAll(groupModelViewsMapper.execute(groupIdsUserIsFollowingMapper.execute(userId))); log.debug("Data retrieval time: " + (System.currentTimeMillis() - start) + "(ms)."); if (results.isEmpty()) { return pagedResults; } start = System.currentTimeMillis(); Collections.sort(results, STREAMDTO_DISPLAYNAME_COMPARATOR); log.debug("Data sort time:" + (System.currentTimeMillis() - start) + "(ms)."); int total = results.size(); int startIndex = request.getStartIndex(); int endIndex = request.getEndIndex() >= total ? total - 1 : request.getEndIndex(); ArrayList<StreamDTO> trimmedResults = new ArrayList<StreamDTO>(results.subList(startIndex, endIndex + 1)); start = System.currentTimeMillis(); followerStatusPopulator.execute(currentUserId, trimmedResults, FollowerStatus.NOTFOLLOWING); log.debug("Populate follower status time: " + (System.currentTimeMillis() - start) + "(ms)."); pagedResults.setFromIndex(startIndex); pagedResults.setToIndex(endIndex); pagedResults.setTotal(total); pagedResults.setPagedSet(trimmedResults); return pagedResults; }
GetStreamsUserIsFollowingExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetStreamsUserIsFollowingRequest request = (GetStreamsUserIsFollowingRequest) inActionContext.getParams(); Long start = System.currentTimeMillis(); Long userId = getPersonIdByAccountIdMapper.execute(request.getAccountId()); log.debug("Lookup requested user id time: " + (System.currentTimeMillis() - start) + "(ms)."); Long currentUserId = inActionContext.getPrincipal().getId(); ArrayList<StreamDTO> results = new ArrayList<StreamDTO>(); PagedSet<StreamDTO> pagedResults = new PagedSet<StreamDTO>(); start = System.currentTimeMillis(); results.addAll(personModelViewsMapper.execute(personIdsUserIsFollowingMapper.execute(userId))); results.addAll(groupModelViewsMapper.execute(groupIdsUserIsFollowingMapper.execute(userId))); log.debug("Data retrieval time: " + (System.currentTimeMillis() - start) + "(ms)."); if (results.isEmpty()) { return pagedResults; } start = System.currentTimeMillis(); Collections.sort(results, STREAMDTO_DISPLAYNAME_COMPARATOR); log.debug("Data sort time:" + (System.currentTimeMillis() - start) + "(ms)."); int total = results.size(); int startIndex = request.getStartIndex(); int endIndex = request.getEndIndex() >= total ? total - 1 : request.getEndIndex(); ArrayList<StreamDTO> trimmedResults = new ArrayList<StreamDTO>(results.subList(startIndex, endIndex + 1)); start = System.currentTimeMillis(); followerStatusPopulator.execute(currentUserId, trimmedResults, FollowerStatus.NOTFOLLOWING); log.debug("Populate follower status time: " + (System.currentTimeMillis() - start) + "(ms)."); pagedResults.setFromIndex(startIndex); pagedResults.setToIndex(endIndex); pagedResults.setTotal(total); pagedResults.setPagedSet(trimmedResults); return pagedResults; } }
GetStreamsUserIsFollowingExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetStreamsUserIsFollowingRequest request = (GetStreamsUserIsFollowingRequest) inActionContext.getParams(); Long start = System.currentTimeMillis(); Long userId = getPersonIdByAccountIdMapper.execute(request.getAccountId()); log.debug("Lookup requested user id time: " + (System.currentTimeMillis() - start) + "(ms)."); Long currentUserId = inActionContext.getPrincipal().getId(); ArrayList<StreamDTO> results = new ArrayList<StreamDTO>(); PagedSet<StreamDTO> pagedResults = new PagedSet<StreamDTO>(); start = System.currentTimeMillis(); results.addAll(personModelViewsMapper.execute(personIdsUserIsFollowingMapper.execute(userId))); results.addAll(groupModelViewsMapper.execute(groupIdsUserIsFollowingMapper.execute(userId))); log.debug("Data retrieval time: " + (System.currentTimeMillis() - start) + "(ms)."); if (results.isEmpty()) { return pagedResults; } start = System.currentTimeMillis(); Collections.sort(results, STREAMDTO_DISPLAYNAME_COMPARATOR); log.debug("Data sort time:" + (System.currentTimeMillis() - start) + "(ms)."); int total = results.size(); int startIndex = request.getStartIndex(); int endIndex = request.getEndIndex() >= total ? total - 1 : request.getEndIndex(); ArrayList<StreamDTO> trimmedResults = new ArrayList<StreamDTO>(results.subList(startIndex, endIndex + 1)); start = System.currentTimeMillis(); followerStatusPopulator.execute(currentUserId, trimmedResults, FollowerStatus.NOTFOLLOWING); log.debug("Populate follower status time: " + (System.currentTimeMillis() - start) + "(ms)."); pagedResults.setFromIndex(startIndex); pagedResults.setToIndex(endIndex); pagedResults.setTotal(total); pagedResults.setPagedSet(trimmedResults); return pagedResults; } GetStreamsUserIsFollowingExecution(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final DomainMapper<Long, List<Long>> inPersonIdsUserIsFollowingMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsUserIsFollowingMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inPersonModelViewsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGroupModelViewsMapper,
            final FollowerStatusPopulator<StreamDTO> inFollowerStatusPopulator); }
GetStreamsUserIsFollowingExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetStreamsUserIsFollowingRequest request = (GetStreamsUserIsFollowingRequest) inActionContext.getParams(); Long start = System.currentTimeMillis(); Long userId = getPersonIdByAccountIdMapper.execute(request.getAccountId()); log.debug("Lookup requested user id time: " + (System.currentTimeMillis() - start) + "(ms)."); Long currentUserId = inActionContext.getPrincipal().getId(); ArrayList<StreamDTO> results = new ArrayList<StreamDTO>(); PagedSet<StreamDTO> pagedResults = new PagedSet<StreamDTO>(); start = System.currentTimeMillis(); results.addAll(personModelViewsMapper.execute(personIdsUserIsFollowingMapper.execute(userId))); results.addAll(groupModelViewsMapper.execute(groupIdsUserIsFollowingMapper.execute(userId))); log.debug("Data retrieval time: " + (System.currentTimeMillis() - start) + "(ms)."); if (results.isEmpty()) { return pagedResults; } start = System.currentTimeMillis(); Collections.sort(results, STREAMDTO_DISPLAYNAME_COMPARATOR); log.debug("Data sort time:" + (System.currentTimeMillis() - start) + "(ms)."); int total = results.size(); int startIndex = request.getStartIndex(); int endIndex = request.getEndIndex() >= total ? total - 1 : request.getEndIndex(); ArrayList<StreamDTO> trimmedResults = new ArrayList<StreamDTO>(results.subList(startIndex, endIndex + 1)); start = System.currentTimeMillis(); followerStatusPopulator.execute(currentUserId, trimmedResults, FollowerStatus.NOTFOLLOWING); log.debug("Populate follower status time: " + (System.currentTimeMillis() - start) + "(ms)."); pagedResults.setFromIndex(startIndex); pagedResults.setToIndex(endIndex); pagedResults.setTotal(total); pagedResults.setPagedSet(trimmedResults); return pagedResults; } GetStreamsUserIsFollowingExecution(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final DomainMapper<Long, List<Long>> inPersonIdsUserIsFollowingMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsUserIsFollowingMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inPersonModelViewsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGroupModelViewsMapper,
            final FollowerStatusPopulator<StreamDTO> inFollowerStatusPopulator); @Override PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext); }
GetStreamsUserIsFollowingExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetStreamsUserIsFollowingRequest request = (GetStreamsUserIsFollowingRequest) inActionContext.getParams(); Long start = System.currentTimeMillis(); Long userId = getPersonIdByAccountIdMapper.execute(request.getAccountId()); log.debug("Lookup requested user id time: " + (System.currentTimeMillis() - start) + "(ms)."); Long currentUserId = inActionContext.getPrincipal().getId(); ArrayList<StreamDTO> results = new ArrayList<StreamDTO>(); PagedSet<StreamDTO> pagedResults = new PagedSet<StreamDTO>(); start = System.currentTimeMillis(); results.addAll(personModelViewsMapper.execute(personIdsUserIsFollowingMapper.execute(userId))); results.addAll(groupModelViewsMapper.execute(groupIdsUserIsFollowingMapper.execute(userId))); log.debug("Data retrieval time: " + (System.currentTimeMillis() - start) + "(ms)."); if (results.isEmpty()) { return pagedResults; } start = System.currentTimeMillis(); Collections.sort(results, STREAMDTO_DISPLAYNAME_COMPARATOR); log.debug("Data sort time:" + (System.currentTimeMillis() - start) + "(ms)."); int total = results.size(); int startIndex = request.getStartIndex(); int endIndex = request.getEndIndex() >= total ? total - 1 : request.getEndIndex(); ArrayList<StreamDTO> trimmedResults = new ArrayList<StreamDTO>(results.subList(startIndex, endIndex + 1)); start = System.currentTimeMillis(); followerStatusPopulator.execute(currentUserId, trimmedResults, FollowerStatus.NOTFOLLOWING); log.debug("Populate follower status time: " + (System.currentTimeMillis() - start) + "(ms)."); pagedResults.setFromIndex(startIndex); pagedResults.setToIndex(endIndex); pagedResults.setTotal(total); pagedResults.setPagedSet(trimmedResults); return pagedResults; } GetStreamsUserIsFollowingExecution(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final DomainMapper<Long, List<Long>> inPersonIdsUserIsFollowingMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsUserIsFollowingMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inPersonModelViewsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGroupModelViewsMapper,
            final FollowerStatusPopulator<StreamDTO> inFollowerStatusPopulator); @Override PagedSet<StreamDTO> execute(final PrincipalActionContext inActionContext); static final Comparator<StreamDTO> STREAMDTO_DISPLAYNAME_COMPARATOR; }