@Test public void testListGroups() throws Exception { endpoint.insert("Adventure", TEST_IMG, user); endpoint.insert("Activities", TEST_IMG, user); endpoint.insert("Tours", TEST_IMG, user); CollectionResponse<TravelerGroupEntity> response = endpoint.list(null, null, null, null); assertEquals(3, response.getItems().size()); Ix.from(response.getItems()).foreach(group -> { assertEquals(0L, group.getPostCount()); assertEquals(0.0D, group.getRank(), 0); assertEquals(ShardConfig.GROUP_SHARD_COUNTER, group.getShards().size()); }); }
public CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter, Optional<Integer> limit, Optional<String> cursor, User user) { Account account = ofy().load().key(Key.<Account>create(user.getUserId())).now(); Query<TravelerGroupEntity> query = ofy().load().type(TravelerGroupEntity.class); query = GroupSorter.sort(query, sorter.or(GroupSorter.DEFAULT)); query = cursor.isPresent() ? query.startAt(Cursor.fromWebSafeString(cursor.get())) : query; query = query.limit(limit.or(DEFAULT_LIST_LIMIT)); final QueryResultIterator<TravelerGroupEntity> qi = query.iterator(); List<TravelerGroupEntity> groups = new ArrayList<>(DEFAULT_LIST_LIMIT); while (qi.hasNext()) { TravelerGroupEntity group = qi.next(); for (Key<TravelerGroupEntity> key : account.getSubscribedGroupKeys()) { if (group.getKey().equivalent(key)) { group = group.withSubscribed(true); break; } } groups.add(group); } return CollectionResponse.<TravelerGroupEntity>builder() .setItems(groups) .setNextPageToken(qi.getCursor().toWebSafeString()) .build(); }
TravelerGroupController extends Controller { public CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter, Optional<Integer> limit, Optional<String> cursor, User user) { Account account = ofy().load().key(Key.<Account>create(user.getUserId())).now(); Query<TravelerGroupEntity> query = ofy().load().type(TravelerGroupEntity.class); query = GroupSorter.sort(query, sorter.or(GroupSorter.DEFAULT)); query = cursor.isPresent() ? query.startAt(Cursor.fromWebSafeString(cursor.get())) : query; query = query.limit(limit.or(DEFAULT_LIST_LIMIT)); final QueryResultIterator<TravelerGroupEntity> qi = query.iterator(); List<TravelerGroupEntity> groups = new ArrayList<>(DEFAULT_LIST_LIMIT); while (qi.hasNext()) { TravelerGroupEntity group = qi.next(); for (Key<TravelerGroupEntity> key : account.getSubscribedGroupKeys()) { if (group.getKey().equivalent(key)) { group = group.withSubscribed(true); break; } } groups.add(group); } return CollectionResponse.<TravelerGroupEntity>builder() .setItems(groups) .setNextPageToken(qi.getCursor().toWebSafeString()) .build(); } }
TravelerGroupController extends Controller { public CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter, Optional<Integer> limit, Optional<String> cursor, User user) { Account account = ofy().load().key(Key.<Account>create(user.getUserId())).now(); Query<TravelerGroupEntity> query = ofy().load().type(TravelerGroupEntity.class); query = GroupSorter.sort(query, sorter.or(GroupSorter.DEFAULT)); query = cursor.isPresent() ? query.startAt(Cursor.fromWebSafeString(cursor.get())) : query; query = query.limit(limit.or(DEFAULT_LIST_LIMIT)); final QueryResultIterator<TravelerGroupEntity> qi = query.iterator(); List<TravelerGroupEntity> groups = new ArrayList<>(DEFAULT_LIST_LIMIT); while (qi.hasNext()) { TravelerGroupEntity group = qi.next(); for (Key<TravelerGroupEntity> key : account.getSubscribedGroupKeys()) { if (group.getKey().equivalent(key)) { group = group.withSubscribed(true); break; } } groups.add(group); } return CollectionResponse.<TravelerGroupEntity>builder() .setItems(groups) .setNextPageToken(qi.getCursor().toWebSafeString()) .build(); }  }
TravelerGroupController extends Controller { public CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter, Optional<Integer> limit, Optional<String> cursor, User user) { Account account = ofy().load().key(Key.<Account>create(user.getUserId())).now(); Query<TravelerGroupEntity> query = ofy().load().type(TravelerGroupEntity.class); query = GroupSorter.sort(query, sorter.or(GroupSorter.DEFAULT)); query = cursor.isPresent() ? query.startAt(Cursor.fromWebSafeString(cursor.get())) : query; query = query.limit(limit.or(DEFAULT_LIST_LIMIT)); final QueryResultIterator<TravelerGroupEntity> qi = query.iterator(); List<TravelerGroupEntity> groups = new ArrayList<>(DEFAULT_LIST_LIMIT); while (qi.hasNext()) { TravelerGroupEntity group = qi.next(); for (Key<TravelerGroupEntity> key : account.getSubscribedGroupKeys()) { if (group.getKey().equivalent(key)) { group = group.withSubscribed(true); break; } } groups.add(group); } return CollectionResponse.<TravelerGroupEntity>builder() .setItems(groups) .setNextPageToken(qi.getCursor().toWebSafeString()) .build(); }  TravelerGroupEntity getGroup(@Nonnull String id, @Nonnull User user); TravelerGroupEntity insertGroup(String displayName, String imageName); TravelerGroupEntity updateGroup(String groupId, Optional<String> name); CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter,
      Optional<Integer> limit, Optional<String> cursor, User user); CollectionResponse<Account> listGroupUsers(String groupId, Optional<Integer> limit,
      Optional<String> cursor); void subscribe(@Nonnull String groupId, @Nonnull User user); void unsubscribe(@Nonnull String groupId, @Nonnull User user); Collection<TravelerGroupEntity> listSubscribedGroups(@Nonnull String userId); Collection<TravelerGroupEntity> searchGroups(@Nonnull String q); void setup(); void setupDev(); }
