Add open access field in stakeholderExtended and change endpoint URL.

This commit is contained in:
Konstantinos Triantafyllou 2024-06-13 13:30:43 +03:00
parent 94fa636aa9
commit eef35e3047
13 changed files with 223 additions and 151 deletions

View File

@ -0,0 +1,31 @@
package eu.dnetlib.irishmonitorservice.configuration.properties;
public class Indicators {
String publications;
String publicationsPR;
String publicationsPROA;
public String getPublications() {
return publications;
}
public void setPublications(String publications) {
this.publications = publications;
}
public String getPublicationsPR() {
return publicationsPR;
}
public void setPublicationsPR(String publicationsPR) {
this.publicationsPR = publicationsPR;
}
public String getPublicationsPROA() {
return publicationsPROA;
}
public void setPublicationsPROA(String publicationsPROA) {
this.publicationsPROA = publicationsPROA;
}
}

View File

@ -4,34 +4,43 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("stats-tool")
public class StatsToolProperties {
private String rpo;
private String rfo;
private String repository;
private String host;
private Indicators rpo;
private Indicators rfo;
private Indicators repository;
public StatsToolProperties() {
}
public String getRpo() {
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public Indicators getRpo() {
return rpo;
}
public void setRpo(String rpo) {
public void setRpo(Indicators rpo) {
this.rpo = rpo;
}
public String getRfo() {
public Indicators getRfo() {
return rfo;
}
public void setRfo(String rfo) {
public void setRfo(Indicators rfo) {
this.rfo = rfo;
}
public String getRepository() {
public Indicators getRepository() {
return repository;
}
public void setRepository(String repository) {
public void setRepository(Indicators repository) {
this.repository = repository;
}
}

View File

@ -0,0 +1,27 @@
package eu.dnetlib.irishmonitorservice.controllers;
import eu.dnetlib.irishmonitorservice.entities.SortBy;
import eu.dnetlib.irishmonitorservice.entities.StakeholderExtended;
import eu.dnetlib.irishmonitorservice.services.StakeholderExtendedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("stakeholder/extended")
public class StakeholderExtendedController {
private final StakeholderExtendedService service;
@Autowired
public StakeholderExtendedController(StakeholderExtendedService service) {
this.service = service;
}
@RequestMapping(value = "/{type}", method = RequestMethod.GET)
public List<StakeholderExtended> getStakeholders(@PathVariable String type, @RequestParam(value = "sort", required = false) SortBy sort) throws UnsupportedEncodingException {
return this.service.sortBy(this.service.getStakeholdersExtended(type), sort);
}
}

View File

@ -1,48 +0,0 @@
package eu.dnetlib.irishmonitorservice.controllers;
import eu.dnetlib.irishmonitorservice.entities.StakeholderPublications;
import eu.dnetlib.irishmonitorservice.services.CacheService;
import eu.dnetlib.irishmonitorservice.services.StatsToolService;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("publications")
public class StakeholderPublicationsController {
private final StakeholderService service;
private final CacheService cacheService;
@Autowired
public StakeholderPublicationsController(StakeholderService service, CacheService cacheService) {
this.service = service;
this.cacheService = cacheService;
}
@RequestMapping(value = "/{type}", method = RequestMethod.GET)
public List<StakeholderPublications> getStakeholders(@PathVariable String type) throws UnsupportedEncodingException, InterruptedException {
List<Stakeholder> stakeholders = this.service.getVisibleStakeholders(type, null);
List<StakeholderPublications> stakeholderPublications = new ArrayList<>();
List<List<String>> data = this.cacheService.getResponse(type);
List<Stakeholder> remain = new ArrayList<>(stakeholders);
if (data != null) {
data.forEach(entity -> {
String id = entity.get(1);
stakeholders.stream().filter(stakeholder -> stakeholder.getIndex_id().equals(id)).findFirst().ifPresent(stakeholder -> {
remain.remove(stakeholder);
stakeholderPublications.add(new StakeholderPublications(stakeholder, Integer.parseInt(entity.get(0))));
});
});
}
remain.forEach(stakeholder -> stakeholderPublications.add(new StakeholderPublications(stakeholder, 0)));
return stakeholderPublications;
}
}

View File

@ -1,14 +1,16 @@
package eu.dnetlib.irishmonitorservice.entities;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Data {
List<List<List<String>>> data;
public Data() {}
public List<List<String>> getData() {
if(data.isEmpty()) {
return new ArrayList<>();
}
return data.get(0);
}
}

View File

@ -0,0 +1,6 @@
package eu.dnetlib.irishmonitorservice.entities;
public enum SortBy {
OPEN_ACCESS,
PUBLICATIONS
}

View File

@ -0,0 +1,27 @@
package eu.dnetlib.irishmonitorservice.entities;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
public class StakeholderExtended extends Stakeholder {
private final Integer publications;
private final Float publicationPR;
private final Float publicationPROA;
public StakeholderExtended(Stakeholder stakeholder, String publications, String publicationPR, String publicationPROA) {
super(stakeholder);
this.publications = publications != null ? Integer.parseInt(publications) : null;
this.publicationPR = publicationPR != null ? Float.parseFloat(publicationPR) : null;
this.publicationPROA = publicationPROA != null ? Float.parseFloat(publicationPROA) : null;
}
public Integer getPublications() {
return publications;
}
public Number getOpenAccess() {
if( publicationPR != null && publicationPROA != null && publicationPR > 0) {
return (publicationPROA / publicationPR) * 100;
}
return 0;
}
}

View File

@ -1,20 +0,0 @@
package eu.dnetlib.irishmonitorservice.entities;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
public class StakeholderPublications extends Stakeholder {
private Number publications;
public StakeholderPublications(Stakeholder stakeholder, Number publications) {
super(stakeholder);
this.publications = publications;
}
public Number getPublications() {
return publications;
}
public void setPublications(Number publications) {
this.publications = publications;
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.irishmonitorservice.services;
import eu.dnetlib.irishmonitorservice.entities.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,15 +19,16 @@ public class CacheService {
@Autowired
private StatsToolService statsToolService;
public List<List<String>> getResponse(String type) throws UnsupportedEncodingException {
if (type.equals("funder")) {
return this.statsToolService.getFunders();
} else if (type.equals("organization")) {
return this.statsToolService.getOrganizations();
} else if (type.equals("datasource")) {
return this.statsToolService.getDataSources();
} else {
return null;
public List<List<List<String>>> getResponse(String type) throws UnsupportedEncodingException {
switch (type) {
case "funder":
return this.statsToolService.getFunders();
case "organization":
return this.statsToolService.getOrganizations();
case "datasource":
return this.statsToolService.getDataSources();
default:
return null;
}
}

View File

@ -0,0 +1,58 @@
package eu.dnetlib.irishmonitorservice.services;
import eu.dnetlib.irishmonitorservice.entities.Data;
import eu.dnetlib.irishmonitorservice.entities.SortBy;
import eu.dnetlib.irishmonitorservice.entities.StakeholderExtended;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class StakeholderExtendedService {
private final StakeholderService service;
private final CacheService cacheService;
@Autowired
public StakeholderExtendedService(StakeholderService service, CacheService cacheService) {
this.service = service;
this.cacheService = cacheService;
}
public List<StakeholderExtended> getStakeholdersExtended(String type) throws UnsupportedEncodingException {
List<Stakeholder> stakeholders = this.service.getVisibleStakeholders(type, null);
List<List<List<String>>> results = this.cacheService.getResponse(type);
if(results != null) {
return stakeholders.stream().map(stakeholder ->
new StakeholderExtended(stakeholder,
getNumber(results, 0, stakeholder.getIndex_id()),
getNumber(results, 1, stakeholder.getIndex_id()),
getNumber(results, 2, stakeholder.getIndex_id()))).collect(Collectors.toList());
}
else {
return stakeholders.stream().map(stakeholder -> new StakeholderExtended(stakeholder, "0", "0", "0")).collect(Collectors.toList());
}
}
public String getNumber(List<List<List<String>>> results, int index, String id) {
if(results != null && index < results.size()) {
return results.get(index).stream().filter(list -> list.get(1).equals(id)).findFirst().orElse(Collections.singletonList("0")).get(0);
}
return "0";
}
public List<StakeholderExtended> sortBy(List<StakeholderExtended> stakeholders, SortBy sort) {
stakeholders.sort(Comparator.comparingInt(StakeholderExtended::getPublications).reversed());
if(sort == SortBy.OPEN_ACCESS) {
stakeholders.sort(Comparator.comparingDouble((StakeholderExtended a) -> a.getOpenAccess().doubleValue()).reversed());
}
return stakeholders;
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.irishmonitorservice.services;
import eu.dnetlib.irishmonitorservice.configuration.properties.Indicators;
import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties;
import eu.dnetlib.irishmonitorservice.entities.Data;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +15,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
@Service
@ -26,37 +28,45 @@ public class StatsToolService {
private RestTemplate restTemplate;
@Cacheable(value = "funders")
public List<List<String>> getFunders() throws UnsupportedEncodingException {
String url = this.properties.getRfo();
return this.getData(url);
public List<List<List<String>>> getFunders() throws UnsupportedEncodingException {
return this.getData(this.properties.getRfo());
}
@Cacheable(value = "organizations")
public List<List<String>> getOrganizations() throws UnsupportedEncodingException {
String url = this.properties.getRpo();
return this.getData(url);
public List<List<List<String>>> getOrganizations() throws UnsupportedEncodingException {
return this.getData(this.properties.getRpo());
}
@Cacheable(value = "datasources")
public List<List<String>> getDataSources() throws UnsupportedEncodingException {
String url = this.properties.getRepository();
return this.getData(url);
public List<List<List<String>>> getDataSources() throws UnsupportedEncodingException {
return this.getData(this.properties.getRepository());
}
private List<List<String>> getData(String url) throws UnsupportedEncodingException {
if(url != null) {
String service = url.substring(0, url.indexOf('=') + 1);
String json = URLDecoder.decode(url.substring(url.indexOf('=') + 1), "UTF-8");
URI uri = UriComponentsBuilder.fromUriString(service + json).build().encode().toUri();
try {
ResponseEntity<Data> data = restTemplate.getForEntity(uri, Data.class);
if(data.getStatusCode() == HttpStatus.OK) {
return data.getBody().getData();
}
} catch (RestClientException e) {
return null;
}
public List<List<List<String>>> getData(Indicators indicators) throws UnsupportedEncodingException {
if(indicators != null) {
List<List<List<String>>> data = new ArrayList<>();
data.add(this.getData(properties.getHost(), indicators.getPublications()));
data.add(this.getData(properties.getHost(), indicators.getPublicationsPR()));
data.add(this.getData(properties.getHost(), indicators.getPublicationsPROA()));
return data;
}
return null;
}
private List<List<String>> getData(String service, String json) throws UnsupportedEncodingException {
if(service == null || json == null) {
return new ArrayList<>();
} else {
URI uri = UriComponentsBuilder.fromUriString(service + URLDecoder.decode(json, "UTF-8")).build().encode().toUri();
try {
ResponseEntity<Data> response = restTemplate.getForEntity(uri, Data.class);
if(response.getStatusCode() == HttpStatus.OK) {
return response.getBody().getData();
}
return new ArrayList<>();
} catch (RestClientException e) {
return new ArrayList<>();
}
}
}
}

View File

@ -1,5 +1,12 @@
irishmonitorservice.globalVars.buildDate=@timestamp@
irishmonitorservice.globalVars.version=@version@
stats-tool.rfo=https://stats.madgik.di.uoa.gr/stats-api/raw?json=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.project.funder.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.project.funder.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D
stats-tool.rpo=https://stats.madgik.di.uoa.gr/stats-api/raw?json=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.organization.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.organization.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D
stats-tool.host=https://stats.madgik.di.uoa.gr/stats-api/raw?json=
stats-tool.rfo.publications=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.project.funder.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.project.funder.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D
stats-tool.rpo.publications=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.organization.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.organization.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D
stats-tool.rfo.publicationsPR=%7B"orderBy"%3A"yAxis"%2C"verbose"%3Afalse%2C"series"%3A%5B%7B"query"%3A%7B"parameters"%3A%5B%5D%2C"select"%3A%5B%7B"field"%3A"publication"%2C"aggregate"%3A"count"%7D%2C%7B"field"%3A"publication.project.funder.id"%2C"aggregate"%3Anull%7D%5D%2C"filters"%3A%5B%7B"groupFilters"%3A%5B%7B"field"%3A"publication.project.funder.country"%2C"type"%3A"%3D"%2C"values"%3A%5B"IE"%5D%7D%2C%7B"field"%3A"publication.result_refereed.refereed"%2C"type"%3A"%3D"%2C"values"%3A%5B"peerReviewed"%5D%7D%5D%2C"op"%3A"AND"%7D%5D%2C"entity"%3A"publication"%2C"profile"%3A"ie_monitor"%2C"useCache"%3Afalse%7D%7D%5D%7D
stats-tool.rpo.publicationsPR=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.organization.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.organization.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%2C%7B%22field%22%3A%22publication.result_refereed.refereed%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22peerReviewed%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D
stats-tool.rfo.publicationsPROA=%7B%22orderBy%22%3A%22yAxis%22%2C%22verbose%22%3Afalse%2C%22series%22%3A%5B%7B%22query%22%3A%7B%22parameters%22%3A%5B%5D%2C%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.project.funder.id%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.project.funder.country%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22IE%22%5D%7D%2C%7B%22field%22%3A%22publication.result_refereed.refereed%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22peerReviewed%22%5D%7D%2C%7B%22field%22%3A%22publication.indi_result_oa_with_license.oa_with_license%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%221%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22ie_monitor%22%2C%22useCache%22%3Afalse%7D%7D%5D%7D%0A
stats-tool.rpo.publicationsPROA=%7B"orderBy"%3A"yAxis"%2C"verbose"%3Afalse%2C"series"%3A%5B%7B"query"%3A%7B"parameters"%3A%5B%5D%2C"select"%3A%5B%7B"field"%3A"publication"%2C"aggregate"%3A"count"%7D%2C%7B"field"%3A"publication.organization.id"%2C"aggregate"%3Anull%7D%5D%2C"filters"%3A%5B%7B"groupFilters"%3A%5B%7B"field"%3A"publication.organization.country"%2C"type"%3A"%3D"%2C"values"%3A%5B"IE"%5D%7D%2C%7B"field"%3A"publication.result_refereed.refereed"%2C"type"%3A"%3D"%2C"values"%3A%5B"peerReviewed"%5D%7D%2C%7B"field"%3A"publication.indi_result_oa_with_license.oa_with_license"%2C"type"%3A"%3D"%2C"values"%3A%5B"1"%5D%7D%5D%2C"op"%3A"AND"%7D%5D%2C"entity"%3A"publication"%2C"profile"%3A"ie_monitor"%2C"useCache"%3Afalse%7D%7D%5D%7D

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="LOG_PATTERN">
%d %p %t [%c] - %m%n
</Property>
</Properties>
<Appenders>
<!-- Rolling File Appender -->
<RollingFile name="R" fileName="/var/log/dnet/irish-monitor-service/irish-monitor-service.log"
filePattern="/var/log/dnet/irish-monitor-service/irish-monitor-service-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="S" fileName="/var/log/dnet/irish-monitor-service/irish-monitor-service-spring.log"
filePattern="/var/log/dnet/irish-monitor-service/irish-monitor-service-spring-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="eu.dnetlib" level="debug" additivity="false">
<AppenderRef ref="R"/>
</Logger>
<Root level="info">
<AppenderRef ref="S"/>
</Root>
</Loggers>
</Configuration>