use of com.redhat.cloud.notifications.models.EmailSubscriptionType in project notifications-backend by RedHatInsights.
the class EmailSubscriptionTypeProcessor method process.
@Override
public List<NotificationHistory> process(Event event, List<Endpoint> endpoints) {
if (endpoints == null || endpoints.isEmpty()) {
return Collections.emptyList();
} else {
Action action = event.getAction();
final EmailTemplate template = emailTemplateFactory.get(action.getBundle(), action.getApplication());
boolean shouldSaveAggregation;
if (useTemplatesFromDb) {
shouldSaveAggregation = templateRepository.isEmailAggregationSupported(action.getBundle(), action.getApplication(), NON_INSTANT_SUBSCRIPTION_TYPES);
} else {
shouldSaveAggregation = NON_INSTANT_SUBSCRIPTION_TYPES.stream().anyMatch(emailSubscriptionType -> template.isSupported(action.getEventType(), emailSubscriptionType));
}
if (shouldSaveAggregation) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setAccountId(action.getAccountId());
aggregation.setApplicationName(action.getApplication());
aggregation.setBundleName(action.getBundle());
JsonObject transformedAction = baseTransformer.transform(action);
aggregation.setPayload(transformedAction);
emailAggregationRepository.addEmailAggregation(aggregation);
}
return sendEmail(event, Set.copyOf(endpoints), template);
}
}
Aggregations