Author: doll
Date: Mon Aug 25 08:47:28 2008
New Revision: 688764
URL: http://svn.apache.org/viewvc?rev=688764&view=rev
Log:
0.8.1 change
Added sortOrder which is either ascending or descending. (the enum will be
renamed in the next change)
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RestfulRequestItemTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RpcRequestItemTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java
Mon Aug 25 08:47:28 2008
@@ -79,8 +79,8 @@
return personService.getPerson(userIds.iterator().next(), fields,
request.getToken());
} else {
return personService.getPeople(userIds, groupId, request.getSortBy(),
- request.getFilterBy(), request.getStartIndex(),
request.getCount(),
- fields, request.getToken());
+ request.getSortOrder(), request.getFilterBy(),
request.getStartIndex(),
+ request.getCount(), fields, request.getToken());
}
} else if (optionalPersonId.size() == 1) {
// TODO: Add some crazy concept to handle the userId?
@@ -94,14 +94,14 @@
}
// Every other case is a collection response of optional person ids
return personService.getPeople(personIds, new
GroupId(GroupId.Type.self, null),
- request.getSortBy(), request.getFilterBy(),
request.getStartIndex(),
- request.getCount(), fields, request.getToken());
+ request.getSortBy(), request.getSortOrder(), request.getFilterBy(),
+ request.getStartIndex(), request.getCount(), fields,
request.getToken());
}
}
// Every other case is a collection response.
return personService.getPeople(userIds, groupId, request.getSortBy(),
- request.getFilterBy(), request.getStartIndex(), request.getCount(),
+ request.getSortOrder(), request.getFilterBy(),
request.getStartIndex(), request.getCount(),
fields, request.getToken());
}
}
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
Mon Aug 25 08:47:28 2008
@@ -45,6 +45,7 @@
public static final String COUNT = "count";
public static final String SORT_BY = "sortBy";
+ public static final String SORT_ORDER = "sortOrder";
public static final String FILTER_BY = "filterBy";
@@ -121,6 +122,13 @@
: PersonService.SortOrder.valueOf(sortBy);
}
+ public PersonService.SortDirection getSortOrder() {
+ String sortOrder = getParameter(SORT_ORDER);
+ return sortOrder == null
+ ? PersonService.SortDirection.ascending
+ : PersonService.SortDirection.valueOf(sortOrder);
+ }
+
public PersonService.FilterType getFilterBy() {
String filterBy = getParameter(FILTER_BY);
return filterBy == null
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/PersonService.java
Mon Aug 25 08:47:28 2008
@@ -32,38 +32,40 @@
public interface PersonService {
public enum SortOrder {
-
topFriends, name
}
- public enum FilterType {
+ public enum SortDirection {
+ ascending, descending
+ }
+ public enum FilterType {
all, hasApp, topFriends
}
/**
* Returns a list of people that correspond to the passed in person ids.
*
- * @param userIds A set of users
- * @param groupId The group
- * @param sortOrder How to sort the people
- * @param filter How the people should be filtered.
- * @param first The index of the first person to fetch.
- * @param max The max number of people to fetch.
- * @param fields The profile details to fetch. Empty set implies all
- * @param token The gadget token
- * @return a list of people.
+ * @param userIds A set of users
+ * @param groupId The group
+ * @param sortBy How to sort the people
+ * @param sortOrder The direction of the sort
+ * @param filter How the people should be filtered.
+ * @param first The index of the first person to fetch.
+ * @param max The max number of people to fetch.
+ * @param fields The profile details to fetch. Empty set implies all
+ * @param token The gadget token @return a list of people.
*/
Future<ResponseItem<RestfulCollection<Person>>> getPeople(Set<UserId>
userIds, GroupId groupId,
- SortOrder sortOrder, FilterType filter, int first, int max,
+ SortOrder sortBy, SortDirection sortOrder, FilterType filter, int first,
int max,
Set<String> fields, SecurityToken token);
/**
* Returns a person that corresponds to the passed in person id.
*
- * @param id The id of the person to fetch.
+ * @param id The id of the person to fetch.
* @param fields The fields to fetch.
- * @param token The gadget token
+ * @param token The gadget token
* @return a list of people.
*/
Future<ResponseItem<Person>> getPerson(UserId id, Set<String> fields,
SecurityToken token);
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
Mon Aug 25 08:47:28 2008
@@ -239,8 +239,8 @@
}
public Future<ResponseItem<RestfulCollection<Person>>> getPeople(Set<UserId>
userIds,
- GroupId groupId, SortOrder sortOrder, FilterType filter, int first, int
max,
- Set<String> fields, SecurityToken token) {
+ GroupId groupId, SortOrder sortBy, SortDirection sortOrder, FilterType
filter, int first,
+ int max, Set<String> fields, SecurityToken token) {
List<Person> result = Lists.newArrayList();
try {
JSONArray people = db.getJSONArray(PEOPLE_TABLE);
@@ -257,10 +257,14 @@
}
// We can pretend that by default the people are in top friends order
- if (sortOrder.equals(PersonService.SortOrder.name)) {
+ if (sortBy.equals(PersonService.SortOrder.name)) {
Collections.sort(result, NAME_COMPARATOR);
}
+ if (sortOrder.equals(SortDirection.descending)) {
+ Collections.reverse(result);
+ }
+
// TODO: The samplecontainer doesn't really have the concept of HAS_APP
so
// we can't support any filters yet. We should fix this.
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
Mon Aug 25 08:47:28 2008
@@ -447,6 +447,7 @@
public void testGetPeople() throws Exception {
Map<String, String> extraParams = Maps.newHashMap();
extraParams.put("sortBy", "name");
+ extraParams.put("sortOrder", null);
extraParams.put("filterBy", null);
extraParams.put("startIndex", null);
extraParams.put("count", "20");
@@ -470,6 +471,7 @@
public void testGetPeoplePagination() throws Exception {
Map<String, String> extraParams = Maps.newHashMap();
extraParams.put("sortBy", "name");
+ extraParams.put("sortOrder", null);
extraParams.put("filterBy", null);
extraParams.put("startIndex", "0");
extraParams.put("count", "1");
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
Mon Aug 25 08:47:28 2008
@@ -73,6 +73,7 @@
private void setPath(String path) {
Map<String, String> params = Maps.newHashMap();
params.put("sortBy", null);
+ params.put("sortOrder", null);
params.put("filterBy", null);
params.put("startIndex", null);
params.put("count", null);
@@ -96,6 +97,7 @@
JOHN_DOE,
new GroupId(GroupId.Type.all, null),
PersonService.SortOrder.topFriends,
+ PersonService.SortDirection.ascending,
PersonService.FilterType.all, 0, 20,
DEFAULT_FIELDS,
token))
@@ -115,6 +117,7 @@
JOHN_DOE,
new GroupId(GroupId.Type.friends, null),
PersonService.SortOrder.topFriends,
+ PersonService.SortDirection.ascending,
PersonService.FilterType.all, 0, 20,
DEFAULT_FIELDS,
token))
@@ -126,11 +129,13 @@
}
public void testHandleGetFriendsWithParams() throws Exception {
- PersonService.SortOrder order = PersonService.SortOrder.name;
+ PersonService.SortOrder sortBy = PersonService.SortOrder.name;
+ PersonService.SortDirection sortOrder =
PersonService.SortDirection.descending;
PersonService.FilterType filter = PersonService.FilterType.topFriends;
Map<String, String> params = Maps.newHashMap();
- params.put("sortBy", order.toString());
+ params.put("sortBy", sortBy.toString());
+ params.put("sortOrder", sortOrder.toString());
params.put("filterBy", filter.toString());
params.put("startIndex", "5");
params.put("count", "10");
@@ -142,7 +147,7 @@
= new ResponseItem<RestfulCollection<Person>>(null);
EasyMock.expect(personService.getPeople(
JOHN_DOE,
- new GroupId(GroupId.Type.friends, null), order,
+ new GroupId(GroupId.Type.friends, null), sortBy, sortOrder,
filter, 5, 10, Sets.newLinkedHashSet("money", "fame", "fortune"),
token))
.andReturn(ImmediateFuture.newInstance(data));
@@ -186,6 +191,7 @@
EasyMock.expect(personService.getPeople(userIdSet,
new GroupId(GroupId.Type.self, null),
PersonService.SortOrder.topFriends,
+ PersonService.SortDirection.ascending,
PersonService.FilterType.all, 0, 20,
DEFAULT_FIELDS,
token)).andReturn(ImmediateFuture.newInstance(data));
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RestfulRequestItemTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RestfulRequestItemTest.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RestfulRequestItemTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RestfulRequestItemTest.java
Mon Aug 25 08:47:28 2008
@@ -111,6 +111,14 @@
assertEquals(PersonService.SortOrder.name, request.getSortBy());
}
+ public void testSortOrder() throws Exception {
+ request.setParameter("sortOrder", null);
+ assertEquals(PersonService.SortDirection.ascending,
request.getSortOrder());
+
+ request.setParameter("sortOrder", "descending");
+ assertEquals(PersonService.SortDirection.descending,
request.getSortOrder());
+ }
+
public void testFilterBy() throws Exception {
request.setParameter("filterBy", null);
assertEquals(PersonService.FilterType.all, request.getFilterBy());
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RpcRequestItemTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RpcRequestItemTest.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RpcRequestItemTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/RpcRequestItemTest.java
Mon Aug 25 08:47:28 2008
@@ -106,6 +106,14 @@
assertEquals(PersonService.SortOrder.name, request.getSortBy());
}
+ public void testSortOrder() throws Exception {
+ request.setParameter("sortOrder", null);
+ assertEquals(PersonService.SortDirection.ascending,
request.getSortOrder());
+
+ request.setParameter("sortOrder", "descending");
+ assertEquals(PersonService.SortDirection.descending,
request.getSortOrder());
+ }
+
public void testFilterBy() throws Exception {
request.setParameter("filterBy", null);
assertEquals(PersonService.FilterType.all, request.getFilterBy());
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=688764&r1=688763&r2=688764&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
Mon Aug 25 08:47:28 2008
@@ -87,7 +87,8 @@
public void testGetExpectedFriends() throws Exception {
ResponseItem<RestfulCollection<Person>> responseItem = db.getPeople(
Sets.newHashSet(CANON_USER), new GroupId(GroupId.Type.friends, null),
- PersonService.SortOrder.topFriends, PersonService.FilterType.all, 0,
+ PersonService.SortOrder.topFriends,
PersonService.SortDirection.ascending,
+ PersonService.FilterType.all, 0,
Integer.MAX_VALUE, Collections.<String>emptySet(), token).get();
assertNotNull(responseItem.getResponse());
assertEquals(responseItem.getResponse().getTotalResults(), 4);
@@ -99,7 +100,8 @@
public void testGetExpectedUsersForPlural() throws Exception {
ResponseItem<RestfulCollection<Person>> responseItem = db.getPeople(
Sets.newLinkedHashSet(JOHN_DOE, JANE_DOE), new
GroupId(GroupId.Type.friends, null),
- PersonService.SortOrder.topFriends, PersonService.FilterType.all, 0,
+ PersonService.SortOrder.topFriends,
PersonService.SortDirection.ascending,
+ PersonService.FilterType.all, 0,
Integer.MAX_VALUE, Collections.<String>emptySet(), token).get();
assertNotNull(responseItem.getResponse());
assertEquals(responseItem.getResponse().getTotalResults(), 4);