@Test public void testExecuteNothingExists() { final long personId = 4507L; NotificationFilterPreferenceDTO dto = new NotificationFilterPreferenceDTO("SMS", "FOLLOW"); SetUserNotificationFilterPreferencesRequest rqst = new SetUserNotificationFilterPreferencesRequest(personId, Collections.singletonList(dto)); sut.execute(rqst); dto.setPersonId(personId); checkAgainstDb(personId, Collections.singletonList(dto)); }
@Override public Void execute(final SetUserNotificationFilterPreferencesRequest inRequest) { Query checkQuery = getEntityManager() .createQuery( "SELECT COUNT(*) FROM NotificationFilterPreference WHERE personId=:personId AND " + "notifierType=:notifierType AND notificationCategory=:notificationCategory") .setParameter("personId", inRequest.getPersonId()); Person user = null; for (NotificationFilterPreferenceDTO dto : inRequest.getPrefList()) { checkQuery.setParameter("notifierType", dto.getNotifierType()); checkQuery.setParameter("notificationCategory", dto.getNotificationCategory()); if ((Long) checkQuery.getSingleResult() == 0) { if (user == null) { user = (Person) getHibernateSession().load(Person.class, inRequest.getPersonId()); } NotificationFilterPreferenceEntity entity = new NotificationFilterPreferenceEntity(); entity.setPerson(user); entity.setNotificationCategory(dto.getNotificationCategory()); entity.setNotifierType(dto.getNotifierType()); getEntityManager().persist(entity); } } return null; }
SetUserNotificationFilterPreferences extends
        BaseArgDomainMapper<SetUserNotificationFilterPreferencesRequest, Void> { @Override public Void execute(final SetUserNotificationFilterPreferencesRequest inRequest) { Query checkQuery = getEntityManager() .createQuery( "SELECT COUNT(*) FROM NotificationFilterPreference WHERE personId=:personId AND " + "notifierType=:notifierType AND notificationCategory=:notificationCategory") .setParameter("personId", inRequest.getPersonId()); Person user = null; for (NotificationFilterPreferenceDTO dto : inRequest.getPrefList()) { checkQuery.setParameter("notifierType", dto.getNotifierType()); checkQuery.setParameter("notificationCategory", dto.getNotificationCategory()); if ((Long) checkQuery.getSingleResult() == 0) { if (user == null) { user = (Person) getHibernateSession().load(Person.class, inRequest.getPersonId()); } NotificationFilterPreferenceEntity entity = new NotificationFilterPreferenceEntity(); entity.setPerson(user); entity.setNotificationCategory(dto.getNotificationCategory()); entity.setNotifierType(dto.getNotifierType()); getEntityManager().persist(entity); } } return null; } }
SetUserNotificationFilterPreferences extends
        BaseArgDomainMapper<SetUserNotificationFilterPreferencesRequest, Void> { @Override public Void execute(final SetUserNotificationFilterPreferencesRequest inRequest) { Query checkQuery = getEntityManager() .createQuery( "SELECT COUNT(*) FROM NotificationFilterPreference WHERE personId=:personId AND " + "notifierType=:notifierType AND notificationCategory=:notificationCategory") .setParameter("personId", inRequest.getPersonId()); Person user = null; for (NotificationFilterPreferenceDTO dto : inRequest.getPrefList()) { checkQuery.setParameter("notifierType", dto.getNotifierType()); checkQuery.setParameter("notificationCategory", dto.getNotificationCategory()); if ((Long) checkQuery.getSingleResult() == 0) { if (user == null) { user = (Person) getHibernateSession().load(Person.class, inRequest.getPersonId()); } NotificationFilterPreferenceEntity entity = new NotificationFilterPreferenceEntity(); entity.setPerson(user); entity.setNotificationCategory(dto.getNotificationCategory()); entity.setNotifierType(dto.getNotifierType()); getEntityManager().persist(entity); } } return null; }  }
SetUserNotificationFilterPreferences extends
        BaseArgDomainMapper<SetUserNotificationFilterPreferencesRequest, Void> { @Override public Void execute(final SetUserNotificationFilterPreferencesRequest inRequest) { Query checkQuery = getEntityManager() .createQuery( "SELECT COUNT(*) FROM NotificationFilterPreference WHERE personId=:personId AND " + "notifierType=:notifierType AND notificationCategory=:notificationCategory") .setParameter("personId", inRequest.getPersonId()); Person user = null; for (NotificationFilterPreferenceDTO dto : inRequest.getPrefList()) { checkQuery.setParameter("notifierType", dto.getNotifierType()); checkQuery.setParameter("notificationCategory", dto.getNotificationCategory()); if ((Long) checkQuery.getSingleResult() == 0) { if (user == null) { user = (Person) getHibernateSession().load(Person.class, inRequest.getPersonId()); } NotificationFilterPreferenceEntity entity = new NotificationFilterPreferenceEntity(); entity.setPerson(user); entity.setNotificationCategory(dto.getNotificationCategory()); entity.setNotifierType(dto.getNotifierType()); getEntityManager().persist(entity); } } return null; }  @Override Void execute(final SetUserNotificationFilterPreferencesRequest inRequest); }
SetUserNotificationFilterPreferences extends
        BaseArgDomainMapper<SetUserNotificationFilterPreferencesRequest, Void> { @Override public Void execute(final SetUserNotificationFilterPreferencesRequest inRequest) { Query checkQuery = getEntityManager() .createQuery( "SELECT COUNT(*) FROM NotificationFilterPreference WHERE personId=:personId AND " + "notifierType=:notifierType AND notificationCategory=:notificationCategory") .setParameter("personId", inRequest.getPersonId()); Person user = null; for (NotificationFilterPreferenceDTO dto : inRequest.getPrefList()) { checkQuery.setParameter("notifierType", dto.getNotifierType()); checkQuery.setParameter("notificationCategory", dto.getNotificationCategory()); if ((Long) checkQuery.getSingleResult() == 0) { if (user == null) { user = (Person) getHibernateSession().load(Person.class, inRequest.getPersonId()); } NotificationFilterPreferenceEntity entity = new NotificationFilterPreferenceEntity(); entity.setPerson(user); entity.setNotificationCategory(dto.getNotificationCategory()); entity.setNotifierType(dto.getNotifierType()); getEntityManager().persist(entity); } } return null; }  @Override Void execute(final SetUserNotificationFilterPreferencesRequest inRequest);  }