Merge remote-tracking branch 'origin/master' into production

This commit is contained in:
Konstantinos Triantafyllou 2024-04-15 11:27:47 +03:00
commit 7319799e92
8 changed files with 123 additions and 51 deletions

View File

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

66
scripts/2024-04-12.js Normal file
View File

@ -0,0 +1,66 @@
function deleteIndexParameters() {
var indicators = db.indicator.find();
indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(path => {
if(path.parameters) {
delete path.parameters['index_id'];
delete path.parameters['index_name'];
delete path.parameters['index_shortName'];
}
db.indicator.save(indicator);
});
})
}
function convertProfilesToReferences() {
var defaultStakeholders = db.stakeholder.find({defaultId: null});
defaultStakeholders.forEach(stakeholder => {
stakeholder.copy = false;
db.stakeholder.save(stakeholder);
})
var stakeholders = db.stakeholder.find({ defaultId: { $exists: true, $ne: null } });
stakeholders.forEach(stakeholder => {
stakeholder.copy = false;
stakeholder.topics.forEach(topicId => {
var topic = db.topic.findOne({_id: ObjectId(topicId)});
topic.categories.forEach(categoryId => {
var category = db.category.findOne({_id: ObjectId(categoryId)});
category.subCategories.forEach(subCategoryId => {
var subCategory = db.subCategory.findOne({_id: ObjectId(subCategoryId)});
subCategory.numbers.forEach(sectionId => {
var section = db.section.findOne({_id: ObjectId(sectionId)});
section.indicators.forEach(indicatorId => {
db.indicator.deleteOne({_id: ObjectId(indicatorId)});
});
db.section.deleteOne({_id: ObjectId(sectionId)});
});
subCategory.charts.forEach(sectionId => {
var section = db.section.findOne({_id: ObjectId(sectionId)});
section.indicators.forEach(indicatorId => {
db.indicator.deleteOne({_id: ObjectId(indicatorId)});
});
db.section.deleteOne({_id: ObjectId(sectionId)});
});
db.subCategory.deleteOne({_id: ObjectId(subCategoryId)});
});
db.category.deleteOne({_id: ObjectId(categoryId)});
});
db.topic.deleteOne({_id: ObjectId(topicId)});
});
stakeholder.topics = [];
db.stakeholder.save(stakeholder);
});
}
print('topic: ' + db.topic.find({ defaultId: { $exists: true, $ne: null } }).count());
print('category: ' + db.category.find({ defaultId: { $exists: true, $ne: null } }).count());
print('subCategory: ' + db.subCategory.find({ defaultId: { $exists: true, $ne: null } }).count());
print('Section: ' + db.section.find({ defaultId: { $exists: true, $ne: null } }).count());
print('Indicator: ' + db.indicator.find({ defaultId: { $exists: true, $ne: null } }).count());
convertProfilesToReferences();
deleteIndexParameters();
print('topic: ' + db.topic.find({ defaultId: { $exists: true, $ne: null } }).count());
print('category: ' + db.category.find({ defaultId: { $exists: true, $ne: null } }).count());
print('subCategory: ' + db.subCategory.find({ defaultId: { $exists: true, $ne: null } }).count());
print('Section: ' + db.section.find({ defaultId: { $exists: true, $ne: null } }).count());
print('Indicator: ' + db.indicator.find({ defaultId: { $exists: true, $ne: null } }).count());

View File

