diff --git a/pom.xml b/pom.xml
index e1d0451..66d7454 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
eu.dnetlib
uoa-admin-tools-library
- 1.0.6
+ 1.0.8
eu.dnetlib
@@ -56,6 +56,7 @@
org.springframework.boot
spring-boot-maven-plugin
+ ${spring-boot-version}
eu.dnetlib.uoamonitorservice.UoaMonitorServiceApplication
true
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 b1de9e7..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,
@@ -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);
+ }
+ }
}
}
@@ -302,6 +318,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()))) {
@@ -534,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);
}
@@ -849,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/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)) {
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);
}
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());
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..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
@@ -24,12 +34,14 @@ 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;
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;
@@ -45,12 +57,14 @@ 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();
alias = stakeholder.getAlias();
description = stakeholder.getDescription();
defaultId = stakeholder.getDefaultId();
+ setLocale(stakeholder.getLocale());
setVisibility(stakeholder.getVisibility());
creationDate = stakeholder.getCreationDate();
updateDate = stakeholder.getUpdateDate();
@@ -112,6 +126,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;
}
@@ -156,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;
diff --git a/update_db.js b/update_db.js
index 459a080..0c896e4 100644
--- a/update_db.js
+++ b/update_db.js
@@ -294,6 +294,185 @@ 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);
+ }
+}
+
+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
@@ -310,12 +489,17 @@ 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();
+// 30-05-2023
+addFundingStreamInDefaultMSCA();