public EntityPushManager( Notifier notifier, EntityManager entityManager, BlockingQueue<SimpleApnsPushNotification> queue, PushManagerConfiguration configuration) { super(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, queue, configuration, notifier.getName()); this.notifier = notifier; this.entityManager = entityManager; }
private String getProviderId(EntityRef device, Notifier notifier) throws Exception { try { Object value = em.getProperty(device, notifier.getName() + NOTIFIER_ID_POSTFIX); if (value == null) { value = em.getProperty(device, notifier.getUuid() + NOTIFIER_ID_POSTFIX); } return value != null ? value.toString() : null; } catch (Exception e) { logger.error("Error getting notifier for device {}, proceeding with rest of batch", device, e); return null; } }
public void removeInactiveDevices( Map<String,Date> inactiveDeviceMap ){ final String notfierPostFix = ApplicationQueueManagerImpl.NOTIFIER_ID_POSTFIX; if (inactiveDeviceMap != null && inactiveDeviceMap.size() > 0) { if (logger.isDebugEnabled()) { logger.debug("processing {} inactive devices", inactiveDeviceMap.size()); } Map<String, Object> clearPushtokenMap = new HashMap<String, Object>( 2); clearPushtokenMap.put(notifier.getName() + notfierPostFix, ""); clearPushtokenMap.put(notifier.getUuid() + notfierPostFix, ""); // todo: this could be done in a single query for (Map.Entry<String, Date> entry : inactiveDeviceMap.entrySet()) { try { // name Query query = Query.fromQL( notifier.getName() + notfierPostFix + " = '" + entry.getKey() + "'"); Results results = entityManager.searchCollection(entityManager.getApplication(), "devices", query); for (Entity e : results.getEntities()) { entityManager.updateProperties(e, clearPushtokenMap); } }catch (Exception e){ logger.error("failed to remove token",e); } } } } }
private void replaceProviderId(EntityRef device, Notifier notifier, String newProviderId) throws Exception { Object value = em.getProperty(device, notifier.getName() + ApplicationQueueManager.NOTIFIER_ID_POSTFIX); if (value != null) { em.setProperty(device, notifier.getName() + ApplicationQueueManager.NOTIFIER_ID_POSTFIX, newProviderId); } else { value = em.getProperty(device, notifier.getUuid() + ApplicationQueueManager.NOTIFIER_ID_POSTFIX); if (value != null) { em.setProperty(device, notifier.getUuid() + ApplicationQueueManager.NOTIFIER_ID_POSTFIX, newProviderId); } } }
protected Map<Object, Notifier> getNotifierMap(Map payloads) throws Exception { Map<Object, Notifier> notifiers = new HashMap<Object, Notifier>( payloads.size() * 2); for (Object id : payloads.keySet()) { Identifier identifier = Identifier.from(id); Notifier notifier; if (identifier.isUUID()) { notifier = em.get(identifier.getUUID(), Notifier.class); } else { EntityRef ref = em.getAlias("notifier", identifier.getName()); notifier = em.get(ref, Notifier.class); } if (notifier != null) { notifiers.put(notifier.getUuid(), notifier); notifiers.put(notifier.getUuid().toString(), notifier); if (notifier.getName() != null) { notifiers.put(notifier.getName(), notifier); } } } return notifiers; }
while (notifierIterator.hasNext()) { Notifier notifier = notifierIterator.next(); String name = notifier.getName() != null ? notifier.getName() : ""; UUID uuid = notifier.getUuid() != null ? notifier.getUuid() : UUID.randomUUID(); ProviderAdapter providerAdapter = ProviderAdapterFactory.getProviderAdapter(notifier, em);
String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getName(), payload); app.put("payloads", payloads); app.put("deliver", System.currentTimeMillis() - 1000); // some time in the past payload = getPayload(); payloads = new HashMap<String, String>(1); payloads.put(notifier.getName(), payload); app.put("payloads", payloads); app.put("deliver", "notatime"); // some time in the past
@Test public void singlePushNotification() throws Exception { app.clear(); String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getName(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug",true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time // post notification to service manager Entity e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); // ensure notification has expected name Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getName().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 1); }
app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x"); Entity badDeviceEntity = app.testRequest(ServiceAction.POST, 1, "devices").getEntity(); Device badDevice = app.getEntityManager().get(badDeviceEntity.getUuid(), Device.class);
assertEquals(notifier2.getName(), notifierName1); assertEquals(notifier2.getProvider(), PROVIDER); assertEquals(notifier2.getEnvironment(), environment1); String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX; app.put(key2, PUSH_TOKEN); app.testRequest(ServiceAction.PUT, 1, "devices", device1).getEntity();
assertEquals(notifier2.getName(), "apNs2"); assertEquals(notifier2.getProvider(), PROVIDER); assertEquals(notifier2.getEnvironment(), "development");
Entity entity = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity(); Notifier notifier = app.getEntityManager().get(entity.getUuid(), Notifier.class); final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX; setup.getEntityIndex().refresh(app.getId());
@Before public void before() throws Exception { // create gcm notifier // app.clear(); app.put("name", "gcm"); app.put("provider", PROVIDER); app.put("environment", "development"); app.put("apiKey", API_KEY); notifier = (Notifier) app .testRequest(ServiceAction.POST, 1, "notifiers").getEntity() .toTypedEntity(); String key = notifier.getName() + NOTIFIER_ID_POSTFIX; // create devices // app.clear(); app.put(key, PUSH_TOKEN); Entity e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity(); app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid()); device1 = app.getEntityManager().get(e.getUuid(), Device.class); assertEquals(device1.getProperty(key), PUSH_TOKEN); app.put(key, PUSH_TOKEN); e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity(); device2 = app.getEntityManager().get(e.getUuid(), Device.class); ns = getNotificationService(); listener = new QueueListener(ns.getServiceManagerFactory(), ns.getEntityManagerFactory(), new Properties()); listener.start(); }
String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getName(), payload); app.put("payloads", payloads); app.put("debug", true);
final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;