RestfulCollection<?> collection = (RestfulCollection<?>) response; if (collection.getTotalResults() != collection.getList().size()) { map.put("startIndex", collection.getStartIndex()); map.put("itemsPerPage", collection.getItemsPerPage()); map.put("totalResults", collection.getTotalResults()); map.put("filtered", collection.isFiltered()); map.put("updatedSince", collection.isUpdatedSince()); map.put("sorted", collection.isSorted()); map.put("list", collection.getList()); addResult(result, map); } else {
@Test public void testConstructors() throws Exception { List<String> entry = Lists.newArrayList("banana", "who"); RestfulCollection<String> collection = new RestfulCollection<String>(entry); assertEquals(entry, collection.getList()); assertEquals(0, collection.getStartIndex()); assertEquals(entry.size(), collection.getTotalResults()); assertEquals(entry.size(), collection.getItemsPerPage()); int startIndex = 9; int totalResults = 10; int resultsPerPage = 1; collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.getList()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); assertEquals(resultsPerPage, collection.getItemsPerPage()); }
RestfulCollection<?> collection = (RestfulCollection<?>) response; if (collection.getTotalResults() != collection.getEntry().size()) { map.put("startIndex", collection.getStartIndex()); map.put("itemsPerPage", collection.getItemsPerPage()); map.put("totalResults", collection.getTotalResults()); if (!collection.isFiltered()) map.put("filtered", collection.isFiltered()); if (!collection.isUpdatedSince()) map.put("updatedSince", collection.isUpdatedSince()); if (!collection.isSorted()) map.put("sorted", collection.isUpdatedSince()); map.put("list", collection.getEntry()); addResult(result, map); } else {
@Override public T apply(RestfulCollection<T> c) { if (c != null && c.getTotalResults() > 0) { return c.getList().get(0); } return null; }; };
private T getFirstFromCollection(RestfulCollection<T> collection) { if (collection.getTotalResults() > 0) { return collection.getEntry().get(0); } return null; } };
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setList(entryList); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entryList, collection.getList()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
RestfulCollection<?> r = (RestfulCollection<?>) obj; entry = Lists.newArrayList(); List<?> entryList = r.getEntry(); for (Object o : entryList) { entry.add(new AtomEntry(o)); startIndex = r.getStartIndex(); totalResults = r.getTotalResults(); itemsPerPage = r.getItemsPerPage(); author = "?"; link = new AtomLink("rel", "???");
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entry = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setEntry(entry); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
/** {@inheritDoc} */ public Future<RestfulCollection<Group>> getGroups(UserId userId, CollectionOptions options, Set<String> fields, SecurityToken token) throws ProtocolException { List<Group> result = Lists.newArrayList(); String user = userId.getUserId(token); try { JSONArray groups = db.getJSONObject(GROUPS_TABLE).getJSONArray(user); for (int i = 0; i < groups.length(); i++) { JSONObject group = groups.getJSONObject(i); Group groupObj = filterFields(group, fields, Group.class); result.add(groupObj); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(new RestfulCollection<Group>(result)); }
RestfulCollection<?> r = (RestfulCollection<?>) obj; entry = Lists.newArrayList(); List<?> entryList = r.getList(); for (Object o : entryList) { entry.add(new AtomEntry(o)); startIndex = r.getStartIndex(); totalResults = r.getTotalResults(); itemsPerPage = r.getItemsPerPage(); author = (r.get(AUTHOR)==null) ? "?" : r.get(AUTHOR).toString(); title = (r.get(TITLE)==null) ? "?" : r.get(TITLE).toString(); id = (r.get(ID)==null) ? "?" : r.get(ID).toString(); updated = (r.get(UPDATED)==null) ? "" : r.get(UPDATED).toString(); if (r.get(URL)!=null) { link = new AtomLink("self", r.get(URL).toString());
@Test public void getJohnDoeActivities() throws Exception { Future<RestfulCollection<Activity>> result = this.activityServiceDb.getActivities(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), null, ACTIVITY_ALL_FIELDS, new CollectionOptions(), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); RestfulCollection<Activity> activityCollection = result.get(); assertEquals(1, activityCollection.getTotalResults()); assertEquals(0, activityCollection.getStartIndex()); SpiTestUtil.assertActivityEquals(activityCollection.getEntry().get(0), testActivity); }
@Test public void testGetExpectedActivities() throws Exception { RestfulCollection<Activity> responseItem = db.getActivities( ImmutableSet.of(CANON_USER), SELF_GROUP, APP_ID, Collections.<String>emptySet(), null, new FakeGadgetToken()).get(); assertSame(2, responseItem.getTotalResults()); }
@Test public void getJohnDoeFriendsActivities() throws Exception { Future<RestfulCollection<Activity>> result = this.activityServiceDb.getActivities(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.friends, "@friends"), null, ACTIVITY_ALL_FIELDS, new CollectionOptions(), SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN); RestfulCollection<Activity> activityCollection = result.get(); assertEquals(2, activityCollection.getTotalResults()); assertEquals(0, activityCollection.getStartIndex()); }
@Test public void testMapMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; String anyItem = "anyvalue"; collection.put("list", entryList); collection.put("startIndex", startIndex); collection.put("totalResults", totalResults); collection.put("anyItem",anyItem); assertEquals(entryList, collection.get("list")); assertEquals(startIndex, collection.get("startIndex")); assertEquals(totalResults, collection.get("totalResults")); assertEquals(anyItem, collection.get("anyItem")); int resultsPerPage = 1; List<String> entry = Lists.newArrayList("banana", "who"); collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.get("list")); assertEquals(startIndex, collection.get("startIndex")); assertEquals(totalResults, collection.get("totalResults")); assertEquals(resultsPerPage, collection.get("itemsPerPage")); } }
@Test public void testGetMessagesSingleId() throws Exception { RestfulCollection<Message> messages = db.getMessages( CANON_USER, "publicMessage", Collections.<String>emptySet(), Collections.<String>singletonList("1"), new CollectionOptions(), token).get(); assertEquals(1, messages.getList().size()); assertEquals("1", messages.getList().get(0).getId()); }
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entryList = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setList(entryList); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entryList, collection.getList()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
@Test public void testConstructors() throws Exception { List<String> entry = Lists.newArrayList("banana", "who"); RestfulCollection<String> collection = new RestfulCollection<String>(entry); assertEquals(entry, collection.getEntry()); assertEquals(0, collection.getStartIndex()); assertEquals(entry.size(), collection.getTotalResults()); assertEquals(entry.size(), collection.getItemsPerPage()); int startIndex = 9; int totalResults = 10; int resultsPerPage = 1; collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); assertEquals(resultsPerPage, collection.getItemsPerPage()); } }
@Test public void testBasicMethods() throws Exception { RestfulCollection<String> collection = new RestfulCollection<String>(Lists.<String>newArrayList()); List<String> entry = Lists.newArrayList("banana"); int startIndex = 5; int totalResults = 8675309; collection.setEntry(entry); collection.setStartIndex(startIndex); collection.setTotalResults(totalResults); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); }
/** {@inheritDoc} */ public Future<RestfulCollection<Group>> getGroups(UserId userId, CollectionOptions options, Set<String> fields, SecurityToken token) throws ProtocolException { List<Group> result = Lists.newArrayList(); String user = userId.getUserId(token); try { JSONArray groups = db.getJSONObject(GROUPS_TABLE).getJSONArray(user); for (int i = 0; i < groups.length(); i++) { JSONObject group = groups.getJSONObject(i); Group groupObj = filterFields(group, fields, Group.class); result.add(groupObj); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(new RestfulCollection<Group>(result)); }
RestfulCollection<?> r = (RestfulCollection<?>) obj; entry = Lists.newArrayList(); List<?> entryList = r.getList(); for (Object o : entryList) { entry.add(new AtomEntry(o)); startIndex = r.getStartIndex(); totalResults = r.getTotalResults(); itemsPerPage = r.getItemsPerPage(); author = (r.get(AUTHOR)==null) ? "?" : r.get(AUTHOR).toString(); title = (r.get(TITLE)==null) ? "?" : r.get(TITLE).toString(); id = (r.get(ID)==null) ? "?" : r.get(ID).toString(); updated = (r.get(UPDATED)==null) ? "" : r.get(UPDATED).toString(); if (r.get(URL)!=null) { link = new AtomLink("self", r.get(URL).toString());