diff --git a/pom.xml b/pom.xml index 52759cb..834ad4f 100644 --- a/pom.xml +++ b/pom.xml @@ -61,10 +61,6 @@ eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication true - - - - @@ -73,12 +69,6 @@ repackage - - - - - - diff --git a/scripts/2020-10-22.js b/scripts/2020-10-22.js new file mode 100644 index 0000000..2f06f0d --- /dev/null +++ b/scripts/2020-10-22.js @@ -0,0 +1,245 @@ +function upperCaseEnumValues() { + stakeholders = db.stakeholder.find().map(function (stakeholders) { + return stakeholders; + }); + for(var i=0; i"+content+"

", + "isActive" : true + } + ); + + print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")"); + } +} + +use monitordb; + +addHomePageInPortalType("funder"); +addFooterDivIdForPortalType("funder"); +addFooterHelpTextForPortalType("funder"); +addHomePageInPortalType("ri"); +addFooterDivIdForPortalType("ri"); +addFooterHelpTextForPortalType("ri"); +addHomePageInPortalType("organization"); +addFooterDivIdForPortalType("organization"); +addFooterHelpTextForPortalType("organization"); diff --git a/scripts/2023-05-30.js b/scripts/2023-05-30.js new file mode 100644 index 0000000..4b5a508 --- /dev/null +++ b/scripts/2023-05-30.js @@ -0,0 +1,182 @@ +function statsProfileOfIndicatorsAsVariable() { + print("statsProfileOfIndicatorsAsVariable"); + + numOfNumbers = 0; + numOfCharts = 0; + numOfNonMonitorProfiles = 0; + numOfMonitorProfiles = 0; + numOfNoProfiles = 0; + differentProfiles = new Set(); + + // indicators = db.indicator.find({"type": "chart"}).map(function (indicator) { + // indicators = db.indicator.find({"type": "number"}).map(function (indicator) { + indicators = db.indicator.find().map(function (indicator) { + return indicator; + }); + + print(indicators.length); + + for (var i = 0; i < indicators.length; i++) { + indicator = indicators[i]; + + indicatorPaths = indicator.indicatorPaths; + if(indicatorPaths) { + for (var j = 0; j < indicatorPaths.length; j++) { + indicatorPath = indicatorPaths[j]; + chartObjectStr = ""; + // if(indicator.type == "chart") { + chartObjectStr = indicatorPath.chartObject; + // chartObject = JSON.parse(chartObjectStr); + if(indicator.type == "chart") { + numOfCharts++; + } else { + numOfNumbers++; + } + + // if(i==0) { + // if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) { + // print(chartObject.chartDescription.queries.length); + // for(var z = 0; z < chartObject.chartDescription.queries.length; z++) { + // query = chartObject.chartDescription.queries[z].query; + // print(query.profile); + // query.profile = "((__statsProfile__))"; + // } + // } + // indicatorPath.chartObject = JSON.stringify(chartObject); + + if(chartObjectStr != null) { + var included = chartObjectStr.includes('"profile":"monitor"'); + if (!included) { + numOfNonMonitorProfiles++; + print("Indicator with id: " + indicator._id + " has not monitor profile."); + } else { + numOfMonitorProfiles++; + } + + splitted = chartObjectStr.split('"profile":"'); + if (splitted.length == 1) { + numOfNoProfiles++; + } + for (var z = 1; z < splitted.length; z = z + 2) { + prof = splitted[z].split('"')[0]; + differentProfiles.add(prof); + } + + chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"'); + chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"'); + chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"'); + indicatorPath.chartObject = chartObjectStr; + } else { + print("Indicator with id: " + indicator._id + " has no chartObject"); + } + } + } + + // save indicator + db.indicator.save(indicator); + } + print("\n"); + print("numOfNumbers: "+numOfNumbers); + print("numOfCharts: "+numOfCharts); + print("numOfMonitorProfiles: "+numOfMonitorProfiles); + print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles); + print("numOfNoProfiles: "+numOfNoProfiles); + print("Different profiles are: "); + for (var item of differentProfiles) { + print(item); + } +} + +function addFundingLevelInFilters(filter) { + if(filter.groupFilters && filter.groupFilters.length > 0) { + var index = filter.groupFilters.findIndex(filter => filter.field.includes('project')); + if(index !== -1) { + print('before: ' + JSON.stringify(filter)); + var prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project')); + if(!filter.groupFilters.find(filter => filter.field === prefix + "project.funding level 1")) { + filter.groupFilters.push({ + "field": prefix + "project.funding level 1", + "type": "contains", + "values": [ + '((__index_shortName__))' + ] + }); + print('after: ' + JSON.stringify(filter)); + } else { + print('Already added'); + } + } + return filter; + } +} + +function addFundingStreamInDefaultMSCA() { + print("addFundingStreamInDefaultMSCA") + + var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"}); + if(stakeholder) { + stakeholder.topics.forEach((topic) => { + var topicObj = db.topic.findOne({"_id": ObjectId(topic)}); + topicObj.categories.forEach((category) => { + var categoryObj = db.category.findOne({"_id": ObjectId(category)}); + categoryObj.subCategories.forEach((subCategory) => { + var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)}); + subCategoryObj.numbers.forEach((number) => { + var section = db.section.findOne({"_id": ObjectId(number)}); + section.indicators.forEach((indicator) => { + var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); + if(indicatorObject.indicatorPaths[0].parameters) { + indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase(); + if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { + var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject); + if(json.series && json.series.length > 0) { + json.series.forEach(query => { + if(query.query && query.query.filters && query.query.filters.length > 0) { + query.query.filters.forEach(filter => { + filter = addFundingLevelInFilters(filter); + }); + } + }); + indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json); + db.indicator.save(indicatorObject); + } + } + } + }); + }); + subCategoryObj.charts.forEach((chart) => { + var section = db.section.findOne({"_id": ObjectId(chart)}); + section.indicators.forEach((indicator) => { + var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); + if(indicatorObject.indicatorPaths[0].parameters) { + indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase(); + if (indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { + var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject); + if (json.chartDescription && json.chartDescription.queries && json.chartDescription.queries.length > 0) { + json.chartDescription.queries.forEach(query => { + if (query.query && query.query.filters && query.query.filters.length > 0) { + query.query.filters.forEach(filter => { + filter = addFundingLevelInFilters(filter); + }); + } + }); + indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json); + db.indicator.save(indicatorObject); + } + } + } + }); + }); + }); + + }); + }); + } else { + print("Profile doesn't exist") + } +} + +use monitordb; + +statsProfileOfIndicatorsAsVariable(); +addFundingStreamInDefaultMSCA(); diff --git a/scripts/2024-02-27.js b/scripts/2024-02-27.js new file mode 100644 index 0000000..5f84810 --- /dev/null +++ b/scripts/2024-02-27.js @@ -0,0 +1,16 @@ +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); + }); + }) +} + +use irish-prod; +deleteIndexParameters(); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java index 3387c9d..84d90a6 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java @@ -41,7 +41,6 @@ public class SwaggerConfig extends WebMvcConfigurerAdapter { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) -// .globalOperationParameters(globalParameterList()) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoamonitorservice.controllers")) diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java index 42c31fd..17e52d1 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java @@ -14,7 +14,6 @@ import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import java.util.Collections; -//"uoahelptexts" @Configuration @EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"}) public class MongoConnection { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java index d2f0d23..e3f6634 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java @@ -259,51 +259,10 @@ public class CategoryController { if(topic.getDefaultId() == null && children != null) { onDeleteDefaultCategory(categoryId, topicId, children); } - -// for(String subCategoryId : category.getSubCategories()) { -// SubCategory subcategory = subCategoryDAO.findById(subCategoryId); -// if(subcategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Delete category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")"); -// } -// -// for(String chartSectionId : subcategory.getCharts()) { -// Section chartSection = sectionDAO.findById(chartSectionId); -// if (chartSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String chartId : chartSection.getIndicators()) { -// indicatorDAO.delete(chartId); -// } -// subcategory.setCharts(null); -// sectionDAO.delete(chartSectionId); -// } -// -// for(String numberSectionId : subcategory.getNumbers()) { -// Section numberSection = sectionDAO.findById(numberSectionId); -// if (numberSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String numberId : numberSection.getIndicators()) { -// indicatorDAO.delete(numberId); -// } -// subcategory.setNumbers(null); -// sectionDAO.delete(numberSectionId); -// } -// -// subCategoryDAO.delete(subCategoryId); -// } subCategoryController.deleteTree(category); - category.setSubCategories(null); - categories.remove(index); topicDAO.save(topic); - categoryDAO.delete(categoryId); log.debug("Category deleted!"); } else { @@ -406,44 +365,6 @@ public class CategoryController { return categoriesFull; } -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId) { -// log.debug("toggle category status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId); -// -// Category category = categoryDAO.findById(categoryId); -// if (category == null) { -// // EXCEPTION - Category not found -// throw new EntityNotFoundException("Toggle category status: Category with id: "+categoryId+" not found"); -// } -// category.setIsActive(!category.getIsActive()); -// -// this.toggleCategory(stakeholderId, topicId, category); -// -// return category.getIsActive(); -// } -// -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleCategoryAccess(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId) { -// log.debug("toggle category access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId); -// -// Category category = categoryDAO.findById(categoryId); -// if (category == null) { -// // EXCEPTION - Category not found -// throw new EntityNotFoundException("Toggle category access: Category with id: "+categoryId+" not found"); -// } -// category.setIsPublic(!category.getIsPublic()); -// -// this.toggleCategory(stakeholderId, topicId, category); -// -// return category.getIsPublic(); -// } - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST) public Category changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId, diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index 9c33130..f67c5c2 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -221,16 +221,9 @@ public class IndicatorController { if(section.getDefaultId() != null && section.getDefaultId().equals(defaultSection.getId())) { Indicator indicatorNew = new Indicator(); indicatorNew.copyFromDefault(indicator, subCategory.getVisibility()); - for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { - Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias()); - parameterMapping(indicatorPath, stakeholder); - } - indicatorDAO.save(indicatorNew); - List indicators = section.getIndicators(); indicators.add(indicatorNew.getId()); - sectionDAO.save(section); } } @@ -300,7 +293,6 @@ public class IndicatorController { if(indicatorPathBasedOnDefault == null) { // Add new indicator path in existing indicators IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath); - parameterMapping(indicatorPathNew, stakeholder); indicatorPaths.add(indicatorPathNew); changed = true; } else { @@ -407,10 +399,6 @@ public class IndicatorController { indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue()); changed = true; } -// else if(parameter.getKey().equals("type")) { -// indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue()); -// changed = true; -// } } // When deleting indicator path parameters in a default profile, delete them also from all children profiles @@ -421,8 +409,6 @@ public class IndicatorController { } } } - parameterMapping(indicatorPathBasedOnDefault, stakeholder); - //} } log.debug("After parameters check: " + changed); @@ -500,65 +486,6 @@ public class IndicatorController { } } - public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) throws UnsupportedEncodingException { - if (indicatorPath.getParameters() != null) { - if (indicatorPath.getParameters().containsKey("index_name")) { - indicatorPath.getParameters().put("index_name", stakeholder.getIndex_name()); - } else if (indicatorPath.getParameters().containsKey("index_shortName")) { - if(stakeholder.getIndex_shortName() != null) { - indicatorPath.getParameters().put("index_shortName", stakeholder.getIndex_shortName().toLowerCase()); - } else { - indicatorPath.getParameters().remove("index_shortName"); - } - } else if (indicatorPath.getParameters().containsKey("index_id")) { - indicatorPath.getParameters().put("index_id", stakeholder.getIndex_id()); - } - } - -// // url encoding for number indicators -// String url = indicatorPath.getUrl(); -// String encoded_index_id = urlEncode(URLEncoder.encode(stakeholder.getIndex_id(), "UTF-8")); -// url = url.replace("index_id", encoded_index_id); -// String encoded_index_name = urlEncode(URLEncoder.encode(stakeholder.getIndex_name(), "UTF-8")); -// url = url.replace("index_name", encoded_index_name); -// String encoded_index_shortName = urlEncode(URLEncoder.encode(stakeholder.getIndex_shortName(), "UTF-8")); -// url = url.replace("index_shortName", encoded_index_shortName); -// indicatorPath.setUrl(url); - } - - public String urlEncode(String encodedIndicatorPathField) { - String indicatorPathField = ""; - - for( int i=0; i sections = sectionDAO.findByDefaultId(defaultSectionId); -// -// for(Section section : sections) { -// List indicators = section.getIndicators(); -// -// Iterator indicatorsIterator = indicators.iterator(); -// while(indicatorsIterator.hasNext()) { -// String indicatorId = indicatorsIterator.next(); -// -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if (indicator.getDefaultId().equals(defaultIndicatorId)) { -// indicatorsIterator.remove(); -// sectionDAO.save(section); -// -// indicatorDAO.delete(indicatorId); -// log.debug("Indicator deleted!"); -// -// break; -// } -// } -// } - // 2nd way List
sections = sectionDAO.findByDefaultId(defaultSectionId); List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); @@ -654,19 +558,6 @@ public class IndicatorController { } } } - -// // 3rd way - parentId -// List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); -// for(Indicator indicator : indicators) { -// Section section = sectionDAO.findById(indicator.getParent()); -// List sectionIndicators = section.getIndicators(); -// -// sectionIndicators.remove(indicator.getId()); -// sectionDAO.save(section); -// -// indicatorDAO.delete(indicator.getId()); -// log.debug("Indicator deleted!"); -// } } else if(children.equals("disconnect")) { List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); for(Indicator indicator : indicators) { @@ -678,79 +569,6 @@ public class IndicatorController { return true; } -// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) -// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { -// log.debug("delete all chart indicators of stakeholder"); -// log.debug("Stakeholder: "+stakeholderId); -// -// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); -// if(stakeholder != null) { -// -// for(String topicId : stakeholder.getTopics()) { -// Topic topic = topicDAO.findById(topicId); -// if(topic != null) { -// for(String categoryId : topic.getCategories()) { -// Category category = categoryDAO.findById(categoryId); -// if(category != null) { -// for(String subcategoryId : category.getSubCategories()) { -// SubCategory subcategory = subCategoryDAO.findById(subcategoryId); -// if(subcategory != null) { -// -// for(String sectionId : subcategory.getCharts()) { -// Section section = sectionDAO.findById(sectionId); -// if (section != null) { -// -// List indicators = section.getIndicators(); -// Iterator indicatorsIterator = section.getIndicators().iterator(); -// -// while (indicatorsIterator.hasNext()) { -// String indicatorId = indicatorsIterator.next(); -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if (indicator != null) { -// int index = indicators.indexOf(indicatorId); -// if (index != -1) { -// indicatorsIterator.remove(); -// //indicators.remove(index); -// -// indicatorDAO.delete(indicatorId); -// log.debug("Indicator deleted!"); -// } else { -// // EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle(); -// throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Section: " + sectionId); -// } -// } else { -// // EXCEPTION - Indicator not found -// throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found"); -// } -// } -// sectionDAO.save(section); -// } else { -// // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -// throw new PathNotValidException("Delete indicator: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId); -// } -// } -// } else { -// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -// throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); -// } -// } -// } else { -// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -// throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); -// } -// } -// } else { -// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); -// throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); -// } -// } -// } else { -// // EXCEPTION - Stakeholder not found -// throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found"); -// } -// return true; -// } - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST) public List reorderIndicators(@PathVariable("stakeholderId") String stakeholderId, @@ -793,50 +611,6 @@ public class IndicatorController { return indicatorsFull; } -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId, -// @PathVariable("sectionId") String sectionId, -// @PathVariable("indicatorId") String indicatorId) { -// log.debug("toggle indicator status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId); -// -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if (indicator == null) { -// // EXCEPTION - Indicator not found -// throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found"); -// } -// indicator.setIsActive(!indicator.getIsActive()); -// -// this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator); -// -// return indicator.getIsActive(); -// } -// -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId, -// @PathVariable("sectionId") String sectionId, -// @PathVariable("indicatorId") String indicatorId) { -// log.debug("toggle indicator access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId); -// -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if (indicator == null) { -// // EXCEPTION - Indicator not found -// throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found"); -// } -// indicator.setIsPublic(!indicator.getIsPublic()); -// -// this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator); -// -// return indicator.getIsPublic(); -// } - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST) public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId, diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java index fa68f01..24587d1 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java @@ -16,9 +16,6 @@ import java.util.*; @CrossOrigin(origins = "*") public class MonitorController { private final Logger log = LogManager.getLogger(this.getClass()); -// -// @Autowired -// private LayoutService layoutService; @Autowired private PortalService portalService; @@ -36,11 +33,6 @@ public class MonitorController { if (!old_pid.equals(new_pid)) { pageService.updatePid(old_pid, new_pid, portal.getType()); } -// String old_pid = portalResponse.getPid(); -// String new_pid = portal.getPid(); -// if(!old_pid.equals(new_pid)) { -// layoutService.updatePid(old_pid, new_pid); -// } return portalResponse; } @@ -60,16 +52,5 @@ public class MonitorController { return true; } - -// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET) -// public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) { -// return layoutService.findByPid(pid); -// } -// -// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST) -// public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) { -// return layoutService.save(layout); -// } - } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java index 6b84e53..802fe33 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java @@ -25,7 +25,6 @@ import java.util.Map; @RestController @CrossOrigin(origins = "*") @RequestMapping("/monitor-library") -//@ConditionalOnBean(UoaMonitorServiceApplication.class) public class MonitorLibraryCheckDeployController { private final Logger log = LogManager.getLogger(this.getClass()); @@ -63,7 +62,6 @@ public class MonitorLibraryCheckDeployController { response.put("monitorservice.mongodb.port", mongoConfig.getPort()+""); response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]"); response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]"); -// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password"); if(globalVars.date != null) { response.put("Date of deploy", globalVars.date.toString()); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java index fea6107..45aecec 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java @@ -58,7 +58,6 @@ public class MonitorServiceCheckDeployController { response.put("monitorservice.mongodb.port", mongoConfig.getPort()+""); response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]"); response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]"); -// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password"); if(globalVars.date != null) { response.put("Date of deploy", globalVars.date.toString()); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java index a7506ee..90b47b0 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java @@ -196,241 +196,6 @@ public class SectionController { public void onUpdateDefaultSection(Section section, Stakeholder stakeholder, Section oldSection) { log.debug("On update default section"); - - // section already exists - check if changed and update all sections based on it - - boolean changed = false; - List
sections = sectionDAO.findByDefaultId(section.getId()); - - for(Section sectionBasedOnDefault : sections) { - if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle()) - && (oldSection.getTitle() == null || oldSection.getTitle().equals(sectionBasedOnDefault.getTitle()))) { - - sectionBasedOnDefault.setTitle(section.getTitle()); - changed = true; - } - - if(!changed) { -// break; - continue; - } - -// sectionBasedOnDefault.setTitle(section.getTitle()); - sectionBasedOnDefault.setUpdateDate(section.getUpdateDate()); - sectionDAO.save(sectionBasedOnDefault); - } - } - - @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete", method = RequestMethod.DELETE) - public boolean deleteSection(@PathVariable("stakeholderId") String stakeholderId, - @PathVariable("topicId") String topicId, - @PathVariable("categoryId") String categoryId, - @PathVariable("subcategoryId") String subcategoryId, - @PathVariable("sectionId") String sectionId, - @RequestParam(required = false) String children) { - log.debug("delete section"); - log.debug("Id: "+sectionId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); - - Section section = sectionDAO.findById(sectionId); - if(section != null) { - SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); - - Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); - if(section.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { - // EXCEPTION - Access denied - throw new ForbiddenException("Delete section: You are not authorized to delete a default Section in stakeholder with id: "+stakeholderId); - } - - String type = ""; - List sections = null; - if (section.getType().equals("chart")) { - sections = subCategory.getCharts(); - type = "chart"; - } else if (section.getType().equals("number")) { - sections = subCategory.getNumbers(); - type = "number"; - } - - int index = sections.indexOf(sectionId); - if (index != -1) { - // this section belongs in default profile - if(subCategory.getDefaultId() == null && children != null) { - onDeleteDefaultSection(sectionId, subcategoryId, children, type); - } - - indicatorController.deleteTree(section); - - sections.remove(index); - subCategoryDAO.save(subCategory); - - sectionDAO.delete(sectionId); - log.debug("Section deleted!"); - } else { - // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); - throw new PathNotValidException("Delete section: Section with id: "+sectionId+" not found in SubCategory: "+subcategoryId); - } - } else { - // EXCEPTION - Section not found - throw new EntityNotFoundException("Delete section: Section with id: "+sectionId+" not found"); - } - return true; - } - - public boolean onDeleteDefaultSection(String defaultSectionId, String defaultSubCategoryId, String children, String type) { - if(children.equals("delete")) { - List subCategories = subCategoryDAO.findByDefaultId(defaultSubCategoryId); - List
sections = sectionDAO.findByDefaultId(defaultSectionId); - - for(SubCategory subCategory : subCategories) { - Iterator
sectionsIterator = sections.iterator(); - while(sectionsIterator.hasNext()) { - Section section = sectionsIterator.next(); - - String sectionId = section.getId(); - List subCategorySections = null; - if(type.equals("chart")) { - subCategorySections = subCategory.getCharts(); - } else if(type.equals("number")) { - subCategorySections = subCategory.getNumbers(); - } - if(subCategorySections != null && subCategorySections.contains(sectionId)) { - sectionsIterator.remove(); - - subCategorySections.remove(sectionId); - subCategoryDAO.save(subCategory); - - indicatorController.deleteTree(section); - - sectionDAO.delete(sectionId); - log.debug("Section with id: "+sectionId+" deleted!"); - - break; - } - } - } - } else if(children.equals("disconnect")) { - List
sections = sectionDAO.findByDefaultId(defaultSectionId); - for(Section section : sections) { - indicatorController.disConnectTree(section); - - section.setDefaultId(null); - sectionDAO.save(section); - - log.debug("DefaultId for Section with id: "+section.getId()+" empty!"); - } - } - return true; - } - - @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST) - public List
reorderSections(@PathVariable("stakeholderId") String stakeholderId, - @PathVariable("topicId") String topicId, - @PathVariable("categoryId") String categoryId, - @PathVariable("subcategoryId") String subcategoryId, - @PathVariable("type") String type, - @RequestBody List sections) { - log.debug("reorder sections of type: "+type); - log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); - - SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); - - if (type.equals("chart")) { - List oldSections = subCategory.getCharts(); - for (String sectionId : oldSections) { - if (!sections.contains(sectionId)) { - sections.add(sectionId); - } - } - subCategory.setCharts(sections); - } else if (type.equals("number")) { - List oldSections = subCategory.getNumbers(); - for (String sectionId : oldSections) { - if (!sections.contains(sectionId)) { - sections.add(sectionId); - } - } - subCategory.setNumbers(sections); - } - - List
sectionsFull = new ArrayList<>(); - for(String sectionId : sections) { - Section section = sectionDAO.findById(sectionId); - if(section == null) { - // EXCEPTION - Section not found - throw new EntityNotFoundException("Reorder sections: Section with id: " + sectionId + " not found"); - } - sectionsFull.add(section); - } - - subCategoryDAO.save(subCategory); - log.debug("Sections reordered!"); - - return sectionsFull; - } - -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleSectionStatus(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId, -// @PathVariable("sectionId") String sectionId) { -// log.debug("toggle section status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Section: "+sectionId); -// -// Section section = sectionDAO.findById(sectionId); -// if (section == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Toggle section status: Section with id: "+sectionId+" not found"); -// } -// section.setIsActive(!section.getIsActive()); -// -// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId, section); -// -// return section.getIsActive(); -// } - -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleSectionAccess(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId, -// @PathVariable("sectionId") String sectionId) { -// log.debug("toggle section access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); -// -// Section section = sectionDAO.findById(sectionId); -// if (section == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Toggle section access: Section with id: "+sectionId+" not found"); -// } -// section.setIsPublic(!section.getIsPublic()); -// -// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId); -// -// return section.getIsPublic(); -// } - - - public void toggleSection(String stakeholderId, String topicId, String categoryId, String subcategoryId, Section section) { - SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); - - List sections = null; - if (section.getType().equals("chart")) { - sections = subCategory.getCharts(); - } else if (section.getType().equals("number")) { - sections = subCategory.getNumbers(); - } - - if(sections.contains(section.getId())) { - sectionDAO.save(section); - log.debug("Section toggled!"); - } else { - // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); - throw new PathNotValidException("Toggle section: Section with id: "+section.getId()+" not found in SubCategory: "+subcategoryId); - } - } private SubCategory checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId) { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index f6293a4..8e2a33f 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -56,19 +56,10 @@ public class StakeholderController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET) public List getAllReservedStakeholderAlias() { -// log.debug("get all stakeholder reserved alias-es"); - List stakeholderAlias = new ArrayList<>(); - - List stakeholders = stakeholderDAO.findAll(); - if(stakeholders != null) { - stakeholders.forEach(stakeholder -> { - stakeholderAlias.add(stakeholder.getAlias()); - }); - } - stakeholderAlias.add( "all"); + List stakeholderAlias = this.stakeholderService.getAllAliases(); + stakeholderAlias.add("all"); stakeholderAlias.add("default"); stakeholderAlias.add("alias"); - return stakeholderAlias; } @@ -120,22 +111,11 @@ public class StakeholderController { boolean addAll = false; boolean addPublicAndRestricted = false; -// if(roles == null -// || roles.contains(authorizationService.PORTAL_ADMIN) -// || roles.contains(authorizationService.curator(stakeholder.getType())) -// || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) { if(rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { - //if(visibility == null || visibility == (Visibility.PRIVATE)) { addAll = true; - //} - //if(visibility == null || visibility == (Visibility.PRIVATE) || visibility == (Visibility.RESTRICTED)) { addPublicAndRestricted = true; - //} -// } else if(roles != null && roles.contains(authorizationService.member(stakeholder.getType(), stakeholder.getAlias()))) { } else if(rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())) { - //if(visibility == null || visibility == (Visibility.PRIVATE) || visibility == (Visibility.RESTRICTED)) { addPublicAndRestricted = true; - //} } Stakeholder stakeholderFull = new Stakeholder<>(stakeholder); @@ -201,62 +181,18 @@ public class StakeholderController { sectionsNumbers.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted)); } subCategoryFull.setNumbers(sectionsNumbers); - -// List charts = new ArrayList<>(); -// for(String indicatorId : subCategory.getCharts()) { -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if(indicator == null) { -// // EXCEPTION - Indicator not found -// throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")"); -// } -// charts.add(indicator); -// } -// subCategoryFull.setCharts(charts); -// -// List numbers = new ArrayList<>(); -// for (String indicatorId : subCategory.getNumbers()) { -// Indicator indicator = indicatorDAO.findById(indicatorId); -// if (indicator == null) { -// // EXCEPTION - Indicator not found -// throw new EntityNotFoundException("Get stakeholder: Indicator with id: " + indicatorId + " not found (indicator exists in subCategory: " + subCategoryId + ")"); -// } -// numbers.add(indicator); -// } -// subCategoryFull.setNumbers(numbers); - subCategories.add(subCategoryFull); } - categoryFull.setSubCategories(subCategories); categories.add(categoryFull); } - topicFull.setCategories(categories); topics.add(topicFull); } - stakeholderFull.setTopics(topics); return stakeholderFull; } -// private SubCategory setFullSubcategory(SubCategory subCategory) { -// SubCategory subCategoryFull = new SubCategory>(subCategory); -// -// List
sectionsCharts = new ArrayList<>(); -// -// for(String sectionId : subCategory.getCharts()) { -// sectionsCharts.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted)); -// } -// subCategoryFull.setCharts(sectionsCharts); -// -// List
sectionsNumbers = new ArrayList<>(); -// -// for(String sectionId : subCategory.getNumbers()) { -// sectionsNumbers.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted)); -// } -// subCategoryFull.setNumbers(sectionsNumbers); -// } - private Section getSectionFull(String sectionId, String subCategoryId, boolean addAll, boolean addPublicAndRestricted) { Section section = sectionDAO.findById(sectionId); if (section == null) { @@ -323,10 +259,6 @@ public class StakeholderController { // Remove stakeholders for which i do not have authority if(stakeholders != null && stakeholders.size() > 0) { -// log.debug("ROLES: "); -// roles.forEach(role -> log.debug(role)); -// -// if (roles.contains(authorizationService.PORTAL_ADMIN)) { if (rolesUtils.isPortalAdmin()) { for(Stakeholder stakeholder : stakeholders) { stakeholdersFull.add(this.setFullEntities(stakeholder)); @@ -337,8 +269,6 @@ public class StakeholderController { Iterator stakeholderIterator = stakeholders.iterator(); while(stakeholderIterator.hasNext()) { Stakeholder stakeholder = stakeholderIterator.next(); - -// if(roles.contains(authorizationService.curator(stakeholder.getType()))) { if(rolesUtils.isCurator(stakeholder.getType())) { stakeholdersFull.add(this.setFullEntities(stakeholder)); continue; @@ -359,13 +289,11 @@ public class StakeholderController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET) public List getMyRealStakeholders(@RequestParam(required = false) String type) { -// log.debug("get my NOT default stakeholders" + (type != null ? " with type: "+type : "")); return stakeholderService.getStakeholdersByTypeAndRole(type, null, true); } @RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET) public Stakeholder getStakeholder(@PathVariable("alias") String alias) { -// log.debug("get stakeholder: "+alias); Stakeholder stakeholder = stakeholderDAO.findByAlias(alias); if(stakeholder == null) { @@ -373,7 +301,6 @@ public class StakeholderController { throw new EntityNotFoundException("Get stakeholder: Stakeholder with alias: "+alias+" not found"); } -// List roles = authorizationService.getRoles(); if(stakeholder.getDefaultId() == null && !rolesUtils.isLoggedIn()) { // EXCEPTION - Unauthorized throw new AccessDeniedException("Get stakeholder: You are not authorized (not logged in) to access stakeholder with alias: "+alias); @@ -386,7 +313,6 @@ public class StakeholderController { if((stakeholder.getVisibility() == Visibility.PRIVATE && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias()) || (stakeholder.getVisibility() == Visibility.RESTRICTED && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias()) && !rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())))) { // // EXCEPTION - Access denied -// throw new ForbiddenException("Get stakeholder: You are not authorized to get stakeholder with alias: "+alias); List topicsEmpty = stakeholder.getTopics(); topicsEmpty.clear(); stakeholder.setTopics(topicsEmpty); @@ -397,7 +323,6 @@ public class StakeholderController { return this.setFullEntities(stakeholder); } -// @PreAuthorize("isAuthenticated()") @PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN, " + "@AuthorizationService.curator(#_stakeholder.getType()), " @@ -407,26 +332,13 @@ public class StakeholderController { public Stakeholder saveStakeholder(@RequestBody Stakeholder _stakeholder) { log.debug("save stakeholder"); log.debug("Alias: "+_stakeholder.getAlias() + " - Id: "+_stakeholder.getId()); - -// if(_stakeholder == null) { -// log.debug("stakeholder null"); -// // EXCEPTION - Parameter for Stakeholder is not accepted -// } - Stakeholder stakeholder = new Stakeholder<>(_stakeholder); Date date = new Date(); stakeholder.setUpdateDate(date); - List topics = new ArrayList<>(); - - // stakeholder does not exist in DB if(_stakeholder.getId() == null) { stakeholder.setCreationDate(date); - -// for(Topic topic : _stakeholder.getTopics()) { -// topics.add(topic.getId()); -// } } else { Stakeholder oldStakeholder = stakeholderDAO.findById(_stakeholder.getId()); if(oldStakeholder == null) { @@ -441,21 +353,12 @@ public class StakeholderController { } topics.add(topic.getId()); } -// stakeholder.setTopics(topics); -// _stakeholder = this.setFullEntities(stakeholder, rolesUtils.getRoles()); } - stakeholder.setTopics(topics); - Stakeholder stakeholderSaved = stakeholderDAO.save(stakeholder); _stakeholder.setId(stakeholderSaved.getId()); _stakeholder.setCreationDate(stakeholderSaved.getCreationDate()); _stakeholder.setUpdateDate(stakeholderSaved.getUpdateDate()); - - topics = null; - stakeholder = null; - stakeholderSaved = null; - return _stakeholder; } @@ -470,78 +373,14 @@ public class StakeholderController { if(stakeholder != null) { pid = stakeholder.getAlias(); - -// if(!roles.contains(authorizationService.PORTAL_ADMIN) -// && !roles.contains(authorizationService.curator(stakeholder.getType()))) { if(!rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: "+stakeholderId); } - -// for(String topicId : stakeholder.getTopics()) { -// Topic topic = topicDAO.findById(topicId); -// if (topic == null) { -// // EXCEPTION - Topic not found -// throw new EntityNotFoundException("Delete stakeholder: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholderId+")"); -// } -// -// for (String categoryId : topic.getCategories()) { -// Category category = categoryDAO.findById(categoryId); -// if (category == null) { -// // EXCEPTION - Category not found -// throw new EntityNotFoundException("Delete stakeholder: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")"); -// } -// -// for (String subCategoryId : category.getSubCategories()) { -// SubCategory subcategory = subCategoryDAO.findById(subCategoryId); -// if (subcategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Delete stakeholder: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")"); -// } -// -// for(String chartSectionId : subcategory.getCharts()) { -// Section chartSection = sectionDAO.findById(chartSectionId); -// if (chartSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String chartId : chartSection.getIndicators()) { -// indicatorDAO.delete(chartId); -// } -// subcategory.setCharts(null); -// sectionDAO.delete(chartSectionId); -// } -// -// for(String numberSectionId : subcategory.getNumbers()) { -// Section numberSection = sectionDAO.findById(numberSectionId); -// if (numberSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String numberId : numberSection.getIndicators()) { -// indicatorDAO.delete(numberId); -// } -// subcategory.setNumbers(null); -// sectionDAO.delete(numberSectionId); -// } -// -// subCategoryDAO.delete(subCategoryId); -// } -// category.setSubCategories(null); -// categoryDAO.delete(categoryId); -// } -// topic.setCategories(null); -// topicDAO.delete(topicId); -// } - topicController.deleteTree(stakeholder); - stakeholder.setTopics(null); stakeholderDAO.delete(stakeholderId); log.debug("Stakeholder deleted!"); - Portal portal = portalService.getPortal(pid); if(portal != null) { portalService.deletePortal(portal.getId()); @@ -553,44 +392,6 @@ public class StakeholderController { return true; } - -// @RequestMapping(value = "/{stakeholderId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleStakeholderStatus(@PathVariable("stakeholderId") String stakeholderId) { -// log.debug("toggle stakeholder status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId); -// -// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); -// if (stakeholder == null) { -// // EXCEPTION - Stakeholder not found -// throw new EntityNotFoundException("Toggle stakeholder status: Stakeholder with id: "+stakeholderId+" not found"); -// } -// stakeholder.setIsActive(!stakeholder.getIsActive()); -// -// stakeholderDAO.save(stakeholder); -// log.debug("Stakeholder toggled!"); -// -// return stakeholder.getIsActive(); -// } -// -// @RequestMapping(value = "/{stakeholderId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleStakeholderAccess(@PathVariable("stakeholderId") String stakeholderId) { -// log.debug("toggle stakeholder access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId); -// -// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); -// if (stakeholder == null) { -// // EXCEPTION - Stakeholder not found -// throw new EntityNotFoundException("Toggle stakeholder access: Stakeholder with id: "+stakeholderId+" not found"); -// } -// stakeholder.setIsPublic(!stakeholder.getIsPublic()); -// -// stakeholderDAO.save(stakeholder); -// log.debug("Stakeholder toggled!"); -// -// return stakeholder.getIsPublic(); -// } - - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST) public Stakeholder changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId, @@ -603,12 +404,6 @@ public class StakeholderController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Change stakeholder visibility: Stakeholder with id: "+stakeholderId+" not found"); } - -// List roles = authorizationService.getRoles(); - -// if(!roles.contains(authorizationService.PORTAL_ADMIN) -// && !roles.contains(authorizationService.curator(stakeholder.getType())) -// && !roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) { if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: "+stakeholderId); @@ -621,7 +416,7 @@ public class StakeholderController { Stakeholder stakeholderFull = new Stakeholder<>(stakeholder); List topicsFull = new ArrayList<>(); - if(propagate != null && propagate) { + if (propagate != null && propagate) { for (String topicId : stakeholder.getTopics()) { topicsFull.add(topicController.changeVisibilityTree(topicId, visibility, propagate)); } @@ -636,45 +431,4 @@ public class StakeholderController { return stakeholder; } - - // The following are not supposed to be used -// @RequestMapping(value = "/stakeholder/dates", method = RequestMethod.GET) -// public List getAllStakeholderDates() { -// List profiles = stakeholderDAO.findAll(); -// List profileDates = new ArrayList<>(); -// -// int i=0; -// for(Stakeholder profile : profiles) { -// log.debug(profile.getCreationDate()); -// profileDates.add(profile.getCreationDate()); -// log.debug(profileDates.get(i)); -// i++; -// } -// return profileDates; -// } -// -// @RequestMapping(value = "/stakeholder/dates1", method = RequestMethod.GET) -// public List getAllStakeholderDates1() { -// List profiles = stakeholderDAO.findAll(); -// List profileDates = new ArrayList<>(); -// -// for(Stakeholder profile : profiles) { -// log.debug(profile.getCreationDate().toString()); -// profileDates.add(profile.getCreationDate().toString()); -// } -// return profileDates; -// } -// -// @RequestMapping(value = "/stakeholder/dates2", method = RequestMethod.GET) -// public List getAllStakeholderDates2() { -// List profiles = stakeholderDAO.findAll(); -// List profileDates = new ArrayList<>(); -// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); -// -// for(Stakeholder profile : profiles) { -// log.debug(format.format(profile.getCreationDate())); -// profileDates.add(format.format(profile.getCreationDate())); -// } -// return profileDates; -// } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java index 06c005f..aaa499b 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java @@ -142,20 +142,6 @@ public class SubCategoryController { numberSections.add(numberSection.getId()); } } - -// List charts = new ArrayList<>(); -// for(Indicator chart : subcategoryFull.getCharts()) { -// charts.add(chart.getId()); -// } -// subCategory.setCharts(charts); -// -// List numbers = new ArrayList<>(); -// for(Indicator numbr : subcategoryFull.getNumbers()) { -// numbers.add(numbr.getId()); -// } -// subCategory.setNumbers(numbers); - - subCategory.setCharts(chartSections); subCategory.setNumbers(numberSections); @@ -181,11 +167,6 @@ public class SubCategoryController { subcategoryFull.setId(subCategory.getId()); } - - chartSections = null; - numberSections = null; - subCategory = null; - return subcategoryFull; } @@ -227,12 +208,8 @@ public class SubCategoryController { } if(!changed) { -// break; continue; } - -// subCategoryBasedOnDefault.setName(subCategory.getName()); -// subCategoryBasedOnDefault.setDescription(subCategory.getDescription()); subCategoryBasedOnDefault.setUpdateDate(subCategory.getUpdateDate()); subCategoryDAO.save(subCategoryBasedOnDefault); } @@ -266,35 +243,6 @@ public class SubCategoryController { if(category.getDefaultId() == null && children != null) { onDeleteDefaultSubCategory(subcategoryId, categoryId, children); } - -// for(String chartSectionId : subcategory.getCharts()) { -// Section chartSection = sectionDAO.findById(chartSectionId); -// if (chartSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subcategoryId+")"); -// } -// -// for (String chartId : chartSection.getIndicators()) { -// indicatorDAO.delete(chartId); -// } -// subcategory.setCharts(null); -// sectionDAO.delete(chartSectionId); -// } -// -// for(String numberSectionId : subcategory.getNumbers()) { -// Section numberSection = sectionDAO.findById(numberSectionId); -// if (numberSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subcategoryId+")"); -// } -// -// for (String numberId : numberSection.getIndicators()) { -// indicatorDAO.delete(numberId); -// } -// subcategory.setNumbers(null); -// sectionDAO.delete(numberSectionId); -// } - sectionController.deleteTree(subcategory); subcategory.setCharts(null); @@ -393,46 +341,6 @@ public class SubCategoryController { return subCategoriesFull; } -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId) { -// log.debug("toggle subCategory status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); -// -// SubCategory subCategory = subCategoryDAO.findById(subcategoryId); -// if (subCategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Toggle subCategory status: SubCategory with id: "+subcategoryId+" not found"); -// } -// subCategory.setIsActive(!subCategory.getIsActive()); -// -// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); -// -// return subCategory.getIsActive(); -// } -// -// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleSubCategoryAccess(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId, -// @PathVariable("categoryId") String categoryId, -// @PathVariable("subcategoryId") String subcategoryId) { -// log.debug("toggle subCategory access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); -// -// SubCategory subCategory = subCategoryDAO.findById(subcategoryId); -// if (subCategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Toggle subCategory access: SubCategory with id: "+subcategoryId+" not found"); -// } -// subCategory.setIsPublic(!subCategory.getIsPublic()); -// -// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); -// -// return subCategory.getIsPublic(); -// } - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST) public SubCategory changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId, @@ -522,18 +430,6 @@ public class SubCategoryController { // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); } - -// SubCategory subcategory = subCategoryDAO.findById(subcategoryId); -// if(subcategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); -// } -// -// if (!category.getSubCategories().contains(subcategoryId)) { -// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -// throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); -// } - return category; } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java deleted file mode 100644 index 6c9fc80..0000000 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java +++ /dev/null @@ -1,44 +0,0 @@ -package eu.dnetlib.uoamonitorservice.controllers; - -import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO; -import eu.dnetlib.uoamonitorservice.entities.Stakeholder; -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.util.List; - -@RestController -@CrossOrigin(origins = "*") -public class TestController { - private final Logger log = LogManager.getLogger(this.getClass()); - - @Autowired - private StakeholderDAO stakeholderDAO; - -// @RequestMapping("/") -// public String index() { -// return "Greetings from Spring Boot!"; -// } - - // Check ExceptionHandler - @RequestMapping(value = "/test-error1", method = RequestMethod.GET) - public Stakeholder getFirstStakeholder() { - List stakeholders; - stakeholders = stakeholderDAO.findAll(); - - return stakeholders.get(0); - } - - @RequestMapping(value = "/test-error2", method = RequestMethod.GET) - public String getParam(@RequestParam String param) { - return param; - } - - @RequestMapping(value = "/test-error3", method = RequestMethod.GET) - public String getSubstringOfNull() { - String str = null; - return str.substring(2); - } -} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java index ab2e4b8..de3c423 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java @@ -132,9 +132,6 @@ public class TopicController { topicFull.setId(topic.getId()); } - - categories = null; - topic = null; } else { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Save topic: Stakeholder with id: "+stakeholderId+" not found"); @@ -186,12 +183,8 @@ public class TopicController { } if(!changed) { -// break; continue; } - -// topicBasedOnDefault.setName(topic.getName()); -// topicBasedOnDefault.setDescription(topic.getDescription()); topicBasedOnDefault.setUpdateDate(topic.getUpdateDate()); topicDAO.save(topicBasedOnDefault); } @@ -229,54 +222,6 @@ public class TopicController { if(stakeholder.getDefaultId() == null && children != null) { onDeleteDefaultTopic(topicId, stakeholderId, children); } - -// for(String categoryId : topic.getCategories()) { -// Category category = categoryDAO.findById(categoryId); -// if(category == null) { -// // EXCEPTION - Category not found -// throw new EntityNotFoundException("Delete topic: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")"); -// } -// -// for(String subCategoryId : category.getSubCategories()) { -// SubCategory subcategory = subCategoryDAO.findById(subCategoryId); -// if (subcategory == null) { -// // EXCEPTION - SubCategory not found -// throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")"); -// } -// -// for(String chartSectionId : subcategory.getCharts()) { -// Section chartSection = sectionDAO.findById(chartSectionId); -// if (chartSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String chartId : chartSection.getIndicators()) { -// indicatorDAO.delete(chartId); -// } -// subcategory.setCharts(null); -// sectionDAO.delete(chartSectionId); -// } -// -// for(String numberSectionId : subcategory.getNumbers()) { -// Section numberSection = sectionDAO.findById(numberSectionId); -// if (numberSection == null) { -// // EXCEPTION - Section not found -// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); -// } -// -// for (String numberId : numberSection.getIndicators()) { -// indicatorDAO.delete(numberId); -// } -// subcategory.setNumbers(null); -// sectionDAO.delete(numberSectionId); -// } -// -// subCategoryDAO.delete(subCategoryId); -// } -// category.setSubCategories(null); -// categoryDAO.delete(categoryId); -// } categoryController.deleteTree(topic); topic.setCategories(null); @@ -387,42 +332,6 @@ public class TopicController { } } -// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST) -// public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId) { -// log.debug("toggle topic status (isActive)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); -// -// Topic topic = topicDAO.findById(topicId); -// if (topic == null) { -// // EXCEPTION - Topic not found -// throw new EntityNotFoundException("Toggle topic status: Topic with id: "+topicId+" not found"); -// } -// topic.setIsActive(!topic.getIsActive()); -// -// this.toggleTopic(stakeholderId, topic); -// -// return topic.getIsActive(); -// } -// -// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-access", method = RequestMethod.POST) -// public Boolean toggleTopicAccess(@PathVariable("stakeholderId") String stakeholderId, -// @PathVariable("topicId") String topicId) { -// log.debug("toggle topic access (isPublic)"); -// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); -// -// Topic topic = topicDAO.findById(topicId); -// if (topic == null) { -// // EXCEPTION - Topic not found -// throw new EntityNotFoundException("Toggle topic access: Topic with id: "+topicId+" not found"); -// } -// topic.setIsPublic(!topic.getIsPublic()); -// -// this.toggleTopic(stakeholderId, topic); -// -// return topic.getIsPublic(); -// } - @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST) public Topic changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId, @@ -449,10 +358,6 @@ public class TopicController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found"); } - - -// this.toggleTopic(stakeholderId, topic); - } public Topic changeVisibilityTree(String topicId, Visibility visibility, Boolean propagate) { @@ -489,9 +394,7 @@ public class TopicController { // EXCEPTION - Topic not found throw new EntityNotFoundException("Topic delete tree: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")"); } - categoryController.deleteTree(topic); - topicDAO.delete(topicId); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java index accce6c..61b4ba4 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java @@ -19,6 +19,10 @@ public class StakeholderService { @Autowired RolesUtils rolesUtils; + public List getAllAliases() { + return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList()); + } + public List getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) { List stakeholders; if(type != null && defaultId != null) { diff --git a/src/main/resources/monitorservice.properties b/src/main/resources/monitorservice.properties index 8ccd226..82627cb 100644 --- a/src/main/resources/monitorservice.properties +++ b/src/main/resources/monitorservice.properties @@ -26,3 +26,30 @@ monitorservice.globalVars.version=@version@ #monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken= #monitorservice.originServer = .openaire.eu +# Monitor +monitorservice.mongodb.host=localhost +monitorservice.mongodb.port=27017 +monitorservice.mongodb.database=production + +# Notification +notification.mongodb.host = localhost +notification.mongodb.port = 27017 +notification.mongodb.database = openaire_notification + +# Admin Tools Library +admintoolslibrary.mail.from = openaire.test@gmail.com +admintoolslibrary.mail.username = openaire.test@gmail.com +admintoolslibrary.mail.password = koujreltgjduicjp +admintoolslibrary.mail.host = smtp.gmail.com +admintoolslibrary.mail.port = 587 +admintoolslibrary.mail.auth = true +admintoolslibrary.mail.sslProtocols = TLSv1.2 +admintoolslibrary.mail.defaultEncoding=UTF-8 +admintoolslibrary.mail.protocol=smtp +admintoolslibrary.mail.testConnection=false +admintoolslibrary.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_ + +# Authorization +authorization.security.userInfoUrl = http://mpagasas.di.uoa.gr:19080/login-service/userInfo + +server.port=8888 \ No newline at end of file diff --git a/update_db.js b/update_db.js deleted file mode 100644 index 0c896e4..0000000 --- a/update_db.js +++ /dev/null @@ -1,505 +0,0 @@ -//version compatibility: 1.0.0-SNAPSHOT - -//use openaire_monitor; - -function upperCaseEnumValues() { - stakeholders = db.stakeholder.find().map(function (stakeholders) { - return stakeholders; - }); - for(var i=0; i"+content+"

", - "isActive" : true - } - ); - - print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")"); - } -} - -function statsProfileOfIndicatorsAsVariable() { - print("statsProfileOfIndicatorsAsVariable"); - - numOfNumbers = 0; - numOfCharts = 0; - numOfNonMonitorProfiles = 0; - numOfMonitorProfiles = 0; - numOfNoProfiles = 0; - differentProfiles = new Set(); - - // indicators = db.indicator.find({"type": "chart"}).map(function (indicator) { - // indicators = db.indicator.find({"type": "number"}).map(function (indicator) { - indicators = db.indicator.find().map(function (indicator) { - return indicator; - }); - - print(indicators.length); - - for (var i = 0; i < indicators.length; i++) { - indicator = indicators[i]; - - indicatorPaths = indicator.indicatorPaths; - if(indicatorPaths) { - for (var j = 0; j < indicatorPaths.length; j++) { - indicatorPath = indicatorPaths[j]; - chartObjectStr = ""; - // if(indicator.type == "chart") { - chartObjectStr = indicatorPath.chartObject; - // chartObject = JSON.parse(chartObjectStr); - if(indicator.type == "chart") { - numOfCharts++; - } else { - numOfNumbers++; - } - - // if(i==0) { - // if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) { - // print(chartObject.chartDescription.queries.length); - // for(var z = 0; z < chartObject.chartDescription.queries.length; z++) { - // query = chartObject.chartDescription.queries[z].query; - // print(query.profile); - // query.profile = "((__statsProfile__))"; - // } - // } - // indicatorPath.chartObject = JSON.stringify(chartObject); - - if(chartObjectStr != null) { - var included = chartObjectStr.includes('"profile":"monitor"'); - if (!included) { - numOfNonMonitorProfiles++; - print("Indicator with id: " + indicator._id + " has not monitor profile."); - } else { - numOfMonitorProfiles++; - } - - splitted = chartObjectStr.split('"profile":"'); - if (splitted.length == 1) { - numOfNoProfiles++; - } - for (var z = 1; z < splitted.length; z = z + 2) { - prof = splitted[z].split('"')[0]; - differentProfiles.add(prof); - } - - chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"'); - chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"'); - chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"'); - indicatorPath.chartObject = chartObjectStr; - } else { - print("Indicator with id: " + indicator._id + " has no chartObject"); - } - } - } - - // save indicator - db.indicator.save(indicator); - } - print("\n"); - print("numOfNumbers: "+numOfNumbers); - print("numOfCharts: "+numOfCharts); - print("numOfMonitorProfiles: "+numOfMonitorProfiles); - print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles); - print("numOfNoProfiles: "+numOfNoProfiles); - print("Different profiles are: "); - for (var item of differentProfiles) { - print(item); - } -} - -function addFundingLevelInFilters(filter) { - if(filter.groupFilters && filter.groupFilters.length > 0) { - var index = filter.groupFilters.findIndex(filter => filter.field.includes('project')); - if(index !== -1) { - print('before: ' + JSON.stringify(filter)); - var prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project')); - if(!filter.groupFilters.find(filter => filter.field === prefix + "project.funding level 1")) { - filter.groupFilters.push({ - "field": prefix + "project.funding level 1", - "type": "contains", - "values": [ - '((__index_shortName__))' - ] - }); - print('after: ' + JSON.stringify(filter)); - } else { - print('Already added'); - } - } - return filter; - } -} - -function addFundingStreamInDefaultMSCA() { - print("addFundingStreamInDefaultMSCA") - - var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"}); - if(stakeholder) { - stakeholder.topics.forEach((topic) => { - var topicObj = db.topic.findOne({"_id": ObjectId(topic)}); - topicObj.categories.forEach((category) => { - var categoryObj = db.category.findOne({"_id": ObjectId(category)}); - categoryObj.subCategories.forEach((subCategory) => { - var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)}); - subCategoryObj.numbers.forEach((number) => { - var section = db.section.findOne({"_id": ObjectId(number)}); - section.indicators.forEach((indicator) => { - var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); - if(indicatorObject.indicatorPaths[0].parameters) { - indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase(); - if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { - var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject); - if(json.series && json.series.length > 0) { - json.series.forEach(query => { - if(query.query && query.query.filters && query.query.filters.length > 0) { - query.query.filters.forEach(filter => { - filter = addFundingLevelInFilters(filter); - }); - } - }); - indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json); - db.indicator.save(indicatorObject); - } - } - } - }); - }); - subCategoryObj.charts.forEach((chart) => { - var section = db.section.findOne({"_id": ObjectId(chart)}); - section.indicators.forEach((indicator) => { - var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); - if(indicatorObject.indicatorPaths[0].parameters) { - indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase(); - if (indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { - var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject); - if (json.chartDescription && json.chartDescription.queries && json.chartDescription.queries.length > 0) { - json.chartDescription.queries.forEach(query => { - if (query.query && query.query.filters && query.query.filters.length > 0) { - query.query.filters.forEach(filter => { - filter = addFundingLevelInFilters(filter); - }); - } - }); - indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json); - db.indicator.save(indicatorObject); - } - } - } - }); - }); - }); - - }); - }); - } else { - print("Profile doesn't exist") - } - -} - - -use monitordb; -// use 1_openaire-mongodb-beta; // dev db - -// 29-09-2020 - 22-10-2020 -//upperCaseEnumValues(); -// addHeightInIndicators(); -// addVisibility(); -// removeIsActiveAndIsPublic(); -// -// addAdminToolsCollections(); -// // addPortals(); -// -// uniqueIndexes(); - -// 04-06-2021 - 24-06-2021 -// addHomePageInPortalType("funder"); -// addFooterDivIdForPortalType("funder"); -// addFooterHelpTextForPortalType("funder"); -// addHomePageInPortalType("ri"); -// addFooterDivIdForPortalType("ri"); -// addFooterHelpTextForPortalType("ri"); -// addHomePageInPortalType("organization"); -// addFooterDivIdForPortalType("organization"); -// addFooterHelpTextForPortalType("organization"); - -// 11-04-2023 -statsProfileOfIndicatorsAsVariable(); -// 30-05-2023 -addFundingStreamInDefaultMSCA();