Search in sources :

Example 1 with Event

use of com.redhat.cloud.notifications.ingress.Event in project notifications-backend by RedHatInsights.

the class FromCamelHistoryFiller method reinjectIfNeeded.

private void reinjectIfNeeded(Map<String, Object> payloadMap) {
    if (!enableReInject || (payloadMap.containsKey("successful") && ((Boolean) payloadMap.get("successful")))) {
        return;
    }
    String historyId = (String) payloadMap.get("historyId");
    log.infof("Notification with id %s was not successful, resubmitting for further processing", historyId);
    Endpoint ep = notificationHistoryRepository.getEndpointForHistoryId(historyId);
    Event event = new Event();
    Payload.PayloadBuilder payloadBuilder = new Payload.PayloadBuilder();
    payloadMap.forEach(payloadBuilder::withAdditionalProperty);
    // TODO augment with details from Endpoint and original event
    event.setPayload(payloadBuilder.build());
    // Save the original id, as we may need it in the future.
    Context.ContextBuilder contextBuilder = new Context.ContextBuilder();
    contextBuilder.withAdditionalProperty("original-id", historyId);
    if (ep != null) {
        // TODO For the current tests. EP should not be null in real life
        contextBuilder.withAdditionalProperty("failed-integration", ep.getName());
    }
    Action action = new Action.ActionBuilder().withId(UUID.randomUUID()).withBundle("console").withApplication("notifications").withEventType("integration-failed").withAccountId(ep != null ? ep.getAccountId() : "").withContext(contextBuilder.build()).withTimestamp(LocalDateTime.now(ZoneOffset.UTC)).withEvents(Collections.singletonList(event)).withRecipients(Collections.singletonList(new Recipient.RecipientBuilder().withOnlyAdmins(true).withIgnoreUserPreferences(true).build())).build();
    String ser = Parser.encode(action);
    // Add the message id in Kafka header for the de-duplicator
    Message<String> message = buildMessageWithId(ser);
    emitter.send(message);
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Endpoint(com.redhat.cloud.notifications.models.Endpoint) Event(com.redhat.cloud.notifications.ingress.Event) Payload(com.redhat.cloud.notifications.ingress.Payload)

Aggregations

Action (com.redhat.cloud.notifications.ingress.Action)1 Context (com.redhat.cloud.notifications.ingress.Context)1 Event (com.redhat.cloud.notifications.ingress.Event)1 Payload (com.redhat.cloud.notifications.ingress.Payload)1 Endpoint (com.redhat.cloud.notifications.models.Endpoint)1