Merge remote-tracking branch 'origin/master' into production
This commit is contained in:
commit
7319799e92
2
pom.xml
2
pom.xml
|
@ -25,7 +25,7 @@
|
|||
<dependency> <!-- this dependency includes dependency to uoa-monitor-service-library -->
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>uoa-monitor-service</artifactId>
|
||||
<version>1.1.10</version>
|
||||
<version>1.1.11</version>
|
||||
<classifier>library</classifier>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -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());
|
|
@ -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();
|
|
@ -1,46 +1,37 @@
|
|||
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.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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*")
|
||||
@RequestMapping("publications")
|
||||
public class StakeholderPublicationsController {
|
||||
private final StakeholderService service;
|
||||
private final CacheService cacheService;
|
||||
|
||||
@Autowired
|
||||
private StakeholderService service;
|
||||
|
||||
@Autowired
|
||||
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;
|
||||
}
|
||||
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.getStakeholdersByTypeAndRole(type, null, false);
|
||||
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);
|
||||
if (data != null) {
|
||||
data.forEach(entity -> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package eu.dnetlib.irishmonitorservice.utils;
|
||||
package eu.dnetlib.irishmonitorservice.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
|
@ -2,7 +2,7 @@ package eu.dnetlib.irishmonitorservice.entities;
|
|||
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
|
||||
public class StakeholderPublications extends Stakeholder<String> {
|
||||
public class StakeholderPublications extends Stakeholder {
|
||||
private Number publications;
|
||||
|
||||
public StakeholderPublications(Stakeholder stakeholder, Number publications) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1,14 +1,11 @@
|
|||
package eu.dnetlib.irishmonitorservice.utils;
|
||||
package eu.dnetlib.irishmonitorservice.services;
|
||||
|
||||
import eu.dnetlib.irishmonitorservice.configuration.properties.StatsToolProperties;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import eu.dnetlib.irishmonitorservice.entities.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -17,12 +14,10 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StatsToolUtils {
|
||||
private final Logger logger = LogManager.getLogger(StatsToolUtils.class);
|
||||
public class StatsToolService {
|
||||
|
||||
@Autowired
|
||||
private StatsToolProperties properties;
|
||||
|
@ -64,10 +59,4 @@ public class StatsToolUtils {
|
|||
}
|
||||
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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue