org.apache.shindig.social.sample.spi
Class JsonDbOpensocialService

java.lang.Object
  extended by org.apache.shindig.social.sample.spi.JsonDbOpensocialService
All Implemented Interfaces:
ActivityService, AlbumService, AppDataService, GroupService, MediaItemService, MessageService, PersonService

public class JsonDbOpensocialService
extends Object
implements ActivityService, PersonService, AppDataService, MessageService, AlbumService, MediaItemService, GroupService

Implementation of supported services backed by a JSON DB.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.shindig.social.opensocial.spi.MessageService
MessageService.NotImplementedMessageService
 
Nested classes/interfaces inherited from interface org.apache.shindig.social.opensocial.spi.AlbumService
AlbumService.NotImplementedAlbumService
 
Nested classes/interfaces inherited from interface org.apache.shindig.social.opensocial.spi.MediaItemService
MediaItemService.NotImplementedMediaItemService
 
Field Summary
 
Fields inherited from interface org.apache.shindig.social.opensocial.spi.PersonService
ALL_FILTER, HAS_APP_FILTER, IS_WITH_FRIENDS_FILTER, TOP_FRIENDS_FILTER, TOP_FRIENDS_SORT
 
Constructor Summary
JsonDbOpensocialService(String jsonLocation, BeanConverter converter)
          Initializes the JsonDbOpensocialService using Guice
 
Method Summary
 Future<Void> createActivity(UserId userId, GroupId groupId, String appId, Set<String> fields, Activity activity, SecurityToken token)
          Creates the passed in activity for the passed in user and group.
 Future<Void> createAlbum(UserId userId, String appId, Album album, SecurityToken token)
          
 Future<Void> createMediaItem(UserId userId, String appId, String albumId, MediaItem mediaItem, SecurityToken token)
          
 Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token)
          Posts a message to the user's specified message collection, to be sent to the set of recipients specified in the message.
 Future<MessageCollection> createMessageCollection(UserId userId, MessageCollection msgCollection, SecurityToken token)
          Creates a new message collection for the given arguments
 Future<Void> deleteActivities(UserId userId, GroupId groupId, String appId, Set<String> activityIds, SecurityToken token)
          Deletes the activity for the passed in user and group that corresponds to the activityId.
 Future<Void> deleteAlbum(UserId userId, String appId, String albumId, SecurityToken token)
          
 Future<Void> deleteMediaItem(UserId userId, String appId, String albumId, String mediaItemId, SecurityToken token)
          
 Future<Void> deleteMessageCollection(UserId userId, String msgCollId, SecurityToken token)
          Deletes a message collection for the given arguments
 Future<Void> deleteMessages(UserId userId, String msgCollId, List<String> ids, SecurityToken token)
          Deletes a set of messages for a given user/message collection
 Future<Void> deletePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields, SecurityToken token)
          Deletes data for the specified user and group.
