|
|
|
@ -5,8 +5,10 @@ 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.apache.log4j.Logger;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
@ -17,9 +19,14 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
@Service
|
|
|
|
|
public class MetricsService {
|
|
|
|
|
|
|
|
|
|
private final Logger logger = Logger.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MetricsDAO metricsDAO;
|
|
|
|
|
|
|
|
|
|
@Value("${search.service.api.url:https://services.openaire.eu/search/v2/api/}")
|
|
|
|
|
private String searchUrl;
|
|
|
|
|
|
|
|
|
|
private final String recordsRequest = "results?size=0&format=json";
|
|
|
|
|
private final String publicationsRequest = "publications?size=0&format=json";
|
|
|
|
|
private final String datasetsRequest = "datasets?size=0&format=json";
|
|
|
|
@ -35,55 +42,56 @@ public class MetricsService {
|
|
|
|
|
" or reldatasourcecompatibilityid exact hostedBy or relproject=*))&type=organizations&size=0&format=json";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "0 0/1 * * * *")
|
|
|
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
|
|
|
private void calculateMetrics() {
|
|
|
|
|
System.out.println("Calculating metrics...");
|
|
|
|
|
logger.info("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);
|
|
|
|
|
= restTemplate.getForEntity(searchUrl + recordsRequest, String.class);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.records= jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + publicationsRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + publicationsRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.publications = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + datasetsRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + datasetsRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.datasets = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + softwareRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + softwareRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.software = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + orpRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + orpRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.orp = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + fundersRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + fundersRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.funders = jsonObject.getJSONObject("refineResults").getJSONArray("relfunder").length()+"";
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + projectsRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + projectsRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.projects = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + contentProvidersRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + contentProvidersRequest, String.class);
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.contentProviders = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|
|
|
|
|
|
System.out.println("https://services.openaire.eu/search/v2/api/" + organizationsRequest);
|
|
|
|
|
response = restTemplate.
|
|
|
|
|
getForEntity("https://services.openaire.eu/search/v2/api/" + organizationsRequest, String.class);
|
|
|
|
|
getForEntity(searchUrl + organizationsRequest, String.class);
|
|
|
|
|
|
|
|
|
|
jsonObject = new JSONObject(response.getBody());
|
|
|
|
|
metrics.organizations = jsonObject.getJSONObject("meta").get("total").toString();
|
|
|
|
|