@Test public final void performActionDateSortWithKeywordTest() throws Exception { final String request = "{ query : { sortBy:\"date\", keywords:\"test\"} }"; final PersonModelView personModel = new PersonModelView(); context.checking(new Expectations() { { ActivityDTO dto = new ActivityDTO(); dto.setId(3); dto.setPostedTime(new Date()); dto.setIsDestinationStreamPublic(true); ArrayList<Long> combinedIds = new ArrayList<Long>(); combinedIds.add(2L); ArrayList<ActivityDTO> activities = new ArrayList<ActivityDTO>(); activities.add(dto); allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getAccountId(); will(returnValue(personAccountId)); allowing(principal).getId(); will(returnValue(personId)); allowing(actionContext).getParams(); will(returnValue(request)); oneOf(getActivityIdsByJsonRequest).execute( with("{\"count\":11,\"query\":{\"keywords\":\"test\",\"sortBy\":\"date\"}}"), with(personId)); will(returnValue(combinedIds)); oneOf(bulkMapper).execute(with(any(ArrayList.class))); will(returnValue(activities)); allowing(filterMock).filter(with(activities), with(any(PersonModelView.class))); oneOf(getPersonModelViewByAccountIdMapper).execute(personAccountId); will(returnValue(personModel)); } }); PagedSet<ActivityDTO> results = (PagedSet<ActivityDTO>) sut.execute(actionContext); context.assertIsSatisfied(); assertEquals(1, results.getPagedSet().size()); }
public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { log.debug("Attempted to parse: " + inActionContext.getParams()); final JSONObject request = JSONObject.fromObject(inActionContext.getParams()); final JSONObject query = request.getJSONObject("query"); if (!request.containsKey("count")) { request.put("count", MAXRESULTS); } final int currentMax = request.getInt("count"); if (!query.containsKey("sortBy") || query.getString("sortBy").equals("date")) { request.put("count", currentMax + 1); } final Long userEntityId = inActionContext.getPrincipal().getId(); final String userAccountId = inActionContext.getPrincipal().getAccountId(); final List<Long> results = getActivityIdsByJsonRequest.execute(request.toString(), userEntityId); PagedSet<ActivityDTO> pagedSet = new PagedSet<ActivityDTO>(); pagedSet.setTotal(results.size()); if (log.isTraceEnabled()) { log.trace(results.size() + " Items found."); } if (results.size() > currentMax) { if (log.isTraceEnabled()) { log.trace("Removing extra item"); } results.remove(currentMax); } final List<ActivityDTO> dtoResults = bulkActivitiesMapper.execute(results); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(userAccountId); for (ActivityFilter filter : filters) { filter.filter(dtoResults, person); } if (log.isTraceEnabled()) { log.trace("Returning " + results.size() + " activities."); } pagedSet.setPagedSet(dtoResults); return pagedSet; }
GetActivitiesByRequestExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { log.debug("Attempted to parse: " + inActionContext.getParams()); final JSONObject request = JSONObject.fromObject(inActionContext.getParams()); final JSONObject query = request.getJSONObject("query"); if (!request.containsKey("count")) { request.put("count", MAXRESULTS); } final int currentMax = request.getInt("count"); if (!query.containsKey("sortBy") || query.getString("sortBy").equals("date")) { request.put("count", currentMax + 1); } final Long userEntityId = inActionContext.getPrincipal().getId(); final String userAccountId = inActionContext.getPrincipal().getAccountId(); final List<Long> results = getActivityIdsByJsonRequest.execute(request.toString(), userEntityId); PagedSet<ActivityDTO> pagedSet = new PagedSet<ActivityDTO>(); pagedSet.setTotal(results.size()); if (log.isTraceEnabled()) { log.trace(results.size() + " Items found."); } if (results.size() > currentMax) { if (log.isTraceEnabled()) { log.trace("Removing extra item"); } results.remove(currentMax); } final List<ActivityDTO> dtoResults = bulkActivitiesMapper.execute(results); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(userAccountId); for (ActivityFilter filter : filters) { filter.filter(dtoResults, person); } if (log.isTraceEnabled()) { log.trace("Returning " + results.size() + " activities."); } pagedSet.setPagedSet(dtoResults); return pagedSet; } }
GetActivitiesByRequestExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { log.debug("Attempted to parse: " + inActionContext.getParams()); final JSONObject request = JSONObject.fromObject(inActionContext.getParams()); final JSONObject query = request.getJSONObject("query"); if (!request.containsKey("count")) { request.put("count", MAXRESULTS); } final int currentMax = request.getInt("count"); if (!query.containsKey("sortBy") || query.getString("sortBy").equals("date")) { request.put("count", currentMax + 1); } final Long userEntityId = inActionContext.getPrincipal().getId(); final String userAccountId = inActionContext.getPrincipal().getAccountId(); final List<Long> results = getActivityIdsByJsonRequest.execute(request.toString(), userEntityId); PagedSet<ActivityDTO> pagedSet = new PagedSet<ActivityDTO>(); pagedSet.setTotal(results.size()); if (log.isTraceEnabled()) { log.trace(results.size() + " Items found."); } if (results.size() > currentMax) { if (log.isTraceEnabled()) { log.trace("Removing extra item"); } results.remove(currentMax); } final List<ActivityDTO> dtoResults = bulkActivitiesMapper.execute(results); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(userAccountId); for (ActivityFilter filter : filters) { filter.filter(dtoResults, person); } if (log.isTraceEnabled()) { log.trace("Returning " + results.size() + " activities."); } pagedSet.setPagedSet(dtoResults); return pagedSet; } GetActivitiesByRequestExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final List<ActivityFilter> inFilters,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final GetActivityIdsByJson inGetActivityIdsByJsonRequest); }
GetActivitiesByRequestExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { log.debug("Attempted to parse: " + inActionContext.getParams()); final JSONObject request = JSONObject.fromObject(inActionContext.getParams()); final JSONObject query = request.getJSONObject("query"); if (!request.containsKey("count")) { request.put("count", MAXRESULTS); } final int currentMax = request.getInt("count"); if (!query.containsKey("sortBy") || query.getString("sortBy").equals("date")) { request.put("count", currentMax + 1); } final Long userEntityId = inActionContext.getPrincipal().getId(); final String userAccountId = inActionContext.getPrincipal().getAccountId(); final List<Long> results = getActivityIdsByJsonRequest.execute(request.toString(), userEntityId); PagedSet<ActivityDTO> pagedSet = new PagedSet<ActivityDTO>(); pagedSet.setTotal(results.size()); if (log.isTraceEnabled()) { log.trace(results.size() + " Items found."); } if (results.size() > currentMax) { if (log.isTraceEnabled()) { log.trace("Removing extra item"); } results.remove(currentMax); } final List<ActivityDTO> dtoResults = bulkActivitiesMapper.execute(results); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(userAccountId); for (ActivityFilter filter : filters) { filter.filter(dtoResults, person); } if (log.isTraceEnabled()) { log.trace("Returning " + results.size() + " activities."); } pagedSet.setPagedSet(dtoResults); return pagedSet; } GetActivitiesByRequestExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final List<ActivityFilter> inFilters,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final GetActivityIdsByJson inGetActivityIdsByJsonRequest); Serializable execute(final PrincipalActionContext inActionContext); }
GetActivitiesByRequestExecution implements ExecutionStrategy<PrincipalActionContext> { public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { log.debug("Attempted to parse: " + inActionContext.getParams()); final JSONObject request = JSONObject.fromObject(inActionContext.getParams()); final JSONObject query = request.getJSONObject("query"); if (!request.containsKey("count")) { request.put("count", MAXRESULTS); } final int currentMax = request.getInt("count"); if (!query.containsKey("sortBy") || query.getString("sortBy").equals("date")) { request.put("count", currentMax + 1); } final Long userEntityId = inActionContext.getPrincipal().getId(); final String userAccountId = inActionContext.getPrincipal().getAccountId(); final List<Long> results = getActivityIdsByJsonRequest.execute(request.toString(), userEntityId); PagedSet<ActivityDTO> pagedSet = new PagedSet<ActivityDTO>(); pagedSet.setTotal(results.size()); if (log.isTraceEnabled()) { log.trace(results.size() + " Items found."); } if (results.size() > currentMax) { if (log.isTraceEnabled()) { log.trace("Removing extra item"); } results.remove(currentMax); } final List<ActivityDTO> dtoResults = bulkActivitiesMapper.execute(results); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(userAccountId); for (ActivityFilter filter : filters) { filter.filter(dtoResults, person); } if (log.isTraceEnabled()) { log.trace("Returning " + results.size() + " activities."); } pagedSet.setPagedSet(dtoResults); return pagedSet; } GetActivitiesByRequestExecution(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final List<ActivityFilter> inFilters,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final GetActivityIdsByJson inGetActivityIdsByJsonRequest); Serializable execute(final PrincipalActionContext inActionContext);  }