From 9b0c12f5d38bd028aa2c21c32323acd00ec6e1e2 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 11 Sep 2020 12:06:16 +0200 Subject: [PATCH] send notifications --- .../dhp/broker/oa/IndexNotificationsJob.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/IndexNotificationsJob.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/IndexNotificationsJob.java index b890ed328..cb7acb46d 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/IndexNotificationsJob.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/IndexNotificationsJob.java @@ -1,6 +1,7 @@ package eu.dnetlib.dhp.broker.oa; +import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -102,6 +103,11 @@ public class IndexNotificationsJob { log.info("*** Deleting old notifications"); final String message = deleteOldNotifications(brokerApiBaseUrl, startTime - 1000); log.info("*** Deleted notifications: " + message); + + log.info("*** sendNotifications (emails, ...)"); + sendNotifications(brokerApiBaseUrl, startTime - 1000); + log.info("*** ALL done."); + } } @@ -194,7 +200,6 @@ public class IndexNotificationsJob { .readValue(s, mapper.getTypeFactory().constructCollectionType(List.class, Subscription.class)); } } - } private static String deleteOldNotifications(final String brokerApiBaseUrl, final long l) throws Exception { @@ -206,7 +211,17 @@ public class IndexNotificationsJob { return IOUtils.toString(response.getEntity().getContent()); } } + } + private static String sendNotifications(final String brokerApiBaseUrl, final long l) throws IOException { + final String url = brokerApiBaseUrl + "/api/openaireBroker/notifications/send/" + l; + final HttpGet req = new HttpGet(url); + + try (final CloseableHttpClient client = HttpClients.createDefault()) { + try (final CloseableHttpResponse response = client.execute(req)) { + return IOUtils.toString(response.getEntity().getContent()); + } + } } private static String prepareForIndexing(final Notification n, final LongAccumulator acc)