Search in sources :

Example 6 with Device

use of com.google.samples.apps.iosched.server.gcm.db.models.Device in project iosched by google.

the class FcmSendEndpoint method sendSessionDataSync.

/**
 * Ping all users' devices to sync session data.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 */
@ApiMethod(name = "sendSessionDataSync", path = "sessions", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public void sendSessionDataSync(ServletContext context, User user) throws UnauthorizedException {
    validateServiceAccount(user);
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.getAllDevices();
    sender.multicastSend(devices, ACTION_SYNC_SCHEDULE, null);
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with Device

use of com.google.samples.apps.iosched.server.gcm.db.models.Device in project iosched by google.

the class FcmSendEndpoint method sendUserSync.

/**
 * Ping a user's devices to sync user data. This is likely called when the server makes
 * a change to user data and wants the corresponding user's clients to sync.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 * @param userId ID of the user whose devices should sync.
 * @return SendUserSyncResult which contains the number of devices pinged.
 */
@ApiMethod(name = "sendUserSync", path = "users/{userId}", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public SendUserSyncResult sendUserSync(ServletContext context, User user, @Named("userId") String userId) throws UnauthorizedException, NotFoundException {
    validateServiceAccount(user);
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.findDevicesByUserId(userId);
    if (devices.isEmpty()) {
        throw new NotFoundException("No devices for user found");
    }
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
    return new SendUserSyncResult(devices.size());
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) NotFoundException(com.google.api.server.spi.response.NotFoundException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 8 with Device

use of com.google.samples.apps.iosched.server.gcm.db.models.Device in project iosched by google.

the class FcmSendEndpoint method sendUserDataSync.

/**
 * Ping all users' devices to sync user data.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 */
@ApiMethod(name = "sendUserDataSync", path = "users", clientIds = { com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID })
public void sendUserDataSync(ServletContext context, User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException(INVALID_CREDENTIALS_MSG);
    }
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.getAllDevices();
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 9 with Device

use of com.google.samples.apps.iosched.server.gcm.db.models.Device in project iosched by google.

the class DeviceStore method unregister.

/**
 * Unregisters a device.
 *
 * @param deviceId device's registration id.
 */
public static void unregister(String deviceId) {
    Device device = findDeviceByDeviceId(deviceId);
    if (device == null) {
        LOG.warning("Device " + deviceId + " already unregistered");
        return;
    }
    LOG.info("Unregistering " + deviceId);
    ofy().delete().entity(device);
}
Also used : Device(com.google.samples.apps.iosched.server.gcm.db.models.Device)

Example 10 with Device

use of com.google.samples.apps.iosched.server.gcm.db.models.Device in project iosched by google.

the class DeviceStore method updateRegistration.

/**
 * Updates the registration id of a device.
 */
public static void updateRegistration(String oldDeviceId, String newDeviceId) {
    LOG.info("Updating " + oldDeviceId + " to " + newDeviceId);
    Device oldDevice = findDeviceByDeviceId(oldDeviceId);
    if (oldDevice == null) {
        LOG.warning("No device for registration id " + oldDeviceId);
        return;
    }
    // Device exists. Since we use the GCM key as the (immutable) primary key,
    // we must create a new entity.
    Device newDevice = new Device();
    newDevice.setDeviceId(newDeviceId);
    newDevice.setUserId(oldDevice.getUserId());
    ofy().save().entity(newDevice);
    ofy().delete().entity(oldDevice);
}
Also used : Device(com.google.samples.apps.iosched.server.gcm.db.models.Device)

Aggregations

Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)11 ApiMethod (com.google.api.server.spi.config.ApiMethod)6 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)6 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)3 BadRequestException (com.google.api.server.spi.response.BadRequestException)1 ForbiddenException (com.google.api.server.spi.response.ForbiddenException)1 NotFoundException (com.google.api.server.spi.response.NotFoundException)1 Queue (com.google.appengine.api.taskqueue.Queue)1 TaskOptions (com.google.appengine.api.taskqueue.TaskOptions)1 AuthInfo (com.google.samples.apps.iosched.server.gcm.AuthHelper.AuthInfo)1 NotFoundException (com.googlecode.objectify.NotFoundException)1 ArrayList (java.util.ArrayList)1