From 4080c5326e11bddee8ee04c2cd44c88f840bfa60 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Sun, 16 Oct 2022 11:41:19 +0300 Subject: [PATCH 1/3] StakeholderController.java: update return type of 'changeStakeholderVisibility()' and 'changeStakeholderVisibilityTree()' from Visibility to Stakeholder. --- .../controllers/StakeholderController.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index 0594742..a8e6797 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -688,7 +688,7 @@ public class StakeholderController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST) - public Visibility changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId, + public Stakeholder changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId, @RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) { log.debug("change stakeholder visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false")); log.debug("Stakeholder: "+stakeholderId); @@ -713,17 +713,24 @@ public class StakeholderController { return changeStakeholderVisibilityTree(stakeholder, visibility, propagate); } - private Visibility changeStakeholderVisibilityTree(Stakeholder stakeholder, Visibility visibility, Boolean propagate) { + private Stakeholder changeStakeholderVisibilityTree(Stakeholder stakeholder, Visibility visibility, Boolean propagate) { + Stakeholder stakeholderFull = new Stakeholder<>(stakeholder); + List topicsFull = new ArrayList<>(); + if(propagate != null && propagate) { for (String topicId : stakeholder.getTopics()) { - topicController.changeVisibilityTree(topicId, visibility, propagate); + topicsFull.add(topicController.changeVisibilityTree(topicId, visibility, propagate)); } } - stakeholder.setVisibility(visibility); + stakeholder.setVisibility(visibility); stakeholderDAO.save(stakeholder); log.debug("Stakeholder toggled!"); - return stakeholder.getVisibility(); + + stakeholderFull.setVisibility(visibility); + stakeholderFull.setTopics(topicsFull); + + return stakeholder; } // The following are not supposed to be used From 806e1e16d85e25b00b81d6fee643358c6c4c522b Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 3 May 2023 12:58:13 +0300 Subject: [PATCH 2/3] [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 3/3] [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