TravelerGroupController extends Controller { public CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter, Optional<Integer> limit, Optional<String> cursor, User user) { Account account = ofy().load().key(Key.<Account>create(user.getUserId())).now(); Query<TravelerGroupEntity> query = ofy().load().type(TravelerGroupEntity.class); query = GroupSorter.sort(query, sorter.or(GroupSorter.DEFAULT)); query = cursor.isPresent() ? query.startAt(Cursor.fromWebSafeString(cursor.get())) : query; query = query.limit(limit.or(DEFAULT_LIST_LIMIT)); final QueryResultIterator<TravelerGroupEntity> qi = query.iterator(); List<TravelerGroupEntity> groups = new ArrayList<>(DEFAULT_LIST_LIMIT); while (qi.hasNext()) { TravelerGroupEntity group = qi.next(); for (Key<TravelerGroupEntity> key : account.getSubscribedGroupKeys()) { if (group.getKey().equivalent(key)) { group = group.withSubscribed(true); break; } } groups.add(group); } return CollectionResponse.<TravelerGroupEntity>builder() .setItems(groups) .setNextPageToken(qi.getCursor().toWebSafeString()) .build(); }  TravelerGroupEntity getGroup(@Nonnull String id, @Nonnull User user); TravelerGroupEntity insertGroup(String displayName, String imageName); TravelerGroupEntity updateGroup(String groupId, Optional<String> name); CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter,
      Optional<Integer> limit, Optional<String> cursor, User user); CollectionResponse<Account> listGroupUsers(String groupId, Optional<Integer> limit,
      Optional<String> cursor); void subscribe(@Nonnull String groupId, @Nonnull User user); void unsubscribe(@Nonnull String groupId, @Nonnull User user); Collection<TravelerGroupEntity> listSubscribedGroups(@Nonnull String userId); Collection<TravelerGroupEntity> searchGroups(@Nonnull String q); void setup(); void setupDev();  }