Search in sources :

Example 46 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod 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 47 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod 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 48 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod 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 49 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod 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)

Example 50 with ApiMethod

use of com.google.api.server.spi.config.ApiMethod in project iosched by google.

the class UserdataEndpoint method addWaitlistedSession.

/**
 * Add a waitlisted session for the specified user. If the session is already in the user's feed,
 * it will be annotated with status=WAITLISTED.
 *
 * @param user         Service account making the request (injected by Endpoints)
 * @param userId       User ID of user that reserved a session.
 * @param sessionId    Session ID to mark as reserved.
 * @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 reserved sessions for the user
 */
@ApiMethod(name = "addWaitlistedSession", path = "reservations/waitlist", httpMethod = ApiMethod.HttpMethod.PUT, clientIds = { Ids.SERVICE_ACCOUNT_CLIENT_ID })
public Map<String, ReservedSession> addWaitlistedSession(User user, @Named("userId") String userId, @Named("sessionId") String sessionId, @Named("timestampUTC") long timestampUTC) throws UnauthorizedException {
    UserData data = getUser(user, userId);
    ReservedSession s = new ReservedSession(sessionId, Status.WAITLISTED, timestampUTC);
    data.reservedSessions.put(sessionId, s);
    save(data);
    // notify user's clients of reservation change change
    new GCMPing().notifyUserSync(data.userId);
    return data.reservedSessions;
}
Also used : GCMPing(com.google.samples.apps.iosched.server.schedule.server.GCMPing) ReservedSession(com.google.samples.apps.iosched.server.userdata.db.ReservedSession) UserData(com.google.samples.apps.iosched.server.userdata.db.UserData) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)54 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)19 Gson (com.google.gson.Gson)16 UserData (com.google.samples.apps.iosched.server.userdata.db.UserData)10 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)10 ArrayList (java.util.ArrayList)9 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)9 NotFoundException (com.google.api.server.spi.response.NotFoundException)8 BadRequestException (com.google.api.server.spi.response.BadRequestException)7 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)7 Queue (com.google.appengine.api.taskqueue.Queue)7 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)6 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)6 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)5 AppSettings (net.cryptonomica.entities.AppSettings)5 PGPPublicKeyGeneralView (net.cryptonomica.returns.PGPPublicKeyGeneralView)5 UserProfileGeneralView (net.cryptonomica.returns.UserProfileGeneralView)5 BookmarkedSession (com.google.samples.apps.iosched.server.userdata.db.BookmarkedSession)4 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)4 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4