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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations