@Test public void testExecuteActivityIdsOnly() { final Long act1Id = 827L; final Long act2Id = 82337L; final List<ActivityDTO> activityList = new ArrayList<ActivityDTO>(); ActivityDTO a1 = new ActivityDTO(); ActivityDTO a2 = new ActivityDTO(); a1.setId(act1Id); a2.setId(act2Id); activityList.add(a1); activityList.add(a2); final ExecutionStrategyFake executionStrategy = new ExecutionStrategyFake(null); GetUserActivitiesExecution sut = new GetUserActivitiesExecution(bulkActivitiesMapper, getPeopleByOpenSocialIds, executionStrategy, maxActivitiesToReturnByOpenSocialId, securityTrimmer); final Principal principal = context.mock(Principal.class); final Long principalId = 1L; final PrincipalActionContext actionContext = context.mock(PrincipalActionContext.class); final GetUserActivitiesRequest request = context.mock(GetUserActivitiesRequest.class); final List<Long> activityIds = new ArrayList<Long>(); activityIds.add(act1Id); activityIds.add(act2Id); final Set<String> openSocialIds = new HashSet<String>(); context.checking(new Expectations() { { allowing(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(actionContext).getParams(); will(returnValue(request)); allowing(request).getActivityIds(); will(returnValue(activityIds)); allowing(request).getOpenSocialIds(); will(returnValue(openSocialIds)); oneOf(principal).getId(); will(returnValue(principalId)); oneOf(securityTrimmer).trim(activityIds, principalId); will(returnValue(activityIds)); oneOf(bulkActivitiesMapper).execute(with(any(List.class))); will(returnValue(activityList)); } }); List<ActivityDTO> results = sut.execute(actionContext); assertEquals(2, results.size()); assertTrue(results.contains(a1)); assertTrue(results.contains(a2)); assertEquals(null, executionStrategy.getContextPassedIn()); context.assertIsSatisfied(); }
@Override public LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetUserActivitiesRequest currentRequest = (GetUserActivitiesRequest) inActionContext.getParams(); LinkedList<ActivityDTO> currentActivityDTOs = new LinkedList<ActivityDTO>(); if (currentRequest.getOpenSocialIds() != null && currentRequest.getOpenSocialIds().size() > 0) { List<PersonModelView> users = getPeopleByOpenSocialIds.execute(new ArrayList<String>(currentRequest .getOpenSocialIds())); if (users.size() > 0) { final JSONObject json = new JSONObject(); json.put("count", maxActivitiesToReturnByOpenSocialId); JSONArray recipients = new JSONArray(); for (PersonModelView user : users) { JSONObject recipient = new JSONObject(); recipient.put("type", "PERSON"); recipient.put("name", user.getAccountId()); recipients.add(recipient); } JSONObject query = new JSONObject(); query.put("recipient", recipients); json.put("query", query); PrincipalActionContext context = new PrincipalActionContext() { @Override public Principal getPrincipal() { return inActionContext.getPrincipal(); } @Override public String getActionId() { return null; } @Override public Serializable getParams() { return json.toString(); } @Override public Map<String, Object> getState() { return null; } @Override public void setActionId(final String inActionId) { } }; PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) getActivitiesByRequestExecution .execute(context); currentActivityDTOs.addAll(activities.getPagedSet()); } } if (currentRequest.getActivityIds() != null && currentRequest.getActivityIds().size() > 0) { List<Long> activityIds = new ArrayList<Long>(currentRequest.getActivityIds()); for (ActivityDTO act : currentActivityDTOs) { if (activityIds.contains(act.getId())) { activityIds.remove(act.getId()); } } activityIds = securityTrimmer.trim(activityIds, inActionContext.getPrincipal().getId()); if (!activityIds.isEmpty()) { currentActivityDTOs.addAll(bulkActivitiesMapper.execute(activityIds)); } } return currentActivityDTOs; }
GetUserActivitiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetUserActivitiesRequest currentRequest = (GetUserActivitiesRequest) inActionContext.getParams(); LinkedList<ActivityDTO> currentActivityDTOs = new LinkedList<ActivityDTO>(); if (currentRequest.getOpenSocialIds() != null && currentRequest.getOpenSocialIds().size() > 0) { List<PersonModelView> users = getPeopleByOpenSocialIds.execute(new ArrayList<String>(currentRequest .getOpenSocialIds())); if (users.size() > 0) { final JSONObject json = new JSONObject(); json.put("count", maxActivitiesToReturnByOpenSocialId); JSONArray recipients = new JSONArray(); for (PersonModelView user : users) { JSONObject recipient = new JSONObject(); recipient.put("type", "PERSON"); recipient.put("name", user.getAccountId()); recipients.add(recipient); } JSONObject query = new JSONObject(); query.put("recipient", recipients); json.put("query", query); PrincipalActionContext context = new PrincipalActionContext() { @Override public Principal getPrincipal() { return inActionContext.getPrincipal(); } @Override public String getActionId() { return null; } @Override public Serializable getParams() { return json.toString(); } @Override public Map<String, Object> getState() { return null; } @Override public void setActionId(final String inActionId) { } }; PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) getActivitiesByRequestExecution .execute(context); currentActivityDTOs.addAll(activities.getPagedSet()); } } if (currentRequest.getActivityIds() != null && currentRequest.getActivityIds().size() > 0) { List<Long> activityIds = new ArrayList<Long>(currentRequest.getActivityIds()); for (ActivityDTO act : currentActivityDTOs) { if (activityIds.contains(act.getId())) { activityIds.remove(act.getId()); } } activityIds = securityTrimmer.trim(activityIds, inActionContext.getPrincipal().getId()); if (!activityIds.isEmpty()) { currentActivityDTOs.addAll(bulkActivitiesMapper.execute(activityIds)); } } return currentActivityDTOs; } }
GetUserActivitiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetUserActivitiesRequest currentRequest = (GetUserActivitiesRequest) inActionContext.getParams(); LinkedList<ActivityDTO> currentActivityDTOs = new LinkedList<ActivityDTO>(); if (currentRequest.getOpenSocialIds() != null && currentRequest.getOpenSocialIds().size() > 0) { List<PersonModelView> users = getPeopleByOpenSocialIds.execute(new ArrayList<String>(currentRequest .getOpenSocialIds())); if (users.size() > 0) { final JSONObject json = new JSONObject(); json.put("count", maxActivitiesToReturnByOpenSocialId); JSONArray recipients = new JSONArray(); for (PersonModelView user : users) { JSONObject recipient = new JSONObject(); recipient.put("type", "PERSON"); recipient.put("name", user.getAccountId()); recipients.add(recipient); } JSONObject query = new JSONObject(); query.put("recipient", recipients); json.put("query", query); PrincipalActionContext context = new PrincipalActionContext() { @Override public Principal getPrincipal() { return inActionContext.getPrincipal(); } @Override public String getActionId() { return null; } @Override public Serializable getParams() { return json.toString(); } @Override public Map<String, Object> getState() { return null; } @Override public void setActionId(final String inActionId) { } }; PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) getActivitiesByRequestExecution .execute(context); currentActivityDTOs.addAll(activities.getPagedSet()); } } if (currentRequest.getActivityIds() != null && currentRequest.getActivityIds().size() > 0) { List<Long> activityIds = new ArrayList<Long>(currentRequest.getActivityIds()); for (ActivityDTO act : currentActivityDTOs) { if (activityIds.contains(act.getId())) { activityIds.remove(act.getId()); } } activityIds = securityTrimmer.trim(activityIds, inActionContext.getPrincipal().getId()); if (!activityIds.isEmpty()) { currentActivityDTOs.addAll(bulkActivitiesMapper.execute(activityIds)); } } return currentActivityDTOs; } GetUserActivitiesExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIds,
            final ExecutionStrategy<PrincipalActionContext> inGetActivitiesByRequestExecution,
            final Long inMaxActivitiesToReturnByOpenSocialId, final ActivitySecurityTrimmer inSecurityTrimmer); }
GetUserActivitiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetUserActivitiesRequest currentRequest = (GetUserActivitiesRequest) inActionContext.getParams(); LinkedList<ActivityDTO> currentActivityDTOs = new LinkedList<ActivityDTO>(); if (currentRequest.getOpenSocialIds() != null && currentRequest.getOpenSocialIds().size() > 0) { List<PersonModelView> users = getPeopleByOpenSocialIds.execute(new ArrayList<String>(currentRequest .getOpenSocialIds())); if (users.size() > 0) { final JSONObject json = new JSONObject(); json.put("count", maxActivitiesToReturnByOpenSocialId); JSONArray recipients = new JSONArray(); for (PersonModelView user : users) { JSONObject recipient = new JSONObject(); recipient.put("type", "PERSON"); recipient.put("name", user.getAccountId()); recipients.add(recipient); } JSONObject query = new JSONObject(); query.put("recipient", recipients); json.put("query", query); PrincipalActionContext context = new PrincipalActionContext() { @Override public Principal getPrincipal() { return inActionContext.getPrincipal(); } @Override public String getActionId() { return null; } @Override public Serializable getParams() { return json.toString(); } @Override public Map<String, Object> getState() { return null; } @Override public void setActionId(final String inActionId) { } }; PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) getActivitiesByRequestExecution .execute(context); currentActivityDTOs.addAll(activities.getPagedSet()); } } if (currentRequest.getActivityIds() != null && currentRequest.getActivityIds().size() > 0) { List<Long> activityIds = new ArrayList<Long>(currentRequest.getActivityIds()); for (ActivityDTO act : currentActivityDTOs) { if (activityIds.contains(act.getId())) { activityIds.remove(act.getId()); } } activityIds = securityTrimmer.trim(activityIds, inActionContext.getPrincipal().getId()); if (!activityIds.isEmpty()) { currentActivityDTOs.addAll(bulkActivitiesMapper.execute(activityIds)); } } return currentActivityDTOs; } GetUserActivitiesExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIds,
            final ExecutionStrategy<PrincipalActionContext> inGetActivitiesByRequestExecution,
            final Long inMaxActivitiesToReturnByOpenSocialId, final ActivitySecurityTrimmer inSecurityTrimmer); @Override LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext); }
GetUserActivitiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext) throws ExecutionException { GetUserActivitiesRequest currentRequest = (GetUserActivitiesRequest) inActionContext.getParams(); LinkedList<ActivityDTO> currentActivityDTOs = new LinkedList<ActivityDTO>(); if (currentRequest.getOpenSocialIds() != null && currentRequest.getOpenSocialIds().size() > 0) { List<PersonModelView> users = getPeopleByOpenSocialIds.execute(new ArrayList<String>(currentRequest .getOpenSocialIds())); if (users.size() > 0) { final JSONObject json = new JSONObject(); json.put("count", maxActivitiesToReturnByOpenSocialId); JSONArray recipients = new JSONArray(); for (PersonModelView user : users) { JSONObject recipient = new JSONObject(); recipient.put("type", "PERSON"); recipient.put("name", user.getAccountId()); recipients.add(recipient); } JSONObject query = new JSONObject(); query.put("recipient", recipients); json.put("query", query); PrincipalActionContext context = new PrincipalActionContext() { @Override public Principal getPrincipal() { return inActionContext.getPrincipal(); } @Override public String getActionId() { return null; } @Override public Serializable getParams() { return json.toString(); } @Override public Map<String, Object> getState() { return null; } @Override public void setActionId(final String inActionId) { } }; PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) getActivitiesByRequestExecution .execute(context); currentActivityDTOs.addAll(activities.getPagedSet()); } } if (currentRequest.getActivityIds() != null && currentRequest.getActivityIds().size() > 0) { List<Long> activityIds = new ArrayList<Long>(currentRequest.getActivityIds()); for (ActivityDTO act : currentActivityDTOs) { if (activityIds.contains(act.getId())) { activityIds.remove(act.getId()); } } activityIds = securityTrimmer.trim(activityIds, inActionContext.getPrincipal().getId()); if (!activityIds.isEmpty()) { currentActivityDTOs.addAll(bulkActivitiesMapper.execute(activityIds)); } } return currentActivityDTOs; } GetUserActivitiesExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIds,
            final ExecutionStrategy<PrincipalActionContext> inGetActivitiesByRequestExecution,
            final Long inMaxActivitiesToReturnByOpenSocialId, final ActivitySecurityTrimmer inSecurityTrimmer); @Override LinkedList<ActivityDTO> execute(final PrincipalActionContext inActionContext);  }