Author: doll
Date: Tue Aug 26 12:14:42 2008
New Revision: 689173
URL: http://svn.apache.org/viewvc?rev=689173&view=rev
Log:
Pulled all of the various filtering, sorting and pagination parameters into a
new collections object. This will become very important because the filterBy
and sortBy parameters are both becoming strings in the next change.
Added:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java
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/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/opensocial/service/PersonHandlerTest.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=689173&r1=689172&r2=689173&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
Tue Aug 26 12:14:42 2008
@@ -20,6 +20,7 @@
import org.apache.shindig.social.ResponseError;
import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.PersonService;
import org.apache.shindig.social.opensocial.spi.UserId;
@@ -73,15 +74,21 @@
throw new IllegalArgumentException("Cannot fetch personIds for multiple
userIds");
}
+ CollectionOptions options = new CollectionOptions();
+ options.setSortBy(request.getSortBy());
+ options.setSortOrder(request.getSortOrder());
+ options.setFilter(request.getFilterBy());
+ options.setFilterOperation(request.getFilterOperation());
+ options.setFilterValue(request.getFilterValue());
+ options.setFirst(request.getStartIndex());
+ options.setMax(request.getCount());
+
if (userIds.size() == 1) {
if (optionalPersonId.isEmpty()) {
if (groupId.getType() == GroupId.Type.self) {
return personService.getPerson(userIds.iterator().next(), fields,
request.getToken());
} else {
- return personService.getPeople(userIds, groupId, request.getSortBy(),
- request.getSortOrder(), request.getFilterBy(),
request.getFilterOperation(),
- request.getFilterValue(), request.getStartIndex(),
- request.getCount(), fields, request.getToken());
+ return personService.getPeople(userIds, groupId, options, fields,
request.getToken());
}
} else if (optionalPersonId.size() == 1) {
// TODO: Add some crazy concept to handle the userId?
@@ -95,16 +102,11 @@
}
// Every other case is a collection response of optional person ids
return personService.getPeople(personIds, new
GroupId(GroupId.Type.self, null),
- request.getSortBy(), request.getSortOrder(), request.getFilterBy(),
- request.getFilterOperation(), request.getFilterValue(),
request.getStartIndex(),
- request.getCount(), fields, request.getToken());
+ options, fields, request.getToken());
}
}
// Every other case is a collection response.
- return personService.getPeople(userIds, groupId, request.getSortBy(),
- request.getSortOrder(), request.getFilterBy(),
request.getFilterOperation(),
- request.getFilterValue(), request.getStartIndex(), request.getCount(),
- fields, request.getToken());
+ return personService.getPeople(userIds, groupId, options, fields,
request.getToken());
}
}
Added:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java?rev=689173&view=auto
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java
(added)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java
Tue Aug 26 12:14:42 2008
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.spi;
+
+import org.apache.commons.lang.StringUtils;
+
+public class CollectionOptions {
+ private PersonService.SortBy sortBy;
+ private PersonService.SortOrder sortOrder;
+ private PersonService.FilterType filter;
+ private PersonService.FilterOperation filterOperation;
+ private String filterValue;
+ private int first;
+ private int max;
+
+ public PersonService.SortBy getSortBy() {
+ return sortBy;
+ }
+
+ public void setSortBy(PersonService.SortBy sortBy) {
+ this.sortBy = sortBy;
+ }
+
+ public PersonService.SortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ public void setSortOrder(PersonService.SortOrder sortOrder) {
+ this.sortOrder = sortOrder;
+ }
+
+ public PersonService.FilterType getFilter() {
+ return filter;
+ }
+
+ public void setFilter(PersonService.FilterType filter) {
+ this.filter = filter;
+ }
+
+ public PersonService.FilterOperation getFilterOperation() {
+ return filterOperation;
+ }
+
+ public void setFilterOperation(PersonService.FilterOperation
filterOperation) {
+ this.filterOperation = filterOperation;
+ }
+
+ public String getFilterValue() {
+ return filterValue;
+ }
+
+ public void setFilterValue(String filterValue) {
+ this.filterValue = filterValue;
+ }
+
+ public int getFirst() {
+ return first;
+ }
+
+ public void setFirst(int first) {
+ this.first = first;
+ }
+
+ public int getMax() {
+ return max;
+ }
+
+ public void setMax(int max) {
+ this.max = max;
+ }
+
+ // These are overriden so that EasyMock doesn't throw a fit
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof CollectionOptions)) {
+ return false;
+ }
+
+ CollectionOptions actual = (CollectionOptions) o;
+ return this.sortBy == actual.sortBy
+ && this.sortOrder == actual.sortOrder
+ && this.filter == actual.filter
+ && this.filterOperation == actual.filterOperation
+ && StringUtils.equals(this.filterValue, actual.filterValue)
+ && this.first == actual.first
+ && this.max == actual.max;
+ }
+
+ @Override
+ public int hashCode() {
+ return getHashCode(this.sortBy) + getHashCode(this.sortOrder) +
getHashCode(this.filter)
+ + getHashCode(this.filterOperation) + getHashCode(this.filterValue)
+ + getHashCode(this.first) + getHashCode(this.max);
+ }
+
+ private int getHashCode(Object o) {
+ return o == null ? 0 : o.hashCode();
+ }
+}
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=689173&r1=689172&r2=689173&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
Tue Aug 26 12:14:42 2008
@@ -51,21 +51,12 @@
*
* @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 filterOperation The operation to filter with
- * @param filterValue The value to filter with.
- * @param first The index of the first person to fetch.
- * @param max The max number of people to fetch.
+ * @param collectionOptions How to filter, sort and paginate the collection
being fetched
* @param fields The profile details to fetch. Empty set implies all
* @param token The gadget token @return a list of people.
- * TODO(doll): This method is getting way too long. We need to pass a more
complex object instead.
*/
Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds, GroupId
groupId,
- SortBy sortBy, SortOrder sortOrder, FilterType filter, FilterOperation
filterOperation,
- String filterValue, int first, int max,
- Set<String> fields, SecurityToken token);
+ CollectionOptions collectionOptions, Set<String> fields, SecurityToken
token);
/**
* Returns a person that corresponds to the passed in person id.
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=689173&r1=689172&r2=689173&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
Tue Aug 26 12:14:42 2008
@@ -28,6 +28,7 @@
import org.apache.shindig.social.opensocial.service.BeanConverter;
import org.apache.shindig.social.opensocial.spi.ActivityService;
import org.apache.shindig.social.opensocial.spi.AppDataService;
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
import org.apache.shindig.social.opensocial.spi.DataCollection;
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.PersonService;
@@ -237,9 +238,7 @@
}
public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds,
- GroupId groupId, SortBy sortBy, SortOrder sortOrder, FilterType filter,
- FilterOperation filterOperation, String filterValue, int first,
- int max, Set<String> fields, SecurityToken token) {
+ GroupId groupId, CollectionOptions options, Set<String> fields,
SecurityToken token) {
List<Person> result = Lists.newArrayList();
try {
JSONArray people = db.getJSONArray(PEOPLE_TABLE);
@@ -256,11 +255,11 @@
}
// We can pretend that by default the people are in top friends order
- if (sortBy.equals(SortBy.name)) {
+ if (options.getSortBy().equals(SortBy.name)) {
Collections.sort(result, NAME_COMPARATOR);
}
- if (sortOrder.equals(SortOrder.descending)) {
+ if (options.getSortOrder().equals(SortOrder.descending)) {
Collections.reverse(result);
}
@@ -268,10 +267,11 @@
// we can't support any filters yet. We should fix this.
int totalSize = result.size();
- int last = first + max;
- result = result.subList(first, Math.min(last, totalSize));
+ int last = options.getFirst() + options.getMax();
+ result = result.subList(options.getFirst(), Math.min(last, totalSize));
- return ImmediateFuture.newInstance(new RestfulCollection<Person>(result,
first, totalSize));
+ return ImmediateFuture.newInstance(new RestfulCollection<Person>(
+ result, options.getFirst(), totalSize));
} catch (JSONException je) {
return ImmediateFuture.newInstance(new RestfulCollection<Person>(
ResponseError.INTERNAL_ERROR, je.getMessage()));
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=689173&r1=689172&r2=689173&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
Tue Aug 26 12:14:42 2008
@@ -20,8 +20,8 @@
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.common.util.ImmediateFuture;
import org.apache.shindig.social.ResponseError;
-import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.PersonService;
import org.apache.shindig.social.opensocial.spi.RestfulCollection;
@@ -37,13 +37,9 @@
import java.util.Set;
public class PersonHandlerTest extends TestCase {
-
private PersonService personService;
-
private PersonHandler handler;
-
private FakeGadgetToken token;
-
private RestfulRequestItem request;
private static final Set<String> DEFAULT_FIELDS =
Sets.newHashSet(Person.Field.ID.toString(),
@@ -53,6 +49,18 @@
private static final Set<UserId> JOHN_DOE = Sets
.newHashSet(new UserId(UserId.Type.userId, "john.doe"));
+ private static CollectionOptions DEFAULT_OPTIONS = new CollectionOptions();
+
+ static {
+ DEFAULT_OPTIONS.setSortBy(PersonService.SortBy.topFriends);
+ DEFAULT_OPTIONS.setSortOrder(PersonService.SortOrder.ascending);
+ DEFAULT_OPTIONS.setFilter(PersonService.FilterType.all);
+ DEFAULT_OPTIONS.setFilterOperation(PersonService.FilterOperation.contains);
+ DEFAULT_OPTIONS.setFilterValue("");
+ DEFAULT_OPTIONS.setFirst(0);
+ DEFAULT_OPTIONS.setMax(20);
+ }
+
@Override
protected void setUp() throws Exception {
token = new FakeGadgetToken();
@@ -91,13 +99,11 @@
setPath("/people/john.doe/@all");
RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
+
EasyMock.expect(personService.getPeople(
JOHN_DOE,
new GroupId(GroupId.Type.all, null),
- PersonService.SortBy.topFriends,
- PersonService.SortOrder.ascending,
- PersonService.FilterType.all,
- PersonService.FilterOperation.contains, "", 0, 20,
+ DEFAULT_OPTIONS,
DEFAULT_FIELDS,
token))
.andReturn(ImmediateFuture.newInstance(data));
@@ -114,11 +120,7 @@
EasyMock.expect(personService.getPeople(
JOHN_DOE,
new GroupId(GroupId.Type.friends, null),
- PersonService.SortBy.topFriends,
- PersonService.SortOrder.ascending,
- PersonService.FilterType.all,
- PersonService.FilterOperation.contains,
- "", 0, 20,
+ DEFAULT_OPTIONS,
DEFAULT_FIELDS,
token))
.andReturn(ImmediateFuture.newInstance(data));
@@ -129,18 +131,21 @@
}
public void testHandleGetFriendsWithParams() throws Exception {
- PersonService.SortBy sortBy = PersonService.SortBy.name;
- PersonService.SortOrder sortOrder = PersonService.SortOrder.descending;
- PersonService.FilterType filter = PersonService.FilterType.topFriends;
- PersonService.FilterOperation filterOp =
PersonService.FilterOperation.present;
- String filterValue = "cassie";
+ CollectionOptions options = new CollectionOptions();
+ options.setSortBy(PersonService.SortBy.name);
+ options.setSortOrder(PersonService.SortOrder.descending);
+ options.setFilter(PersonService.FilterType.topFriends);
+ options.setFilterOperation(PersonService.FilterOperation.present);
+ options.setFilterValue("cassie");
+ options.setFirst(5);
+ options.setMax(10);
Map<String, String> params = Maps.newHashMap();
- params.put("sortBy", sortBy.toString());
- params.put("sortOrder", sortOrder.toString());
- params.put("filterBy", filter.toString());
- params.put("filterOp", filterOp.toString());
- params.put("filterValue", filterValue);
+ params.put("sortBy", options.getSortBy().toString());
+ params.put("sortOrder", options.getSortOrder().toString());
+ params.put("filterBy", options.getFilter().toString());
+ params.put("filterOp", options.getFilterOperation().toString());
+ params.put("filterValue", options.getFilterValue());
params.put("startIndex", "5");
params.put("count", "10");
params.put("fields", "money,fame,fortune");
@@ -150,8 +155,7 @@
RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
EasyMock.expect(personService.getPeople(
JOHN_DOE,
- new GroupId(GroupId.Type.friends, null), sortBy, sortOrder,
- filter, filterOp, filterValue, 5, 10,
+ new GroupId(GroupId.Type.friends, null), options,
Sets.newLinkedHashSet("money", "fame", "fortune"), token))
.andReturn(ImmediateFuture.newInstance(data));
@@ -193,11 +197,7 @@
userIdSet.add(new UserId(UserId.Type.userId, "jane.doe"));
EasyMock.expect(personService.getPeople(userIdSet,
new GroupId(GroupId.Type.self, null),
- PersonService.SortBy.topFriends,
- PersonService.SortOrder.ascending,
- PersonService.FilterType.all,
- PersonService.FilterOperation.contains,
- "", 0, 20,
+ DEFAULT_OPTIONS,
DEFAULT_FIELDS,
token)).andReturn(ImmediateFuture.newInstance(data));
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=689173&r1=689172&r2=689173&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
Tue Aug 26 12:14:42 2008
@@ -29,6 +29,7 @@
import org.apache.shindig.social.opensocial.spi.RestfulCollection;
import org.apache.shindig.social.opensocial.spi.RestfulItem;
import org.apache.shindig.social.opensocial.spi.UserId;
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -78,11 +79,18 @@
}
public void testGetExpectedFriends() throws Exception {
+ CollectionOptions options = new CollectionOptions();
+ options.setSortBy(PersonService.SortBy.topFriends);
+ options.setSortOrder(PersonService.SortOrder.ascending);
+ options.setFilter(PersonService.FilterType.all);
+ options.setFilterOperation(PersonService.FilterOperation.contains);
+ options.setFilterValue("");
+ options.setFirst(0);
+ options.setMax(20);
+
RestfulCollection<Person> responseItem = db.getPeople(
Sets.newHashSet(CANON_USER), new GroupId(GroupId.Type.friends, null),
- PersonService.SortBy.topFriends, PersonService.SortOrder.ascending,
- PersonService.FilterType.all, PersonService.FilterOperation.contains,
"", 0,
- Integer.MAX_VALUE, Collections.<String>emptySet(), token).get();
+ options, Collections.<String>emptySet(), token).get();
assertNotNull(responseItem);
assertEquals(responseItem.getTotalResults(), 4);
// Test a couple of users
@@ -91,11 +99,18 @@
}
public void testGetExpectedUsersForPlural() throws Exception {
+ CollectionOptions options = new CollectionOptions();
+ options.setSortBy(PersonService.SortBy.topFriends);
+ options.setSortOrder(PersonService.SortOrder.ascending);
+ options.setFilter(PersonService.FilterType.all);
+ options.setFilterOperation(PersonService.FilterOperation.contains);
+ options.setFilterValue("");
+ options.setFirst(0);
+ options.setMax(20);
+
RestfulCollection<Person> responseItem = db.getPeople(
Sets.newLinkedHashSet(JOHN_DOE, JANE_DOE), new
GroupId(GroupId.Type.friends, null),
- PersonService.SortBy.topFriends, PersonService.SortOrder.ascending,
- PersonService.FilterType.all, PersonService.FilterOperation.contains,
"", 0,
- Integer.MAX_VALUE, Collections.<String>emptySet(), token).get();
+ options, Collections.<String>emptySet(), token).get();
assertNotNull(responseItem);
assertEquals(responseItem.getTotalResults(), 4);
// Test a couple of users