@Test public void testExecuteNoBatch() { final CreateNotificationsRequest request = new CreateNotificationsRequest(RequestType.COMMENT, 0); context.checking(new Expectations() { { oneOf(translator).translate(request); will(returnValue(null)); } }); TaskHandlerActionContext<ActionContext> ac = TestContextCreator.createTaskHandlerAsyncContext(request); sut.execute(ac); context.assertIsSatisfied(); assertTrue(ac.getUserActionRequests().isEmpty()); }
@Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) throws ExecutionException { CreateNotificationsRequest currentRequest = (CreateNotificationsRequest) inActionContext.getActionContext() .getParams(); log.info("Generating notifications for {}", currentRequest.getType()); NotificationTranslator translator = translators.get(currentRequest.getType()); if (translator == null) { return Boolean.FALSE; } NotificationBatch batch = translator.translate(currentRequest); if (batch == null || batch.getRecipients().isEmpty()) { return Boolean.TRUE; } List<NotificationFilterPreferenceDTO> recipientFilterPreferences = null; Map<Long, PersonModelView> recipientIndex = buildRecipientIndex(batch); Set<String> categories = new HashSet<String>(); for (NotificationType type : batch.getRecipients().keySet()) { String category = notificationTypeToCategory.get(type); if (category != null) { categories.add(category); } } if (!categories.isEmpty()) { recipientFilterPreferences = preferencesMapper.execute(new GetNotificationFilterPreferenceRequest( recipientIndex.keySet(), categories)); } PropertyMap<Object> propertyList = new PropertyHashMap<Object>(); propertyList.putAll(defaultProperties); propertyList.putAll(batch.getProperties()); Map<String, Object> properties = new LazyLoadPropertiesMap<Object>(propertyList, propertyLoadMappers); List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); for (Entry<NotificationType, Collection<Long>> notification : batch.getRecipients().entrySet()) { NotificationType type = notification.getKey(); Collection<Long> recipientIds = notification.getValue(); for (String notifierKey : notifiers.keySet()) { log.debug("Filtering {} recipients for notifier {} from this list: {}", new Object[] { type, notifierKey, recipientIds }); Collection<Long> filteredRecipients = filterRecipients(recipientIds, type, properties, notifierKey, recipientFilterPreferences, recipientIndex); if (!filteredRecipients.isEmpty()) { try { log.info("Sending notification {} via {} to {}", new Object[] { type, notifierKey, filteredRecipients }); Collection<UserActionRequest> actionRequests = notifiers.get(notifierKey).notify(type, filteredRecipients, properties, recipientIndex); if (actionRequests != null && !actionRequests.isEmpty()) { asyncRequests.addAll(actionRequests); } } catch (Exception ex) { log.error("Failed to send notifications from " + notifierKey + " for " + type, ex); } } } } return Boolean.TRUE; }
CreateNotificationsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) throws ExecutionException { CreateNotificationsRequest currentRequest = (CreateNotificationsRequest) inActionContext.getActionContext() .getParams(); log.info("Generating notifications for {}", currentRequest.getType()); NotificationTranslator translator = translators.get(currentRequest.getType()); if (translator == null) { return Boolean.FALSE; } NotificationBatch batch = translator.translate(currentRequest); if (batch == null || batch.getRecipients().isEmpty()) { return Boolean.TRUE; } List<NotificationFilterPreferenceDTO> recipientFilterPreferences = null; Map<Long, PersonModelView> recipientIndex = buildRecipientIndex(batch); Set<String> categories = new HashSet<String>(); for (NotificationType type : batch.getRecipients().keySet()) { String category = notificationTypeToCategory.get(type); if (category != null) { categories.add(category); } } if (!categories.isEmpty()) { recipientFilterPreferences = preferencesMapper.execute(new GetNotificationFilterPreferenceRequest( recipientIndex.keySet(), categories)); } PropertyMap<Object> propertyList = new PropertyHashMap<Object>(); propertyList.putAll(defaultProperties); propertyList.putAll(batch.getProperties()); Map<String, Object> properties = new LazyLoadPropertiesMap<Object>(propertyList, propertyLoadMappers); List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); for (Entry<NotificationType, Collection<Long>> notification : batch.getRecipients().entrySet()) { NotificationType type = notification.getKey(); Collection<Long> recipientIds = notification.getValue(); for (String notifierKey : notifiers.keySet()) { log.debug("Filtering {} recipients for notifier {} from this list: {}", new Object[] { type, notifierKey, recipientIds }); Collection<Long> filteredRecipients = filterRecipients(recipientIds, type, properties, notifierKey, recipientFilterPreferences, recipientIndex); if (!filteredRecipients.isEmpty()) { try { log.info("Sending notification {} via {} to {}", new Object[] { type, notifierKey, filteredRecipients }); Collection<UserActionRequest> actionRequests = notifiers.get(notifierKey).notify(type, filteredRecipients, properties, recipientIndex); if (actionRequests != null && !actionRequests.isEmpty()) { asyncRequests.addAll(actionRequests); } } catch (Exception ex) { log.error("Failed to send notifications from " + notifierKey + " for " + type, ex); } } } } return Boolean.TRUE; } }
CreateNotificationsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) throws ExecutionException { CreateNotificationsRequest currentRequest = (CreateNotificationsRequest) inActionContext.getActionContext() .getParams(); log.info("Generating notifications for {}", currentRequest.getType()); NotificationTranslator translator = translators.get(currentRequest.getType()); if (translator == null) { return Boolean.FALSE; } NotificationBatch batch = translator.translate(currentRequest); if (batch == null || batch.getRecipients().isEmpty()) { return Boolean.TRUE; } List<NotificationFilterPreferenceDTO> recipientFilterPreferences = null; Map<Long, PersonModelView> recipientIndex = buildRecipientIndex(batch); Set<String> categories = new HashSet<String>(); for (NotificationType type : batch.getRecipients().keySet()) { String category = notificationTypeToCategory.get(type); if (category != null) { categories.add(category); } } if (!categories.isEmpty()) { recipientFilterPreferences = preferencesMapper.execute(new GetNotificationFilterPreferenceRequest( recipientIndex.keySet(), categories)); } PropertyMap<Object> propertyList = new PropertyHashMap<Object>(); propertyList.putAll(defaultProperties); propertyList.putAll(batch.getProperties()); Map<String, Object> properties = new LazyLoadPropertiesMap<Object>(propertyList, propertyLoadMappers); List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); for (Entry<NotificationType, Collection<Long>> notification : batch.getRecipients().entrySet()) { NotificationType type = notification.getKey(); Collection<Long> recipientIds = notification.getValue(); for (String notifierKey : notifiers.keySet()) { log.debug("Filtering {} recipients for notifier {} from this list: {}", new Object[] { type, notifierKey, recipientIds }); Collection<Long> filteredRecipients = filterRecipients(recipientIds, type, properties, notifierKey, recipientFilterPreferences, recipientIndex); if (!filteredRecipients.isEmpty()) { try { log.info("Sending notification {} via {} to {}", new Object[] { type, notifierKey, filteredRecipients }); Collection<UserActionRequest> actionRequests = notifiers.get(notifierKey).notify(type, filteredRecipients, properties, recipientIndex); if (actionRequests != null && !actionRequests.isEmpty()) { asyncRequests.addAll(actionRequests); } } catch (Exception ex) { log.error("Failed to send notifications from " + notifierKey + " for " + type, ex); } } } } return Boolean.TRUE; } CreateNotificationsExecution(
            final Map<RequestType, NotificationTranslator> inTranslators,
            final Map<String, Notifier> inNotifiers,
            final DomainMapper<GetNotificationFilterPreferenceRequest, List<NotificationFilterPreferenceDTO>> // \n
            inPreferencesMapper, final DomainMapper<List<Long>, List<PersonModelView>> inPersonsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories,
            final Map<String, Collection<RecipientFilter>> inBulkFilters,
            final Map<String, Collection<RecipientFilter>> inRecipientFilters,
            final Map<String, Property<Object>> inDefaultProperties,
            final Map<Class, DomainMapper<Serializable, Object>> inPropertyLoadMappers); }
CreateNotificationsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) throws ExecutionException { CreateNotificationsRequest currentRequest = (CreateNotificationsRequest) inActionContext.getActionContext() .getParams(); log.info("Generating notifications for {}", currentRequest.getType()); NotificationTranslator translator = translators.get(currentRequest.getType()); if (translator == null) { return Boolean.FALSE; } NotificationBatch batch = translator.translate(currentRequest); if (batch == null || batch.getRecipients().isEmpty()) { return Boolean.TRUE; } List<NotificationFilterPreferenceDTO> recipientFilterPreferences = null; Map<Long, PersonModelView> recipientIndex = buildRecipientIndex(batch); Set<String> categories = new HashSet<String>(); for (NotificationType type : batch.getRecipients().keySet()) { String category = notificationTypeToCategory.get(type); if (category != null) { categories.add(category); } } if (!categories.isEmpty()) { recipientFilterPreferences = preferencesMapper.execute(new GetNotificationFilterPreferenceRequest( recipientIndex.keySet(), categories)); } PropertyMap<Object> propertyList = new PropertyHashMap<Object>(); propertyList.putAll(defaultProperties); propertyList.putAll(batch.getProperties()); Map<String, Object> properties = new LazyLoadPropertiesMap<Object>(propertyList, propertyLoadMappers); List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); for (Entry<NotificationType, Collection<Long>> notification : batch.getRecipients().entrySet()) { NotificationType type = notification.getKey(); Collection<Long> recipientIds = notification.getValue(); for (String notifierKey : notifiers.keySet()) { log.debug("Filtering {} recipients for notifier {} from this list: {}", new Object[] { type, notifierKey, recipientIds }); Collection<Long> filteredRecipients = filterRecipients(recipientIds, type, properties, notifierKey, recipientFilterPreferences, recipientIndex); if (!filteredRecipients.isEmpty()) { try { log.info("Sending notification {} via {} to {}", new Object[] { type, notifierKey, filteredRecipients }); Collection<UserActionRequest> actionRequests = notifiers.get(notifierKey).notify(type, filteredRecipients, properties, recipientIndex); if (actionRequests != null && !actionRequests.isEmpty()) { asyncRequests.addAll(actionRequests); } } catch (Exception ex) { log.error("Failed to send notifications from " + notifierKey + " for " + type, ex); } } } } return Boolean.TRUE; } CreateNotificationsExecution(
            final Map<RequestType, NotificationTranslator> inTranslators,
            final Map<String, Notifier> inNotifiers,
            final DomainMapper<GetNotificationFilterPreferenceRequest, List<NotificationFilterPreferenceDTO>> // \n
            inPreferencesMapper, final DomainMapper<List<Long>, List<PersonModelView>> inPersonsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories,
            final Map<String, Collection<RecipientFilter>> inBulkFilters,
            final Map<String, Collection<RecipientFilter>> inRecipientFilters,
            final Map<String, Property<Object>> inDefaultProperties,
            final Map<Class, DomainMapper<Serializable, Object>> inPropertyLoadMappers); @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext); }
CreateNotificationsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) throws ExecutionException { CreateNotificationsRequest currentRequest = (CreateNotificationsRequest) inActionContext.getActionContext() .getParams(); log.info("Generating notifications for {}", currentRequest.getType()); NotificationTranslator translator = translators.get(currentRequest.getType()); if (translator == null) { return Boolean.FALSE; } NotificationBatch batch = translator.translate(currentRequest); if (batch == null || batch.getRecipients().isEmpty()) { return Boolean.TRUE; } List<NotificationFilterPreferenceDTO> recipientFilterPreferences = null; Map<Long, PersonModelView> recipientIndex = buildRecipientIndex(batch); Set<String> categories = new HashSet<String>(); for (NotificationType type : batch.getRecipients().keySet()) { String category = notificationTypeToCategory.get(type); if (category != null) { categories.add(category); } } if (!categories.isEmpty()) { recipientFilterPreferences = preferencesMapper.execute(new GetNotificationFilterPreferenceRequest( recipientIndex.keySet(), categories)); } PropertyMap<Object> propertyList = new PropertyHashMap<Object>(); propertyList.putAll(defaultProperties); propertyList.putAll(batch.getProperties()); Map<String, Object> properties = new LazyLoadPropertiesMap<Object>(propertyList, propertyLoadMappers); List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); for (Entry<NotificationType, Collection<Long>> notification : batch.getRecipients().entrySet()) { NotificationType type = notification.getKey(); Collection<Long> recipientIds = notification.getValue(); for (String notifierKey : notifiers.keySet()) { log.debug("Filtering {} recipients for notifier {} from this list: {}", new Object[] { type, notifierKey, recipientIds }); Collection<Long> filteredRecipients = filterRecipients(recipientIds, type, properties, notifierKey, recipientFilterPreferences, recipientIndex); if (!filteredRecipients.isEmpty()) { try { log.info("Sending notification {} via {} to {}", new Object[] { type, notifierKey, filteredRecipients }); Collection<UserActionRequest> actionRequests = notifiers.get(notifierKey).notify(type, filteredRecipients, properties, recipientIndex); if (actionRequests != null && !actionRequests.isEmpty()) { asyncRequests.addAll(actionRequests); } } catch (Exception ex) { log.error("Failed to send notifications from " + notifierKey + " for " + type, ex); } } } } return Boolean.TRUE; } CreateNotificationsExecution(
            final Map<RequestType, NotificationTranslator> inTranslators,
            final Map<String, Notifier> inNotifiers,
            final DomainMapper<GetNotificationFilterPreferenceRequest, List<NotificationFilterPreferenceDTO>> // \n
            inPreferencesMapper, final DomainMapper<List<Long>, List<PersonModelView>> inPersonsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories,
            final Map<String, Collection<RecipientFilter>> inBulkFilters,
            final Map<String, Collection<RecipientFilter>> inRecipientFilters,
            final Map<String, Property<Object>> inDefaultProperties,
            final Map<Class, DomainMapper<Serializable, Object>> inPropertyLoadMappers); @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext);  }