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/05/06 14:00:56 UTC
svn commit: r653756 -
/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
Author: doll
Date: Tue May 6 05:00:55 2008
New Revision: 653756
URL: http://svn.apache.org/viewvc?rev=653756&view=rev
Log:
SHINDIG-238
Patch from David Primmer. Cleans up the social api provider to use enums and specify all accepted urls.
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java?rev=653756&r1=653755&r2=653756&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/abdera/SocialApiProvider.java Tue May 6 05:00:55 2008
@@ -26,11 +26,51 @@
public class SocialApiProvider extends DefaultProvider {
//TODO why is this hardcoded here. can't this be from servletContext?
private static final String BASE = "/social/rest/";
- private static final String ROUTENAME_NOT_USED = "not_used_right_now";
private Provider<PeopleServiceAdapter> peopleAdapterProvider;
private Provider<ActivitiesServiceAdapter> activitiesAdapterProvider;
+ /**
+ * The CollectionAdapter enum standardizes the names and descriptions of the
+ * URL templates as defined in the RESTful API spec. Each unique template has
+ * a corresponding CollectionAdapter. For example, "/people/{uid}/@all" is
+ * roughly translated in English to read "Profiles of Connections of User" and
+ * is the referred to in the code as PROFILES_OF_CONNECTIONS_OF_USER. The
+ * descriptions can be customized by an implementer and used as the titles for
+ * feeds.
+ * TODO: Add ResourceBundle functions.
+ */
+ public enum CollectionAdapter {
+ //People
+ PROFILES_OF_CONNECTIONS_OF_USER("Profiles of Connections of User"),
+ PROFILES_OF_FRIENDS_OF_USER("Profiles of Friends of User"),
+ CONNECTIONS_OF_USER("Connections of User"),
+ PROFILE_OF_CONNECTION_OF_USER("Profile of Connection of User"),
+ PROFILE_OF_USER("Profile of User"),
+ //Activities
+ ACTIVITIES_OF_USER("Activities of User"),
+ ACTIVITIES_OF_FRIENDS_OF_USER("Activities of Friends of User"),
+ ACTIVITIES_OF_GROUP_OF_USER("Activities of Group of User"),
+ ACTIVITY_OF_USER("Activity of User"),
+ //AppData
+ APPDATA_OF_APP_OF_USER("AppData of App of User"),
+ APPDATA_OF_FRIENDS_OF_USER("AppData of Friends of User");
+
+ private String description;
+
+ private CollectionAdapter(String description) {
+ this.description = description;
+ }
+
+ public String toString() {
+ return description;
+ }
+
+ public static CollectionAdapter getValue(String value) {
+ return valueOf(value.replaceAll(" ", "_").toUpperCase());
+ }
+ }
+
@Inject
public void setPeopleAdapter(Provider<PeopleServiceAdapter>
peopleAdapterProvider) {
@@ -43,47 +83,103 @@
this.activitiesAdapterProvider = activitiesAdapterProvider;
}
+ /**
+ * CollectionAdapters are provided via Guice and the RouteManager wires
+ * together the Routes, their TargetTypes and CollectionAdapters.
+ *
+ * TODO: Create one CollectionAdapter per URL. There is currently logic in the
+ * People and Activities Adapters that allows them to be multi-purpose, but
+ * this will need to change.
+ *
+ * TODO: Fully implement all routes in the 0.8 RESTful API spec.
+ * They are specified here, but only some produce output from the server.
+ * Currently implemented:
+ * /people/{uid}/@all
+ * /people/{uid}/@all/{pid}
+ * /people/{uid}/@self
+ * /activities/{uid}/@self/{aid}
+ * /activities/{uid}/@self
+ */
public void initialize() {
PeopleServiceAdapter peopleAdapter = peopleAdapterProvider.get();
ActivitiesServiceAdapter activitiesAdapter
= activitiesAdapterProvider.get();
// Add the RouteManager that parses incoming and builds outgoing URLs
+ // {uid} is assumed to be a deterministic GUID for the service
routeManager = new RouteManager()
+ // People
- // Collection of all people connected to user {uid}
- // /people/{uid}/@all
- .addRoute(ROUTENAME_NOT_USED,
+ // Collection of all people connected to user {uid}
+ // /people/{uid}/@all
+ .addRoute(CollectionAdapter.CONNECTIONS_OF_USER.toString(),
BASE + "people/:uid/@all",
- TargetType.TYPE_COLLECTION,
- peopleAdapter)
+ TargetType.TYPE_COLLECTION, peopleAdapter)
+
+ // Collection of all friends of user {uid}; subset of all
+ // /people/{uid}/@friends
+ .addRoute(CollectionAdapter.PROFILES_OF_FRIENDS_OF_USER.toString(),
+ BASE + "people/:uid/@friends",
+ TargetType.TYPE_COLLECTION, peopleAdapter)
+
+ // Collection of all people connected to user {uid} in group {groupid}
+ // /people/{uid}/{groupid}
+ .addRoute(CollectionAdapter.PROFILES_OF_CONNECTIONS_OF_USER.toString(),
+ BASE + "people/:uid/:groupid",
+ TargetType.TYPE_COLLECTION, peopleAdapter)
+
+ // Individual person record. /people/{uid}/@all/{pid}
+ .addRoute(CollectionAdapter.PROFILE_OF_CONNECTION_OF_USER.toString(),
+ BASE + "people/:uid/@all/:pid",
+ TargetType.TYPE_ENTRY, peopleAdapter)
+
+ // Self Profile record for user {uid} /people/{uid}/@self
+ .addRoute(CollectionAdapter.PROFILE_OF_USER.toString(),
+ BASE + "people/:uid/@self",
+ TargetType.TYPE_ENTRY, peopleAdapter)
+
+
+ // Activities
+
+ // Collection of activities for given user /activities/{uid}/@self
+ .addRoute(CollectionAdapter.ACTIVITIES_OF_USER.toString(),
+ BASE + "activities/:uid/@self",
+ TargetType.TYPE_COLLECTION, activitiesAdapter)
+
+ // Collection of activities for friends of the given user {uid}
+ // /activities/{uid}/@friends
+ .addRoute(CollectionAdapter.ACTIVITIES_OF_FRIENDS_OF_USER.toString(),
+ BASE + "activities/:uid/@friends",
+ TargetType.TYPE_COLLECTION, activitiesAdapter)
+
+ // Collection of activities for people in group {groupid}
+ // belonging to given user {uid} -- /activities/{uid}/{groupid}
+ .addRoute(CollectionAdapter.ACTIVITIES_OF_GROUP_OF_USER.toString(),
+ BASE + "activities/:uid/:groupid",
+ TargetType.TYPE_COLLECTION, activitiesAdapter)
+
+ // Individual activity resource; usually discovered from collection
+ // /activities/{uid}/@self/{aid}
+ .addRoute(CollectionAdapter.ACTIVITY_OF_USER.toString(),
+ BASE + "activities/:uid/@self/:aid",
+ TargetType.TYPE_ENTRY, activitiesAdapter)
+
+
+ // AppData
+
+ // Individual App Data record for a given user+app, consisting primarily
+ // of a bag of key/value pairs. -- /appdata/{uid}/self/{aid}
+ .addRoute(CollectionAdapter.APPDATA_OF_APP_OF_USER.toString(),
+ BASE + "appdata/:uid/self/:aid",
+ TargetType.TYPE_ENTRY, null)
+
+ // Collection of App Data records for friends of {uid}
+ // /appdata/{uid}/friends/{aid}
+ .addRoute(CollectionAdapter.APPDATA_OF_FRIENDS_OF_USER.toString(),
+ BASE + "appdata/:uid/friends/:aid",
+ TargetType.TYPE_COLLECTION, null)
- // Individual person record. /people/{uid}/@all/{pid}
- .addRoute(ROUTENAME_NOT_USED,
- BASE + "people/:uid/@all/:pid",
- TargetType.TYPE_ENTRY,
- peopleAdapter)
-
- // Self Profile record for user {uid} /people/{uid}/@self
- .addRoute(ROUTENAME_NOT_USED,
- BASE + "people/:uid/@self",
- TargetType.TYPE_ENTRY,
- peopleAdapter)
-
- // Activities
- // Collection of activities for given user /activities/{uid}/@self
- .addRoute(ROUTENAME_NOT_USED,
- BASE + "activities/:uid/@self",
- TargetType.TYPE_COLLECTION,
- activitiesAdapter)
-
- // Individual activity resource; usually discovered from collection
- // /activities/{uid}/@self/{aid}
- .addRoute(ROUTENAME_NOT_USED,
- BASE + "activities/:uid/@self/:aid",
- TargetType.TYPE_ENTRY,
- activitiesAdapter)
- ;
+ ;
targetBuilder = routeManager;
targetResolver = routeManager;