@ -1,15 +0,0 @@
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,46 +1,37 @@
package eu.dnetlib.irishmonitorservice.controllers; package eu.dnetlib.irishmonitorservice.controllers;
import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties;
import eu.dnetlib.irishmonitorservice.entities.StakeholderPublications; import eu.dnetlib.irishmonitorservice.entities.StakeholderPublications;
import eu.dnetlib.irishmonitorservice.utils.StatsToolUtils; import eu.dnetlib.irishmonitorservice.services.CacheService;
import eu.dnetlib.irishmonitorservice.services.StatsToolService;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.service.StakeholderService; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@RequestMapping("publications") @RequestMapping("publications")
public class StakeholderPublicationsController { public class StakeholderPublicationsController {
private final StakeholderService service;
private final CacheService cacheService;
@Autowired @Autowired
private StakeholderService service; public StakeholderPublicationsController(StakeholderService service, CacheService cacheService) {
this.service = service;
@Autowired this.cacheService = cacheService;
private StatsToolUtils utils;
public List<List<String>> getResponse(String type) throws UnsupportedEncodingException {
if(type.equals("funder")) {
return this.utils.getFunders();
} else if(type.equals("organization")) {
return this.utils.getOrganizations();
} else if(type.equals("datasource")) {
return this.utils.getDataSources();
} else {
return null;
}
} }
@RequestMapping(value = "/{type}", method = RequestMethod.GET) @RequestMapping(value = "/{type}", method = RequestMethod.GET)
public List<StakeholderPublications> getStakeholders(@PathVariable String type) throws UnsupportedEncodingException, InterruptedException { public List<StakeholderPublications> getStakeholders(@PathVariable String type) throws UnsupportedEncodingException, InterruptedException {
List<Stakeholder> stakeholders = this.service.getStakeholdersByTypeAndRole(type, null, false); List<Stakeholder> stakeholders = this.service.getStakeholdersByTypeAndRole(type, null, false);
List<StakeholderPublications> stakeholderPublications = new ArrayList<>(); List<StakeholderPublications> stakeholderPublications = new ArrayList<>();
List<List<String>> data = this.getResponse(type); List<List<String>> data = this.cacheService.getResponse(type);
List<Stakeholder> remain = new ArrayList<>(stakeholders); List<Stakeholder> remain = new ArrayList<>(stakeholders);
if (data != null) { if (data != null) {
data.forEach(entity -> { data.forEach(entity -> {

View File

@ -1,4 +1,4 @@
package eu.dnetlib.irishmonitorservice.utils; package eu.dnetlib.irishmonitorservice.entities;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -2,7 +2,7 @@ package eu.dnetlib.irishmonitorservice.entities;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
public class StakeholderPublications extends Stakeholder<String> { public class StakeholderPublications extends Stakeholder {
private Number publications; private Number publications;
public StakeholderPublications(Stakeholder stakeholder, Number publications) { public StakeholderPublications(Stakeholder stakeholder, Number publications) {

View File

@ -0,0 +1,41 @@
package eu.dnetlib.irishmonitorservice.services;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class CacheService {
private final Logger logger = LogManager.getLogger(CacheService.class);
@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;
}
}
@CacheEvict(allEntries = true, value = {"funders", "organizations", "datasources"}, beforeInvocation = true)
@Scheduled(cron = "0 0 0 * * *") // Reset cache every day at 00:00
public void clearCacheAtMidnight() throws UnsupportedEncodingException {
logger.info("Cache cleared at " + LocalDateTime.now());
this.statsToolService.getFunders();
this.statsToolService.getOrganizations();
this.statsToolService.getDataSources();
}
}

View File

@ -1,14 +1,11 @@
package eu.dnetlib.irishmonitorservice.utils; package eu.dnetlib.irishmonitorservice.services;
import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties; import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties;
import org.apache.logging.log4j.LogManager; import eu.dnetlib.irishmonitorservice.entities.Data;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -17,12 +14,10 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Service @Service
public class StatsToolUtils { public class StatsToolService {
private final Logger logger = LogManager.getLogger(StatsToolUtils.class);
@Autowired @Autowired
private StatsToolProperties properties; private StatsToolProperties properties;
@ -64,10 +59,4 @@ public class StatsToolUtils {
} }
return null; return null;
} }
@CacheEvict(allEntries = true, value = {"funders", "organizations", "datasources"})
@Scheduled(cron = "0 0 0 * * *") // Reset cache every day at 00:00
public void clearCacheAtMidnight() {
logger.info("Cache cleared at " + LocalDateTime.now());
}
} }