Add Stakeholder publications controller to get stakeholders ordered by number of publications

This commit is contained in:
Konstantinos Triantafyllou 2024-02-20 09:22:02 +02:00
parent dfb633f721
commit e5e9f07fd1
10 changed files with 183 additions and 6 deletions

View File

@ -26,7 +26,7 @@
<dependency> <!-- this dependency includes dependency to uoa-monitor-service-library -->
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-monitor-service</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
<classifier>library</classifier>
</dependency>

View File

@ -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();

View File

@ -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"});

View File

@ -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) {

View File

@ -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;
}
}
}

View File

@ -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<StakeholderPublications> getStakeholders(@PathVariable String type) throws UnsupportedEncodingException {
List<Stakeholder> stakeholders = this.service.getStakeholdersByTypeAndRole(type, null, false);
String url = this.properties.getUrlByType(type);
if (url != null) {
List<StakeholderPublications> stakeholderPublications = new ArrayList<>();
List<List<String>> 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());
}
}
}

View File

@ -0,0 +1,20 @@
package eu.dnetlib.irishmonitorservice.entities;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
public class StakeholderPublications extends Stakeholder<String> {
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

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

View File

@ -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<List<String>> 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> data = restTemplate.getForEntity(uri, Data.class);
return data.getBody().getData();
}
}

View File

@ -1,2 +1,5 @@
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