From 806e1e16d85e25b00b81d6fee643358c6c4c522b Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 3 May 2023 12:58:13 +0300 Subject: [PATCH 01/10] [Monitor Service | master]: MonitorController.java: In method "updatePortal()" call also pageService.updatePid if pid was changed | pom.xml: Updated version of uoa-admin-tools-library to 1.0.7 (previous was 1.0.6). --- pom.xml | 2 +- .../controllers/MonitorController.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a4613cd..da91096 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ eu.dnetlib uoa-admin-tools-library - 1.0.6 + 1.0.7 eu.dnetlib diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java index 99aadb7..fa68f01 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java @@ -2,6 +2,7 @@ package eu.dnetlib.uoamonitorservice.controllers; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*; +import eu.dnetlib.uoaadmintoolslibrary.services.PageService; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,10 +23,19 @@ public class MonitorController { @Autowired private PortalService portalService; + @Autowired + private PageService pageService; + @RequestMapping(value = "/update", method = RequestMethod.POST) public PortalResponse updatePortal(@RequestBody Portal portal) { + String old_pid = portalService.getPortalById(portal.getId()).getPid(); + String new_pid = portal.getPid(); + PortalResponse portalResponse = portalService.updatePortal(portal); + 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)) { From 1119c1fdcf9b721f1d95d233c2077d19857e3ac3 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 3 May 2023 13:02:56 +0300 Subject: [PATCH 02/10] [Monitor Service | master]: Stakeholder.java: Added field private String statsProfile = "monitor"; and getter/setter methods | IndicatorPath.java: Added field private Format format = Format.NUMBER; where Format is enum {NUMBER, PERCENTAGE} and getter/setter methods | IndicatorController.java: On method "onUpdateDefaultIndicator()" check if format was changed | update_db.js: Added method "statsProfileOfIndicatorsAsVariable()". --- .../controllers/IndicatorController.java | 14 +++ .../entities/IndicatorPath.java | 22 ++++ .../entities/Stakeholder.java | 10 ++ update_db.js | 109 ++++++++++++++++-- 4 files changed, 146 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index b1de9e7..86cccb4 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -302,6 +302,20 @@ public class IndicatorController { } log.debug("After type check: "+changed); + if(( + (indicatorPath.getFormat() == null && oldIndicatorPath.getFormat() != null) + || + (indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat())) + ) && ( + (oldIndicatorPath.getFormat() == null && indicatorPathBasedOnDefault.getFormat() == null) + || + (oldIndicatorPath.getFormat() != null && oldIndicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat())) + )) { + indicatorPathBasedOnDefault.setFormat(indicatorPath.getFormat()); + changed = true; + } + log.debug("After type check: "+changed); + // if(indicatorPath.getSource() != null // && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()) // && (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java index 3814476..63bc04a 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java @@ -13,8 +13,13 @@ enum IndicatorPathType { // STATISTICS, SEARCH, METRICS, STATS_TOOL,OLD,IMAGE; //} +enum Format { + NUMBER, PERCENTAGE +} + public class IndicatorPath { private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc} + private Format format = Format.NUMBER; // for numbers is if number is percentage or not private String source; // for numbers is the service {statistics, search, metrics} for charts is the tool {stats-tool,old,metrics, image} private String url; private List jsonPath; @@ -27,6 +32,7 @@ public class IndicatorPath { public IndicatorPath(IndicatorPath indicatorPath) { setType(indicatorPath.getType()); + setFormat(indicatorPath.getFormat()); source = indicatorPath.getSource(); url = indicatorPath.getUrl(); jsonPath = indicatorPath.getJsonPath(); @@ -55,6 +61,22 @@ public class IndicatorPath { } } + public String getFormat() { + if(format == null) { + return null; + } + return format.name(); + } + + public void setFormat(String format) { + if(format == null) { + this.format = null; + } else { + Format _format = Format.valueOf(format); + this.format = _format; + } + } + public String getSource() { return source; } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java index 524eb08..d47a749 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java @@ -24,6 +24,7 @@ public class Stakeholder { private String index_id; private String index_name; private String index_shortName; + private String statsProfile = "monitor"; private String logoUrl; private boolean isUpload = false; private String name; @@ -45,6 +46,7 @@ public class Stakeholder { index_id = stakeholder.getIndex_id(); index_name = stakeholder.getIndex_name(); index_shortName = stakeholder.getIndex_shortName(); + statsProfile = stakeholder.getStatsProfile(); logoUrl = stakeholder.getLogoUrl(); isUpload = stakeholder.getIsUpload(); name = stakeholder.getName(); @@ -112,6 +114,14 @@ public class Stakeholder { this.index_shortName = index_shortName; } + public String getStatsProfile() { + return statsProfile; + } + + public void setStatsProfile(String statsProfile) { + this.statsProfile = statsProfile; + } + public String getLogoUrl() { return logoUrl; } diff --git a/update_db.js b/update_db.js index 459a080..0af2edc 100644 --- a/update_db.js +++ b/update_db.js @@ -294,6 +294,94 @@ function addFooterHelpTextForPortalType(portalType) { } } +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); + } +} use monitordb; // use 1_openaire-mongodb-beta; // dev db @@ -310,12 +398,15 @@ use monitordb; // 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"); +// addHomePageInPortalType("funder"); +// addFooterDivIdForPortalType("funder"); +// addFooterHelpTextForPortalType("funder"); +// addHomePageInPortalType("ri"); +// addFooterDivIdForPortalType("ri"); +// addFooterHelpTextForPortalType("ri"); +// addHomePageInPortalType("organization"); +// addFooterDivIdForPortalType("organization"); +// addFooterHelpTextForPortalType("organization"); + +// 11-04-2023 +statsProfileOfIndicatorsAsVariable(); \ No newline at end of file From e363a04f8445e0e1fb29e3940d97cd835236b0aa Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 19 May 2023 16:47:19 +0300 Subject: [PATCH 03/10] Pom: Add spring-boot-version in maven-plugin --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index da91096..83e6fd5 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot-version} eu.dnetlib.uoamonitorservice.UoaMonitorServiceApplication true From 31f758d534b2379118f184f1866a886bab0c793b Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 30 May 2023 16:26:45 +0300 Subject: [PATCH 04/10] Add addFundingStreamInDefaultMSCA in migration script. --- update_db.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/update_db.js b/update_db.js index 0af2edc..3e22b7e 100644 --- a/update_db.js +++ b/update_db.js @@ -369,7 +369,7 @@ function statsProfileOfIndicatorsAsVariable() { } // save indicator - // db.indicator.save(indicator); + db.indicator.save(indicator); } print("\n"); print("numOfNumbers: "+numOfNumbers); @@ -383,6 +383,94 @@ function statsProfileOfIndicatorsAsVariable() { } } +function addFundingLevelInFilters(filter) { + if(filter.groupFilters && filter.groupFilters.length > 0) { + let index = filter.groupFilters.findIndex(filter => filter.field.includes('project')); + if(index !== -1) { + print('before: ' + JSON.stringify(filter)); + let 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") + + let stakeholder = db.stakeholder.findOne({"alias": "default-funding-stream"}); + if(stakeholder) { + stakeholder.topics.forEach((topic) => { + let topicObj = db.topic.findOne({"_id": ObjectId(topic)}); + topicObj.categories.forEach((category) => { + let categoryObj = db.category.findOne({"_id": ObjectId(category)}); + categoryObj.subCategories.forEach((subCategory) => { + let subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)}); + subCategoryObj.numbers.forEach((number) => { + let section = db.section.findOne({"_id": ObjectId(number)}); + section.indicators.forEach((indicator) => { + let 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) { + let 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) => { + let section = db.section.findOne({"_id": ObjectId(chart)}); + section.indicators.forEach((indicator) => { + let indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); + if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { + let 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 @@ -409,4 +497,5 @@ use monitordb; // addFooterHelpTextForPortalType("organization"); // 11-04-2023 -statsProfileOfIndicatorsAsVariable(); \ No newline at end of file +statsProfileOfIndicatorsAsVariable(); +addFundingStreamInDefaultMSCA(); From 06be4d37ce28854334074f4abf39f9ff0805251b Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 31 May 2023 14:07:56 +0300 Subject: [PATCH 05/10] Update script with alias of default-fl1. --- update_db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update_db.js b/update_db.js index 3e22b7e..8d48605 100644 --- a/update_db.js +++ b/update_db.js @@ -409,7 +409,7 @@ function addFundingLevelInFilters(filter) { function addFundingStreamInDefaultMSCA() { print("addFundingStreamInDefaultMSCA") - let stakeholder = db.stakeholder.findOne({"alias": "default-funding-stream"}); + let stakeholder = db.stakeholder.findOne({"alias": "default-fl1"}); if(stakeholder) { stakeholder.topics.forEach((topic) => { let topicObj = db.topic.findOne({"_id": ObjectId(topic)}); From 273858cc2cf073f0d8576a63a6a3dc60bd05896a Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 31 May 2023 16:27:15 +0300 Subject: [PATCH 06/10] Replace let with var in update.js --- update_db.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/update_db.js b/update_db.js index 8d48605..974edf2 100644 --- a/update_db.js +++ b/update_db.js @@ -385,10 +385,10 @@ function statsProfileOfIndicatorsAsVariable() { function addFundingLevelInFilters(filter) { if(filter.groupFilters && filter.groupFilters.length > 0) { - let index = filter.groupFilters.findIndex(filter => filter.field.includes('project')); + var index = filter.groupFilters.findIndex(filter => filter.field.includes('project')); if(index !== -1) { print('before: ' + JSON.stringify(filter)); - let prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project')); + 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", @@ -409,22 +409,22 @@ function addFundingLevelInFilters(filter) { function addFundingStreamInDefaultMSCA() { print("addFundingStreamInDefaultMSCA") - let stakeholder = db.stakeholder.findOne({"alias": "default-fl1"}); + var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"}); if(stakeholder) { stakeholder.topics.forEach((topic) => { - let topicObj = db.topic.findOne({"_id": ObjectId(topic)}); + var topicObj = db.topic.findOne({"_id": ObjectId(topic)}); topicObj.categories.forEach((category) => { - let categoryObj = db.category.findOne({"_id": ObjectId(category)}); + var categoryObj = db.category.findOne({"_id": ObjectId(category)}); categoryObj.subCategories.forEach((subCategory) => { - let subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)}); + var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)}); subCategoryObj.numbers.forEach((number) => { - let section = db.section.findOne({"_id": ObjectId(number)}); + var section = db.section.findOne({"_id": ObjectId(number)}); section.indicators.forEach((indicator) => { - let indicatorObject = db.indicator.findOne({"_id": ObjectId(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) { - let json = JSON.parse(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) { @@ -441,11 +441,11 @@ function addFundingStreamInDefaultMSCA() { }); }); subCategoryObj.charts.forEach((chart) => { - let section = db.section.findOne({"_id": ObjectId(chart)}); + var section = db.section.findOne({"_id": ObjectId(chart)}); section.indicators.forEach((indicator) => { - let indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); + var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) { - let json = JSON.parse(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) { @@ -498,4 +498,5 @@ use monitordb; // 11-04-2023 statsProfileOfIndicatorsAsVariable(); +// 30-05-2023 addFundingStreamInDefaultMSCA(); From f246e4d6b8c6e1d1b5881f07939aa637b4a933db Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 9 Jun 2023 13:35:03 +0300 Subject: [PATCH 07/10] Fix script for add funding stream in default msca --- update_db.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/update_db.js b/update_db.js index 974edf2..0c896e4 100644 --- a/update_db.js +++ b/update_db.js @@ -444,19 +444,22 @@ function addFundingStreamInDefaultMSCA() { var section = db.section.findOne({"_id": ObjectId(chart)}); section.indicators.forEach((indicator) => { var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)}); - 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); - } + 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); + } + } } }); }); From 0184da8a8e1c2be465cd00f5be22676a6d30d262 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 19 Jun 2023 13:28:32 +0300 Subject: [PATCH 08/10] [Monitor Service | master]: Stakeholder.java: Added field private Locale locale = Locale.EU; (Local is enum with values: EN("en"), EU("eu")) and getter/setter methods. --- .../entities/Stakeholder.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java index d47a749..f0dfb09 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java @@ -14,6 +14,16 @@ enum StakeholderType FUNDER, RI, PROJECT, ORGANIZATION; } +enum Locale { + EN("en"), EU("eu"); + + public final String label; + + private Locale(String label) { + this.label = label; + } +} + public class Stakeholder { @Id @@ -31,6 +41,7 @@ public class Stakeholder { private String alias; private String description; private String defaultId = null; + private Locale locale = Locale.EU; private Visibility visibility = Visibility.PRIVATE; private Date creationDate; private Date updateDate; @@ -53,6 +64,7 @@ public class Stakeholder { alias = stakeholder.getAlias(); description = stakeholder.getDescription(); defaultId = stakeholder.getDefaultId(); + setLocale(stakeholder.getLocale()); setVisibility(stakeholder.getVisibility()); creationDate = stakeholder.getCreationDate(); updateDate = stakeholder.getUpdateDate(); @@ -166,6 +178,20 @@ public class Stakeholder { this.defaultId = defaultId; } + public String getLocale() { + return locale.label; + } + + public void setLocale(String label) { + Locale locale = null; + for (Locale l : Locale.values()) { + if (l.label.equals(label)) { + locale = l; + } + } + this.locale = locale; + } + public Visibility getVisibility() { //return visibility.getLabel(); return visibility; From 09b8d2188f85e5bcbc3f0ac0e50c8fa7a462e686 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 3 Jul 2023 10:42:46 +0300 Subject: [PATCH 09/10] [Monitor Service | master]: Indicator.java: In method "copyFromDefault()", get visibility as parameter and set the visibility of the new-copied indicator accordingly | IndicatorController.java: When creating indicators copied from a new default indicator, set the visibility of each new indicator same as of its parent subcategory. --- .../controllers/IndicatorController.java | 50 ++++++++++++------- .../uoamonitorservice/entities/Indicator.java | 4 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index 86cccb4..74c223e 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -88,10 +88,10 @@ public class IndicatorController { List indicators = section.getIndicators(); for (Indicator indicator : indicators) { if (indicator.getType().equals("chart")) { - saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators); + saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, chart_section, chart_indicators); } else if (indicator.getType().equals("number")) { - saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators); + saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, number_section, number_indicators); } } @@ -118,14 +118,18 @@ public class IndicatorController { return section; } - private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List indicators) throws UnsupportedEncodingException { +// private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List indicators) throws UnsupportedEncodingException { +// saveIndicatorAndAddInSection(indicator, date, stakeholder, section, indicators); +// } + + private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, String subcategoryId, Section section, List indicators) throws UnsupportedEncodingException { // indicator does not exist in DB indicator.setCreationDate(date); indicator.setUpdateDate(date); if (stakeholder.getDefaultId() == null) { // this indicator belongs in default profile and it is new indicatorDAO.save(indicator); - onSaveDefaultIndicator(indicator, section.getId()); + onSaveDefaultIndicator(indicator, section, subcategoryId); } else { // this indicator belongs in a stakeholder's profile and it is new indicatorDAO.save(indicator); } @@ -168,7 +172,7 @@ public class IndicatorController { if(stakeholder.getDefaultId() == null) { if(indicatorId == null) { indicatorDAO.save(indicator); - onSaveDefaultIndicator(indicator, sectionId); + onSaveDefaultIndicator(indicator, section, subcategoryId); } else { onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator); @@ -190,26 +194,38 @@ public class IndicatorController { return indicator; } - public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) throws UnsupportedEncodingException { + public void onSaveDefaultIndicator(Indicator indicator, Section defaultSection, String defaultSubcategoryId) throws UnsupportedEncodingException { log.debug("On save default indicator"); // new indicator in default profile - add it on profiles of the same type - List
sections = sectionDAO.findByDefaultId(defaultSectionId); + List subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId); + for (SubCategory subCategory : subCategories) { - for (Section section : sections) { - Indicator indicatorNew = new Indicator(); - indicatorNew.copyFromDefault(indicator); - for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { - Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias()); - parameterMapping(indicatorPath, stakeholder); + List sections = null; + if(defaultSection.getType().equals("chart")) { + sections = subCategory.getCharts(); + } else { + sections = subCategory.getNumbers(); } - indicatorDAO.save(indicatorNew); + for (String sectionId : sections) { + Section section = sectionDAO.findById(sectionId); + if(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); + } - List indicators = section.getIndicators(); - indicators.add(indicatorNew.getId()); + indicatorDAO.save(indicatorNew); - sectionDAO.save(section); + List indicators = section.getIndicators(); + indicators.add(indicatorNew.getId()); + + sectionDAO.save(section); + } + } } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java index 27d19a0..ca6947c 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java @@ -36,7 +36,7 @@ public class Indicator { private String defaultId; private List indicatorPaths; - public void copyFromDefault(Indicator defaultIndicator) { + public void copyFromDefault(Indicator defaultIndicator, Visibility visibility) { setName(defaultIndicator.getName()); setDescription(defaultIndicator.getDescription()); setAdditionalDescription(defaultIndicator.getAdditionalDescription()); @@ -44,7 +44,7 @@ public class Indicator { setWidth(defaultIndicator.getWidth()); setHeight(defaultIndicator.getHeight()); setTags(defaultIndicator.getTags()); - setVisibility(Visibility.RESTRICTED); + setVisibility(visibility); setCreationDate(defaultIndicator.getCreationDate()); setUpdateDate(defaultIndicator.getUpdateDate()); setDefaultId(defaultIndicator.getId()); From 7b4f0a9eec79d6133682e20d4b9adfd61d170422 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 4 Jul 2023 16:02:34 +0300 Subject: [PATCH 10/10] Fix role utils methods --- pom.xml | 2 +- .../controllers/CategoryController.java | 18 ++---- .../controllers/IndicatorController.java | 9 +-- .../controllers/SectionController.java | 7 +-- .../controllers/StakeholderController.java | 56 +++++++------------ .../controllers/SubCategoryController.java | 7 +-- .../controllers/TopicController.java | 16 ++---- 7 files changed, 39 insertions(+), 76 deletions(-) diff --git a/pom.xml b/pom.xml index 83e6fd5..d112dc3 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ eu.dnetlib uoa-admin-tools-library - 1.0.7 + 1.0.8 eu.dnetlib diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java index 5517b08..d2f0d23 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java @@ -77,9 +77,7 @@ public class CategoryController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if(stakeholder != null) { - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Save Category: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -236,9 +234,7 @@ public class CategoryController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if(stakeholder != null) { - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete category: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -250,7 +246,7 @@ public class CategoryController { Category category = categoryDAO.findById(categoryId); if(category != null) { - if(category.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + if(category.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete category: You are not authorized to delete a default Category in stakeholder with id: "+stakeholderId); } @@ -460,9 +456,7 @@ public class CategoryController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if (stakeholder != null) { - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Toggle category: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -525,9 +519,7 @@ public class CategoryController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("checkForExceptions category: Stakeholder with id: " + stakeholderId + " not found"); } - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("checkForExceptions category: You are not authorized to update stakeholder with id: "+stakeholderId); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index 74c223e..9a9d5ae 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -65,7 +65,7 @@ public class IndicatorController { createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId); // createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId); - return stakeholderController.setFullEntities(stakeholder, rolesUtils.getRoles()); + return stakeholderController.setFullEntities(stakeholder); } private void createSectionsAndSaveBulk(Date date, List> old_sections, @@ -564,8 +564,7 @@ public class IndicatorController { Section section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); - List roles = rolesUtils.getRoles(); - if(indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + if(indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete indicator: You are not authorized to delete a default Indicator in stakeholder with id: "+stakeholderId); } @@ -879,9 +878,7 @@ public class IndicatorController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); } - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("CheckForExceptions Indicator: You are not authorized to update stakeholder with id: "+stakeholderId); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java index 6599231..a7506ee 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java @@ -237,8 +237,7 @@ public class SectionController { SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); - List roles = rolesUtils.getRoles(); - if(section.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + 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); } @@ -442,9 +441,7 @@ public class SectionController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); } - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("CheckForExceptions Section: You are not authorized to update stakeholder with id: "+stakeholderId); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index b595ce3..7fc188f 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -112,7 +112,7 @@ public class StakeholderController { //return null; } - public Stakeholder setFullEntities(Stakeholder stakeholder, List roles) { + public Stakeholder setFullEntities(Stakeholder stakeholder) { boolean addAll = false; boolean addPublicAndRestricted = false; @@ -120,7 +120,7 @@ public class StakeholderController { // || roles.contains(authorizationService.PORTAL_ADMIN) // || roles.contains(authorizationService.curator(stakeholder.getType())) // || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) { - if(rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { //if(visibility == null || visibility == (Visibility.PRIVATE)) { addAll = true; //} @@ -128,7 +128,7 @@ public class StakeholderController { addPublicAndRestricted = true; //} // } else if(roles != null && roles.contains(authorizationService.member(stakeholder.getType(), stakeholder.getAlias()))) { - } else if(rolesUtils.isMember(roles, stakeholder.getType(), stakeholder.getAlias())) { + } else if(rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())) { //if(visibility == null || visibility == (Visibility.PRIVATE) || visibility == (Visibility.RESTRICTED)) { addPublicAndRestricted = true; //} @@ -297,8 +297,7 @@ public class StakeholderController { List stakeholdersFull = new ArrayList<>(); for(Stakeholder stakeholder : stakeholders) { - List roles = rolesUtils.getRoles(); - stakeholdersFull.add(this.setFullEntities(stakeholder, roles)); + stakeholdersFull.add(this.setFullEntities(stakeholder)); } return stakeholdersFull; @@ -320,14 +319,13 @@ public class StakeholderController { // Remove stakeholders for which i do not have authority if(stakeholders != null && stakeholders.size() > 0) { - List roles = rolesUtils.getRoles(); // log.debug("ROLES: "); // roles.forEach(role -> log.debug(role)); // // if (roles.contains(authorizationService.PORTAL_ADMIN)) { - if (rolesUtils.isPortalAdmin(roles)) { + if (rolesUtils.isPortalAdmin()) { for(Stakeholder stakeholder : stakeholders) { - stakeholdersFull.add(this.setFullEntities(stakeholder, roles)); + stakeholdersFull.add(this.setFullEntities(stakeholder)); } return stakeholdersFull; } @@ -337,8 +335,8 @@ public class StakeholderController { Stakeholder stakeholder = stakeholderIterator.next(); // if(roles.contains(authorizationService.curator(stakeholder.getType()))) { - if(rolesUtils.isCurator(roles, stakeholder.getType())) { - stakeholdersFull.add(this.setFullEntities(stakeholder, roles)); + if(rolesUtils.isCurator(stakeholder.getType())) { + stakeholdersFull.add(this.setFullEntities(stakeholder)); continue; } stakeholderIterator.remove(); @@ -368,10 +366,8 @@ public class StakeholderController { if(stakeholders != null && stakeholders.size() > 0) { // List roles = authorizationService.getRoles(); - List roles = rolesUtils.getRoles(); - // if (roles.contains(authorizationService.PORTAL_ADMIN)) { - if (rolesUtils.isPortalAdmin(roles)) { + if (rolesUtils.isPortalAdmin()) { // for(Stakeholder stakeholder : stakeholders) { // stakeholdersFull.add(this.setFullEntities(stakeholder)); // } @@ -387,8 +383,8 @@ public class StakeholderController { // || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias())) // || stakeholder.getVisibility() == Visibility.PUBLIC // || (stakeholder.getVisibility() == Visibility.RESTRICTED && roles.contains(authorizationService.member(stakeholder.getType(), stakeholder.getAlias())))) { - if(rolesUtils.isCurator(roles, stakeholder.getType()) - || rolesUtils.isManager(roles, stakeholder.getType(), stakeholder.getAlias()) + if(rolesUtils.isCurator(stakeholder.getType()) + || rolesUtils.isManager(stakeholder.getType(), stakeholder.getAlias()) || stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED) { // || (stakeholder.getVisibility() == Visibility.RESTRICTED && rolesUtils.isMember(roles, stakeholder.getType(), stakeholder.getAlias()))) { @@ -420,13 +416,8 @@ public class StakeholderController { List stakeholdersFull = new ArrayList<>(); if(stakeholders != null && stakeholders.size() > 0) { -// List roles = authorizationService.getRoles(); - List roles = rolesUtils.getRoles(); -// log.debug("ROLES: "); -// roles.forEach(role -> log.debug(role)); - // if (roles.contains(authorizationService.PORTAL_ADMIN)) { - if (rolesUtils.isPortalAdmin(roles)) { + if (rolesUtils.isPortalAdmin()) { // for(Stakeholder stakeholder : stakeholders) { // stakeholdersFull.add(this.setFullEntities(stakeholder, roles)); // } @@ -440,8 +431,8 @@ public class StakeholderController { // if(roles.contains(authorizationService.curator(stakeholder.getType())) // || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) { - if(rolesUtils.isCurator(roles, stakeholder.getType()) - || rolesUtils.isManager(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(rolesUtils.isCurator(stakeholder.getType()) + || rolesUtils.isManager(stakeholder.getType(), stakeholder.getAlias())) { //stakeholdersFull.add(this.setFullEntities(stakeholder, roles)); continue; } else { @@ -466,19 +457,17 @@ public class StakeholderController { } // List roles = authorizationService.getRoles(); - List roles = rolesUtils.getRoles(); - - if(stakeholder.getDefaultId() == null && !rolesUtils.isLoggedIn(roles)) { + 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); } - if(stakeholder.getDefaultId() == null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + if(stakeholder.getDefaultId() == null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: "+alias); } - if((stakeholder.getVisibility() == Visibility.PRIVATE && !rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias()) - || (stakeholder.getVisibility() == Visibility.RESTRICTED && !rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias()) && !rolesUtils.isMember(roles, stakeholder.getType(), stakeholder.getAlias())))) { + 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(); @@ -488,7 +477,7 @@ public class StakeholderController { return stakeholder; } - return this.setFullEntities(stakeholder, roles); + return this.setFullEntities(stakeholder); } // @PreAuthorize("isAuthenticated()") @@ -564,12 +553,10 @@ public class StakeholderController { if(stakeholder != null) { pid = stakeholder.getAlias(); -// List roles = authorizationService.getRoles(); - List roles = rolesUtils.getRoles(); // if(!roles.contains(authorizationService.PORTAL_ADMIN) // && !roles.contains(authorizationService.curator(stakeholder.getType()))) { - if(!rolesUtils.hasCreateAndDeleteAuthority(roles, 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); } @@ -701,12 +688,11 @@ public class StakeholderController { } // List roles = authorizationService.getRoles(); - List roles = rolesUtils.getRoles(); // if(!roles.contains(authorizationService.PORTAL_ADMIN) // && !roles.contains(authorizationService.curator(stakeholder.getType())) // && !roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) { - if(!rolesUtils.hasUpdateAuthority(roles, 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); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java index f96d683..06c005f 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java @@ -254,8 +254,7 @@ public class SubCategoryController { if(subcategory != null) { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); - List roles = rolesUtils.getRoles(); - if(subcategory.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + if(subcategory.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete subcategory: You are not authorized to delete a default SubCategory in stakeholder with id: "+stakeholderId); } @@ -497,9 +496,7 @@ public class SubCategoryController { // EXCEPTION - Stakeholder not found throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); } - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("CheckForExceptions SubCategory: You are not authorized to update stakeholder with id: "+stakeholderId); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java index 1539d4e..ab2e4b8 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java @@ -73,8 +73,7 @@ public class TopicController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if(stakeholder != null) { - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Save Topic: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -210,8 +209,7 @@ public class TopicController { if(stakeholder != null) { - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete topic: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -219,7 +217,7 @@ public class TopicController { Topic topic = topicDAO.findById(topicId); if(topic != null) { - if(topic.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(roles, stakeholder.getType())) { + if(topic.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { // EXCEPTION - Access denied throw new ForbiddenException("Delete topic: You are not authorized to delete a default Topic in stakeholder with id: "+stakeholderId); } @@ -356,9 +354,7 @@ public class TopicController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if(stakeholder != null) { - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Reorder topics: You are not authorized to update stakeholder with id: "+stakeholderId); } @@ -438,9 +434,7 @@ public class TopicController { Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); if (stakeholder != null) { - - List roles = rolesUtils.getRoles(); - if(!rolesUtils.hasUpdateAuthority(roles, stakeholder.getType(), stakeholder.getAlias())) { + if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { // EXCEPTION - Access denied throw new ForbiddenException("Toggle topic: You are not authorized to update stakeholder with id: "+stakeholderId); }