@Test public void testRegisterDevice() throws Exception { final User user = UserServiceFactory.getUserService().getCurrentUser(); DeviceController controller = getDeviceController(); String regId = UUID.randomUUID().toString(); controller.registerDevice(regId, user); DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .first().now(); assertNotNull(record); assertEquals(regId, record.getRegId()); assertEquals(user.getUserId(), record.getParent().toWebSafeString()); }
public void registerDevice(String regId, User user) { final Key<Account> accountKey = Key.create(user.getUserId()); ofy().transact(() -> { try { DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(accountKey).first().safe(); ofy().save().entity(record.withRegId(regId)).now(); } catch (NotFoundException e) { DeviceRecord record = DeviceRecord.builder() .id(accountKey.toWebSafeString()) .parent(accountKey) .regId(regId) .build(); ofy().save().entity(record).now(); } }); }
DeviceController extends Controller { public void registerDevice(String regId, User user) { final Key<Account> accountKey = Key.create(user.getUserId()); ofy().transact(() -> { try { DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(accountKey).first().safe(); ofy().save().entity(record.withRegId(regId)).now(); } catch (NotFoundException e) { DeviceRecord record = DeviceRecord.builder() .id(accountKey.toWebSafeString()) .parent(accountKey) .regId(regId) .build(); ofy().save().entity(record).now(); } }); } }
DeviceController extends Controller { public void registerDevice(String regId, User user) { final Key<Account> accountKey = Key.create(user.getUserId()); ofy().transact(() -> { try { DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(accountKey).first().safe(); ofy().save().entity(record.withRegId(regId)).now(); } catch (NotFoundException e) { DeviceRecord record = DeviceRecord.builder() .id(accountKey.toWebSafeString()) .parent(accountKey) .regId(regId) .build(); ofy().save().entity(record).now(); } }); }  }
DeviceController extends Controller { public void registerDevice(String regId, User user) { final Key<Account> accountKey = Key.create(user.getUserId()); ofy().transact(() -> { try { DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(accountKey).first().safe(); ofy().save().entity(record.withRegId(regId)).now(); } catch (NotFoundException e) { DeviceRecord record = DeviceRecord.builder() .id(accountKey.toWebSafeString()) .parent(accountKey) .regId(regId) .build(); ofy().save().entity(record).now(); } }); }  void registerDevice(String regId, User user); void unregisterDevice(String regId, User user); }
DeviceController extends Controller { public void registerDevice(String regId, User user) { final Key<Account> accountKey = Key.create(user.getUserId()); ofy().transact(() -> { try { DeviceRecord record = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(accountKey).first().safe(); ofy().save().entity(record.withRegId(regId)).now(); } catch (NotFoundException e) { DeviceRecord record = DeviceRecord.builder() .id(accountKey.toWebSafeString()) .parent(accountKey) .regId(regId) .build(); ofy().save().entity(record).now(); } }); }  void registerDevice(String regId, User user); void unregisterDevice(String regId, User user);  }