use of com.redhat.cloud.notifications.processors.EndpointTypeProcessor in project notifications-backend by RedHatInsights.
the class EndpointProcessor method process.
public void process(Event event) {
processedItems.increment();
List<Endpoint> endpoints = endpointRepository.getTargetEndpoints(event.getAccountId(), event.getEventType());
// Target endpoints are grouped by endpoint type.
endpointTargeted.increment(endpoints.size());
Map<EndpointType, List<Endpoint>> endpointsByType = endpoints.stream().collect(Collectors.groupingBy(Endpoint::getType));
for (Map.Entry<EndpointType, List<Endpoint>> entry : endpointsByType.entrySet()) {
/*
* For each endpoint type, the list of target endpoints is sent alongside with the action to the relevant processor.
* Each processor returns a list of history entries. All of the returned lists are flattened into a single list.
*/
EndpointTypeProcessor processor = endpointTypeToProcessor(entry.getKey());
List<NotificationHistory> historyEntries = processor.process(event, entry.getValue());
// Now each history entry is persisted.
for (NotificationHistory history : historyEntries) {
try {
notificationHistoryRepository.createNotificationHistory(history);
} catch (Exception e) {
LOGGER.errorf("Notification history creation failed for %s", history.getEndpoint());
}
}
}
}
Aggregations