refactoring of some functionality for openaire
This commit is contained in:
parent
beff40f729
commit
64ef867437
|
@ -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
|
||||
|
|
|
@ -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<Event> 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<Event> 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<String, Long> deleteExpiredEvents() {
|
||||
final Map<String, Long> 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<Subscription> iter = subscriptionRepo.findAll();
|
||||
|
||||
final Set<String> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String> 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<String> startMatching(@PathVariable final String subscriptionId) {
|
||||
final Optional<Subscription> 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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String> verifyTopic = Pattern.compile("^[a-zA-Z0-9._-]+(\\/[a-zA-Z0-9._-]+)+$").asPredicate();
|
||||
public static final Predicate<String> 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<String> startMatching() {
|
||||
schedulerActions.startSubscriptionEventsMatcher();
|
||||
return Arrays.asList("done");
|
||||
}
|
||||
|
||||
@ApiOperation("Launch the thread that produces new notifications by subscriptuion id")
|
||||
@GetMapping("/startMatching/{subscriptionId}")
|
||||
public List<String> startMatching(@PathVariable final String subscriptionId) {
|
||||
final Optional<Subscription> 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<MapCondition> conditions) {
|
||||
final List<MapCondition> conditions) {
|
||||
this.subscriber = subscriber;
|
||||
this.topic = topic;
|
||||
this.frequency = frequency;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -19,28 +19,24 @@
|
|||
<th class="col-xs-6">n. subscriptions</th>
|
||||
<td class="col-xs-6 text-right">
|
||||
{{summary.totals.subscriptions}}
|
||||
<two-step-button label="clear" action="deleteAllSubscriptions()" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="col-xs-6">n. events</th>
|
||||
<td class="col-xs-6 text-right">
|
||||
{{summary.totals.events}}
|
||||
<two-step-button label="clear" action="deleteAllEvents()" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="col-xs-6">n. topic types</th>
|
||||
<td class="col-xs-6 text-right">
|
||||
{{summary.totals.topics}}
|
||||
<two-step-button label="clear" action="deleteAllTopicTypes()" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="col-xs-6">n. notifications</th>
|
||||
<td class="col-xs-6 text-right">
|
||||
{{summary.totals.notifications}}
|
||||
<two-step-button label="clear" action="deleteAllNotifications()" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -213,13 +209,6 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-bordered">
|
||||
<tr admin-operation label="delete expired events"
|
||||
description="Delete the expired events"
|
||||
alert="It can't be UNDONE."
|
||||
action="deleteExpiredEvents()"></tr>
|
||||
<tr admin-operation label="subscription/events matcher"
|
||||
description="Start the subscription/events matcher"
|
||||
action="startSubscriptionEventsMatcher()"></admin-operation>
|
||||
<tr admin-operation label="reset counters"
|
||||
description="Reset the counters of the internal queues."
|
||||
action="resetCounters()"></tr>
|
||||
|
|
|
@ -112,54 +112,6 @@ lbsControllers.controller('lbsSummaryCtrl', function ($scope, $http, $sce, $loca
|
|||
});
|
||||
};
|
||||
|
||||
$scope.deleteAllSubscriptions = function() {
|
||||
$http.delete('api/subscriptions').success(function(data) {
|
||||
$scope.summary.totals.subscriptions = 0;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteAllEvents = function() {
|
||||
$http.delete('api/events/all').success(function(data) {
|
||||
$scope.summary.totals.events = 0;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteExpiredEvents = function() {
|
||||
$http.delete('api/events/expired').success(function(data) {
|
||||
$scope.summary.totals.events = $scope.summary.totals.events - data.deleted;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteAllTopicTypes = function() {
|
||||
$http.delete('api/topic-types').success(function(data) {
|
||||
$scope.summary.totals.topics = 0;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteAllNotifications = function() {
|
||||
$http.delete('api/notifications').success(function(data) {
|
||||
$scope.summary.totals.notifications = 0;
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope. startSubscriptionEventsMatcher = function() {
|
||||
$http.get('api/subscriptions/startMatching').success(function(data) {
|
||||
alert("matching is running");
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
});
|
||||
};
|
||||
|
||||
$scope.refresh();
|
||||
});
|
||||
|
||||
|
@ -262,10 +214,10 @@ lbsControllers.controller('lbsSubscriptionsCtrl', function ($scope, $http, $sce,
|
|||
};
|
||||
|
||||
$scope.startMatching = function(id) {
|
||||
$http.get('api/subscriptions/startMatching/' + id).success(function(data) {
|
||||
$http.get('api/matching/start/' + id).success(function(data) {
|
||||
alert("Matching in queue");
|
||||
}).error(function() {
|
||||
alert("error");
|
||||
alert("Error: The functionality could be disabled in current configuration profile !");
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue