com.fabula.timeline.service.rest.impl
Class TimelineResource

java.lang.Object
  extended by com.fabula.timeline.service.rest.impl.TimelineResource

public class TimelineResource
extends java.lang.Object

REST services for Fabula Timeline Android Application.

Author:
andekr, andrstor

Constructor Summary
TimelineResource()
           
 
Method Summary
 void addUserToGroup(java.lang.String groupid, java.lang.String username)
          PUT
Adds a user to a group
URL: /group/{groupid}/user/{username}/
TODO: Register user if not registered
 Experiences GetAllExperiences()
          GET
Gets all experiences in server
URL: /experiences/
Gets all the experiences stored.
 Experiences GetAllExperiencesWithSharedEventsAndUsersMoodEvent(java.lang.String username)
          Helper method to retrieve all shared experiences of a user as well as the MoodEvents of the user.
 Mood getAverageMoodByID(java.lang.String experienceid)
          GET
Gets the average mood of an experience by ID
URL: /mood/id/{experienceid}/
Produces a JSON String with the average mood including valence and arousal.
 Mood getAverageMoodByName(java.lang.String title)
          GET
Gets the average mood of an experience by title
Note: Not as accurate as ID, and is case sensitive.
 java.lang.String getEvents()
          GET
Get events as String (Mainly for testing purposes)
URL: /events/
Produces toString of all events as String
 Experiences getExperiences(java.lang.String username)
          Helper method to retrieve all experiences of a user
 Group getGroup(java.lang.String groupid)
          GET
Gets the group with the id sent as parameter
URL: /group/{groupid}
Produces JSON or XML with group information.
 Groups getGroups()
          GET
Gets all the groups
URL: /groups/
Produces JSON or XML with list of all groups
 Groups getGroupsOfUser(java.lang.String username)
          GET
Gets the groups the user is member of
URL: /groups/{username}
Produces JSON or XML with list of groups the user is member of.
 java.lang.String getRabbitAverageMoodByName(java.lang.String title)
          A test method to satisfy input format(csv) for the Nabaztag rabbit.
 Experiences GetSharedExperiences(java.lang.String username)
          GET
Gets all experiences of a user
URL: /experiences/{username}
Takes username of the user to get experiences Produces the all experiences shared with the user as JSON or XML
 User getUser(java.lang.String username)
          GET
Gets the user with the username sent as parameter
URL: /user/{username}
Produces JSON or XML with user information.
 Users getUsers()
          GET
Gets all the users
URL: /users/ Produces JSON or XML with all users.
 java.lang.String isUserInGroup(java.lang.String groupid, java.lang.String username)
          GET
Gets if user is member in a group.
 void putEvent(Event event)
          PUT
Store or update one Event
URL: /event/
Consumes a complete event as JSON or XML and stores/updates in Google App Engine.
 void putExperience(Experience experience)
          PUT
Store or update one Experience
URL: /experience/
Consumes a complete experience as JSON or XML and stores/updates in Google App Engine.
 void putExperiences(Experiences experiences)
          PUT
Stores/updates all experiences in server URL: /experiences/
Stores all the experiences sent in.
 void putGroup(Group group)
          PUT
Registers a group
URL: /group/
Consumes a JSON or XML with the group information.
 void putMood(Mood mood, java.lang.String username, java.lang.String id)
          PUT
Inserts a mood to an experience
Uses experience id to identify experience
URL: /mood/id/{id}/{username}/{moodX}/{moodY}
Consumes a Mood as JSON or XML.
 void putMoodByID(java.lang.String id, java.lang.String username, double valence, double arousal)
          PUT
Inserts a mood to an experience only by parameters, and no content needed
Uses experience id to identify experience
Merely for testing.Should use the method taking in mood as JSON, not in parameters.
 void putMoodByName(java.lang.String title, java.lang.String username, double valence, double arousal)
          PUT
Inserts a mood to an experience only by parameters, and no content needed.
 void putUser(User user)
          PUT
