@Test public void testExecute() throws ParseException { long maxId = (Long) getEntityManager().createQuery("SELECT MAX(id) FROM InAppNotification").getSingleResult(); getEntityManager().createQuery("UPDATE Person SET accountLocked=true WHERE id > 100").executeUpdate(); long unlockedPersonCount = (Long) getEntityManager().createQuery( "SELECT COUNT(*) FROM Person WHERE accountLocked=false").getSingleResult(); assertTrue("Test is meaningless with no unlocked users.", unlockedPersonCount > 0); sut.execute(new SendPrebuiltNotificationRequest(true, null, MESSAGE, URL)); List results = getEntityManager().createQuery("FROM InAppNotification WHERE id > :id") .setParameter("id", maxId).getResultList(); assertEquals(unlockedPersonCount, results.size()); for (InAppNotificationEntity notif : (List<InAppNotificationEntity>) results) { assertTrue(notif.isHighPriority()); assertEquals(MESSAGE, notif.getMessage()); assertEquals(URL, notif.getUrl()); } }
@Override public Serializable execute(final SendPrebuiltNotificationRequest inRequest) { InAppNotificationEntity dbNotif = new InAppNotificationEntity(); dbNotif.setNotificationType(NotificationType.PASS_THROUGH); dbNotif.setMessage(inRequest.getMessage()); dbNotif.setUrl(inRequest.getUrl()); dbNotif.setHighPriority(inRequest.isHighPriority()); getEntityManager().persist(dbNotif); String q = "insert into InAppNotification (recipient, notificationType, notificationDate, message, url, " + "highPriority, isRead, sourceType, avatarOwnerType, aggregationCount) " + "select p, n.notificationType, n.notificationDate, n.message, n.url, n.highPriority, n.isRead, " + "n.sourceType, n.avatarOwnerType, n.aggregationCount from Person p, InAppNotification n " + "where n.id = :id and p.accountLocked = false"; Query query = getEntityManager().createQuery(q).setParameter("id", dbNotif.getId()); int count = query.executeUpdate(); getEntityManager().remove(dbNotif); return count; }
InsertInAppNotificationForAllUsers extends
        BaseArgDomainMapper<SendPrebuiltNotificationRequest, Serializable> { @Override public Serializable execute(final SendPrebuiltNotificationRequest inRequest) { InAppNotificationEntity dbNotif = new InAppNotificationEntity(); dbNotif.setNotificationType(NotificationType.PASS_THROUGH); dbNotif.setMessage(inRequest.getMessage()); dbNotif.setUrl(inRequest.getUrl()); dbNotif.setHighPriority(inRequest.isHighPriority()); getEntityManager().persist(dbNotif); String q = "insert into InAppNotification (recipient, notificationType, notificationDate, message, url, " + "highPriority, isRead, sourceType, avatarOwnerType, aggregationCount) " + "select p, n.notificationType, n.notificationDate, n.message, n.url, n.highPriority, n.isRead, " + "n.sourceType, n.avatarOwnerType, n.aggregationCount from Person p, InAppNotification n " + "where n.id = :id and p.accountLocked = false"; Query query = getEntityManager().createQuery(q).setParameter("id", dbNotif.getId()); int count = query.executeUpdate(); getEntityManager().remove(dbNotif); return count; } }
InsertInAppNotificationForAllUsers extends
        BaseArgDomainMapper<SendPrebuiltNotificationRequest, Serializable> { @Override public Serializable execute(final SendPrebuiltNotificationRequest inRequest) { InAppNotificationEntity dbNotif = new InAppNotificationEntity(); dbNotif.setNotificationType(NotificationType.PASS_THROUGH); dbNotif.setMessage(inRequest.getMessage()); dbNotif.setUrl(inRequest.getUrl()); dbNotif.setHighPriority(inRequest.isHighPriority()); getEntityManager().persist(dbNotif); String q = "insert into InAppNotification (recipient, notificationType, notificationDate, message, url, " + "highPriority, isRead, sourceType, avatarOwnerType, aggregationCount) " + "select p, n.notificationType, n.notificationDate, n.message, n.url, n.highPriority, n.isRead, " + "n.sourceType, n.avatarOwnerType, n.aggregationCount from Person p, InAppNotification n " + "where n.id = :id and p.accountLocked = false"; Query query = getEntityManager().createQuery(q).setParameter("id", dbNotif.getId()); int count = query.executeUpdate(); getEntityManager().remove(dbNotif); return count; }  }
InsertInAppNotificationForAllUsers extends
        BaseArgDomainMapper<SendPrebuiltNotificationRequest, Serializable> { @Override public Serializable execute(final SendPrebuiltNotificationRequest inRequest) { InAppNotificationEntity dbNotif = new InAppNotificationEntity(); dbNotif.setNotificationType(NotificationType.PASS_THROUGH); dbNotif.setMessage(inRequest.getMessage()); dbNotif.setUrl(inRequest.getUrl()); dbNotif.setHighPriority(inRequest.isHighPriority()); getEntityManager().persist(dbNotif); String q = "insert into InAppNotification (recipient, notificationType, notificationDate, message, url, " + "highPriority, isRead, sourceType, avatarOwnerType, aggregationCount) " + "select p, n.notificationType, n.notificationDate, n.message, n.url, n.highPriority, n.isRead, " + "n.sourceType, n.avatarOwnerType, n.aggregationCount from Person p, InAppNotification n " + "where n.id = :id and p.accountLocked = false"; Query query = getEntityManager().createQuery(q).setParameter("id", dbNotif.getId()); int count = query.executeUpdate(); getEntityManager().remove(dbNotif); return count; }  @Override Serializable execute(final SendPrebuiltNotificationRequest inRequest); }
InsertInAppNotificationForAllUsers extends
        BaseArgDomainMapper<SendPrebuiltNotificationRequest, Serializable> { @Override public Serializable execute(final SendPrebuiltNotificationRequest inRequest) { InAppNotificationEntity dbNotif = new InAppNotificationEntity(); dbNotif.setNotificationType(NotificationType.PASS_THROUGH); dbNotif.setMessage(inRequest.getMessage()); dbNotif.setUrl(inRequest.getUrl()); dbNotif.setHighPriority(inRequest.isHighPriority()); getEntityManager().persist(dbNotif); String q = "insert into InAppNotification (recipient, notificationType, notificationDate, message, url, " + "highPriority, isRead, sourceType, avatarOwnerType, aggregationCount) " + "select p, n.notificationType, n.notificationDate, n.message, n.url, n.highPriority, n.isRead, " + "n.sourceType, n.avatarOwnerType, n.aggregationCount from Person p, InAppNotification n " + "where n.id = :id and p.accountLocked = false"; Query query = getEntityManager().createQuery(q).setParameter("id", dbNotif.getId()); int count = query.executeUpdate(); getEntityManager().remove(dbNotif); return count; }  @Override Serializable execute(final SendPrebuiltNotificationRequest inRequest);  }