diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/LiteratureBrokerServiceConfiguration.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/LiteratureBrokerServiceConfiguration.java index 92b5067b..192e4cc0 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/LiteratureBrokerServiceConfiguration.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/LiteratureBrokerServiceConfiguration.java @@ -47,6 +47,7 @@ public class LiteratureBrokerServiceConfiguration extends AbstractElasticsearchC public static final String TAG_NOTIFICATIONS = "Notifications"; public static final String TAG_TOPIC_TYPES = "Topic Types"; public static final String TAG_OPENAIRE = "OpenAIRE"; + public static final String TAG_MATCHING = "Subscription-Event Matching"; @Override @Bean diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/EventsController.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/EventsController.java index 592127b0..e8db2f6b 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/EventsController.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/EventsController.java @@ -45,7 +45,7 @@ public class EventsController extends AbstractLbsController { @Autowired private EventStatsManager eventStatsManager; - @Autowired + @Autowired(required = false) private ScheduledActions scheduledActions; @ApiOperation("Return an event by ID") @@ -69,17 +69,17 @@ public class EventsController extends AbstractLbsController { @ApiOperation("Return a page of events") @GetMapping("/list/{page}/{pageSize}") public List events( - @PathVariable final int page, - @PathVariable final int pageSize) { + @PathVariable final int page, + @PathVariable final int pageSize) { return Lists.newArrayList(eventRepository.findAll(PageRequest.of(page, pageSize))); } @ApiOperation("Return a page of events by topic") @GetMapping("/byTopic/{page}/{pageSize}") public List eventsByTopic( - @PathVariable final int page, - @PathVariable final int pageSize, - @RequestParam final String topic) { + @PathVariable final int page, + @PathVariable final int pageSize, + @RequestParam final String topic) { return Lists.newArrayList(eventRepository.findByTopic(topic, PageRequest.of(page, pageSize))); } @@ -96,7 +96,11 @@ public class EventsController extends AbstractLbsController { @DeleteMapping("/expired") public Map deleteExpiredEvents() { final Map res = new HashMap<>(); - res.put("deleted", scheduledActions.deleteExpiredEvents()); + if (scheduledActions != null) { + res.put("deleted", scheduledActions.deleteExpiredEvents()); + } else { + res.put("error (deletion of expired events is disabled)", 0l); + } return res; } @@ -113,13 +117,13 @@ public class EventsController extends AbstractLbsController { final Iterable iter = subscriptionRepo.findAll(); final Set validTopics = StreamSupport.stream(iter.spliterator(), false) - .map(Subscription::getTopic) - .collect(Collectors.toSet()); + .map(Subscription::getTopic) + .collect(Collectors.toSet()); return this.browseTopics() - .stream() - .filter(e -> validTopics.contains(e.getValue())) - .collect(Collectors.toList()); + .stream() + .filter(e -> validTopics.contains(e.getValue())) + .collect(Collectors.toList()); } } diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/StartMatchingController.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/StartMatchingController.java new file mode 100644 index 00000000..98bcc3f2 --- /dev/null +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/StartMatchingController.java @@ -0,0 +1,59 @@ +package eu.dnetlib.lbs.controllers; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import eu.dnetlib.lbs.LiteratureBrokerServiceConfiguration; +import eu.dnetlib.lbs.matchers.SubscriptionEventMatcher; +import eu.dnetlib.lbs.subscriptions.Subscription; +import eu.dnetlib.lbs.subscriptions.SubscriptionRepository; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +@Profile("!openaire") +@RestController +@RequestMapping("/api/matching") +@Api(tags = LiteratureBrokerServiceConfiguration.TAG_MATCHING) +public class StartMatchingController extends AbstractLbsController { + + @Autowired + private SubscriptionRepository subscriptionRepo; + + @Autowired(required = false) + private SubscriptionEventMatcher subscriptionEventMatcher; + + @ApiOperation("Launch the thread that produces new notifications") + @GetMapping("/start") + public List startMatching() { + if (subscriptionEventMatcher != null) { + this.subscriptionRepo.findAll().forEach(this.subscriptionEventMatcher::startMatching); + return Arrays.asList("done"); + } else { + return Arrays.asList("matching is disabled"); + } + } + + @ApiOperation("Launch the thread that produces new notifications by subscriptuion id") + @GetMapping("/start/{subscriptionId}") + public List startMatching(@PathVariable final String subscriptionId) { + final Optional s = subscriptionRepo.findById(subscriptionId); + + if (subscriptionEventMatcher == null) { + return Arrays.asList("matching is disabled"); + } else if (s.isPresent()) { + subscriptionEventMatcher.startMatching(s.get()); + return Arrays.asList("done"); + } else { + return Arrays.asList("subscription not present"); + } + } + +} diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/SubscriptionsController.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/SubscriptionsController.java index 144a75e7..0c8ab0aa 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/SubscriptionsController.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/SubscriptionsController.java @@ -1,11 +1,9 @@ package eu.dnetlib.lbs.controllers; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.UUID; import java.util.function.Predicate; import java.util.regex.Pattern; @@ -24,9 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.lbs.LiteratureBrokerServiceConfiguration; -import eu.dnetlib.lbs.cron.ScheduledActions; import eu.dnetlib.lbs.elasticsearch.NotificationRepository; -import eu.dnetlib.lbs.matchers.SubscriptionEventMatcher; import eu.dnetlib.lbs.subscriptions.MapCondition; import eu.dnetlib.lbs.subscriptions.NotificationFrequency; import eu.dnetlib.lbs.subscriptions.NotificationMode; @@ -46,12 +42,6 @@ public class SubscriptionsController extends AbstractLbsController { @Autowired private NotificationRepository notificationRepo; - @Autowired - private ScheduledActions schedulerActions; - - @Autowired - private SubscriptionEventMatcher subscriptionEventMatcher; - public static final Predicate verifyTopic = Pattern.compile("^[a-zA-Z0-9._-]+(\\/[a-zA-Z0-9._-]+)+$").asPredicate(); public static final Predicate verifyEmail = email -> { try { @@ -99,25 +89,6 @@ public class SubscriptionsController extends AbstractLbsController { return res; } - @ApiOperation("Launch the thread that produces new notifications") - @GetMapping("/startMatching") - public List startMatching() { - schedulerActions.startSubscriptionEventsMatcher(); - return Arrays.asList("done"); - } - - @ApiOperation("Launch the thread that produces new notifications by subscriptuion id") - @GetMapping("/startMatching/{subscriptionId}") - public List startMatching(@PathVariable final String subscriptionId) { - final Optional s = subscriptionRepo.findById(subscriptionId); - if (s.isPresent()) { - subscriptionEventMatcher.startMatching(s.get()); - return Arrays.asList("done"); - } else { - return Arrays.asList("subscription not present"); - } - } - @ApiOperation("Reset the last notification date") @DeleteMapping("/{id}/date") public void deleteNotificationDate(@PathVariable final String id) { @@ -147,7 +118,7 @@ class InSubscription { public InSubscription() {} public InSubscription(final String subscriber, final String topic, final NotificationFrequency frequency, final NotificationMode mode, - final List conditions) { + final List conditions) { this.subscriber = subscriber; this.topic = topic; this.frequency = frequency; diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/cron/ScheduledActions.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/cron/ScheduledActions.java index 6d7401cf..fabc6d08 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/cron/ScheduledActions.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/cron/ScheduledActions.java @@ -5,23 +5,21 @@ import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import eu.dnetlib.lbs.elasticsearch.EventRepository; -import eu.dnetlib.lbs.elasticsearch.NotificationRepository; import eu.dnetlib.lbs.matchers.SubscriptionEventMatcher; import eu.dnetlib.lbs.subscriptions.SubscriptionRepository; @Component +@Profile("!openaire") public class ScheduledActions { @Autowired private EventRepository eventRepository; - @Autowired - private NotificationRepository notificationRepository; - @Autowired private SubscriptionRepository subscriptionRepo; @@ -40,13 +38,6 @@ public class ScheduledActions { return n; } - @Scheduled(cron = "${lbs.task.deleteOldNotifications.cron}") - public long deleteExpiredNotifications() { - // TODO - - return 0; - } - @Scheduled(cron = "${lbs.task.subscriptionEventsMatcher.cron}") public void startSubscriptionEventsMatcher() { this.subscriptionRepo.findAll().forEach(this.subscriptionEventMatcher::startMatching); diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/matchers/SubscriptionEventMatcher.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/matchers/SubscriptionEventMatcher.java index 7075deaa..f9fc76ee 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/matchers/SubscriptionEventMatcher.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/matchers/SubscriptionEventMatcher.java @@ -15,6 +15,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilders; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; import org.springframework.data.domain.PageRequest; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.SearchHit; @@ -36,6 +37,7 @@ import eu.dnetlib.lbs.utils.LbsQueue; import eu.dnetlib.lbs.utils.QueueManager; import eu.dnetlib.lbs.utils.ThreadManager; +@Profile("!openaire") @Component public class SubscriptionEventMatcher implements Runnable { diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/openaire/OpenaireBrokerController.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/openaire/OpenaireBrokerController.java index fd10ff86..d6a6b5b0 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/openaire/OpenaireBrokerController.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/openaire/OpenaireBrokerController.java @@ -21,6 +21,7 @@ import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested; import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; import org.springframework.data.domain.PageRequest; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; @@ -53,6 +54,7 @@ import eu.dnetlib.lbs.subscriptions.SubscriptionRepository; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +@Profile("openaire") @RestController @RequestMapping("/api/openaireBroker") @Api(tags = LiteratureBrokerServiceConfiguration.TAG_OPENAIRE) diff --git a/apps/dhp-broker-application/src/main/resources/application.properties b/apps/dhp-broker-application/src/main/resources/application.properties index 9e09bfab..e7fc79c4 100644 --- a/apps/dhp-broker-application/src/main/resources/application.properties +++ b/apps/dhp-broker-application/src/main/resources/application.properties @@ -1,4 +1,6 @@ -spring.profiles.active = dev +spring.profiles.active = dev,openaire + +#logging.level.root=DEBUG spring.datasource.url=jdbc:postgresql://localhost:5432/dnet_broker spring.datasource.username= @@ -50,6 +52,4 @@ spring.data.elasticsearch.cluster-name = ${lbs.elastic.clusterName} spring.data.elasticsearch.cluster-nodes = ${lbs.elastic.clusterNodes} -logging.level.root=DEBUG - diff --git a/apps/dhp-broker-application/src/main/resources/static/html/summary.html b/apps/dhp-broker-application/src/main/resources/static/html/summary.html index 93a1a191..ef9d3914 100644 --- a/apps/dhp-broker-application/src/main/resources/static/html/summary.html +++ b/apps/dhp-broker-application/src/main/resources/static/html/summary.html @@ -19,28 +19,24 @@ n. subscriptions {{summary.totals.subscriptions}} - n. events {{summary.totals.events}} - n. topic types {{summary.totals.topics}} - n. notifications {{summary.totals.notifications}} - @@ -213,13 +209,6 @@