@Test(expected = NotFoundException.class) public void testUnregisterDevice() 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()); controller.unregisterDevice(regId, user); ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .first().safe(); }
public void unregisterDevice(String regId, User user) { ofy().transact(() -> { Key<DeviceRecord> recordKey = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .keys().first().now(); if (recordKey != null) { ofy().delete().key(recordKey).now(); } }); }
DeviceController extends Controller { public void unregisterDevice(String regId, User user) { ofy().transact(() -> { Key<DeviceRecord> recordKey = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .keys().first().now(); if (recordKey != null) { ofy().delete().key(recordKey).now(); } }); } }
DeviceController extends Controller { public void unregisterDevice(String regId, User user) { ofy().transact(() -> { Key<DeviceRecord> recordKey = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .keys().first().now(); if (recordKey != null) { ofy().delete().key(recordKey).now(); } }); }  }
DeviceController extends Controller { public void unregisterDevice(String regId, User user) { ofy().transact(() -> { Key<DeviceRecord> recordKey = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .keys().first().now(); if (recordKey != null) { ofy().delete().key(recordKey).now(); } }); }  void registerDevice(String regId, User user); void unregisterDevice(String regId, User user); }
DeviceController extends Controller { public void unregisterDevice(String regId, User user) { ofy().transact(() -> { Key<DeviceRecord> recordKey = ofy().load().type(DeviceRecord.class) .filter(DeviceRecord.FIELD_REG_ID + " =", regId) .ancestor(Key.<Account>create(user.getUserId())) .keys().first().now(); if (recordKey != null) { ofy().delete().key(recordKey).now(); } }); }  void registerDevice(String regId, User user); void unregisterDevice(String regId, User user);  }