<T> T
filterFields(org.json.JSONObject object, Set<String> fields, Class<T> clz)
           
 Future<RestfulCollection<Activity>> getActivities(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions options, SecurityToken token)
          Returns a list of activities that correspond to the passed in users and group.
 Future<RestfulCollection<Activity>> getActivities(UserId userId, GroupId groupId, String appId, Set<String> fields, CollectionOptions options, Set<String> activityIds, SecurityToken token)
          Returns a set of activities for the passed in user and group that corresponds to a list of activityIds.
 Future<Activity> getActivity(UserId userId, GroupId groupId, String appId, Set<String> fields, String activityId, SecurityToken token)
          Returns an activity for the passed in user and group that corresponds to a single activityId.
 Future<Album> getAlbum(UserId userId, String appId, Set<String> fields, String albumId, SecurityToken token)
          
 Future<RestfulCollection<Album>> getAlbums(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions options, SecurityToken token)
          
 Future<RestfulCollection<Album>> getAlbums(UserId userId, String appId, Set<String> fields, CollectionOptions options, Set<String> albumIds, SecurityToken token)
          
 org.json.JSONObject getDb()
          Allows access to the underlying json db.
 Future<RestfulCollection<Group>> getGroups(UserId userId, CollectionOptions options, Set<String> fields, SecurityToken token)
           
 Set<String> getIdSet(Set<UserId> users, GroupId group, SecurityToken token)
          Get the set of user id's for a set of users and a group
 Future<MediaItem> getMediaItem(UserId userId, String appId, String albumId, String mediaItemId, Set<String> fields, SecurityToken token)
          
 Future<RestfulCollection<MediaItem>> getMediaItems(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions options, SecurityToken token)
          
 Future<RestfulCollection<MediaItem>> getMediaItems(UserId userId, String appId, String albumId, Set<String> fields, CollectionOptions options, SecurityToken token)
          
 Future<RestfulCollection<MediaItem>> getMediaItems(UserId userId, String appId, String albumId, Set<String> mediaItemIds, Set<String> fields, CollectionOptions options, SecurityToken token)
          
 Future<RestfulCollection<MessageCollection>> getMessageCollections(UserId userId, Set<String> fields, CollectionOptions options, SecurityToken token)
          Returns a list of message collections corresponding to the given user
 Future<RestfulCollection<Message>> getMessages(UserId userId, String msgCollId, Set<String> fields, List<String> msgIds, CollectionOptions options, SecurityToken token)
          Returns a list of messages that correspond to the passed in data
 String getPassword(String username)
          Public methods for use with Authentication Classes
 Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds, GroupId groupId, CollectionOptions options, Set<String> fields, SecurityToken token)
          Returns a list of people that correspond to the passed in person ids.
 Future<Person> getPerson(UserId id, Set<String> fields, SecurityToken token)
          Returns a person that corresponds to the passed in person id.
 Future<DataCollection> getPersonData(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, SecurityToken token)
          Retrives app data for the specified user list and group.
 Future<Void> modifyMessage(UserId userId, String msgCollId, String messageId, Message message, SecurityToken token)
          Modifies/Updates a specific message with new data
 Future<Void> modifyMessageCollection(UserId userId, MessageCollection msgCollection, SecurityToken token)
          Modifies/Updates a message collection for the given arguments
 void setDb(org.json.JSONObject db)
          override the json database
 Future<Void> updateAlbum(UserId userId, String appId, Album album, String albumId, SecurityToken token)
          
 Future<Void> updateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken token)
          
 Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields, Map<String,String> values, SecurityToken token)
          Updates app data for the specified user and group with the new values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonDbOpensocialService

@Inject
public JsonDbOpensocialService(String jsonLocation,
                                      BeanConverter converter)
                        throws Exception
Initializes the JsonDbOpensocialService using Guice

Parameters:
jsonLocation - location of the json data provided by the shindig.canonical.json.db parameter
converter - an injected BeanConverter
Throws:
Exception - if any
Method Detail

getDb

public org.json.JSONObject getDb()
Allows access to the underlying json db.

Returns:
a reference to the json db

setDb

public void setDb(org.json.JSONObject db)
override the json database

Parameters:
db - a JSONObject.

getActivities

public Future<RestfulCollection<Activity>> getActivities(Set<UserId> userIds,
                                                         GroupId groupId,
                                                         String appId,
                                                         Set<String> fields,
                                                         CollectionOptions options,
                                                         SecurityToken token)
                                                  throws ProtocolException
Returns a list of activities that correspond to the passed in users and group.

Specified by:
getActivities in interface ActivityService
Parameters:
userIds - The set of ids of the people to fetch activities for.
groupId - Indicates whether to fetch activities for a group.
appId - The app id.
fields - The fields to return. Empty set implies all
options - The sorting/filtering/pagination options
token - A valid SecurityToken
Returns:
a response item with the list of activities.
Throws:
ProtocolException

getActivities

public Future<RestfulCollection<Activity>> getActivities(UserId userId,
                                                         GroupId groupId,
                                                         String appId,
                                                         Set<String> fields,
                                                         CollectionOptions options,
                                                         Set<String> activityIds,
                                                         SecurityToken token)
                                                  throws ProtocolException
Returns a set of activities for the passed in user and group that corresponds to a list of activityIds.

Specified by:
getActivities in interface ActivityService
Parameters:
userId - The set of ids of the people to fetch activities for.
groupId - Indicates whether to fetch activities for a group.
appId - The app id.
fields - The fields to return. Empty set implies all
options - The sorting/filtering/pagination options
activityIds - The set of activity ids to fetch.
token - A valid SecurityToken
Returns:
a response item with the list of activities.
Throws:
ProtocolException

getActivity

public Future<Activity> getActivity(UserId userId,
                                    GroupId groupId,
                                    String appId,
                                    Set<String> fields,
                                    String activityId,
                                    SecurityToken token)
                             throws ProtocolException
Returns an activity for the passed in user and group that corresponds to a single activityId.

