Search in sources :

Example 6 with UserData

use of com.google.samples.apps.iosched.server.userdata.db.UserData in project iosched by google.

the class UserdataEndpoint method addReviewedSession.

/**
 * Mark a session as reviewed for the current user. This can not be unset.
 *
 * @param user      Current user (injected by Endpoints)
 * @param sessionId Session ID to mark as reviewed.
 * @return The list of reviewed sessions for the user (as an array of Strings)
 */
@ApiMethod(name = "addReviewedSession", path = "reviewed", httpMethod = ApiMethod.HttpMethod.PUT)
public Object[] addReviewedSession(User user, @Named("sessionId") String sessionId) throws UnauthorizedException {
    UserData data = getUser(user);
    data.reviewedSessions.add(sessionId);
    save(data);
    return data.reviewedSessions.toArray();
}
Also used : UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with UserData

use of com.google.samples.apps.iosched.server.userdata.db.UserData in project iosched by google.

the class UserdataEndpoint method removeBookmarkedSessions.

/**
 * Remove a bookmarked session for the current user. The session will still be
 * attached to the user's feed, but will be annotated with inSchedule=false.
 *
 * @param user          Current user (injected by Endpoints)
 * @param sessionIds    Session IDs to mark as not bookmarked.
 * @param timestampUTC  The time (in millis, UTC) when the user performed this action. May be
 *                      different than the time this method is called if offline sync is
 *                      implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 */
@ApiMethod(name = "removeBookmarkedSessions", path = "bookmarked/batch", httpMethod = ApiMethod.HttpMethod.DELETE)
public void removeBookmarkedSessions(User user, @Named("sessionIds") String[] sessionIds, @Named("timestampUTC") long timestampUTC) throws UnauthorizedException {
    UserData data = getUser(user);
    for (String session : sessionIds) {
        BookmarkedSession s = new BookmarkedSession(session, false, timestampUTC);
        data.bookmarkedSessions.put(session, s);
    }
    save(data);
}
Also used : BookmarkedSession(com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession) UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 8 with UserData

use of com.google.samples.apps.iosched.server.userdata.db.UserData in project iosched by google.

the class UserdataEndpoint method removeBookmarkedSession.

/**
 * Remove a bookmarked session for the current user. The session will still be
 * attached to the user's feed, but will be annotated with inSchedule=false.
 *
 * @param user         Current user (injected by Endpoints)
 * @param sessionId    Session ID to mark as not bookmarked.
 * @param timestampUTC The time (in millis, UTC) when the user performed this action. May be
 *                     different than the time this method is called if offline sync is
 *                     implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 */
@ApiMethod(name = "removeBookmarkedSession", path = "bookmarked", httpMethod = ApiMethod.HttpMethod.DELETE)
public void removeBookmarkedSession(User user, @Named("sessionId") String sessionId, @Named("timestampUTC") long timestampUTC) throws UnauthorizedException {
    UserData data = getUser(user);
    BookmarkedSession s = new BookmarkedSession(sessionId, false, timestampUTC);
    data.bookmarkedSessions.put(sessionId, s);
    save(data);
}
Also used : BookmarkedSession(com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession) UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 9 with UserData

use of com.google.samples.apps.iosched.server.userdata.db.UserData in project iosched by google.

the class UserdataEndpoint method updateUser.

/**
 * Batch update user data
 *
 * @param user Current user (injected by Endpoints)
 * @param userData UserData object with new values to save
 * @return Updated UserData object
 */
// http://b.android.com/201031
@SuppressWarnings("ResourceParameter")
@ApiMethod(name = "updateUser", path = "all", httpMethod = ApiMethod.HttpMethod.PUT)
public UserData updateUser(User user, UserData userData) throws UnauthorizedException {
    UserData savedData = getUser(user);
    // Bookmarked sessions can be overwritten
    savedData.bookmarkedSessions = userData.bookmarkedSessions;
    // Reviewed sessions should be merged with old values
    for (String session : userData.reviewedSessions) {
        savedData.reviewedSessions.add(session);
    }
    // We don't allow clients to update reserved sessions, preserve old values
    save(savedData);
    return savedData;
}
Also used : UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 10 with UserData

use of com.google.samples.apps.iosched.server.userdata.db.UserData in project iosched by google.

the class UserdataEndpoint method addBookmarkedSession.

/**
 * Add a bookmarked session for the current user. If the session is already in the user's feed,
 * it will be annotated with inSchedule=true.
 *
 * @param user         Current user (injected by Endpoints)
 * @param sessionId    Session ID to mark as bookmarked.
 * @param timestampUTC The time (in millis, UTC) when the user performed this action. May be
 *                     different than the time this method is called if offline sync is
 *                     implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 * @return The list of bookmarked sessions for the user
 */
@ApiMethod(name = "addBookmarkedSession", path = "bookmarked", httpMethod = ApiMethod.HttpMethod.PUT)
public Map<String, BookmarkedSession> addBookmarkedSession(User user, @Named("sessionId") String sessionId, @Named("timestampUTC") long timestampUTC) throws UnauthorizedException {
    UserData data = getUser(user);
    BookmarkedSession s = new BookmarkedSession(sessionId, true, timestampUTC);
    data.bookmarkedSessions.put(sessionId, s);
    save(data);
    return data.bookmarkedSessions;
}
Also used : BookmarkedSession(com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession) UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

UserData (com.google.samples.apps.iosched.server.userdata.db.UserData)11 ApiMethod (com.google.api.server.spi.config.ApiMethod)10 BookmarkedSession (com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession)4 ReservedSession (com.google.samples.apps.iosched.server.userdata.db.ReservedSession)4 GCMPing (com.google.samples.apps.iosched.server.schedule.server.GCMPing)3 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Status (com.google.samples.apps.iosched.server.userdata.db.ReservedSession.Status)1 NotFoundException (com.googlecode.objectify.NotFoundException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1