Registers a user
URL: /user/
Consumes a JSON or XML with the user information.
 void removeGroup(java.lang.String groupid)
          DELETE
Deletes a group
URL: /group/{groupid}
Takes a group id as parameter.
 void removeUserFromGroup(java.lang.String groupid, java.lang.String username)
          DELETE
Removes a user form a group
URL: /group/{groupid}/user/{username}/
 void sendTimelineActivityReport(java.lang.String username)
          The resource to send Timeline Activity Report.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimelineResource

public TimelineResource()
Method Detail

putEvent

public void putEvent(Event event)
PUT
Store or update one Event
URL: /event/
Consumes a complete event as JSON or XML and stores/updates in Google App Engine. Requires that the "father-experience" is already registered.
Example of JSON:
{"eventItems":[ {"className":"SimpleNote", "creator":"anderskri@gmail.com", "id":"516733c5-ef9e-4324-bd93-ee204a582036", "noteText":"Examplenote","noteTitle":"Example"} ], "className":"Event", "creator":"anderskri@gmail.com", "experienceid":"a6a18076-9b96-4952-8bb6-cf56fee7b759", "id":"7f8189b9-11cf-4b8a-9456-29d9359f6dad", "latitude":63.40958633333333, "longitude":10.431676433333333, "valence":0.0, "arousal":0.0, "datetimemillis":1304362625287, "shared":true, "average":false }


getEvents

public java.lang.String getEvents()
GET
Get events as String (Mainly for testing purposes)
URL: /events/
Produces toString of all events as String


putExperience

public void putExperience(Experience experience)
PUT
Store or update one Experience
URL: /experience/
Consumes a complete experience as JSON or XML and stores/updates in Google App Engine. Also stores all children
Example of JSON:
{ "creator":"anderskri@gmail.com", "events":[ { "className":"MoodEvent", "creator":"anderskri@gmail.com", "datetimemillis":"1301556003782", "experienceid":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "id":"43799bf7-53fa-4acc-8045-0d8a0f29ea8b", "latitude":"63.41652448", "longitude":"10.4027416", "valence":"1.0", "arousal":"1.0", "shared":"false", "average":false }, { "className":"MoodEvent", "creator":"andrstor87@gmail.com", "datetimemillis":"1301556030401", "experienceid":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "id":"9689012d-520b-4bf1-b19f-06c1072f9f8b", "latitude":"63.4165383", "longitude":"10.40269734", "valence":"0.0", "arousal":"1.0", "shared":"false", "average":false }, { "className":"Event", "creator":"andrstor87@gmail.com", "datetimemillis":"1301556205024", "emotionList":[ { "emotionType":"LIKE", "emotionid":"22d08b27-0266-4561-8a16-96b86b099aa9" } ], "eventItems":[ { "className":"SimplePicture", "creator":"andrstor87@gmail.com", "filename":"-1779601815.jpg", "id":"91e0b5ba-a384-40b4-88ac-edecf8c28e91" }, { "className":"SimpleNote", "creator":"andrstor87@gmail.com", "id":"9b3dd9a7-ac7e-44e2-a62d-e6191c2a3aff", "noteText":"The most productive in the world.", "noteTitle":"My workplace" } ], "experienceid":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "id":"b05348b2-d827-4192-b153-c283ac251586", "latitude":"63.41654401", "longitude":"10.4027174", "valence":"0.0", "arousal":"0.0", "shared":"true", "average":false }, { "className":"Event", "creator":"anderskri@gmail.com", "datetimemillis":"1301564716999", "eventItems":[ { "className":"SimpleNote", "creator":"test@timelineapp.no", "id":"5c58f9ae-3f6a-4a79-b09e-a3ad9b58d26b", "noteText":"Finally Fabula is on Timeline!", "noteTitle":"Fabula on Timeline" } ], "experienceid":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "id":"adf77be1-fc8d-4a5b-b465-16c4d09a68f6", "latitude":"63.41654447", "longitude":"10.402711", "valence":"0.0", "arousal":"0.0", "shared":"true", "average":false }, { "className":"Event", "creator":"test@timelineapp.no", "datetimemillis":"1301567596334", "eventItems":[ { "className":"SimplePicture", "creator":"test@timelineapp.no", "filename":"1689419062.mp4", "id":"5fc3463d-31ef-42a4-8b5e-3ae5a9a58f57" } ], "experienceid":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "id":"76d46599-eda8-487d-a829-b5517bc6ab43", "latitude":"0.0", "longitude":"0.0", "valence":"0.0", "arousal":"0.0", "shared":"true", "average":false } ], "id":"4cfb71dc-30f6-47e5-829a-a21e08e568b9", "shared":"true", "sharingGroup":"4bbd7541-5c49-45e5-87c9-d75ac1e3a36a", "title":"Fabula" }