Specified by:
getActivity in interface ActivityService
Parameters:
userId - The set of ids of the people to fetch activities for.
groupId - Indicates whether to fetch activities for a group.
appId - The app id.
fields - The fields to return. Empty set implies all
activityId - The activity id to fetch.
token - A valid SecurityToken
Returns:
a response item with the list of activities.
Throws:
ProtocolException

deleteActivities

public Future<Void> deleteActivities(UserId userId,
                                     GroupId groupId,
                                     String appId,
                                     Set<String> activityIds,
                                     SecurityToken token)
                              throws ProtocolException
Deletes the activity for the passed in user and group that corresponds to the activityId.

Specified by:
deleteActivities in interface ActivityService
Parameters:
userId - The user.
groupId - The group.
appId - The app id.
activityIds - A list of activity ids to delete.
token - A valid SecurityToken.
Returns:
a response item containing any errors
Throws:
ProtocolException

createActivity

public Future<Void> createActivity(UserId userId,
                                   GroupId groupId,
                                   String appId,
                                   Set<String> fields,
                                   Activity activity,
                                   SecurityToken token)
                            throws ProtocolException
Creates the passed in activity for the passed in user and group. Once createActivity is called, getActivities will be able to return the Activity.

Specified by:
createActivity in interface ActivityService
Parameters:
userId - The id of the person to create the activity for.
groupId - The group.
appId - The app id.
fields - The fields to return.
activity - The activity to create.
token - A valid SecurityToken
Returns:
a response item containing any errors
Throws:
ProtocolException

getPeople

public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds,
                                                   GroupId groupId,
                                                   CollectionOptions options,
                                                   Set<String> fields,
                                                   SecurityToken token)
                                            throws ProtocolException
Returns a list of people that correspond to the passed in person ids.

Specified by:
getPeople in interface PersonService
Parameters:
userIds - A set of users
groupId - The group
options - How to filter, sort and paginate the collection being fetched
fields - The profile details to fetch. Empty set implies all
token - The gadget token @return a list of people.
Returns:
Future that returns a RestfulCollection of Person
Throws:
ProtocolException

getPerson

public Future<Person> getPerson(UserId id,
                                Set<String> fields,
                                SecurityToken token)
                         throws ProtocolException
Returns a person that corresponds to the passed in person id.

Specified by:
getPerson in interface PersonService
Parameters:
id - The id of the person to fetch.
fields - The fields to fetch.
token - The gadget token
Returns:
a list of people.
Throws:
ProtocolException

getPersonData

public Future<DataCollection> getPersonData(Set<UserId> userIds,
                                            GroupId groupId,
                                            String appId,
                                            Set<String> fields,
                                            SecurityToken token)
                                     throws ProtocolException
Retrives app data for the specified user list and group.

Specified by:
getPersonData in interface AppDataService
Parameters:
userIds - A set of UserIds.
groupId - The group
appId - The app
fields - The fields to filter the data by. Empty set implies all
token - The security token
Returns:
The data fetched
Throws:
ProtocolException

deletePersonData

public Future<Void> deletePersonData(UserId userId,
                                     GroupId groupId,
                                     String appId,
                                     Set<String> fields,
                                     SecurityToken token)
                              throws ProtocolException
Deletes data for the specified user and group.

Specified by:
deletePersonData in interface AppDataService
Parameters:
userId - The user
groupId - The group
appId - The app
fields - The fields to delete. Empty set implies all
token - The security token
Returns:
an error if one occurs
Throws:
ProtocolException

updatePersonData

public Future<Void> updatePersonData(UserId userId,
                                     GroupId groupId,
                                     String appId,
                                     Set<String> fields,
                                     Map<String,String> values,
                                     SecurityToken token)
                              throws ProtocolException
Updates app data for the specified user and group with the new values.

Specified by:
updatePersonData in interface AppDataService
Parameters:
userId - The user
groupId - The group
appId - The app
fields - The fields to filter the data by. Empty set implies all
values - The values to set
token - The security token
Returns:
an error if one occurs
Throws:
ProtocolException

createMessage

public Future<Void> createMessage(UserId userId,
                                  String appId,
                                  String msgCollId,
                                  Message message,
                                  SecurityToken token)
                           throws ProtocolException
Posts a message to the user's specified message collection, to be sent to the set of recipients specified in the message. Post a message for a set of users.

Specified by:
createMessage in interface MessageService
Parameters:
userId - The user posting the message.
appId - The app id
msgCollId - The message collection Id to post to, default @outbox
message - The message to post
token - A valid security token @return a response item containing any errors/
Returns:
Void Future
Throws:
ProtocolException - when invalid parameters are given

getMessageCollections

