|
|
|
@ -1,18 +1,24 @@
|
|
|
|
|
package eu.dnetlib.dnetexploremetrics.service;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.util.JSONPObject;
|
|
|
|
|
import eu.dnetlib.dnetexploremetrics.dao.MetricsDAO;
|
|
|
|
|
import eu.dnetlib.dnetexploremetrics.dao.MetricsFileDAO;
|
|
|
|
|
import eu.dnetlib.dnetexploremetrics.model.Metrics;
|
|
|
|
|
import eu.dnetlib.dnetexploremetrics.utils.PrometheusMetricsFormatter;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
@EnableScheduling
|
|
|
|
|
@Service
|
|
|
|
|
public class MetricsService {
|
|
|
|
|
|
|
|
|
|
@Value("${search.service.url}")
|
|
|
|
|
private String searchServiceUrl;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MetricsDAO metricsDAO;
|
|
|
|
|
|
|
|
|
|
private final String recordsRequest = "results?size=0&format=json";
|
|
|
|
|
private final String publicationsRequest = "publications?size=0&format=json";
|
|
|
|
@ -22,9 +28,17 @@ public class MetricsService {
|
|
|
|
|
private final String fundersRequest = "resources2?format=json&refine=true&fields=relfunder&type=results&page=0&size=0";
|
|
|
|
|
private final String projectsRequest = "projects?size=0&format=json";
|
|
|
|
|
private final String contentProvidersRequest = "datasources?size=0&format=json";
|
|
|
|
|
private final String organizationsRequest = "resources2?query=((reldatasourcecompatibilityid exact driver or " +
|
|
|
|
|
"reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or " +
|
|
|
|
|
"reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire4.0 or " +
|
|
|
|
|
"reldatasourcecompatibilityid exact openaire-cris_1.1 or reldatasourcecompatibilityid exact openaire2.0_data" +
|
|
|
|
|
" or reldatasourcecompatibilityid exact hostedBy or relproject=*))&type=organizations&size=0&format=json";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void getMetrics(Metrics metrics) {
|
|
|
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
|
|
|
private void calculateMetrics() {
|
|
|
|
|
System.out.println("Calculating metrics...");
|
|
|
|
|
Metrics metrics = new Metrics();
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
ResponseEntity<String> response
|
|
|
|
|
= restTemplate.getForEntity("https://services.openaire.eu/search/v2/api/" + recordsRequest, String.class);
|
|
|
|
@ -66,13 +80,19 @@ public class MetricsService {
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + contentProvidersRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.contentProviders = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
MetricsService ms = new MetricsService();
|
|
|
|
|
Metrics m = new Metrics();
|
|
|
|
|
ms.getMetrics(m);
|
|
|
|
|
PrometheusMetricsFormatter.formatMetrics(m);
|
|
|
|
|
System.out.println("https://services.openaire.eu/search/v2/api/" + organizationsRequest);
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + organizationsRequest, String.class);
|
|
|
|
|
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.organizations = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
metricsDAO.save(metrics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getMetrics() {
|
|
|
|
|
MetricsDAO metricsDAO = new MetricsFileDAO();
|
|
|
|
|
return metricsDAO.getMetrics();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|