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);
}