public Future<RestfulCollection<MessageCollection>> getMessageCollections(UserId userId,
                                                                          Set<String> fields,
                                                                          CollectionOptions options,
                                                                          SecurityToken token)
                                                                   throws ProtocolException
Returns a list of message collections corresponding to the given user

Specified by:
getMessageCollections in interface MessageService
Parameters:
userId - The User to fetch for
fields - The fields to fetch for the message collections
options - Pagination, etal
token - Given security token for this request
Returns:
a collection of message collections.
Throws:
ProtocolException - when invalid parameters are given

deleteMessages

public Future<Void> deleteMessages(UserId userId,
                                   String msgCollId,
                                   List<String> ids,
                                   SecurityToken token)
                            throws ProtocolException
Deletes a set of messages for a given user/message collection

Specified by:
deleteMessages in interface MessageService
Parameters:
userId - The User to delete for
msgCollId - The Message Collection ID to delete from, default @all
ids - List of IDs to delete
token - Given Security Token for this request
Returns:
Future
Throws:
ProtocolException

getMessages

public Future<RestfulCollection<Message>> getMessages(UserId userId,
                                                      String msgCollId,
                                                      Set<String> fields,
                                                      List<String> msgIds,
                                                      CollectionOptions options,
                                                      SecurityToken token)
                                               throws ProtocolException
Returns a list of messages that correspond to the passed in data Gets the messsages in an user's queue.

Specified by:
getMessages in interface MessageService
Parameters:
userId - The User to fetch for
msgCollId - The message Collection ID to fetch from, default @all
fields - The fields to fetch for the messages
msgIds - An explicit set of message ids to fetch
options - Options to control the fetch
token - Given security token for this request
Returns:
a collection of messages
Throws:
ProtocolException - when invalid parameters are given

createMessageCollection

public Future<MessageCollection> createMessageCollection(UserId userId,
                                                         MessageCollection msgCollection,
                                                         SecurityToken token)
                                                  throws ProtocolException
Creates a new message collection for the given arguments

Specified by:
createMessageCollection in interface MessageService
Parameters:
userId - The userId to create the message collection for
msgCollection - A message collection that is to be created
token - A security token for this request
Returns:
Data for the message collection that is created
Throws:
ProtocolException - when invalid parameters are given or not implemented

modifyMessage

public Future<Void> modifyMessage(UserId userId,
                                  String msgCollId,
                                  String messageId,
                                  Message message,
                                  SecurityToken token)
                           throws ProtocolException
Modifies/Updates a specific message with new data

Specified by:
modifyMessage in interface MessageService
Parameters:
userId - The User to modify for
msgCollId - The Message Collection ID to modify from, default @all
messageId - The messageId to modify
message - The message details to modify
token - Given Security Token for this request
Returns:
Future
Throws:
ProtocolException - for invalid parameters or missing messages or users

modifyMessageCollection

public Future<Void> modifyMessageCollection(UserId userId,
                                            MessageCollection msgCollection,
                                            SecurityToken token)
                                     throws ProtocolException
Modifies/Updates a message collection for the given arguments

Specified by:
modifyMessageCollection in interface MessageService
Parameters:
userId - The userId to modify the message collection for
msgCollection - Data for the message collection to be modified
token - A security token for this request
Throws:
ProtocolException - when invalid parameters are given or not implemented

deleteMessageCollection

public Future<Void> deleteMessageCollection(UserId userId,
                                            String msgCollId,
                                            SecurityToken token)
                                     throws ProtocolException
Deletes a message collection for the given arguments

Specified by:
deleteMessageCollection in interface MessageService
Parameters:
userId - The userId to create the message collection for
msgCollId - Data for the message collection to be modified
token - A security token for this request
Returns:
Future
Throws:
ProtocolException - when invalid parameters are given, the message collection does not exist or not implemented

getPassword

public String getPassword(String username)
Public methods for use with Authentication Classes

Parameters:
username - a String object.
Returns:
a String object.

getIdSet

public Set<String> getIdSet(Set<UserId> users,
                            GroupId group,
                            SecurityToken token)
                     throws org.json.JSONException
Get the set of user id's for a set of users and a group

Parameters:
users - set of UserIds
group - the group
token - a token
Returns:
set of Id strings
Throws:
org.json.JSONException - if errors in Json

getAlbum

public Future<Album> getAlbum(UserId userId,
                              String appId,
                              Set<String> fields,
                              String albumId,
                              SecurityToken token)
                       throws ProtocolException

Specified by:
getAlbum in interface AlbumService
Throws:
ProtocolException

