new public apis

This commit is contained in:
Michele Artini 2020-12-07 11:10:44 +01:00
parent ad33d158bd
commit 0f65824250
4 changed files with 33 additions and 5 deletions

View File

@ -2,8 +2,8 @@ spring.profiles.active = dev,openaire
#logging.level.root=DEBUG
spring.datasource.url=jdbc:postgresql://localhost:5432/dnet_broker
spring.datasource.username=
spring.datasource.url=jdbc:postgresql://localhost:5432/oa_broker
spring.datasource.username=oa_broker
spring.datasource.password=
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

View File

@ -5,7 +5,9 @@ import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
@ -39,6 +41,7 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.google.gson.Gson;
@ -46,7 +49,9 @@ import com.google.gson.Gson;
import eu.dnetlib.broker.BrokerConfiguration;
import eu.dnetlib.broker.api.ShortEventMessage;
import eu.dnetlib.broker.common.controllers.AbstractLbsController;
import eu.dnetlib.broker.common.elasticsearch.EventRepository;
import eu.dnetlib.broker.common.elasticsearch.Notification;
import eu.dnetlib.broker.common.elasticsearch.NotificationRepository;
import eu.dnetlib.broker.common.properties.ElasticSearchProperties;
import eu.dnetlib.broker.common.subscriptions.Subscription;
import eu.dnetlib.broker.common.subscriptions.SubscriptionRepository;
@ -63,6 +68,12 @@ public class OpenairePublicController extends AbstractLbsController {
@Autowired
private ElasticsearchOperations esOperations;
@Autowired
private EventRepository eventRepository;
@Autowired
private NotificationRepository notificationRepository;
@Autowired
private SubscriptionRepository subscriptionRepo;
@ -221,6 +232,22 @@ public class OpenairePublicController extends AbstractLbsController {
}
}
@ApiOperation("Returns the list of subscriptions by user email")
@GetMapping(value = "/subscriptions")
private Iterable<Subscription> listSubscriptionsByUser(@RequestParam final String email) {
return subscriptionRepo.findBySubscriber(email);
}
@ApiOperation("Returns the status of the application")
@GetMapping(value = "/status")
private Map<String, Long> status() {
final Map<String, Long> res = new LinkedHashMap<>();
res.put("n_subscriptions", subscriptionRepo.count());
res.put("n_events", eventRepository.count());
res.put("n_notifications", notificationRepository.count());
return res;
}
private List<ShortEventMessage> calculateNotificationMessages(final SearchScrollHits<Notification> scroll) {
if (scroll.getSearchHits().size() > 0) {
return scroll.stream()

View File

@ -1,9 +1,10 @@
spring.profiles.active = dev,openaire
#logging.level.root=DEBUG
spring.datasource.url=jdbc:postgresql://localhost:5432/dnet_broker
spring.datasource.username=
spring.datasource.url=jdbc:postgresql://localhost:5432/oa_broker
spring.datasource.username=oa_broker
spring.datasource.password=
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

View File

@ -2,6 +2,6 @@
<html>
<head>
<title>OpenAIRE Broker Public API</title>
<meta http-equiv="refresh" content="2; url = /swagger" />
<meta http-equiv="refresh" content="2; url = ./swagger" />
</head>
</html>