GetSharedExperiences

public Experiences GetSharedExperiences(java.lang.String username)
GET
Gets all experiences of a user
URL: /experiences/{username}
Takes username of the user to get experiences Produces the all experiences shared with the user as JSON or XML

Parameters:
username - The username of the user to get shared experiences from
Returns:
list of experiences wrapped in a Experiences object.

getExperiences

public Experiences getExperiences(java.lang.String username)
Helper method to retrieve all experiences of a user

Parameters:
username - The username of the user to get experiences from
Returns:
list of experiences wrapped in a Experiences object.

GetAllExperiencesWithSharedEventsAndUsersMoodEvent

public Experiences GetAllExperiencesWithSharedEventsAndUsersMoodEvent(java.lang.String username)
Helper method to retrieve all shared experiences of a user as well as the MoodEvents of the user.
This is a helper method used by the Timeline Activity Report Resource.

Parameters:
username - The username of the user to get experiences from
Returns:
list of experiences wrapped in a Experiences object.

GetAllExperiences

public Experiences GetAllExperiences()
GET
Gets all experiences in server
URL: /experiences/
Gets all the experiences stored. Mainly for testing and administrative purposes. Produces the all experiences as JSON or XML


putExperiences

public void putExperiences(Experiences experiences)
PUT
Stores/updates all experiences in server URL: /experiences/
Stores all the experiences sent in. Produces the all experiences as JSON or XML

Parameters:
experiences - Experiences to insert

putUser

public void putUser(User user)
PUT
Registers a user
URL: /user/
Consumes a JSON or XML with the user information. Currently only a username.
Example JSON:
{"username":"yourusername@mail.com"}

Parameters:
user - User to insert

getUser

public User getUser(java.lang.String username)
GET
Gets the user with the username sent as parameter
URL: /user/{username}
Produces JSON or XML with user information.

Parameters:
username - of user to get
Returns:
User the user with the username sent as parameter

getUsers

public Users getUsers()
GET
Gets all the users
URL: /users/ Produces JSON or XML with all users.
Example of returning JSON:
{"users":[{"username":"user1@gmail.com"},{"username":"user2@gmail.com"},{"username":"test@timelineapp.no"}]}

Returns:
Users the users

getGroup

public Group getGroup(java.lang.String groupid)
GET
Gets the group with the id sent as parameter
URL: /group/{groupid}
Produces JSON or XML with group information.

Parameters:
groupid - of group to get
Returns:
Group the group with the id sent as parameter

putGroup

public void putGroup(Group group)
PUT
Registers a group
URL: /group/
Consumes a JSON or XML with the group information. The JSON should contain at least one member(the creator).

Parameters:
group - The Group to register

removeGroup

public void removeGroup(java.lang.String groupid)
DELETE
Deletes a group
URL: /group/{groupid}
Takes a group id as parameter. Deletes the group with the given id. Returns a boolean as String of the status of the delete. Not implemented yet.

Parameters:
groupid - groupid of group to delete

getGroupsOfUser

public Groups getGroupsOfUser(java.lang.String username)
GET
Gets the groups the user is member of
URL: /groups/{username}
Produces JSON or XML with list of groups the user is member of.

Parameters:
username - of user to get groups from.
Returns:
Groups the user is member of.

getGroups

public Groups getGroups()
GET
Gets all the groups
URL: /groups/
Produces JSON or XML with list of all groups

Returns:
Groups the user is member of.

isUserInGroup

public java.lang.String isUserInGroup(java.lang.String groupid,
                                      java.lang.String username)
GET
Gets if user is member in a group. For testing purposes.
URL: /group/{groupid}/{username}/

Parameters:
groupid -
username -
Returns:
String true if user is in group

addUserToGroup

public void addUserToGroup(java.lang.String groupid,
                           java.lang.String username)
PUT
Adds a user to a group
URL: /group/{groupid}/user/{username}/
TODO: Register user if not registered

Parameters:
groupid - Id of group to add user to
username - username of already registered user

removeUserFromGroup

public void removeUserFromGroup(java.lang.String groupid,
                                java.lang.String username)
DELETE
Removes a user form a group
URL: /group/{groupid}/user/{username}/

Parameters:
groupid - id of group to remove user from
username - of user to remove

getAverageMoodByID

public Mood getAverageMoodByID(java.lang.String experienceid)
GET
Gets the average mood of an experience by ID
URL: /mood/id/{experienceid}/
Produces a JSON String with the average mood including valence and arousal.
Produces a Mood as JSON or XML. Example of JSON:
{"valence":"0.1", "arousal":"0.4"}
This is the preferred method to fetch the average mood.

Parameters:
experienceid - Experience id of the experience to get average mood from.
Returns:
averageMood The average Mood of the Experience

getAverageMoodByName

public Mood getAverageMoodByName(java.lang.String title)
GET
Gets the average mood of an experience by title
Note: Not as accurate as ID, and is case sensitive. Merely for testing.
URL: /mood/title/{title}/

Parameters:
title - title of the experience to get average mood from.
Returns:
averageMood The average Mood of the Experience

getRabbitAverageMoodByName

public java.lang.String getRabbitAverageMoodByName(java.lang.String title)
A test method to satisfy input format(csv) for the Nabaztag rabbit.

Parameters:
title -

putMoodByName

public void putMoodByName(java.lang.String title,
                          java.lang.String username,
                          double valence,
                          double arousal)
PUT
Inserts a mood to an experience only by parameters, and no content needed.
Uses experience title to identify experience. Merely for testing.
Should use the method taking in mood as JSON, not in parameters.

URL: /mood/title/{title}/{username}/{moodX}/{moodY}

Parameters:
title - of experience to insert mood
username - of user to set as creator
valence - Mood valence to insert. Double from 0 to 1.
arousal - Mood arousal to insert. Double from 0 to 1.

putMoodByID

public void putMoodByID(java.lang.String id,
                        java.lang.String username,
                        double valence,
                        double arousal)
PUT
Inserts a mood to an experience only by parameters, and no content needed
Uses experience id to identify experience
Merely for testing.Should use the method taking in mood as JSON, not in parameters.

URL: /mood/id/{id}/{username}/{moodX}/{moodY}

Parameters:
id - of experience to insert mood
username - of user to set as creator
valence - Mood valence to insert. Double from 0 to 1.
arousal - Mood arousal to insert. Double from 0 to 1.

putMood

public void putMood(Mood mood,
                    java.lang.String username,
                    java.lang.String id)
PUT
Inserts a mood to an experience
Uses experience id to identify experience
URL: /mood/id/{id}/{username}/{moodX}/{moodY}
Consumes a Mood as JSON or XML. Example of JSON:
{"valence":"0.1", "arousal":"0.4"}

Parameters:
id - of experience to insert mood
username - of user to set as creator
mood - The Mood to insert.

sendTimelineActivityReport

public void sendTimelineActivityReport(java.lang.String username)
The resource to send Timeline Activity Report.
Create a HTML e-mail containing the activity of the user sent as parameter.
Iterates all shared experiences, and adds them to the e-mail using the objects toString methods.
Sends the e-mail to the users e-mail(which is the username).

Parameters:
username - of the user to create and send activity report to.