Search in sources :

Example 1 with EndpointTypeProcessor

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());
            }
        }
    }
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) EndpointTypeProcessor(com.redhat.cloud.notifications.processors.EndpointTypeProcessor) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) EndpointType(com.redhat.cloud.notifications.models.EndpointType) List(java.util.List) Map(java.util.Map)

Aggregations

Endpoint (com.redhat.cloud.notifications.models.Endpoint)1 EndpointType (com.redhat.cloud.notifications.models.EndpointType)1 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)1 EndpointTypeProcessor (com.redhat.cloud.notifications.processors.EndpointTypeProcessor)1 List (java.util.List)1 Map (java.util.Map)1