From e5e9f07fd193ca2762b040a34548ec48e2b999c6 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 20 Feb 2024 09:22:02 +0200 Subject: [PATCH] Add Stakeholder publications controller to get stakeholders ordered by number of publications --- pom.xml | 2 +- scripts/datasourceProfile.js | 15 ++++++ scripts/initialize.js | 6 +-- .../IrishMonitorServiceApplication.java | 3 +- .../properties/StatsToolProperties.java | 50 +++++++++++++++++++ .../StakeholderPublicationsController.java | 46 +++++++++++++++++ .../entities/StakeholderPublications.java | 20 ++++++++ .../irishmonitorservice/utils/Data.java | 14 ++++++ .../utils/StatsToolUtils.java | 28 +++++++++++ .../resources/irishmonitorservice.properties | 5 +- 10 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 scripts/datasourceProfile.js create mode 100644 src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/StatsToolProperties.java create mode 100644 src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderPublicationsController.java create mode 100644 src/main/java/eu/dnetlib/irishmonitorservice/entities/StakeholderPublications.java create mode 100644 src/main/java/eu/dnetlib/irishmonitorservice/utils/Data.java create mode 100644 src/main/java/eu/dnetlib/irishmonitorservice/utils/StatsToolUtils.java diff --git a/pom.xml b/pom.xml index 6113ebd..987f438 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ eu.dnetlib uoa-monitor-service - 1.1.7 + 1.1.8 library diff --git a/scripts/datasourceProfile.js b/scripts/datasourceProfile.js new file mode 100644 index 0000000..5416bf9 --- /dev/null +++ b/scripts/datasourceProfile.js @@ -0,0 +1,15 @@ +function updateDatasourceIndicators() { + var indicators = db.indicator.find(); + indicators.forEach(indicator => { + indicator.indicatorPaths.forEach(path => { + if(path.chartObject && path.chartObject.includes('opendoar____::115f89503138416a242f40fb7d7f338e')) { + while(path.chartObject.includes('opendoar____::115f89503138416a242f40fb7d7f338e')) { + path.chartObject = path.chartObject.replace('opendoar____::115f89503138416a242f40fb7d7f338e', '((__index_id__))'); + } + db.indicator.save(indicator); + } + }); + }); +} + +updateDatasourceIndicators(); diff --git a/scripts/initialize.js b/scripts/initialize.js index a2f66af..a995e6d 100644 --- a/scripts/initialize.js +++ b/scripts/initialize.js @@ -1,6 +1,6 @@ -load('organization.js') -load('funder.js') -load('datasource.js') +//load('organization.js') +//load('funder.js') +//load('datasource.js') function initializeRPOs(rpos) { var defaultRPO = db.stakeholder.findOne({"alias": "default-rpo"}); diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java b/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java index 1e0c0a9..f5af305 100644 --- a/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java +++ b/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java @@ -3,6 +3,7 @@ package eu.dnetlib.irishmonitorservice; import eu.dnetlib.authentication.configuration.AuthenticationConfiguration; import eu.dnetlib.irishmonitorservice.configuration.GlobalVars; import eu.dnetlib.irishmonitorservice.configuration.properties.APIProperties; +import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties; import eu.dnetlib.uoamonitorservice.UoaMonitorServiceConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -19,7 +20,7 @@ import org.springframework.context.annotation.PropertySources; @PropertySource("classpath:irishmonitorservice.properties"), @PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true) }) -@EnableConfigurationProperties({GlobalVars.class, APIProperties.class}) +@EnableConfigurationProperties({GlobalVars.class, APIProperties.class, StatsToolProperties.class}) @Import({UoaMonitorServiceConfiguration.class, AuthenticationConfiguration.class}) public class IrishMonitorServiceApplication { public static void main(String[] args) { diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/StatsToolProperties.java b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/StatsToolProperties.java new file mode 100644 index 0000000..0ee19a9 --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/StatsToolProperties.java @@ -0,0 +1,50 @@ +package eu.dnetlib.irishmonitorservice.configuration.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("stats-tool") +public class StatsToolProperties { + private String rpo; + private String rfo; + private String repository; + + public StatsToolProperties() { + } + + public String getRpo() { + return rpo; + } + + public void setRpo(String rpo) { + this.rpo = rpo; + } + + public String getRfo() { + return rfo; + } + + public void setRfo(String rfo) { + this.rfo = rfo; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + + public String getUrlByType(String type) { + switch (type) { + case "funder": + return this.rfo; + case "organization": + return this.rpo; + case "datasource": + return this.repository; + default: + return null; + } + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderPublicationsController.java b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderPublicationsController.java new file mode 100644 index 0000000..6bda0bc --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderPublicationsController.java @@ -0,0 +1,46 @@ +package eu.dnetlib.irishmonitorservice.controllers; + +import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties; +import eu.dnetlib.irishmonitorservice.entities.StakeholderPublications; +import eu.dnetlib.irishmonitorservice.utils.StatsToolUtils; +import eu.dnetlib.uoamonitorservice.entities.Stakeholder; +import eu.dnetlib.uoamonitorservice.service.StakeholderService; +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; +import java.util.stream.Collectors; + +@RestController +@CrossOrigin(origins = "*") +@RequestMapping("publications") +public class StakeholderPublicationsController { + + @Autowired + private StatsToolProperties properties; + + @Autowired + private StakeholderService service; + + @Autowired + private StatsToolUtils utils; + + @RequestMapping(value = "/{type}", method = RequestMethod.GET) + public List getStakeholders(@PathVariable String type) throws UnsupportedEncodingException { + List stakeholders = this.service.getStakeholdersByTypeAndRole(type, null, false); + String url = this.properties.getUrlByType(type); + if (url != null) { + List stakeholderPublications = new ArrayList<>(); + List> data = this.utils.getData(url); + data.forEach(entity -> { + String id = entity.get(1); + stakeholders.stream().filter(stakeholder -> stakeholder.getIndex_id().equals(id)).findFirst().ifPresent(stakeholder -> stakeholderPublications.add(new StakeholderPublications(stakeholder, Integer.parseInt(entity.get(0))))); + }); + return stakeholderPublications; + } else { + return stakeholders.stream().map(stakeholder -> new StakeholderPublications(stakeholder, 0)).collect(Collectors.toList()); + } + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/entities/StakeholderPublications.java b/src/main/java/eu/dnetlib/irishmonitorservice/entities/StakeholderPublications.java new file mode 100644 index 0000000..6560f5f --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/entities/StakeholderPublications.java @@ -0,0 +1,20 @@ +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; + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/utils/Data.java b/src/main/java/eu/dnetlib/irishmonitorservice/utils/Data.java new file mode 100644 index 0000000..40a58f2 --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/utils/Data.java @@ -0,0 +1,14 @@ +package eu.dnetlib.irishmonitorservice.utils; + +import java.util.List; +import java.util.Map; + +public class Data { + List>> data; + + public Data() {} + + public List> getData() { + return data.get(0); + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/utils/StatsToolUtils.java b/src/main/java/eu/dnetlib/irishmonitorservice/utils/StatsToolUtils.java new file mode 100644 index 0000000..69ed7e1 --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/utils/StatsToolUtils.java @@ -0,0 +1,28 @@ +package eu.dnetlib.irishmonitorservice.utils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.List; + +@Service +public class StatsToolUtils { + + @Autowired + private RestTemplate restTemplate; + + public List> getData(String url) throws UnsupportedEncodingException { + 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(); + ResponseEntity data = restTemplate.getForEntity(uri, Data.class); + return data.getBody().getData(); + } +} diff --git a/src/main/resources/irishmonitorservice.properties b/src/main/resources/irishmonitorservice.properties index 299af37..0eb78d8 100644 --- a/src/main/resources/irishmonitorservice.properties +++ b/src/main/resources/irishmonitorservice.properties @@ -1,2 +1,5 @@ irishmonitorservice.globalVars.buildDate=@timestamp@ -irishmonitorservice.globalVars.version=@version@ \ No newline at end of file +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