You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/06/19 22:52:41 UTC
svn commit: r669687 - in /incubator/shindig/trunk/java/social-api/src:
main/java/org/apache/shindig/social/dataservice/
main/java/org/apache/shindig/social/samplecontainer/
test/java/org/apache/shindig/social/dataservice/
Author: doll
Date: Thu Jun 19 13:52:40 2008
New Revision: 669687
URL: http://svn.apache.org/viewvc?rev=669687&view=rev
Log:
Updated the ActivityService to use appId and field params and include a deletion method.
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityService.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/GroupId.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/UserId.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/BasicActivitiesService.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/XmlStateFileFetcher.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/ActivityHandlerTest.java
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityHandler.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityHandler.java Thu Jun 19 13:52:40 2008
@@ -18,12 +18,15 @@
package org.apache.shindig.social.dataservice;
import com.google.inject.Inject;
+import com.google.common.collect.Sets;
import org.apache.shindig.social.ResponseError;
import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.opensocial.model.ActivityImpl;
import org.apache.shindig.social.opensocial.model.Activity;
+import java.util.Set;
+import java.util.List;
+
public class ActivityHandler extends DataRequestHandler {
private ActivityService service;
@@ -32,9 +35,23 @@
this.service = service;
}
+ /**
+ * /activities/{userId}/@self/{actvityId}
+ *
+ * examples:
+ * /activities/john.doe/@self/1
+ */
protected ResponseItem handleDelete(RequestItem request) {
- return new ResponseItem<Object>(ResponseError.BAD_REQUEST,
- "You can't delete activities. ", null);
+ String[] segments = getParamsFromRequest(request);
+
+ UserId userId = UserId.fromJson(segments[0]);
+ GroupId groupId = GroupId.fromJson(segments[1]);
+ String activityId = segments[2];
+
+ // TODO: The appId should come from the url. The spec needs to be fixed.
+ String appId = "appId";
+
+ return service.deleteActivity(userId, groupId, appId, activityId, request.getToken());
}
/**
@@ -60,12 +77,20 @@
UserId userId = UserId.fromJson(segments[0]);
GroupId groupId = GroupId.fromJson(segments[1]);
- // TODO: Should we pass the groupId through to the service?
String jsonActivity = request.getParameters().get("entry");
Activity activity = converter.convertToObject(jsonActivity, Activity.class);
- return service.createActivity(userId, activity, request.getToken());
+ // TODO: The appId should come from the url. The spec needs to be fixed.
+ String appId = "appId";
+
+ Set<String> fields = Sets.newHashSet();
+ List<String> urlFields = getListParam(request, "fields", null);
+ if (urlFields != null) {
+ fields = Sets.newHashSet(urlFields);
+ }
+
+ return service.createActivity(userId, groupId, appId, fields, activity, request.getToken());
}
/**
@@ -86,12 +111,21 @@
optionalActivityId = segments[2];
}
- // TODO: Filter by fields
- // TODO: do we need to add pagination and sorting support?
+ // TODO: The appId should come from the url. The spec needs to be fixed.
+ String appId = "appId";
+
+ Set<String> fields = Sets.newHashSet();
+ List<String> urlFields = getListParam(request, "fields", null);
+ if (urlFields != null) {
+ fields = Sets.newHashSet(urlFields);
+ }
+
+ // TODO: add pagination and sorting support
if (optionalActivityId != null) {
- return service.getActivity(userId, groupId, optionalActivityId, request.getToken());
+ return service.getActivity(userId, groupId, appId, fields, optionalActivityId,
+ request.getToken());
}
- return service.getActivities(userId, groupId, request.getToken());
+ return service.getActivities(userId, groupId, appId, fields, request.getToken());
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityService.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityService.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityService.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/ActivityService.java Thu Jun 19 13:52:40 2008
@@ -21,18 +21,22 @@
import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.opensocial.model.Activity;
+import java.util.Set;
+
public interface ActivityService {
/**
- * Returns a list of activities that correspond to the passed in person ids.
+ * Returns a list of activities that correspond to the passed in user and group.
*
* @param userId The id of the person to fetch activities for.
* @param groupId Indicates whether to fetch activities for a group.
+ * @param appId The app id.
+ * @param fields The fields to return.
* @param token A valid SecurityToken
* @return a response item with the list of activities.
*/
public ResponseItem<RestfulCollection<Activity>> getActivities(UserId userId,
- GroupId groupId, SecurityToken token);
+ GroupId groupId, String appId, Set<String> fields, SecurityToken token);
/**
* Returns the activity for the passed in user and group that corresponds to
@@ -40,24 +44,41 @@
*
* @param userId The id of the person to fetch activities for.
* @param groupId Indicates whether to fetch activities for a group.
+ * @param appId The app id.
+ * @param fields The fields to return.
* @param activityId The id of the activity to fetch.
* @param token A valid SecurityToken
* @return a response item with the list of activities.
*/
- public ResponseItem<Activity> getActivity(UserId userId,
- GroupId groupId, String activityId,
- SecurityToken token);
+ public ResponseItem<Activity> getActivity(UserId userId, GroupId groupId, String appId,
+ Set<String> fields, String activityId, SecurityToken token);
+
+ /**
+ * Deletes the activity for the passed in user and group that corresponds to
+ * the activityId.
+ *
+ * @param userId The user.
+ * @param groupId The group.
+ * @param appId The app id.
+ * @param activityId The id of the activity to delete.
+ * @param token A valid SecurityToken.
+ * @return a response item containing any errors
+ */
+ public ResponseItem deleteActivity(UserId userId, GroupId groupId, String appId,
+ String activityId, SecurityToken token);
/**
- * Creates the passed in activity for the given user. Once createActivity is
+ * Creates the passed in activity for the passed in user and group. Once createActivity is
* called, getActivities will be able to return the Activity.
*
- * @param personId The id of the person to create the activity for.
+ * @param userId The id of the person to create the activity for.
+ * @param groupId The group.
+ * @param appId The app id.
+ * @param fields The fields to return.
* @param activity The activity to create.
* @param token A valid SecurityToken
* @return a response item containing any errors
*/
- public ResponseItem createActivity(UserId personId, Activity activity,
- SecurityToken token);
-
+ public ResponseItem createActivity(UserId userId, GroupId groupId, String appId,
+ Set<String> fields, Activity activity, SecurityToken token);
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/GroupId.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/GroupId.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/GroupId.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/GroupId.java Thu Jun 19 13:52:40 2008
@@ -64,6 +64,7 @@
@Override
public int hashCode() {
- return this.type.hashCode() + this.groupId.hashCode();
+ int groupHashCode = this.groupId == null ? 0 : this.groupId.hashCode();
+ return this.type.hashCode() + groupHashCode;
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/UserId.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/UserId.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/UserId.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/dataservice/UserId.java Thu Jun 19 13:52:40 2008
@@ -70,6 +70,7 @@
@Override
public int hashCode() {
- return this.type.hashCode() + this.userId.hashCode();
+ int userHashCode = this.userId == null ? 0 : this.userId.hashCode();
+ return this.type.hashCode() + userHashCode;
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/BasicActivitiesService.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/BasicActivitiesService.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/BasicActivitiesService.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/BasicActivitiesService.java Thu Jun 19 13:52:40 2008
@@ -34,6 +34,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class BasicActivitiesService implements ActivitiesService,
ActivityService {
@@ -89,7 +90,7 @@
// New interface methods
public ResponseItem<RestfulCollection<Activity>> getActivities(UserId userId,
- GroupId groupId, SecurityToken token) {
+ GroupId groupId, String appId, Set<String> fields, SecurityToken token) {
List<String> ids = Lists.newArrayList();
switch (groupId.getType()) {
case all:
@@ -113,16 +114,16 @@
}
}
- // TODO: Sort them
+ // TODO: Sort them, respect the fields param etc
return new ResponseItem<RestfulCollection<Activity>>(
new RestfulCollection<Activity>(activities));
}
- public ResponseItem<Activity> getActivity(UserId userId,
- GroupId groupId, String activityId,
- SecurityToken token) {
+ public ResponseItem<Activity> getActivity(UserId userId, GroupId groupId, String appId,
+ Set<String> fields, String activityId, SecurityToken token) {
+
RestfulCollection<Activity> allActivities = getActivities(userId, groupId,
- token).getResponse();
+ appId, fields, token).getResponse();
for (Activity activity : allActivities.getEntry()) {
if (activity.getId().equals(activityId)) {
return new ResponseItem<Activity>(activity);
@@ -132,14 +133,21 @@
"Activity not found", null);
}
- public ResponseItem createActivity(UserId personId, Activity activity,
- SecurityToken token) {
- // TODO: Validate the activity and do any template expanding
- activity.setUserId(personId.getUserId(token));
+ public ResponseItem deleteActivity(UserId userId, GroupId groupId, String appId,
+ String activityId, SecurityToken token) {
+ fetcher.deleteActivity(userId.getUserId(token), activityId);
+ return new ResponseItem<Object>(new Object());
+ }
+
+ public ResponseItem createActivity(UserId userId, GroupId groupId, String appId,
+ Set<String> fields, Activity activity, SecurityToken token) {
+
+ // TODO: Validate the activity, respect the fields param, and do any template expanding
+ activity.setUserId(userId.getUserId(token));
activity.setPostedTime(new Date().getTime());
- fetcher.createActivity(personId.getUserId(token), activity);
- return new ResponseItem<JSONObject>(new JSONObject());
+ fetcher.createActivity(userId.getUserId(token), activity);
+ return new ResponseItem<Object>(new Object());
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/XmlStateFileFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/XmlStateFileFetcher.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/XmlStateFileFetcher.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/samplecontainer/XmlStateFileFetcher.java Thu Jun 19 13:52:40 2008
@@ -130,11 +130,29 @@
public void createActivity(String userId, Activity activity) {
if (allActivities.get(userId) == null) {
- allActivities.put(userId, new ArrayList<Activity>());
+ allActivities.put(userId, Lists.<Activity>newArrayList());
}
allActivities.get(userId).add(activity);
}
+ public void deleteActivity(String userId, String activityId) {
+ if (allActivities.get(userId) == null) {
+ allActivities.put(userId, Lists.<Activity>newArrayList());
+ }
+ List<Activity> allActivities = this.allActivities.get(userId);
+ Activity activityToRemove = null;
+ for (Activity activity : allActivities) {
+ if (activity.getId().equals(activityId)) {
+ activityToRemove = activity;
+ break;
+ }
+ }
+
+ if (activityToRemove != null) {
+ allActivities.remove(activityToRemove);
+ }
+ }
+
private Document fetchStateDocument() {
String errorMessage = "The state file " + stateFile
+ " could not be fetched and parsed.";
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/ActivityHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/ActivityHandlerTest.java?rev=669687&r1=669686&r2=669687&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/ActivityHandlerTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/ActivityHandlerTest.java Thu Jun 19 13:52:40 2008
@@ -30,6 +30,7 @@
import java.util.Map;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
public class ActivityHandlerTest extends TestCase {
private BeanJsonConverter converter;
@@ -60,7 +61,9 @@
}
private void setPath(String path) {
- this.setPathAndParams(path, null);
+ Map<String, String> params = Maps.newHashMap();
+ params.put("fields", null);
+ this.setPathAndParams(path, params);
}
private void setPathAndParams(String path, Map<String, String> params) {
@@ -73,7 +76,7 @@
ResponseItem<RestfulCollection<Activity>> data
= new ResponseItem<RestfulCollection<Activity>>(null);
EasyMock.expect(activityService.getActivities(new UserId(UserId.Type.userId, "john.doe"),
- new GroupId(group, null), token)).andReturn(data);
+ new GroupId(group, null), "appId", Sets.<String>newHashSet(), token)).andReturn(data);
replay();
assertEquals(data, handler.handleGet(request));
@@ -98,7 +101,7 @@
ResponseItem<Activity> data = new ResponseItem<Activity>(null);
EasyMock.expect(activityService.getActivity(new UserId(UserId.Type.userId, "john.doe"),
new GroupId(GroupId.Type.friends, null),
- "jane.doe", token)).andReturn(data);
+ "appId", Sets.<String>newHashSet(), "jane.doe", token)).andReturn(data);
replay();
assertEquals(data, handler.handleGet(request));
@@ -110,6 +113,7 @@
Map<String, String> params = Maps.newHashMap();
params.put("entry", jsonActivity);
+ params.put("fields", null);
setPathAndParams("/people/john.doe/@self", params);
Activity activity = new ActivityImpl();
@@ -117,6 +121,7 @@
ResponseItem data = new ResponseItem<Object>(null);
EasyMock.expect(activityService.createActivity(new UserId(UserId.Type.userId, "john.doe"),
+ new GroupId(GroupId.Type.self, null), "appId", Sets.<String>newHashSet(),
activity, token)).andReturn(data);
replay();
return data;
@@ -135,8 +140,14 @@
}
public void testHandleDelete() throws Exception {
+ setPath("/people/john.doe/@self/1");
+
+ ResponseItem data = new ResponseItem<Object>(null);
+ EasyMock.expect(activityService.deleteActivity(new UserId(UserId.Type.userId, "john.doe"),
+ new GroupId(GroupId.Type.self, null), "appId", "1", token)).andReturn(data);
+
replay();
- assertEquals(ResponseError.BAD_REQUEST, handler.handleDelete(request).getError());
+ assertEquals(data, handler.handleDelete(request));
verify();
}
}
\ No newline at end of file