getAlbums

public Future<RestfulCollection<Album>> getAlbums(UserId userId,
                                                  String appId,
                                                  Set<String> fields,
                                                  CollectionOptions options,
                                                  Set<String> albumIds,
                                                  SecurityToken token)
                                           throws ProtocolException

Specified by:
getAlbums in interface AlbumService
Throws:
ProtocolException

getAlbums

public Future<RestfulCollection<Album>> getAlbums(Set<UserId> userIds,
                                                  GroupId groupId,
                                                  String appId,
                                                  Set<String> fields,
                                                  CollectionOptions options,
                                                  SecurityToken token)
                                           throws ProtocolException

Specified by:
getAlbums in interface AlbumService
Throws:
ProtocolException

deleteAlbum

public Future<Void> deleteAlbum(UserId userId,
                                String appId,
                                String albumId,
                                SecurityToken token)
                         throws ProtocolException

Specified by:
deleteAlbum in interface AlbumService
Throws:
ProtocolException

createAlbum

public Future<Void> createAlbum(UserId userId,
                                String appId,
                                Album album,
                                SecurityToken token)
                         throws ProtocolException

Specified by:
createAlbum in interface AlbumService
Throws:
ProtocolException

updateAlbum

public Future<Void> updateAlbum(UserId userId,
                                String appId,
                                Album album,
                                String albumId,
                                SecurityToken token)
                         throws ProtocolException

Specified by:
updateAlbum in interface AlbumService
Throws:
ProtocolException

getMediaItem

public Future<MediaItem> getMediaItem(UserId userId,
                                      String appId,
                                      String albumId,
                                      String mediaItemId,
                                      Set<String> fields,
                                      SecurityToken token)
                               throws ProtocolException

Specified by:
getMediaItem in interface MediaItemService
Throws:
ProtocolException

getMediaItems

public Future<RestfulCollection<MediaItem>> getMediaItems(UserId userId,
                                                          String appId,
                                                          String albumId,
                                                          Set<String> mediaItemIds,
                                                          Set<String> fields,
                                                          CollectionOptions options,
                                                          SecurityToken token)
                                                   throws ProtocolException

Specified by:
getMediaItems in interface MediaItemService
Throws:
ProtocolException

getMediaItems

public Future<RestfulCollection<MediaItem>> getMediaItems(UserId userId,
                                                          String appId,
                                                          String albumId,
                                                          Set<String> fields,
                                                          CollectionOptions options,
                                                          SecurityToken token)
                                                   throws ProtocolException

Specified by:
getMediaItems in interface MediaItemService
Throws:
ProtocolException

getMediaItems

public Future<RestfulCollection<MediaItem>> getMediaItems(Set<UserId> userIds,
                                                          GroupId groupId,
                                                          String appId,
                                                          Set<String> fields,
                                                          CollectionOptions options,
                                                          SecurityToken token)
                                                   throws ProtocolException

Specified by:
getMediaItems in interface MediaItemService
Throws:
ProtocolException

deleteMediaItem

public Future<Void> deleteMediaItem(UserId userId,
                                    String appId,
                                    String albumId,
                                    String mediaItemId,
                                    SecurityToken token)
                             throws ProtocolException

Specified by:
deleteMediaItem in interface MediaItemService
Throws:
ProtocolException

createMediaItem

public Future<Void> createMediaItem(UserId userId,
                                    String appId,
                                    String albumId,
                                    MediaItem mediaItem,
                                    SecurityToken token)
                             throws ProtocolException

Specified by:
createMediaItem in interface MediaItemService
Throws:
ProtocolException

updateMediaItem

public Future<Void> updateMediaItem(UserId userId,
                                    String appId,
                                    String albumId,
                                    String mediaItemId,
                                    MediaItem mediaItem,
                                    SecurityToken token)
                             throws ProtocolException

Specified by:
updateMediaItem in interface MediaItemService
Throws:
ProtocolException

filterFields

public <T> T filterFields(org.json.JSONObject object,
                          Set<String> fields,
                          Class<T> clz)
               throws org.json.JSONException
Throws:
org.json.JSONException

getGroups

public Future<RestfulCollection<Group>> getGroups(UserId userId,
                                                  CollectionOptions options,
                                                  Set<String> fields,
                                                  SecurityToken token)
Specified by:
getGroups in interface GroupService
Parameters:
userId - a userId object
options - search/sort/filtering options
fields - Field search/sort
token - a valid security token
Returns:
a collection of groups for a specific userId


Copyright © 2007-2012. All Rights Reserved.