From 89188267666dfc96cb41f63eb930e7c36ad5a71c Mon Sep 17 00:00:00 2001
From: "k.triantafyllou"
Date: Tue, 5 Mar 2024 18:51:14 +0200
Subject: [PATCH 01/11] Remove comments. Add getAliases method in
stakeholderService. Remove parametersMapping
---
pom.xml | 10 -
scripts/2020-10-22.js | 245 +++++++++
scripts/2021-06-24.js | 65 +++
scripts/2023-05-30.js | 182 +++++++
scripts/2024-02-27.js | 16 +
.../configuration/SwaggerConfig.java | 1 -
.../configuration/mongo/MongoConnection.java | 1 -
.../controllers/CategoryController.java | 79 ---
.../controllers/IndicatorController.java | 226 --------
.../controllers/MonitorController.java | 19 -
.../MonitorLibraryCheckDeployController.java | 2 -
.../MonitorServiceCheckDeployController.java | 1 -
.../controllers/SectionController.java | 235 --------
.../controllers/StakeholderController.java | 252 +--------
.../controllers/SubCategoryController.java | 104 ----
.../controllers/TestController.java | 44 --
.../controllers/TopicController.java | 97 ----
.../service/StakeholderService.java | 4 +
src/main/resources/monitorservice.properties | 27 +
update_db.js | 505 ------------------
20 files changed, 542 insertions(+), 1573 deletions(-)
create mode 100644 scripts/2020-10-22.js
create mode 100644 scripts/2021-06-24.js
create mode 100644 scripts/2023-05-30.js
create mode 100644 scripts/2024-02-27.js
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java
delete mode 100644 update_db.js
diff --git a/pom.xml b/pom.xml
index 52759cb..834ad4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,10 +61,6 @@
eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication
true
-
-
-
-
@@ -73,12 +69,6 @@
repackage
-
-
-
-
-
-
diff --git a/scripts/2020-10-22.js b/scripts/2020-10-22.js
new file mode 100644
index 0000000..2f06f0d
--- /dev/null
+++ b/scripts/2020-10-22.js
@@ -0,0 +1,245 @@
+function upperCaseEnumValues() {
+ stakeholders = db.stakeholder.find().map(function (stakeholders) {
+ return stakeholders;
+ });
+ for(var i=0; i"+content+"
",
+ "isActive" : true
+ }
+ );
+
+ print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")");
+ }
+}
+
+use monitordb;
+
+addHomePageInPortalType("funder");
+addFooterDivIdForPortalType("funder");
+addFooterHelpTextForPortalType("funder");
+addHomePageInPortalType("ri");
+addFooterDivIdForPortalType("ri");
+addFooterHelpTextForPortalType("ri");
+addHomePageInPortalType("organization");
+addFooterDivIdForPortalType("organization");
+addFooterHelpTextForPortalType("organization");
diff --git a/scripts/2023-05-30.js b/scripts/2023-05-30.js
new file mode 100644
index 0000000..4b5a508
--- /dev/null
+++ b/scripts/2023-05-30.js
@@ -0,0 +1,182 @@
+function statsProfileOfIndicatorsAsVariable() {
+ print("statsProfileOfIndicatorsAsVariable");
+
+ numOfNumbers = 0;
+ numOfCharts = 0;
+ numOfNonMonitorProfiles = 0;
+ numOfMonitorProfiles = 0;
+ numOfNoProfiles = 0;
+ differentProfiles = new Set();
+
+ // indicators = db.indicator.find({"type": "chart"}).map(function (indicator) {
+ // indicators = db.indicator.find({"type": "number"}).map(function (indicator) {
+ indicators = db.indicator.find().map(function (indicator) {
+ return indicator;
+ });
+
+ print(indicators.length);
+
+ for (var i = 0; i < indicators.length; i++) {
+ indicator = indicators[i];
+
+ indicatorPaths = indicator.indicatorPaths;
+ if(indicatorPaths) {
+ for (var j = 0; j < indicatorPaths.length; j++) {
+ indicatorPath = indicatorPaths[j];
+ chartObjectStr = "";
+ // if(indicator.type == "chart") {
+ chartObjectStr = indicatorPath.chartObject;
+ // chartObject = JSON.parse(chartObjectStr);
+ if(indicator.type == "chart") {
+ numOfCharts++;
+ } else {
+ numOfNumbers++;
+ }
+
+ // if(i==0) {
+ // if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) {
+ // print(chartObject.chartDescription.queries.length);
+ // for(var z = 0; z < chartObject.chartDescription.queries.length; z++) {
+ // query = chartObject.chartDescription.queries[z].query;
+ // print(query.profile);
+ // query.profile = "((__statsProfile__))";
+ // }
+ // }
+ // indicatorPath.chartObject = JSON.stringify(chartObject);
+
+ if(chartObjectStr != null) {
+ var included = chartObjectStr.includes('"profile":"monitor"');
+ if (!included) {
+ numOfNonMonitorProfiles++;
+ print("Indicator with id: " + indicator._id + " has not monitor profile.");
+ } else {
+ numOfMonitorProfiles++;
+ }
+
+ splitted = chartObjectStr.split('"profile":"');
+ if (splitted.length == 1) {
+ numOfNoProfiles++;
+ }
+ for (var z = 1; z < splitted.length; z = z + 2) {
+ prof = splitted[z].split('"')[0];
+ differentProfiles.add(prof);
+ }
+
+ chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"');
+ chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"');
+ chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"');
+ indicatorPath.chartObject = chartObjectStr;
+ } else {
+ print("Indicator with id: " + indicator._id + " has no chartObject");
+ }
+ }
+ }
+
+ // save indicator
+ db.indicator.save(indicator);
+ }
+ print("\n");
+ print("numOfNumbers: "+numOfNumbers);
+ print("numOfCharts: "+numOfCharts);
+ print("numOfMonitorProfiles: "+numOfMonitorProfiles);
+ print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles);
+ print("numOfNoProfiles: "+numOfNoProfiles);
+ print("Different profiles are: ");
+ for (var item of differentProfiles) {
+ print(item);
+ }
+}
+
+function addFundingLevelInFilters(filter) {
+ if(filter.groupFilters && filter.groupFilters.length > 0) {
+ var index = filter.groupFilters.findIndex(filter => filter.field.includes('project'));
+ if(index !== -1) {
+ print('before: ' + JSON.stringify(filter));
+ var prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project'));
+ if(!filter.groupFilters.find(filter => filter.field === prefix + "project.funding level 1")) {
+ filter.groupFilters.push({
+ "field": prefix + "project.funding level 1",
+ "type": "contains",
+ "values": [
+ '((__index_shortName__))'
+ ]
+ });
+ print('after: ' + JSON.stringify(filter));
+ } else {
+ print('Already added');
+ }
+ }
+ return filter;
+ }
+}
+
+function addFundingStreamInDefaultMSCA() {
+ print("addFundingStreamInDefaultMSCA")
+
+ var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"});
+ if(stakeholder) {
+ stakeholder.topics.forEach((topic) => {
+ var topicObj = db.topic.findOne({"_id": ObjectId(topic)});
+ topicObj.categories.forEach((category) => {
+ var categoryObj = db.category.findOne({"_id": ObjectId(category)});
+ categoryObj.subCategories.forEach((subCategory) => {
+ var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)});
+ subCategoryObj.numbers.forEach((number) => {
+ var section = db.section.findOne({"_id": ObjectId(number)});
+ section.indicators.forEach((indicator) => {
+ var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
+ if(indicatorObject.indicatorPaths[0].parameters) {
+ indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
+ if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
+ var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
+ if(json.series && json.series.length > 0) {
+ json.series.forEach(query => {
+ if(query.query && query.query.filters && query.query.filters.length > 0) {
+ query.query.filters.forEach(filter => {
+ filter = addFundingLevelInFilters(filter);
+ });
+ }
+ });
+ indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
+ db.indicator.save(indicatorObject);
+ }
+ }
+ }
+ });
+ });
+ subCategoryObj.charts.forEach((chart) => {
+ var section = db.section.findOne({"_id": ObjectId(chart)});
+ section.indicators.forEach((indicator) => {
+ var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
+ if(indicatorObject.indicatorPaths[0].parameters) {
+ indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
+ if (indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
+ var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
+ if (json.chartDescription && json.chartDescription.queries && json.chartDescription.queries.length > 0) {
+ json.chartDescription.queries.forEach(query => {
+ if (query.query && query.query.filters && query.query.filters.length > 0) {
+ query.query.filters.forEach(filter => {
+ filter = addFundingLevelInFilters(filter);
+ });
+ }
+ });
+ indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
+ db.indicator.save(indicatorObject);
+ }
+ }
+ }
+ });
+ });
+ });
+
+ });
+ });
+ } else {
+ print("Profile doesn't exist")
+ }
+}
+
+use monitordb;
+
+statsProfileOfIndicatorsAsVariable();
+addFundingStreamInDefaultMSCA();
diff --git a/scripts/2024-02-27.js b/scripts/2024-02-27.js
new file mode 100644
index 0000000..5f84810
--- /dev/null
+++ b/scripts/2024-02-27.js
@@ -0,0 +1,16 @@
+function deleteIndexParameters() {
+ var indicators = db.indicator.find();
+ indicators.forEach(indicator => {
+ indicator.indicatorPaths.forEach(path => {
+ if(path.parameters) {
+ delete path.parameters['index_id'];
+ delete path.parameters['index_name'];
+ delete path.parameters['index_shortName'];
+ }
+ db.indicator.save(indicator);
+ });
+ })
+}
+
+use irish-prod;
+deleteIndexParameters();
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java
index 3387c9d..84d90a6 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java
@@ -41,7 +41,6 @@ public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
-// .globalOperationParameters(globalParameterList())
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoamonitorservice.controllers"))
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java
index 42c31fd..17e52d1 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java
@@ -14,7 +14,6 @@ import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import java.util.Collections;
-//"uoahelptexts"
@Configuration
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"})
public class MongoConnection {
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
index d2f0d23..e3f6634 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
@@ -259,51 +259,10 @@ public class CategoryController {
if(topic.getDefaultId() == null && children != null) {
onDeleteDefaultCategory(categoryId, topicId, children);
}
-
-// for(String subCategoryId : category.getSubCategories()) {
-// SubCategory subcategory = subCategoryDAO.findById(subCategoryId);
-// if(subcategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Delete category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
-// }
-//
-// for(String chartSectionId : subcategory.getCharts()) {
-// Section chartSection = sectionDAO.findById(chartSectionId);
-// if (chartSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String chartId : chartSection.getIndicators()) {
-// indicatorDAO.delete(chartId);
-// }
-// subcategory.setCharts(null);
-// sectionDAO.delete(chartSectionId);
-// }
-//
-// for(String numberSectionId : subcategory.getNumbers()) {
-// Section numberSection = sectionDAO.findById(numberSectionId);
-// if (numberSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String numberId : numberSection.getIndicators()) {
-// indicatorDAO.delete(numberId);
-// }
-// subcategory.setNumbers(null);
-// sectionDAO.delete(numberSectionId);
-// }
-//
-// subCategoryDAO.delete(subCategoryId);
-// }
subCategoryController.deleteTree(category);
-
category.setSubCategories(null);
-
categories.remove(index);
topicDAO.save(topic);
-
categoryDAO.delete(categoryId);
log.debug("Category deleted!");
} else {
@@ -406,44 +365,6 @@ public class CategoryController {
return categoriesFull;
}
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId) {
-// log.debug("toggle category status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
-//
-// Category category = categoryDAO.findById(categoryId);
-// if (category == null) {
-// // EXCEPTION - Category not found
-// throw new EntityNotFoundException("Toggle category status: Category with id: "+categoryId+" not found");
-// }
-// category.setIsActive(!category.getIsActive());
-//
-// this.toggleCategory(stakeholderId, topicId, category);
-//
-// return category.getIsActive();
-// }
-//
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleCategoryAccess(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId) {
-// log.debug("toggle category access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
-//
-// Category category = categoryDAO.findById(categoryId);
-// if (category == null) {
-// // EXCEPTION - Category not found
-// throw new EntityNotFoundException("Toggle category access: Category with id: "+categoryId+" not found");
-// }
-// category.setIsPublic(!category.getIsPublic());
-//
-// this.toggleCategory(stakeholderId, topicId, category);
-//
-// return category.getIsPublic();
-// }
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
public Category changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
index 9c33130..f67c5c2 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
@@ -221,16 +221,9 @@ public class IndicatorController {
if(section.getDefaultId() != null && section.getDefaultId().equals(defaultSection.getId())) {
Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator, subCategory.getVisibility());
- for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
- Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
- parameterMapping(indicatorPath, stakeholder);
- }
-
indicatorDAO.save(indicatorNew);
-
List indicators = section.getIndicators();
indicators.add(indicatorNew.getId());
-
sectionDAO.save(section);
}
}
@@ -300,7 +293,6 @@ public class IndicatorController {
if(indicatorPathBasedOnDefault == null) {
// Add new indicator path in existing indicators
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
- parameterMapping(indicatorPathNew, stakeholder);
indicatorPaths.add(indicatorPathNew);
changed = true;
} else {
@@ -407,10 +399,6 @@ public class IndicatorController {
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
changed = true;
}
-// else if(parameter.getKey().equals("type")) {
-// indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
-// changed = true;
-// }
}
// When deleting indicator path parameters in a default profile, delete them also from all children profiles
@@ -421,8 +409,6 @@ public class IndicatorController {
}
}
}
- parameterMapping(indicatorPathBasedOnDefault, stakeholder);
- //}
}
log.debug("After parameters check: " + changed);
@@ -500,65 +486,6 @@ public class IndicatorController {
}
}
- public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) throws UnsupportedEncodingException {
- if (indicatorPath.getParameters() != null) {
- if (indicatorPath.getParameters().containsKey("index_name")) {
- indicatorPath.getParameters().put("index_name", stakeholder.getIndex_name());
- } else if (indicatorPath.getParameters().containsKey("index_shortName")) {
- if(stakeholder.getIndex_shortName() != null) {
- indicatorPath.getParameters().put("index_shortName", stakeholder.getIndex_shortName().toLowerCase());
- } else {
- indicatorPath.getParameters().remove("index_shortName");
- }
- } else if (indicatorPath.getParameters().containsKey("index_id")) {
- indicatorPath.getParameters().put("index_id", stakeholder.getIndex_id());
- }
- }
-
-// // url encoding for number indicators
-// String url = indicatorPath.getUrl();
-// String encoded_index_id = urlEncode(URLEncoder.encode(stakeholder.getIndex_id(), "UTF-8"));
-// url = url.replace("index_id", encoded_index_id);
-// String encoded_index_name = urlEncode(URLEncoder.encode(stakeholder.getIndex_name(), "UTF-8"));
-// url = url.replace("index_name", encoded_index_name);
-// String encoded_index_shortName = urlEncode(URLEncoder.encode(stakeholder.getIndex_shortName(), "UTF-8"));
-// url = url.replace("index_shortName", encoded_index_shortName);
-// indicatorPath.setUrl(url);
- }
-
- public String urlEncode(String encodedIndicatorPathField) {
- String indicatorPathField = "";
-
- for( int i=0; i sections = sectionDAO.findByDefaultId(defaultSectionId);
-//
-// for(Section section : sections) {
-// List indicators = section.getIndicators();
-//
-// Iterator indicatorsIterator = indicators.iterator();
-// while(indicatorsIterator.hasNext()) {
-// String indicatorId = indicatorsIterator.next();
-//
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if (indicator.getDefaultId().equals(defaultIndicatorId)) {
-// indicatorsIterator.remove();
-// sectionDAO.save(section);
-//
-// indicatorDAO.delete(indicatorId);
-// log.debug("Indicator deleted!");
-//
-// break;
-// }
-// }
-// }
-
// 2nd way
List sections = sectionDAO.findByDefaultId(defaultSectionId);
List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
@@ -654,19 +558,6 @@ public class IndicatorController {
}
}
}
-
-// // 3rd way - parentId
-// List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
-// for(Indicator indicator : indicators) {
-// Section section = sectionDAO.findById(indicator.getParent());
-// List sectionIndicators = section.getIndicators();
-//
-// sectionIndicators.remove(indicator.getId());
-// sectionDAO.save(section);
-//
-// indicatorDAO.delete(indicator.getId());
-// log.debug("Indicator deleted!");
-// }
} else if(children.equals("disconnect")) {
List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
for(Indicator indicator : indicators) {
@@ -678,79 +569,6 @@ public class IndicatorController {
return true;
}
-// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE)
-// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) {
-// log.debug("delete all chart indicators of stakeholder");
-// log.debug("Stakeholder: "+stakeholderId);
-//
-// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
-// if(stakeholder != null) {
-//
-// for(String topicId : stakeholder.getTopics()) {
-// Topic topic = topicDAO.findById(topicId);
-// if(topic != null) {
-// for(String categoryId : topic.getCategories()) {
-// Category category = categoryDAO.findById(categoryId);
-// if(category != null) {
-// for(String subcategoryId : category.getSubCategories()) {
-// SubCategory subcategory = subCategoryDAO.findById(subcategoryId);
-// if(subcategory != null) {
-//
-// for(String sectionId : subcategory.getCharts()) {
-// Section section = sectionDAO.findById(sectionId);
-// if (section != null) {
-//
-// List indicators = section.getIndicators();
-// Iterator indicatorsIterator = section.getIndicators().iterator();
-//
-// while (indicatorsIterator.hasNext()) {
-// String indicatorId = indicatorsIterator.next();
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if (indicator != null) {
-// int index = indicators.indexOf(indicatorId);
-// if (index != -1) {
-// indicatorsIterator.remove();
-// //indicators.remove(index);
-//
-// indicatorDAO.delete(indicatorId);
-// log.debug("Indicator deleted!");
-// } else {
-// // EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
-// throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Section: " + sectionId);
-// }
-// } else {
-// // EXCEPTION - Indicator not found
-// throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found");
-// }
-// }
-// sectionDAO.save(section);
-// } else {
-// // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
-// throw new PathNotValidException("Delete indicator: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId);
-// }
-// }
-// } else {
-// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
-// throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
-// }
-// }
-// } else {
-// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
-// throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
-// }
-// }
-// } else {
-// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
-// throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
-// }
-// }
-// } else {
-// // EXCEPTION - Stakeholder not found
-// throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found");
-// }
-// return true;
-// }
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST)
public List reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
@@ -793,50 +611,6 @@ public class IndicatorController {
return indicatorsFull;
}
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId,
-// @PathVariable("sectionId") String sectionId,
-// @PathVariable("indicatorId") String indicatorId) {
-// log.debug("toggle indicator status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
-//
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if (indicator == null) {
-// // EXCEPTION - Indicator not found
-// throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found");
-// }
-// indicator.setIsActive(!indicator.getIsActive());
-//
-// this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
-//
-// return indicator.getIsActive();
-// }
-//
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId,
-// @PathVariable("sectionId") String sectionId,
-// @PathVariable("indicatorId") String indicatorId) {
-// log.debug("toggle indicator access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
-//
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if (indicator == null) {
-// // EXCEPTION - Indicator not found
-// throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found");
-// }
-// indicator.setIsPublic(!indicator.getIsPublic());
-//
-// this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
-//
-// return indicator.getIsPublic();
-// }
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
index fa68f01..24587d1 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
@@ -16,9 +16,6 @@ import java.util.*;
@CrossOrigin(origins = "*")
public class MonitorController {
private final Logger log = LogManager.getLogger(this.getClass());
-//
-// @Autowired
-// private LayoutService layoutService;
@Autowired
private PortalService portalService;
@@ -36,11 +33,6 @@ public class MonitorController {
if (!old_pid.equals(new_pid)) {
pageService.updatePid(old_pid, new_pid, portal.getType());
}
-// String old_pid = portalResponse.getPid();
-// String new_pid = portal.getPid();
-// if(!old_pid.equals(new_pid)) {
-// layoutService.updatePid(old_pid, new_pid);
-// }
return portalResponse;
}
@@ -60,16 +52,5 @@ public class MonitorController {
return true;
}
-
-// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
-// public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
-// return layoutService.findByPid(pid);
-// }
-//
-// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
-// public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
-// return layoutService.save(layout);
-// }
-
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
index 6b84e53..802fe33 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
@@ -25,7 +25,6 @@ import java.util.Map;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/monitor-library")
-//@ConditionalOnBean(UoaMonitorServiceApplication.class)
public class MonitorLibraryCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
@@ -63,7 +62,6 @@ public class MonitorLibraryCheckDeployController {
response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
-// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
if(globalVars.date != null) {
response.put("Date of deploy", globalVars.date.toString());
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
index fea6107..45aecec 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
@@ -58,7 +58,6 @@ public class MonitorServiceCheckDeployController {
response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
-// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
if(globalVars.date != null) {
response.put("Date of deploy", globalVars.date.toString());
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
index a7506ee..90b47b0 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
@@ -196,241 +196,6 @@ public class SectionController {
public void onUpdateDefaultSection(Section section, Stakeholder stakeholder, Section oldSection) {
log.debug("On update default section");
-
- // section already exists - check if changed and update all sections based on it
-
- boolean changed = false;
- List sections = sectionDAO.findByDefaultId(section.getId());
-
- for(Section sectionBasedOnDefault : sections) {
- if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())
- && (oldSection.getTitle() == null || oldSection.getTitle().equals(sectionBasedOnDefault.getTitle()))) {
-
- sectionBasedOnDefault.setTitle(section.getTitle());
- changed = true;
- }
-
- if(!changed) {
-// break;
- continue;
- }
-
-// sectionBasedOnDefault.setTitle(section.getTitle());
- sectionBasedOnDefault.setUpdateDate(section.getUpdateDate());
- sectionDAO.save(sectionBasedOnDefault);
- }
- }
-
- @PreAuthorize("isAuthenticated()")
- @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete", method = RequestMethod.DELETE)
- public boolean deleteSection(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @PathVariable("subcategoryId") String subcategoryId,
- @PathVariable("sectionId") String sectionId,
- @RequestParam(required = false) String children) {
- log.debug("delete section");
- log.debug("Id: "+sectionId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
-
- Section section = sectionDAO.findById(sectionId);
- if(section != null) {
- SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
-
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(section.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
- // EXCEPTION - Access denied
- throw new ForbiddenException("Delete section: You are not authorized to delete a default Section in stakeholder with id: "+stakeholderId);
- }
-
- String type = "";
- List sections = null;
- if (section.getType().equals("chart")) {
- sections = subCategory.getCharts();
- type = "chart";
- } else if (section.getType().equals("number")) {
- sections = subCategory.getNumbers();
- type = "number";
- }
-
- int index = sections.indexOf(sectionId);
- if (index != -1) {
- // this section belongs in default profile
- if(subCategory.getDefaultId() == null && children != null) {
- onDeleteDefaultSection(sectionId, subcategoryId, children, type);
- }
-
- indicatorController.deleteTree(section);
-
- sections.remove(index);
- subCategoryDAO.save(subCategory);
-
- sectionDAO.delete(sectionId);
- log.debug("Section deleted!");
- } else {
- // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
- throw new PathNotValidException("Delete section: Section with id: "+sectionId+" not found in SubCategory: "+subcategoryId);
- }
- } else {
- // EXCEPTION - Section not found
- throw new EntityNotFoundException("Delete section: Section with id: "+sectionId+" not found");
- }
- return true;
- }
-
- public boolean onDeleteDefaultSection(String defaultSectionId, String defaultSubCategoryId, String children, String type) {
- if(children.equals("delete")) {
- List subCategories = subCategoryDAO.findByDefaultId(defaultSubCategoryId);
- List sections = sectionDAO.findByDefaultId(defaultSectionId);
-
- for(SubCategory subCategory : subCategories) {
- Iterator sectionsIterator = sections.iterator();
- while(sectionsIterator.hasNext()) {
- Section section = sectionsIterator.next();
-
- String sectionId = section.getId();
- List subCategorySections = null;
- if(type.equals("chart")) {
- subCategorySections = subCategory.getCharts();
- } else if(type.equals("number")) {
- subCategorySections = subCategory.getNumbers();
- }
- if(subCategorySections != null && subCategorySections.contains(sectionId)) {
- sectionsIterator.remove();
-
- subCategorySections.remove(sectionId);
- subCategoryDAO.save(subCategory);
-
- indicatorController.deleteTree(section);
-
- sectionDAO.delete(sectionId);
- log.debug("Section with id: "+sectionId+" deleted!");
-
- break;
- }
- }
- }
- } else if(children.equals("disconnect")) {
- List sections = sectionDAO.findByDefaultId(defaultSectionId);
- for(Section section : sections) {
- indicatorController.disConnectTree(section);
-
- section.setDefaultId(null);
- sectionDAO.save(section);
-
- log.debug("DefaultId for Section with id: "+section.getId()+" empty!");
- }
- }
- return true;
- }
-
- @PreAuthorize("isAuthenticated()")
- @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
- public List reorderSections(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @PathVariable("subcategoryId") String subcategoryId,
- @PathVariable("type") String type,
- @RequestBody List sections) {
- log.debug("reorder sections of type: "+type);
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
-
- SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
-
- if (type.equals("chart")) {
- List oldSections = subCategory.getCharts();
- for (String sectionId : oldSections) {
- if (!sections.contains(sectionId)) {
- sections.add(sectionId);
- }
- }
- subCategory.setCharts(sections);
- } else if (type.equals("number")) {
- List oldSections = subCategory.getNumbers();
- for (String sectionId : oldSections) {
- if (!sections.contains(sectionId)) {
- sections.add(sectionId);
- }
- }
- subCategory.setNumbers(sections);
- }
-
- List sectionsFull = new ArrayList<>();
- for(String sectionId : sections) {
- Section section = sectionDAO.findById(sectionId);
- if(section == null) {
- // EXCEPTION - Section not found
- throw new EntityNotFoundException("Reorder sections: Section with id: " + sectionId + " not found");
- }
- sectionsFull.add(section);
- }
-
- subCategoryDAO.save(subCategory);
- log.debug("Sections reordered!");
-
- return sectionsFull;
- }
-
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleSectionStatus(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId,
-// @PathVariable("sectionId") String sectionId) {
-// log.debug("toggle section status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Section: "+sectionId);
-//
-// Section section = sectionDAO.findById(sectionId);
-// if (section == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Toggle section status: Section with id: "+sectionId+" not found");
-// }
-// section.setIsActive(!section.getIsActive());
-//
-// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId, section);
-//
-// return section.getIsActive();
-// }
-
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleSectionAccess(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId,
-// @PathVariable("sectionId") String sectionId) {
-// log.debug("toggle section access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
-//
-// Section section = sectionDAO.findById(sectionId);
-// if (section == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Toggle section access: Section with id: "+sectionId+" not found");
-// }
-// section.setIsPublic(!section.getIsPublic());
-//
-// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId);
-//
-// return section.getIsPublic();
-// }
-
-
- public void toggleSection(String stakeholderId, String topicId, String categoryId, String subcategoryId, Section section) {
- SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
-
- List sections = null;
- if (section.getType().equals("chart")) {
- sections = subCategory.getCharts();
- } else if (section.getType().equals("number")) {
- sections = subCategory.getNumbers();
- }
-
- if(sections.contains(section.getId())) {
- sectionDAO.save(section);
- log.debug("Section toggled!");
- } else {
- // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias();
- throw new PathNotValidException("Toggle section: Section with id: "+section.getId()+" not found in SubCategory: "+subcategoryId);
- }
-
}
private SubCategory checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId) {
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
index f6293a4..8e2a33f 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
@@ -56,19 +56,10 @@ public class StakeholderController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
public List getAllReservedStakeholderAlias() {
-// log.debug("get all stakeholder reserved alias-es");
- List stakeholderAlias = new ArrayList<>();
-
- List stakeholders = stakeholderDAO.findAll();
- if(stakeholders != null) {
- stakeholders.forEach(stakeholder -> {
- stakeholderAlias.add(stakeholder.getAlias());
- });
- }
- stakeholderAlias.add( "all");
+ List stakeholderAlias = this.stakeholderService.getAllAliases();
+ stakeholderAlias.add("all");
stakeholderAlias.add("default");
stakeholderAlias.add("alias");
-
return stakeholderAlias;
}
@@ -120,22 +111,11 @@ public class StakeholderController {
boolean addAll = false;
boolean addPublicAndRestricted = false;
-// if(roles == null
-// || roles.contains(authorizationService.PORTAL_ADMIN)
-// || roles.contains(authorizationService.curator(stakeholder.getType()))
-// || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) {
if(rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
- //if(visibility == null || visibility == (Visibility.PRIVATE)) {
addAll = true;
- //}
- //if(visibility == null || visibility == (Visibility.PRIVATE) || visibility == (Visibility.RESTRICTED)) {
addPublicAndRestricted = true;
- //}
-// } else if(roles != null && roles.contains(authorizationService.member(stakeholder.getType(), stakeholder.getAlias()))) {
} else if(rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())) {
- //if(visibility == null || visibility == (Visibility.PRIVATE) || visibility == (Visibility.RESTRICTED)) {
addPublicAndRestricted = true;
- //}
}
Stakeholder stakeholderFull = new Stakeholder<>(stakeholder);
@@ -201,62 +181,18 @@ public class StakeholderController {
sectionsNumbers.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted));
}
subCategoryFull.setNumbers(sectionsNumbers);
-
-// List charts = new ArrayList<>();
-// for(String indicatorId : subCategory.getCharts()) {
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if(indicator == null) {
-// // EXCEPTION - Indicator not found
-// throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
-// }
-// charts.add(indicator);
-// }
-// subCategoryFull.setCharts(charts);
-//
-// List numbers = new ArrayList<>();
-// for (String indicatorId : subCategory.getNumbers()) {
-// Indicator indicator = indicatorDAO.findById(indicatorId);
-// if (indicator == null) {
-// // EXCEPTION - Indicator not found
-// throw new EntityNotFoundException("Get stakeholder: Indicator with id: " + indicatorId + " not found (indicator exists in subCategory: " + subCategoryId + ")");
-// }
-// numbers.add(indicator);
-// }
-// subCategoryFull.setNumbers(numbers);
-
subCategories.add(subCategoryFull);
}
-
categoryFull.setSubCategories(subCategories);
categories.add(categoryFull);
}
-
topicFull.setCategories(categories);
topics.add(topicFull);
}
-
stakeholderFull.setTopics(topics);
return stakeholderFull;
}
-// private SubCategory setFullSubcategory(SubCategory subCategory) {
-// SubCategory subCategoryFull = new SubCategory>(subCategory);
-//
-// List sectionsCharts = new ArrayList<>();
-//
-// for(String sectionId : subCategory.getCharts()) {
-// sectionsCharts.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted));
-// }
-// subCategoryFull.setCharts(sectionsCharts);
-//
-// List sectionsNumbers = new ArrayList<>();
-//
-// for(String sectionId : subCategory.getNumbers()) {
-// sectionsNumbers.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted));
-// }
-// subCategoryFull.setNumbers(sectionsNumbers);
-// }
-
private Section getSectionFull(String sectionId, String subCategoryId, boolean addAll, boolean addPublicAndRestricted) {
Section section = sectionDAO.findById(sectionId);
if (section == null) {
@@ -323,10 +259,6 @@ public class StakeholderController {
// Remove stakeholders for which i do not have authority
if(stakeholders != null && stakeholders.size() > 0) {
-// log.debug("ROLES: ");
-// roles.forEach(role -> log.debug(role));
-//
-// if (roles.contains(authorizationService.PORTAL_ADMIN)) {
if (rolesUtils.isPortalAdmin()) {
for(Stakeholder stakeholder : stakeholders) {
stakeholdersFull.add(this.setFullEntities(stakeholder));
@@ -337,8 +269,6 @@ public class StakeholderController {
Iterator stakeholderIterator = stakeholders.iterator();
while(stakeholderIterator.hasNext()) {
Stakeholder stakeholder = stakeholderIterator.next();
-
-// if(roles.contains(authorizationService.curator(stakeholder.getType()))) {
if(rolesUtils.isCurator(stakeholder.getType())) {
stakeholdersFull.add(this.setFullEntities(stakeholder));
continue;
@@ -359,13 +289,11 @@ public class StakeholderController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
public List getMyRealStakeholders(@RequestParam(required = false) String type) {
-// log.debug("get my NOT default stakeholders" + (type != null ? " with type: "+type : ""));
return stakeholderService.getStakeholdersByTypeAndRole(type, null, true);
}
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
public Stakeholder getStakeholder(@PathVariable("alias") String alias) {
-// log.debug("get stakeholder: "+alias);
Stakeholder stakeholder = stakeholderDAO.findByAlias(alias);
if(stakeholder == null) {
@@ -373,7 +301,6 @@ public class StakeholderController {
throw new EntityNotFoundException("Get stakeholder: Stakeholder with alias: "+alias+" not found");
}
-// List roles = authorizationService.getRoles();
if(stakeholder.getDefaultId() == null && !rolesUtils.isLoggedIn()) {
// EXCEPTION - Unauthorized
throw new AccessDeniedException("Get stakeholder: You are not authorized (not logged in) to access stakeholder with alias: "+alias);
@@ -386,7 +313,6 @@ public class StakeholderController {
if((stakeholder.getVisibility() == Visibility.PRIVATE && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())
|| (stakeholder.getVisibility() == Visibility.RESTRICTED && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias()) && !rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())))) {
// // EXCEPTION - Access denied
-// throw new ForbiddenException("Get stakeholder: You are not authorized to get stakeholder with alias: "+alias);
List topicsEmpty = stakeholder.getTopics();
topicsEmpty.clear();
stakeholder.setTopics(topicsEmpty);
@@ -397,7 +323,6 @@ public class StakeholderController {
return this.setFullEntities(stakeholder);
}
-// @PreAuthorize("isAuthenticated()")
@PreAuthorize("hasAnyAuthority("
+ "@AuthorizationService.PORTAL_ADMIN, "
+ "@AuthorizationService.curator(#_stakeholder.getType()), "
@@ -407,26 +332,13 @@ public class StakeholderController {
public Stakeholder saveStakeholder(@RequestBody Stakeholder _stakeholder) {
log.debug("save stakeholder");
log.debug("Alias: "+_stakeholder.getAlias() + " - Id: "+_stakeholder.getId());
-
-// if(_stakeholder == null) {
-// log.debug("stakeholder null");
-// // EXCEPTION - Parameter for Stakeholder is not accepted
-// }
-
Stakeholder stakeholder = new Stakeholder<>(_stakeholder);
Date date = new Date();
stakeholder.setUpdateDate(date);
-
List topics = new ArrayList<>();
-
- // stakeholder does not exist in DB
if(_stakeholder.getId() == null) {
stakeholder.setCreationDate(date);
-
-// for(Topic topic : _stakeholder.getTopics()) {
-// topics.add(topic.getId());
-// }
} else {
Stakeholder oldStakeholder = stakeholderDAO.findById(_stakeholder.getId());
if(oldStakeholder == null) {
@@ -441,21 +353,12 @@ public class StakeholderController {
}
topics.add(topic.getId());
}
-// stakeholder.setTopics(topics);
-// _stakeholder = this.setFullEntities(stakeholder, rolesUtils.getRoles());
}
-
stakeholder.setTopics(topics);
-
Stakeholder stakeholderSaved = stakeholderDAO.save(stakeholder);
_stakeholder.setId(stakeholderSaved.getId());
_stakeholder.setCreationDate(stakeholderSaved.getCreationDate());
_stakeholder.setUpdateDate(stakeholderSaved.getUpdateDate());
-
- topics = null;
- stakeholder = null;
- stakeholderSaved = null;
-
return _stakeholder;
}
@@ -470,78 +373,14 @@ public class StakeholderController {
if(stakeholder != null) {
pid = stakeholder.getAlias();
-
-// if(!roles.contains(authorizationService.PORTAL_ADMIN)
-// && !roles.contains(authorizationService.curator(stakeholder.getType()))) {
if(!rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
// EXCEPTION - Access denied
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: "+stakeholderId);
}
-
-// for(String topicId : stakeholder.getTopics()) {
-// Topic topic = topicDAO.findById(topicId);
-// if (topic == null) {
-// // EXCEPTION - Topic not found
-// throw new EntityNotFoundException("Delete stakeholder: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholderId+")");
-// }
-//
-// for (String categoryId : topic.getCategories()) {
-// Category category = categoryDAO.findById(categoryId);
-// if (category == null) {
-// // EXCEPTION - Category not found
-// throw new EntityNotFoundException("Delete stakeholder: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
-// }
-//
-// for (String subCategoryId : category.getSubCategories()) {
-// SubCategory subcategory = subCategoryDAO.findById(subCategoryId);
-// if (subcategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Delete stakeholder: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
-// }
-//
-// for(String chartSectionId : subcategory.getCharts()) {
-// Section chartSection = sectionDAO.findById(chartSectionId);
-// if (chartSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String chartId : chartSection.getIndicators()) {
-// indicatorDAO.delete(chartId);
-// }
-// subcategory.setCharts(null);
-// sectionDAO.delete(chartSectionId);
-// }
-//
-// for(String numberSectionId : subcategory.getNumbers()) {
-// Section numberSection = sectionDAO.findById(numberSectionId);
-// if (numberSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String numberId : numberSection.getIndicators()) {
-// indicatorDAO.delete(numberId);
-// }
-// subcategory.setNumbers(null);
-// sectionDAO.delete(numberSectionId);
-// }
-//
-// subCategoryDAO.delete(subCategoryId);
-// }
-// category.setSubCategories(null);
-// categoryDAO.delete(categoryId);
-// }
-// topic.setCategories(null);
-// topicDAO.delete(topicId);
-// }
-
topicController.deleteTree(stakeholder);
-
stakeholder.setTopics(null);
stakeholderDAO.delete(stakeholderId);
log.debug("Stakeholder deleted!");
-
Portal portal = portalService.getPortal(pid);
if(portal != null) {
portalService.deletePortal(portal.getId());
@@ -553,44 +392,6 @@ public class StakeholderController {
return true;
}
-
-// @RequestMapping(value = "/{stakeholderId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleStakeholderStatus(@PathVariable("stakeholderId") String stakeholderId) {
-// log.debug("toggle stakeholder status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId);
-//
-// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
-// if (stakeholder == null) {
-// // EXCEPTION - Stakeholder not found
-// throw new EntityNotFoundException("Toggle stakeholder status: Stakeholder with id: "+stakeholderId+" not found");
-// }
-// stakeholder.setIsActive(!stakeholder.getIsActive());
-//
-// stakeholderDAO.save(stakeholder);
-// log.debug("Stakeholder toggled!");
-//
-// return stakeholder.getIsActive();
-// }
-//
-// @RequestMapping(value = "/{stakeholderId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleStakeholderAccess(@PathVariable("stakeholderId") String stakeholderId) {
-// log.debug("toggle stakeholder access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId);
-//
-// Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
-// if (stakeholder == null) {
-// // EXCEPTION - Stakeholder not found
-// throw new EntityNotFoundException("Toggle stakeholder access: Stakeholder with id: "+stakeholderId+" not found");
-// }
-// stakeholder.setIsPublic(!stakeholder.getIsPublic());
-//
-// stakeholderDAO.save(stakeholder);
-// log.debug("Stakeholder toggled!");
-//
-// return stakeholder.getIsPublic();
-// }
-
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
public Stakeholder changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
@@ -603,12 +404,6 @@ public class StakeholderController {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Change stakeholder visibility: Stakeholder with id: "+stakeholderId+" not found");
}
-
-// List roles = authorizationService.getRoles();
-
-// if(!roles.contains(authorizationService.PORTAL_ADMIN)
-// && !roles.contains(authorizationService.curator(stakeholder.getType()))
-// && !roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
// EXCEPTION - Access denied
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: "+stakeholderId);
@@ -621,7 +416,7 @@ public class StakeholderController {
Stakeholder stakeholderFull = new Stakeholder<>(stakeholder);
List topicsFull = new ArrayList<>();
- if(propagate != null && propagate) {
+ if (propagate != null && propagate) {
for (String topicId : stakeholder.getTopics()) {
topicsFull.add(topicController.changeVisibilityTree(topicId, visibility, propagate));
}
@@ -636,45 +431,4 @@ public class StakeholderController {
return stakeholder;
}
-
- // The following are not supposed to be used
-// @RequestMapping(value = "/stakeholder/dates", method = RequestMethod.GET)
-// public List getAllStakeholderDates() {
-// List profiles = stakeholderDAO.findAll();
-// List profileDates = new ArrayList<>();
-//
-// int i=0;
-// for(Stakeholder profile : profiles) {
-// log.debug(profile.getCreationDate());
-// profileDates.add(profile.getCreationDate());
-// log.debug(profileDates.get(i));
-// i++;
-// }
-// return profileDates;
-// }
-//
-// @RequestMapping(value = "/stakeholder/dates1", method = RequestMethod.GET)
-// public List getAllStakeholderDates1() {
-// List profiles = stakeholderDAO.findAll();
-// List profileDates = new ArrayList<>();
-//
-// for(Stakeholder profile : profiles) {
-// log.debug(profile.getCreationDate().toString());
-// profileDates.add(profile.getCreationDate().toString());
-// }
-// return profileDates;
-// }
-//
-// @RequestMapping(value = "/stakeholder/dates2", method = RequestMethod.GET)
-// public List getAllStakeholderDates2() {
-// List profiles = stakeholderDAO.findAll();
-// List profileDates = new ArrayList<>();
-// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-//
-// for(Stakeholder profile : profiles) {
-// log.debug(format.format(profile.getCreationDate()));
-// profileDates.add(format.format(profile.getCreationDate()));
-// }
-// return profileDates;
-// }
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java
index 06c005f..aaa499b 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java
@@ -142,20 +142,6 @@ public class SubCategoryController {
numberSections.add(numberSection.getId());
}
}
-
-// List charts = new ArrayList<>();
-// for(Indicator chart : subcategoryFull.getCharts()) {
-// charts.add(chart.getId());
-// }
-// subCategory.setCharts(charts);
-//
-// List numbers = new ArrayList<>();
-// for(Indicator numbr : subcategoryFull.getNumbers()) {
-// numbers.add(numbr.getId());
-// }
-// subCategory.setNumbers(numbers);
-
-
subCategory.setCharts(chartSections);
subCategory.setNumbers(numberSections);
@@ -181,11 +167,6 @@ public class SubCategoryController {
subcategoryFull.setId(subCategory.getId());
}
-
- chartSections = null;
- numberSections = null;
- subCategory = null;
-
return subcategoryFull;
}
@@ -227,12 +208,8 @@ public class SubCategoryController {
}
if(!changed) {
-// break;
continue;
}
-
-// subCategoryBasedOnDefault.setName(subCategory.getName());
-// subCategoryBasedOnDefault.setDescription(subCategory.getDescription());
subCategoryBasedOnDefault.setUpdateDate(subCategory.getUpdateDate());
subCategoryDAO.save(subCategoryBasedOnDefault);
}
@@ -266,35 +243,6 @@ public class SubCategoryController {
if(category.getDefaultId() == null && children != null) {
onDeleteDefaultSubCategory(subcategoryId, categoryId, children);
}
-
-// for(String chartSectionId : subcategory.getCharts()) {
-// Section chartSection = sectionDAO.findById(chartSectionId);
-// if (chartSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subcategoryId+")");
-// }
-//
-// for (String chartId : chartSection.getIndicators()) {
-// indicatorDAO.delete(chartId);
-// }
-// subcategory.setCharts(null);
-// sectionDAO.delete(chartSectionId);
-// }
-//
-// for(String numberSectionId : subcategory.getNumbers()) {
-// Section numberSection = sectionDAO.findById(numberSectionId);
-// if (numberSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete SubCategory: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subcategoryId+")");
-// }
-//
-// for (String numberId : numberSection.getIndicators()) {
-// indicatorDAO.delete(numberId);
-// }
-// subcategory.setNumbers(null);
-// sectionDAO.delete(numberSectionId);
-// }
-
sectionController.deleteTree(subcategory);
subcategory.setCharts(null);
@@ -393,46 +341,6 @@ public class SubCategoryController {
return subCategoriesFull;
}
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId) {
-// log.debug("toggle subCategory status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
-//
-// SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
-// if (subCategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Toggle subCategory status: SubCategory with id: "+subcategoryId+" not found");
-// }
-// subCategory.setIsActive(!subCategory.getIsActive());
-//
-// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory);
-//
-// return subCategory.getIsActive();
-// }
-//
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleSubCategoryAccess(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId,
-// @PathVariable("categoryId") String categoryId,
-// @PathVariable("subcategoryId") String subcategoryId) {
-// log.debug("toggle subCategory access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
-//
-// SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
-// if (subCategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Toggle subCategory access: SubCategory with id: "+subcategoryId+" not found");
-// }
-// subCategory.setIsPublic(!subCategory.getIsPublic());
-//
-// this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory);
-//
-// return subCategory.getIsPublic();
-// }
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
public SubCategory changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
@@ -522,18 +430,6 @@ public class SubCategoryController {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
}
-
-// SubCategory subcategory = subCategoryDAO.findById(subcategoryId);
-// if(subcategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found");
-// }
-//
-// if (!category.getSubCategories().contains(subcategoryId)) {
-// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
-// throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
-// }
-
return category;
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java
deleted file mode 100644
index 6c9fc80..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TestController.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package eu.dnetlib.uoamonitorservice.controllers;
-
-import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
-import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-@RestController
-@CrossOrigin(origins = "*")
-public class TestController {
- private final Logger log = LogManager.getLogger(this.getClass());
-
- @Autowired
- private StakeholderDAO stakeholderDAO;
-
-// @RequestMapping("/")
-// public String index() {
-// return "Greetings from Spring Boot!";
-// }
-
- // Check ExceptionHandler
- @RequestMapping(value = "/test-error1", method = RequestMethod.GET)
- public Stakeholder getFirstStakeholder() {
- List stakeholders;
- stakeholders = stakeholderDAO.findAll();
-
- return stakeholders.get(0);
- }
-
- @RequestMapping(value = "/test-error2", method = RequestMethod.GET)
- public String getParam(@RequestParam String param) {
- return param;
- }
-
- @RequestMapping(value = "/test-error3", method = RequestMethod.GET)
- public String getSubstringOfNull() {
- String str = null;
- return str.substring(2);
- }
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
index ab2e4b8..de3c423 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java
@@ -132,9 +132,6 @@ public class TopicController {
topicFull.setId(topic.getId());
}
-
- categories = null;
- topic = null;
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Save topic: Stakeholder with id: "+stakeholderId+" not found");
@@ -186,12 +183,8 @@ public class TopicController {
}
if(!changed) {
-// break;
continue;
}
-
-// topicBasedOnDefault.setName(topic.getName());
-// topicBasedOnDefault.setDescription(topic.getDescription());
topicBasedOnDefault.setUpdateDate(topic.getUpdateDate());
topicDAO.save(topicBasedOnDefault);
}
@@ -229,54 +222,6 @@ public class TopicController {
if(stakeholder.getDefaultId() == null && children != null) {
onDeleteDefaultTopic(topicId, stakeholderId, children);
}
-
-// for(String categoryId : topic.getCategories()) {
-// Category category = categoryDAO.findById(categoryId);
-// if(category == null) {
-// // EXCEPTION - Category not found
-// throw new EntityNotFoundException("Delete topic: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
-// }
-//
-// for(String subCategoryId : category.getSubCategories()) {
-// SubCategory subcategory = subCategoryDAO.findById(subCategoryId);
-// if (subcategory == null) {
-// // EXCEPTION - SubCategory not found
-// throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
-// }
-//
-// for(String chartSectionId : subcategory.getCharts()) {
-// Section chartSection = sectionDAO.findById(chartSectionId);
-// if (chartSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String chartId : chartSection.getIndicators()) {
-// indicatorDAO.delete(chartId);
-// }
-// subcategory.setCharts(null);
-// sectionDAO.delete(chartSectionId);
-// }
-//
-// for(String numberSectionId : subcategory.getNumbers()) {
-// Section numberSection = sectionDAO.findById(numberSectionId);
-// if (numberSection == null) {
-// // EXCEPTION - Section not found
-// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
-// }
-//
-// for (String numberId : numberSection.getIndicators()) {
-// indicatorDAO.delete(numberId);
-// }
-// subcategory.setNumbers(null);
-// sectionDAO.delete(numberSectionId);
-// }
-//
-// subCategoryDAO.delete(subCategoryId);
-// }
-// category.setSubCategories(null);
-// categoryDAO.delete(categoryId);
-// }
categoryController.deleteTree(topic);
topic.setCategories(null);
@@ -387,42 +332,6 @@ public class TopicController {
}
}
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST)
-// public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId) {
-// log.debug("toggle topic status (isActive)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
-//
-// Topic topic = topicDAO.findById(topicId);
-// if (topic == null) {
-// // EXCEPTION - Topic not found
-// throw new EntityNotFoundException("Toggle topic status: Topic with id: "+topicId+" not found");
-// }
-// topic.setIsActive(!topic.getIsActive());
-//
-// this.toggleTopic(stakeholderId, topic);
-//
-// return topic.getIsActive();
-// }
-//
-// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-access", method = RequestMethod.POST)
-// public Boolean toggleTopicAccess(@PathVariable("stakeholderId") String stakeholderId,
-// @PathVariable("topicId") String topicId) {
-// log.debug("toggle topic access (isPublic)");
-// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
-//
-// Topic topic = topicDAO.findById(topicId);
-// if (topic == null) {
-// // EXCEPTION - Topic not found
-// throw new EntityNotFoundException("Toggle topic access: Topic with id: "+topicId+" not found");
-// }
-// topic.setIsPublic(!topic.getIsPublic());
-//
-// this.toggleTopic(stakeholderId, topic);
-//
-// return topic.getIsPublic();
-// }
-
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST)
public Topic changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
@@ -449,10 +358,6 @@ public class TopicController {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found");
}
-
-
-// this.toggleTopic(stakeholderId, topic);
-
}
public Topic changeVisibilityTree(String topicId, Visibility visibility, Boolean propagate) {
@@ -489,9 +394,7 @@ public class TopicController {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Topic delete tree: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")");
}
-
categoryController.deleteTree(topic);
-
topicDAO.delete(topicId);
}
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java
index accce6c..61b4ba4 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java
@@ -19,6 +19,10 @@ public class StakeholderService {
@Autowired
RolesUtils rolesUtils;
+ public List getAllAliases() {
+ return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
+ }
+
public List getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
List stakeholders;
if(type != null && defaultId != null) {
diff --git a/src/main/resources/monitorservice.properties b/src/main/resources/monitorservice.properties
index 8ccd226..82627cb 100644
--- a/src/main/resources/monitorservice.properties
+++ b/src/main/resources/monitorservice.properties
@@ -26,3 +26,30 @@ monitorservice.globalVars.version=@version@
#monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
#monitorservice.originServer = .openaire.eu
+# Monitor
+monitorservice.mongodb.host=localhost
+monitorservice.mongodb.port=27017
+monitorservice.mongodb.database=production
+
+# Notification
+notification.mongodb.host = localhost
+notification.mongodb.port = 27017
+notification.mongodb.database = openaire_notification
+
+# Admin Tools Library
+admintoolslibrary.mail.from = openaire.test@gmail.com
+admintoolslibrary.mail.username = openaire.test@gmail.com
+admintoolslibrary.mail.password = koujreltgjduicjp
+admintoolslibrary.mail.host = smtp.gmail.com
+admintoolslibrary.mail.port = 587
+admintoolslibrary.mail.auth = true
+admintoolslibrary.mail.sslProtocols = TLSv1.2
+admintoolslibrary.mail.defaultEncoding=UTF-8
+admintoolslibrary.mail.protocol=smtp
+admintoolslibrary.mail.testConnection=false
+admintoolslibrary.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
+
+# Authorization
+authorization.security.userInfoUrl = http://mpagasas.di.uoa.gr:19080/login-service/userInfo
+
+server.port=8888
\ No newline at end of file
diff --git a/update_db.js b/update_db.js
deleted file mode 100644
index 0c896e4..0000000
--- a/update_db.js
+++ /dev/null
@@ -1,505 +0,0 @@
-//version compatibility: 1.0.0-SNAPSHOT
-
-//use openaire_monitor;
-
-function upperCaseEnumValues() {
- stakeholders = db.stakeholder.find().map(function (stakeholders) {
- return stakeholders;
- });
- for(var i=0; i"+content+"",
- "isActive" : true
- }
- );
-
- print("div help text for divId 'footer' added for "+portalType +" (id: "+ portal._id + " - pid: " + portal.pid + " - footer divId id: "+footerDivIdID + ")");
- }
-}
-
-function statsProfileOfIndicatorsAsVariable() {
- print("statsProfileOfIndicatorsAsVariable");
-
- numOfNumbers = 0;
- numOfCharts = 0;
- numOfNonMonitorProfiles = 0;
- numOfMonitorProfiles = 0;
- numOfNoProfiles = 0;
- differentProfiles = new Set();
-
- // indicators = db.indicator.find({"type": "chart"}).map(function (indicator) {
- // indicators = db.indicator.find({"type": "number"}).map(function (indicator) {
- indicators = db.indicator.find().map(function (indicator) {
- return indicator;
- });
-
- print(indicators.length);
-
- for (var i = 0; i < indicators.length; i++) {
- indicator = indicators[i];
-
- indicatorPaths = indicator.indicatorPaths;
- if(indicatorPaths) {
- for (var j = 0; j < indicatorPaths.length; j++) {
- indicatorPath = indicatorPaths[j];
- chartObjectStr = "";
- // if(indicator.type == "chart") {
- chartObjectStr = indicatorPath.chartObject;
- // chartObject = JSON.parse(chartObjectStr);
- if(indicator.type == "chart") {
- numOfCharts++;
- } else {
- numOfNumbers++;
- }
-
- // if(i==0) {
- // if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) {
- // print(chartObject.chartDescription.queries.length);
- // for(var z = 0; z < chartObject.chartDescription.queries.length; z++) {
- // query = chartObject.chartDescription.queries[z].query;
- // print(query.profile);
- // query.profile = "((__statsProfile__))";
- // }
- // }
- // indicatorPath.chartObject = JSON.stringify(chartObject);
-
- if(chartObjectStr != null) {
- var included = chartObjectStr.includes('"profile":"monitor"');
- if (!included) {
- numOfNonMonitorProfiles++;
- print("Indicator with id: " + indicator._id + " has not monitor profile.");
- } else {
- numOfMonitorProfiles++;
- }
-
- splitted = chartObjectStr.split('"profile":"');
- if (splitted.length == 1) {
- numOfNoProfiles++;
- }
- for (var z = 1; z < splitted.length; z = z + 2) {
- prof = splitted[z].split('"')[0];
- differentProfiles.add(prof);
- }
-
- chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"');
- chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"');
- chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"');
- indicatorPath.chartObject = chartObjectStr;
- } else {
- print("Indicator with id: " + indicator._id + " has no chartObject");
- }
- }
- }
-
- // save indicator
- db.indicator.save(indicator);
- }
- print("\n");
- print("numOfNumbers: "+numOfNumbers);
- print("numOfCharts: "+numOfCharts);
- print("numOfMonitorProfiles: "+numOfMonitorProfiles);
- print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles);
- print("numOfNoProfiles: "+numOfNoProfiles);
- print("Different profiles are: ");
- for (var item of differentProfiles) {
- print(item);
- }
-}
-
-function addFundingLevelInFilters(filter) {
- if(filter.groupFilters && filter.groupFilters.length > 0) {
- var index = filter.groupFilters.findIndex(filter => filter.field.includes('project'));
- if(index !== -1) {
- print('before: ' + JSON.stringify(filter));
- var prefix = filter.groupFilters[index].field.substring(0, filter.groupFilters[index].field.indexOf('project'));
- if(!filter.groupFilters.find(filter => filter.field === prefix + "project.funding level 1")) {
- filter.groupFilters.push({
- "field": prefix + "project.funding level 1",
- "type": "contains",
- "values": [
- '((__index_shortName__))'
- ]
- });
- print('after: ' + JSON.stringify(filter));
- } else {
- print('Already added');
- }
- }
- return filter;
- }
-}
-
-function addFundingStreamInDefaultMSCA() {
- print("addFundingStreamInDefaultMSCA")
-
- var stakeholder = db.stakeholder.findOne({"alias": "default-fl1"});
- if(stakeholder) {
- stakeholder.topics.forEach((topic) => {
- var topicObj = db.topic.findOne({"_id": ObjectId(topic)});
- topicObj.categories.forEach((category) => {
- var categoryObj = db.category.findOne({"_id": ObjectId(category)});
- categoryObj.subCategories.forEach((subCategory) => {
- var subCategoryObj = db.subCategory.findOne({"_id": ObjectId(subCategory)});
- subCategoryObj.numbers.forEach((number) => {
- var section = db.section.findOne({"_id": ObjectId(number)});
- section.indicators.forEach((indicator) => {
- var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
- if(indicatorObject.indicatorPaths[0].parameters) {
- indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
- if(indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
- var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
- if(json.series && json.series.length > 0) {
- json.series.forEach(query => {
- if(query.query && query.query.filters && query.query.filters.length > 0) {
- query.query.filters.forEach(filter => {
- filter = addFundingLevelInFilters(filter);
- });
- }
- });
- indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
- db.indicator.save(indicatorObject);
- }
- }
- }
- });
- });
- subCategoryObj.charts.forEach((chart) => {
- var section = db.section.findOne({"_id": ObjectId(chart)});
- section.indicators.forEach((indicator) => {
- var indicatorObject = db.indicator.findOne({"_id": ObjectId(indicator)});
- if(indicatorObject.indicatorPaths[0].parameters) {
- indicatorObject.indicatorPaths[0].parameters['index_shortName'] = stakeholder.index_shortName.toLowerCase();
- if (indicatorObject.indicatorPaths[0] && indicatorObject.indicatorPaths[0].chartObject) {
- var json = JSON.parse(indicatorObject.indicatorPaths[0].chartObject);
- if (json.chartDescription && json.chartDescription.queries && json.chartDescription.queries.length > 0) {
- json.chartDescription.queries.forEach(query => {
- if (query.query && query.query.filters && query.query.filters.length > 0) {
- query.query.filters.forEach(filter => {
- filter = addFundingLevelInFilters(filter);
- });
- }
- });
- indicatorObject.indicatorPaths[0].chartObject = JSON.stringify(json);
- db.indicator.save(indicatorObject);
- }
- }
- }
- });
- });
- });
-
- });
- });
- } else {
- print("Profile doesn't exist")
- }
-
-}
-
-
-use monitordb;
-// use 1_openaire-mongodb-beta; // dev db
-
-// 29-09-2020 - 22-10-2020
-//upperCaseEnumValues();
-// addHeightInIndicators();
-// addVisibility();
-// removeIsActiveAndIsPublic();
-//
-// addAdminToolsCollections();
-// // addPortals();
-//
-// uniqueIndexes();
-
-// 04-06-2021 - 24-06-2021
-// addHomePageInPortalType("funder");
-// addFooterDivIdForPortalType("funder");
-// addFooterHelpTextForPortalType("funder");
-// addHomePageInPortalType("ri");
-// addFooterDivIdForPortalType("ri");
-// addFooterHelpTextForPortalType("ri");
-// addHomePageInPortalType("organization");
-// addFooterDivIdForPortalType("organization");
-// addFooterHelpTextForPortalType("organization");
-
-// 11-04-2023
-statsProfileOfIndicatorsAsVariable();
-// 30-05-2023
-addFundingStreamInDefaultMSCA();
From 76c39d6eb3472a0086057efda05a4da23eeda726 Mon Sep 17 00:00:00 2001
From: "k.triantafyllou"
Date: Wed, 6 Mar 2024 01:27:38 +0200
Subject: [PATCH 02/11] Add monitor deploy service
---
.../controllers/EmailController.java | 17 +++---
.../controllers/MonitorController.java | 6 +-
.../MonitorLibraryCheckDeployController.java | 53 ++---------------
.../MonitorServiceCheckDeployController.java | 41 ++-----------
.../handlers/utils/UserInfo.java | 43 --------------
.../service/MonitorDeployService.java | 59 +++++++++++++++++++
6 files changed, 80 insertions(+), 139 deletions(-)
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/UserInfo.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
index 24dc8c2..d8380ac 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
@@ -17,21 +17,20 @@ import java.util.*;
public class EmailController {
private final Logger log = LogManager.getLogger(this.getClass());
- @Autowired
- private EmailSender emailSender;
+ private final EmailSender emailSender;
+ private final VerifyRecaptcha verifyRecaptcha;
@Autowired
- private VerifyRecaptcha verifyRecaptcha;
+ public EmailController(EmailSender emailSender, VerifyRecaptcha verifyRecaptcha) {
+ this.emailSender = emailSender;
+ this.verifyRecaptcha = verifyRecaptcha;
+ }
@RequestMapping(value = "/contact", method = RequestMethod.POST)
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
verifyRecaptcha.processResponse(form.getRecaptcha());
Email email = form.getEmail();
- ArrayList sendTo = new ArrayList<>();
- for(String userMail: email.getRecipients()){
- sendTo.add(userMail);
- }
- return emailSender.send(sendTo, email.getSubject(), email.getBody(), false);
+ return emailSender.send(email.getRecipients(), email.getSubject(), email.getBody(), false);
}
@RequestMapping(value = "/sendMail", method = RequestMethod.POST)
@@ -40,7 +39,7 @@ public class EmailController {
String successString = "success";
String failureString = "failure";
Map> mailResults = new HashMap<>();
- boolean bcc = (optional.isPresent())?optional.get():true;
+ boolean bcc = optional.orElse(true);
for(String userMail:email.getRecipients()){
ArrayList sendTo = new ArrayList<>();
sendTo.add(userMail);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
index 24587d1..1c959e3 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java
@@ -45,11 +45,7 @@ public class MonitorController {
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deletePortals(@RequestBody List portals) {
- for (String id: portals) {
- String pid = portalService.deletePortal(id);
-// layoutService.deleteByPid(pid);
- }
-
+ portals.forEach(id -> portalService.deletePortal(id));
return true;
}
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
index 802fe33..3fd7065 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java
@@ -1,25 +1,14 @@
package eu.dnetlib.uoamonitorservice.controllers;
-import com.mongodb.BasicDBObject;
-import com.mongodb.CommandResult;
-import com.mongodb.DBObject;
-import eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication;
-import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
-import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
-import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
+import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
-import java.util.HashMap;
import java.util.Map;
@RestController
@@ -28,14 +17,11 @@ import java.util.Map;
public class MonitorLibraryCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
- @Autowired
- private MongoConnection mongoConnection;
+ private final MonitorDeployService service;
- @Autowired
- private MongoConfig mongoConfig;
-
- @Autowired
- private GlobalVars globalVars;
+ public MonitorLibraryCheckDeployController(MonitorDeployService service) {
+ this.service = service;
+ }
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
public String hello() {
@@ -46,33 +32,6 @@ public class MonitorLibraryCheckDeployController {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
public Map checkEverything() {
- Map response = new HashMap<>();
-
- MongoTemplate mt = mongoConnection.getMongoTemplate();
- DBObject ping = new BasicDBObject("ping", "1");
- try {
- CommandResult answer = mt.getDb().command(ping);
- response.put("Mongo try: error", answer.getErrorMessage());
- } catch (Exception e) {
- response.put("Mongo catch: error", e.getMessage());
- }
-
- response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
- response.put("monitorservice.mongodb.host", mongoConfig.getHost());
- response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
- response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
- response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
-
- if(globalVars.date != null) {
- response.put("Date of deploy", globalVars.date.toString());
- }
- if(globalVars.getBuildDate() != null) {
- response.put("Date of build", globalVars.getBuildDate());
- }
- if(globalVars.getVersion() != null) {
- response.put("Version", globalVars.getVersion());
- }
-
- return response;
+ return this.service.checkEverything();
}
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
index 45aecec..ae7fee7 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
@@ -6,6 +6,7 @@ import com.mongodb.DBObject;
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
+import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,14 +25,11 @@ import java.util.Map;
public class MonitorServiceCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
- @Autowired
- private MongoConnection mongoConnection;
+ private final MonitorDeployService service;
- @Autowired
- private MongoConfig mongoConfig;
-
- @Autowired
- private GlobalVars globalVars;
+ public MonitorServiceCheckDeployController(MonitorDeployService service) {
+ this.service = service;
+ }
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
public String hello() {
@@ -42,33 +40,6 @@ public class MonitorServiceCheckDeployController {
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
public Map checkEverything() {
- Map response = new HashMap<>();
-
- MongoTemplate mt = mongoConnection.getMongoTemplate();
- DBObject ping = new BasicDBObject("ping", "1");
- try {
- CommandResult answer = mt.getDb().command(ping);
- response.put("Mongo try: error", answer.getErrorMessage());
- } catch (Exception e) {
- response.put("Mongo catch: error", e.getMessage());
- }
-
- response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
- response.put("monitorservice.mongodb.host", mongoConfig.getHost());
- response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
- response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
- response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
-
- if(globalVars.date != null) {
- response.put("Date of deploy", globalVars.date.toString());
- }
- if(globalVars.getBuildDate() != null) {
- response.put("Date of build", globalVars.getBuildDate());
- }
- if(globalVars.getVersion() != null) {
- response.put("Version", globalVars.getVersion());
- }
-
- return response;
+ return this.service.checkEverything();
}
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/UserInfo.java b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/UserInfo.java
deleted file mode 100644
index 446b49e..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/UserInfo.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package eu.dnetlib.uoamonitorservice.handlers.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class UserInfo {
- String name;
- String email;
- List edu_person_entitlements = new ArrayList();
-
- @Override
- public String toString() {
- return "UserInfo{" +
- "name='" + name + '\'' +
- ", email='" + email + '\'' +
- ", edu_person_entitlements=" + edu_person_entitlements +
- '}';
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public List getEdu_person_entitlements() {
- return edu_person_entitlements;
- }
-
- public void setEdu_person_entitlements(List edu_person_entitlements) {
- this.edu_person_entitlements = edu_person_entitlements;
- }
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java
new file mode 100644
index 0000000..c25daee
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java
@@ -0,0 +1,59 @@
+package eu.dnetlib.uoamonitorservice.service;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.CommandResult;
+import com.mongodb.DBObject;
+import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
+import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
+import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class MonitorDeployService {
+ private final MongoConnection mongoConnection;
+ private final MongoConfig mongoConfig;
+ private final GlobalVars globalVars;
+
+ @Autowired
+ public MonitorDeployService(MongoConnection mongoConnection, MongoConfig mongoConfig, GlobalVars globalVars) {
+ this.mongoConnection = mongoConnection;
+ this.mongoConfig = mongoConfig;
+ this.globalVars = globalVars;
+ }
+
+ public Map checkEverything() {
+ Map response = new HashMap<>();
+
+ MongoTemplate mt = mongoConnection.getMongoTemplate();
+ DBObject ping = new BasicDBObject("ping", "1");
+ try {
+ CommandResult answer = mt.getDb().command(ping);
+ response.put("Mongo try: error", answer.getErrorMessage());
+ } catch (Exception e) {
+ response.put("Mongo catch: error", e.getMessage());
+ }
+
+ response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
+ response.put("monitorservice.mongodb.host", mongoConfig.getHost());
+ response.put("monitorservice.mongodb.port", mongoConfig.getPort() + "");
+ response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
+ response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
+
+ if (globalVars.date != null) {
+ response.put("Date of deploy", globalVars.date.toString());
+ }
+ if (globalVars.getBuildDate() != null) {
+ response.put("Date of build", globalVars.getBuildDate());
+ }
+ if (globalVars.getVersion() != null) {
+ response.put("Version", globalVars.getVersion());
+ }
+
+ return response;
+ }
+}
From 1158b676e41b641c16b894475acac718002d26e7 Mon Sep 17 00:00:00 2001
From: "k.triantafyllou"
Date: Wed, 6 Mar 2024 01:48:31 +0200
Subject: [PATCH 03/11] Revert properties. Remove some comments. Remove mongodb
DAOs. Move primitives classes and enums to new package primitives.
---
.../controllers/CategoryController.java | 170 ++++++-----
.../controllers/EmailController.java | 17 +-
.../controllers/IndicatorController.java | 263 ++++++++----------
.../uoamonitorservice/dao/CategoryDAO.java | 5 +-
.../uoamonitorservice/dao/IndicatorDAO.java | 5 +-
.../dao/MongoDBCategoryDAO.java | 19 --
.../dao/MongoDBIndicatorDAO.java | 18 --
.../dao/MongoDBSectionDAO.java | 17 --
.../dao/MongoDBStakeholderDAO.java | 26 --
.../dao/MongoDBSubCategoryDAO.java | 17 --
.../dao/MongoDBTopicDAO.java | 19 --
.../uoamonitorservice/dao/SectionDAO.java | 5 +-
.../uoamonitorservice/dao/StakeholderDAO.java | 5 +-
.../uoamonitorservice/dao/SubCategoryDAO.java | 5 +-
.../uoamonitorservice/dao/TopicDAO.java | 5 +-
.../uoamonitorservice/entities/Indicator.java | 15 +-
.../uoamonitorservice/entities/Section.java | 12 +-
.../entities/Stakeholder.java | 30 +-
.../uoamonitorservice/primitives/Format.java | 5 +
.../IndicatorPath.java | 16 +-
.../primitives/IndicatorPathType.java | 7 +
.../primitives/IndicatorSize.java | 7 +
.../primitives/IndicatorType.java | 7 +
.../uoamonitorservice/primitives/Locale.java | 11 +
.../ReorderEvent.java | 2 +-
.../primitives/StakeholderType.java | 9 +
src/main/resources/monitorservice.properties | 30 +-
27 files changed, 293 insertions(+), 454 deletions(-)
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBIndicatorDAO.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSectionDAO.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSubCategoryDAO.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/Format.java
rename src/main/java/eu/dnetlib/uoamonitorservice/{entities => primitives}/IndicatorPath.java (88%)
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPathType.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorSize.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorType.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/Locale.java
rename src/main/java/eu/dnetlib/uoamonitorservice/{entities => primitives}/ReorderEvent.java (94%)
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
index e3f6634..ea5110e 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.controllers;
+import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
-import eu.dnetlib.uoamonitorservice.dao.*;
+import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
+import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
+import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
+import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
-import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -45,7 +48,7 @@ public class CategoryController {
List subCategories = new ArrayList<>();
List subCategoriesFull = new ArrayList<>();
- for(SubCategory> subCategory : categoryFull.getSubCategories()) {
+ for (SubCategory> subCategory : categoryFull.getSubCategories()) {
SubCategory> subcategoryFull = subCategoryController.buildSubCategory(subCategory);
subCategoriesFull.add(subcategoryFull);
subCategories.add(subcategoryFull.getId());
@@ -72,28 +75,28 @@ public class CategoryController {
@PathVariable("topicId") String topicId,
@RequestBody Category categoryFull) {
log.debug("save category");
- log.debug("Alias: "+categoryFull.getAlias() + " - Id: "+categoryFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
+ log.debug("Alias: " + categoryFull.getAlias() + " - Id: " + categoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(stakeholder != null) {
- if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
+ if (stakeholder != null) {
+ 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);
+ throw new ForbiddenException("Save Category: You are not authorized to update stakeholder with id: " + stakeholderId);
}
Category oldCategory = null;
- if(categoryFull.getId() != null) {
+ if (categoryFull.getId() != null) {
oldCategory = categoryDAO.findById(categoryFull.getId());
- if(oldCategory == null) {
+ if (oldCategory == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("save category: Category with id: " + categoryFull.getId() + " not found");
}
}
Topic topic = topicDAO.findById(topicId);
- if(topic != null) {
- if(stakeholder.getTopics().contains(topicId)) {
+ if (topic != null) {
+ if (stakeholder.getTopics().contains(topicId)) {
Category category = new Category<>(categoryFull);
Date date = new Date();
@@ -103,7 +106,7 @@ public class CategoryController {
List subCategories = new ArrayList<>();
// if category not exists (no id), create a new default subcategory, identical to category
- if(categoryFull.getId() == null) {
+ if (categoryFull.getId() == null) {
category.setCreationDate(date);
categoryFull.setCreationDate(date);
@@ -115,15 +118,15 @@ public class CategoryController {
List subCategoriesFull = categoryFull.getSubCategories();
subCategoriesFull.add(subCategory);
- for(SubCategory oldSubCategory : subCategoriesFull) {
+ for (SubCategory oldSubCategory : subCategoriesFull) {
subCategories.add(oldSubCategory.getId());
}
} else {
- for(String subCategoryId : oldCategory.getSubCategories()) {
+ for (String subCategoryId : oldCategory.getSubCategories()) {
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) {
// EXCEPTION - SubCategory not found
- throw new EntityNotFoundException("Save category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+category.getId()+")");
+ throw new EntityNotFoundException("Save category: SubCategory with id: " + subCategoryId + " not found (subcategory exists in category: " + category.getId() + ")");
}
subCategories.add(subCategory.getId());
}
@@ -131,8 +134,8 @@ public class CategoryController {
category.setSubCategories(subCategories);
- if(stakeholder.getDefaultId() == null) {
- if(categoryFull.getId() == null) {
+ if (stakeholder.getDefaultId() == null) {
+ if (categoryFull.getId() == null) {
categoryDAO.save(category);
onSaveDefaultCategory(category, topicId);
} else {
@@ -145,27 +148,24 @@ public class CategoryController {
List categories = topic.getCategories();
int index = categories.indexOf(category.getId());
- if(index == -1) {
+ if (index == -1) {
categories.add(category.getId());
topicDAO.save(topic);
log.debug("Category saved!");
categoryFull.setId(category.getId());
}
-
- subCategories = null;
- category = null;
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
- throw new PathNotValidException("Save category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
+ throw new PathNotValidException("Save category: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
} else {
// EXCEPTION - Topic not found
- throw new EntityNotFoundException("Save category: Topic with id: "+topicId+" not found");
+ throw new EntityNotFoundException("Save category: Topic with id: " + topicId + " not found");
}
} else {
// EXCEPTION - Stakeholder not found
- throw new EntityNotFoundException("Save category: Stakeholder with id: "+stakeholderId+" not found");
+ throw new EntityNotFoundException("Save category: Stakeholder with id: " + stakeholderId + " not found");
}
return categoryFull;
}
@@ -174,7 +174,7 @@ public class CategoryController {
log.debug("On save default category");
List topics = topicDAO.findByDefaultId(topicId);
- for(Topic topic : topics) {
+ for (Topic topic : topics) {
Category categoryNew = new Category();
categoryNew.copyFromDefault(category);
@@ -195,28 +195,24 @@ public class CategoryController {
List categories = categoryDAO.findByDefaultId(category.getId());
boolean changed = false;
- for(Category categoryBasedOnDefault : categories) {
- if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
+ for (Category categoryBasedOnDefault : categories) {
+ if (category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
&& (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) {
categoryBasedOnDefault.setName(category.getName());
categoryBasedOnDefault.setAlias(category.getAlias());
changed = true;
}
- if(category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())
+ if (category.getDescription() != null && !category.getDescription().equals(categoryBasedOnDefault.getDescription())
&& (oldCategory.getDescription() == null || oldCategory.getDescription().equals(categoryBasedOnDefault.getDescription()))) {
categoryBasedOnDefault.setDescription(category.getDescription());
changed = true;
}
- if(!changed) {
-// break;
+ if (!changed) {
continue;
}
-
-// categoryBasedOnDefault.setName(category.getName());
-// categoryBasedOnDefault.setDescription(category.getDescription());
categoryBasedOnDefault.setUpdateDate(category.getUpdateDate());
categoryDAO.save(categoryBasedOnDefault);
}
@@ -229,34 +225,34 @@ public class CategoryController {
@PathVariable("categoryId") String categoryId,
@RequestParam(required = false) String children) {
log.debug("delete category");
- log.debug("Id: "+categoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId);
+ log.debug("Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(stakeholder != null) {
- if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
+ if (stakeholder != null) {
+ 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);
+ throw new ForbiddenException("Delete category: You are not authorized to update stakeholder with id: " + stakeholderId);
}
Topic topic = topicDAO.findById(topicId);
- if(topic != null) {
- if(stakeholder.getTopics().contains(topicId)) {
+ if (topic != null) {
+ if (stakeholder.getTopics().contains(topicId)) {
Category category = categoryDAO.findById(categoryId);
- if(category != null) {
+ if (category != null) {
- if(category.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(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);
+ throw new ForbiddenException("Delete category: You are not authorized to delete a default Category in stakeholder with id: " + stakeholderId);
}
List categories = topic.getCategories();
int index = categories.indexOf(categoryId);
- if(index != -1) {
+ if (index != -1) {
// this category belongs in default profile
- if(topic.getDefaultId() == null && children != null) {
+ if (topic.getDefaultId() == null && children != null) {
onDeleteDefaultCategory(categoryId, topicId, children);
}
subCategoryController.deleteTree(category);
@@ -267,42 +263,42 @@ public class CategoryController {
log.debug("Category deleted!");
} else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
- throw new PathNotValidException("Delete category: Category with id: "+categoryId+" not found in Topic: "+topicId);
+ throw new PathNotValidException("Delete category: Category with id: " + categoryId + " not found in Topic: " + topicId);
}
} else {
// EXCEPTION - Category not found
- throw new EntityNotFoundException("Delete category: Category with id: "+categoryId+" not found");
+ throw new EntityNotFoundException("Delete category: Category with id: " + categoryId + " not found");
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
- throw new PathNotValidException("Delete category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
+ throw new PathNotValidException("Delete category: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
} else {
// EXCEPTION - Topic not found
- throw new EntityNotFoundException("Delete category: Topic with id: "+topicId+" not found");
+ throw new EntityNotFoundException("Delete category: Topic with id: " + topicId + " not found");
}
} else {
// EXCEPTION - Stakeholder not found
- throw new EntityNotFoundException("Delete category: Stakeholder with id: "+stakeholderId+" not found");
+ throw new EntityNotFoundException("Delete category: Stakeholder with id: " + stakeholderId + " not found");
}
return true;
}
public boolean onDeleteDefaultCategory(String defaultCategoryId, String defaultTopicId, String children) {
- if(children.equals("delete")) {
+ if (children.equals("delete")) {
List topics = topicDAO.findByDefaultId(defaultTopicId);
List categories = categoryDAO.findByDefaultId(defaultCategoryId);
- for(Topic topic : topics) {
+ for (Topic topic : topics) {
Iterator categoriesIterator = categories.iterator();
- while(categoriesIterator.hasNext()) {
+ while (categoriesIterator.hasNext()) {
Category category = categoriesIterator.next();
String categoryId = category.getId();
- if(topic.getCategories() != null && topic.getCategories().contains(categoryId)) {
+ if (topic.getCategories() != null && topic.getCategories().contains(categoryId)) {
categoriesIterator.remove();
topic.getCategories().remove(categoryId);
@@ -311,21 +307,21 @@ public class CategoryController {
subCategoryController.deleteTree(category);
categoryDAO.delete(categoryId);
- log.debug("Category with id: "+categoryId+" deleted!");
+ log.debug("Category with id: " + categoryId + " deleted!");
break;
}
}
}
- } else if(children.equals("disconnect")) {
+ } else if (children.equals("disconnect")) {
List categories = categoryDAO.findByDefaultId(defaultCategoryId);
- for(Category category : categories) {
+ for (Category category : categories) {
subCategoryController.disConnectTree(category);
category.setDefaultId(null);
categoryDAO.save(category);
- log.debug("DefaultId for Category with id: "+category.getId()+" empty!");
+ log.debug("DefaultId for Category with id: " + category.getId() + " empty!");
}
}
return true;
@@ -334,10 +330,10 @@ public class CategoryController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/reorder", method = RequestMethod.POST)
public List reorderCategories(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @RequestBody List categories) {
+ @PathVariable("topicId") String topicId,
+ @RequestBody List categories) {
log.debug("reorder categories");
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
+ log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Topic topic = checkForExceptions(stakeholderId, topicId);
@@ -350,9 +346,9 @@ public class CategoryController {
topic.setCategories(categories);
List categoriesFull = new ArrayList<>();
- for(String categoryId : categories) {
+ for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId);
- if(category == null) {
+ if (category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Reorder Categories: Category with id: " + categoryId + " not found");
}
@@ -368,18 +364,18 @@ public class CategoryController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
public Category changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
- log.debug("change category visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
+ @PathVariable("topicId") String topicId,
+ @PathVariable("categoryId") String categoryId,
+ @RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
+ log.debug("change category visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
+ log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
- if(!rolesUtils.hasUpdateAuthority(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);
+ throw new ForbiddenException("Toggle category: You are not authorized to update stakeholder with id: " + stakeholderId);
}
Topic topic = topicDAO.findById(topicId);
@@ -389,19 +385,19 @@ public class CategoryController {
return changeVisibilityTree(categoryId, visibility, propagate);
} else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
- throw new PathNotValidException("Toggle category: Category with id: "+categoryId+" not found in Topic: "+topicId);
+ throw new PathNotValidException("Toggle category: Category with id: " + categoryId + " not found in Topic: " + topicId);
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
- throw new PathNotValidException("Toggle category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
+ throw new PathNotValidException("Toggle category: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
} else {
// EXCEPTION - Topic not found
- throw new EntityNotFoundException("Toggle category: Topic with id: "+topicId+" not found");
+ throw new EntityNotFoundException("Toggle category: Topic with id: " + topicId + " not found");
}
} else {
// EXCEPTION - Stakeholder not found
- throw new EntityNotFoundException("Toggle category: Stakeholder with id: "+stakeholderId+" not found");
+ throw new EntityNotFoundException("Toggle category: Stakeholder with id: " + stakeholderId + " not found");
}
}
@@ -409,13 +405,13 @@ public class CategoryController {
Category category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
- throw new EntityNotFoundException("Change category visibility: Category with id: "+categoryId+" not found");
+ throw new EntityNotFoundException("Change category visibility: Category with id: " + categoryId + " not found");
}
Category categoryFull = new Category(category);
List subCategoriesFull = new ArrayList<>();
- if(propagate != null && propagate) {
+ if (propagate != null && propagate) {
for (String subCategoryId : category.getSubCategories()) {
subCategoriesFull.add(subCategoryController.changeVisibilityTree(subCategoryId, visibility, propagate));
}
@@ -436,36 +432,36 @@ public class CategoryController {
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(stakeholder == null) {
+ if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("checkForExceptions category: Stakeholder with id: " + stakeholderId + " not found");
}
- if(!rolesUtils.hasUpdateAuthority(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);
+ throw new ForbiddenException("checkForExceptions category: You are not authorized to update stakeholder with id: " + stakeholderId);
}
Topic topic = topicDAO.findById(topicId);
- if(topic == null) {
+ if (topic == null) {
// EXCEPTION - Topic not found
- throw new EntityNotFoundException("checkForExceptions category: Topic with id: "+topicId+" not found");
+ throw new EntityNotFoundException("checkForExceptions category: Topic with id: " + topicId + " not found");
}
- if(!stakeholder.getTopics().contains(topicId)) {
+ if (!stakeholder.getTopics().contains(topicId)) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
- throw new PathNotValidException("checkForExceptions category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
+ throw new PathNotValidException("checkForExceptions category: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
- return topic;
+ return topic;
}
public void deleteTree(Topic topic) {
List categories = topic.getCategories();
- for(String categoryId : categories) {
+ for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
- throw new EntityNotFoundException("Category delete tree: Category with id: "+categoryId+" not found (category exists in topic: "+topic.getId()+")");
+ throw new EntityNotFoundException("Category delete tree: Category with id: " + categoryId + " not found (category exists in topic: " + topic.getId() + ")");
}
subCategoryController.deleteTree(category);
@@ -476,11 +472,11 @@ public class CategoryController {
public void disConnectTree(Topic topic) {
List categories = topic.getCategories();
- for(String categoryId : categories) {
+ for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId);
if (category == null) {
// EXCEPTION - Category not found
- throw new EntityNotFoundException("Category disconnect tree: Category with id: "+categoryId+" not found (category exists in topic: "+topic.getId()+")");
+ throw new EntityNotFoundException("Category disconnect tree: Category with id: " + categoryId + " not found (category exists in topic: " + topic.getId() + ")");
}
subCategoryController.disConnectTree(category);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
index d8380ac..960fe75 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java
@@ -10,7 +10,10 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
@RestController
@CrossOrigin(origins = "*")
@@ -27,7 +30,7 @@ public class EmailController {
}
@RequestMapping(value = "/contact", method = RequestMethod.POST)
- public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
+ public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
verifyRecaptcha.processResponse(form.getRecaptcha());
Email email = form.getEmail();
return emailSender.send(email.getRecipients(), email.getSubject(), email.getBody(), false);
@@ -40,17 +43,17 @@ public class EmailController {
String failureString = "failure";
Map> mailResults = new HashMap<>();
boolean bcc = optional.orElse(true);
- for(String userMail:email.getRecipients()){
+ for (String userMail : email.getRecipients()) {
ArrayList sendTo = new ArrayList<>();
sendTo.add(userMail);
- boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), bcc);
- if(success){
- if(!mailResults.containsKey(successString)) {
+ boolean success = emailSender.send(sendTo, email.getSubject(), email.getBody(), bcc);
+ if (success) {
+ if (!mailResults.containsKey(successString)) {
mailResults.put(successString, new ArrayList<>());
}
mailResults.get(successString).add(userMail);
} else {
- if(!mailResults.containsKey(failureString)) {
+ if (!mailResults.containsKey(failureString)) {
mailResults.put(failureString, new ArrayList<>());
}
mailResults.get(failureString).add(userMail);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
index f67c5c2..f8746a5 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
@@ -1,12 +1,14 @@
package eu.dnetlib.uoamonitorservice.controllers;
+import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
-import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
+import eu.dnetlib.uoamonitorservice.primitives.IndicatorPath;
+import eu.dnetlib.uoamonitorservice.primitives.ReorderEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,27 +53,25 @@ public class IndicatorController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk", method = RequestMethod.POST)
public Stakeholder saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @PathVariable("subcategoryId") String subcategoryId,
- @RequestBody List> sections) throws UnsupportedEncodingException {
+ @PathVariable("topicId") String topicId,
+ @PathVariable("categoryId") String categoryId,
+ @PathVariable("subcategoryId") String subcategoryId,
+ @RequestBody List> sections) throws UnsupportedEncodingException {
log.debug("save bulk indicators");
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
+ log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
Date date = new Date();
createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId);
-// createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId);
-
return stakeholderController.setFullEntities(stakeholder);
}
private void createSectionsAndSaveBulk(Date date, List> old_sections,
- Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
- for(Section section : old_sections) {
- if(section == null) {
+ Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
+ for (Section section : old_sections) {
+ if (section == null) {
continue;
}
@@ -81,17 +81,17 @@ public class IndicatorController {
List chart_indicators = null;
List number_indicators = null;
- if(section.getType().equals("chart")) {
+ if (section.getType().equals("chart")) {
chart_section = createSection(chart_section, "chart", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
chart_indicators = chart_section.getIndicators();
- } else if(section.getType().equals("number")) {
+ } else if (section.getType().equals("number")) {
number_section = createSection(number_section, "number", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
number_indicators = number_section.getIndicators();
}
List indicators = section.getIndicators();
for (Indicator indicator : indicators) {
- if(indicator == null) {
+ if (indicator == null) {
continue;
}
@@ -126,10 +126,6 @@ public class IndicatorController {
return section;
}
-// 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);
@@ -155,7 +151,7 @@ public class IndicatorController {
@PathVariable("sectionId") String sectionId,
@RequestBody Indicator indicator) throws UnsupportedEncodingException {
log.debug("save indicator");
- log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
+ log.debug("Name: " + indicator.getName() + " - Id: " + indicator.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
Section section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
@@ -163,9 +159,9 @@ public class IndicatorController {
indicator.setUpdateDate(date);
Indicator oldIndicator = null;
- if(indicator.getId() != null) {
+ if (indicator.getId() != null) {
oldIndicator = indicatorDAO.findById(indicator.getId());
- if(oldIndicator == null) {
+ if (oldIndicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("save indicator: Indicator with id: " + indicator.getId() + " not found");
}
@@ -177,12 +173,11 @@ public class IndicatorController {
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
// this indicator belongs in default profile and it is new or it is updated
- if(stakeholder.getDefaultId() == null) {
- if(indicatorId == null) {
+ if (stakeholder.getDefaultId() == null) {
+ if (indicatorId == null) {
indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, section, subcategoryId);
- }
- else {
+ } else {
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
indicatorDAO.save(indicator);
}
@@ -210,7 +205,7 @@ public class IndicatorController {
for (SubCategory subCategory : subCategories) {
List sections = null;
- if(defaultSection.getType().equals("chart")) {
+ if (defaultSection.getType().equals("chart")) {
sections = subCategory.getCharts();
} else {
sections = subCategory.getNumbers();
@@ -218,7 +213,7 @@ public class IndicatorController {
for (String sectionId : sections) {
Section section = sectionDAO.findById(sectionId);
- if(section.getDefaultId() != null && section.getDefaultId().equals(defaultSection.getId())) {
+ if (section.getDefaultId() != null && section.getDefaultId().equals(defaultSection.getId())) {
Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator, subCategory.getVisibility());
indicatorDAO.save(indicatorNew);
@@ -238,12 +233,9 @@ public class IndicatorController {
boolean changed;
List indicators = indicatorDAO.findByDefaultId(indicator.getId());
- for(Indicator indicatorBasedOnDefault : indicators) {
+ for (Indicator indicatorBasedOnDefault : indicators) {
changed = false;
-
-// if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
-// && (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
- if((
+ if ((
(indicator.getName() == null && oldIndicator.getName() != null)
||
(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName()))
@@ -256,16 +248,13 @@ public class IndicatorController {
changed = true;
}
- if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
- || indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) {
+ if (indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
+ || indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) {
indicatorBasedOnDefault.setDescription(indicator.getDescription());
changed = true;
}
-
-// if(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription())
-// && (oldIndicator.getAdditionalDescription() == null || oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))) {
- if((
+ if ((
(indicator.getAdditionalDescription() == null && oldIndicator.getAdditionalDescription() != null)
||
(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
@@ -280,17 +269,17 @@ public class IndicatorController {
int i = 0;
List indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
- if(indicatorPaths == null && indicator.getIndicatorPaths() != null) {
+ if (indicatorPaths == null && indicator.getIndicatorPaths() != null) {
indicatorPaths = new ArrayList<>();
}
for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
IndicatorPath indicatorPathBasedOnDefault = null;
- if(i < indicatorPaths.size()) {
+ if (i < indicatorPaths.size()) {
indicatorPathBasedOnDefault = indicatorPaths.get(i);
}
- if(indicatorPathBasedOnDefault == null) {
+ if (indicatorPathBasedOnDefault == null) {
// Add new indicator path in existing indicators
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
indicatorPaths.add(indicatorPathNew);
@@ -299,12 +288,8 @@ public class IndicatorController {
IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i);
// Check if there are changes in indicator path and update existing indicators if needed
- log.debug("update indicator path: "+i + " (indicator id: "+indicatorBasedOnDefault.getId()+")");
-
-// if(indicatorPath.getType() != null
-// && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
-// && (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
- if((
+ log.debug("update indicator path: " + i + " (indicator id: " + indicatorBasedOnDefault.getId() + ")");
+ if ((
(indicatorPath.getType() == null && oldIndicatorPath.getType() != null)
||
(indicatorPath.getType() != null && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
@@ -316,9 +301,9 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
changed = true; // parameter "type" needs to be changed as well
}
- log.debug("After type check: "+changed);
+ log.debug("After type check: " + changed);
- if((
+ if ((
(indicatorPath.getFormat() == null && oldIndicatorPath.getFormat() != null)
||
(indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
@@ -330,12 +315,8 @@ public class IndicatorController {
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()))) {
- if((
+ log.debug("After type check: " + changed);
+ if ((
(indicatorPath.getSource() == null && oldIndicatorPath.getSource() != null)
||
(indicatorPath.getSource() != null && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
@@ -347,12 +328,8 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
changed = true;
}
- log.debug("After source check: "+changed);
-
-// if(indicatorPath.getUrl() != null
-// && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
-// && (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
- if((
+ log.debug("After source check: " + changed);
+ if ((
(indicatorPath.getUrl() == null && oldIndicatorPath.getUrl() != null)
||
(indicatorPath.getUrl() != null && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
@@ -364,37 +341,35 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
changed = true;
}
- log.debug("After url check: "+changed);
+ log.debug("After url check: " + changed);
- if((
+ if ((
(indicatorPath.getChartObject() == null && oldIndicatorPath.getChartObject() != null)
- ||
- (indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
- ) && (
+ ||
+ (indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
+ ) && (
(oldIndicatorPath.getChartObject() == null && indicatorPathBasedOnDefault.getChartObject() == null)
- ||
- (oldIndicatorPath.getChartObject() != null && oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
+ ||
+ (oldIndicatorPath.getChartObject() != null && oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
)) {
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
changed = true;
}
- log.debug("After chartObject check: "+changed);
+ log.debug("After chartObject check: " + changed);
- if(indicatorPath.getParameters() != null) {
+ if (indicatorPath.getParameters() != null) {
if (indicatorPathBasedOnDefault.getParameters() == null) {
indicatorPathBasedOnDefault.setParameters(new HashMap<>());
}
- //if (indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
- //log.debug("Different number of parameters");
for (Map.Entry parameter : indicatorPath.getParameters().entrySet()) {
- log.debug("\nindicatorPath: parameter.getKey(): "+parameter.getKey()+" - value: "+parameter.getValue()
- +"\nindicatorPathBasedOnDefault:parameters:key: "+ indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
- +"\noldIndicatorPath:parameters:key: "+ (oldIndicatorPath.getParameters() == null ? "null" : oldIndicatorPath.getParameters().get(parameter.getKey())));
+ log.debug("\nindicatorPath: parameter.getKey(): " + parameter.getKey() + " - value: " + parameter.getValue()
+ + "\nindicatorPathBasedOnDefault:parameters:key: " + indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
+ + "\noldIndicatorPath:parameters:key: " + (oldIndicatorPath.getParameters() == null ? "null" : oldIndicatorPath.getParameters().get(parameter.getKey())));
if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())
|| (oldIndicatorPath.getParameters() == null || oldIndicatorPath.getParameters().get(parameter.getKey()) == null
- || (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
- && !parameter.getValue().equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))))
+ || (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
+ && !parameter.getValue().equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))))
) {
indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
changed = true;
@@ -402,9 +377,9 @@ public class IndicatorController {
}
// When deleting indicator path parameters in a default profile, delete them also from all children profiles
- if(oldIndicatorPath.getParameters() != null && indicatorPath.getParameters().size() < oldIndicatorPath.getParameters().size()) {
+ if (oldIndicatorPath.getParameters() != null && indicatorPath.getParameters().size() < oldIndicatorPath.getParameters().size()) {
for (Map.Entry parameter : oldIndicatorPath.getParameters().entrySet()) {
- if(!indicatorPath.getParameters().containsKey(parameter.getKey())) {
+ if (!indicatorPath.getParameters().containsKey(parameter.getKey())) {
indicatorPathBasedOnDefault.getParameters().remove(parameter.getKey());
}
}
@@ -412,21 +387,21 @@ public class IndicatorController {
}
log.debug("After parameters check: " + changed);
- if(indicatorPath.getJsonPath() != null) {
+ if (indicatorPath.getJsonPath() != null) {
boolean jsonPathChanged = false;
boolean breaked = false;
int oldJsonPathSize = 0;
- if(oldIndicatorPath.getJsonPath() != null) {
+ if (oldIndicatorPath.getJsonPath() != null) {
oldJsonPathSize = oldIndicatorPath.getJsonPath().size();
}
int basedOnDefaultJsonPathSize = 0;
- if(indicatorPathBasedOnDefault.getJsonPath() != null) {
+ if (indicatorPathBasedOnDefault.getJsonPath() != null) {
basedOnDefaultJsonPathSize = indicatorPathBasedOnDefault.getJsonPath().size();
}
- log.debug("old: "+oldJsonPathSize+" - based on default: "+basedOnDefaultJsonPathSize+" - new: "+indicatorPath.getJsonPath().size());
- if(oldJsonPathSize == basedOnDefaultJsonPathSize) {
- if(indicatorPathBasedOnDefault.getJsonPath() == null && indicatorPath.getJsonPath().size() > 0) {
+ log.debug("old: " + oldJsonPathSize + " - based on default: " + basedOnDefaultJsonPathSize + " - new: " + indicatorPath.getJsonPath().size());
+ if (oldJsonPathSize == basedOnDefaultJsonPathSize) {
+ if (indicatorPathBasedOnDefault.getJsonPath() == null && indicatorPath.getJsonPath().size() > 0) {
indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>());
}
@@ -436,12 +411,12 @@ public class IndicatorController {
Iterator jsonStringBasedOnDefaultIterator = indicatorPathBasedOnDefault.getJsonPath().iterator();
while (jsonStringBasedOnDefaultIterator.hasNext()) {
String jsonStringBasedOnDefault = jsonStringBasedOnDefaultIterator.next();
- if(oldIndicatorPath.getJsonPath().get(oldIndex).equals(jsonStringBasedOnDefault)) {
- if(basedOnDefaultIndex >= indicatorPath.getJsonPath().size()) { // string deleted
+ if (oldIndicatorPath.getJsonPath().get(oldIndex).equals(jsonStringBasedOnDefault)) {
+ if (basedOnDefaultIndex >= indicatorPath.getJsonPath().size()) { // string deleted
jsonStringBasedOnDefaultIterator.remove();
jsonPathChanged = true;
} else { // check if string changed
- if(!indicatorPath.getJsonPath().get(basedOnDefaultIndex).equals(jsonStringBasedOnDefault)) {
+ if (!indicatorPath.getJsonPath().get(basedOnDefaultIndex).equals(jsonStringBasedOnDefault)) {
indicatorPathBasedOnDefault.getJsonPath().set(basedOnDefaultIndex, indicatorPath.getJsonPath().get(basedOnDefaultIndex));
jsonPathChanged = true;
}
@@ -451,20 +426,20 @@ public class IndicatorController {
} else {
breaked = true;
jsonPathChanged = false;
- log.debug("not the same: "+oldIndex);
+ log.debug("not the same: " + oldIndex);
break;
}
}
- int index=0;
- if(!breaked && indicatorPath.getJsonPath().size() > indicatorPathBasedOnDefault.getJsonPath().size()) { // strings added
+ int index = 0;
+ if (!breaked && indicatorPath.getJsonPath().size() > indicatorPathBasedOnDefault.getJsonPath().size()) { // strings added
jsonPathChanged = true;
- for(index=indicatorPathBasedOnDefault.getJsonPath().size(); index < indicatorPath.getJsonPath().size(); index++) {
+ for (index = indicatorPathBasedOnDefault.getJsonPath().size(); index < indicatorPath.getJsonPath().size(); index++) {
indicatorPathBasedOnDefault.getJsonPath().add(indicatorPath.getJsonPath().get(index));
}
}
- if(jsonPathChanged) {
+ if (jsonPathChanged) {
changed = true;
}
}
@@ -476,7 +451,7 @@ public class IndicatorController {
}
// TODO when deleting indicator paths...
- if(!changed) {
+ if (!changed) {
// break;
continue;
}
@@ -496,16 +471,16 @@ public class IndicatorController {
@PathVariable("indicatorId") String indicatorId,
@RequestParam(required = false) String children) {
log.debug("delete indicator");
- log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
+ log.debug("Id: " + indicatorId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
Indicator indicator = indicatorDAO.findById(indicatorId);
- if(indicator != null) {
+ if (indicator != null) {
Section section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(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);
+ throw new ForbiddenException("Delete indicator: You are not authorized to delete a default Indicator in stakeholder with id: " + stakeholderId);
}
List indicators = section.getIndicators();
@@ -514,7 +489,7 @@ public class IndicatorController {
if (index != -1) {
// this indicator belongs in default profile
- if(section.getDefaultId() == null && children != null) {
+ if (section.getDefaultId() == null && children != null) {
onDeleteDefaultIndicator(indicatorId, sectionId, children);
}
@@ -526,44 +501,44 @@ public class IndicatorController {
log.debug("Indicator deleted!");
} else {
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
- throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in Sectiom: "+sectionId);
+ throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Sectiom: " + sectionId);
}
} else {
// EXCEPTION - Indicator not found
- throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found");
+ throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found");
}
return true;
}
public boolean onDeleteDefaultIndicator(String defaultIndicatorId, String defaultSectionId, String children) {
- if(children.equals("delete")) {
+ if (children.equals("delete")) {
// 2nd way
List sections = sectionDAO.findByDefaultId(defaultSectionId);
List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
- for(Section section : sections) {
+ for (Section section : sections) {
Iterator indicatorsIterator = indicators.iterator();
- while(indicatorsIterator.hasNext()) {
+ while (indicatorsIterator.hasNext()) {
String indicatorId = indicatorsIterator.next().getId();
- if(section.getIndicators().contains(indicatorId)) {
+ if (section.getIndicators().contains(indicatorId)) {
indicatorsIterator.remove();
section.getIndicators().remove(indicatorId);
sectionDAO.save(section);
indicatorDAO.delete(indicatorId);
- log.debug("Indicator with id: "+indicatorId+" deleted!");
+ log.debug("Indicator with id: " + indicatorId + " deleted!");
break;
}
}
}
- } else if(children.equals("disconnect")) {
+ } else if (children.equals("disconnect")) {
List indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
- for(Indicator indicator : indicators) {
+ for (Indicator indicator : indicators) {
indicator.setDefaultId(null);
indicatorDAO.save(indicator);
- log.debug("DefaultId for Indicator with id: "+indicator.getId()+" empty!");
+ log.debug("DefaultId for Indicator with id: " + indicator.getId() + " empty!");
}
}
return true;
@@ -578,8 +553,8 @@ public class IndicatorController {
@PathVariable("sectionId") String sectionId,
@PathVariable("type") String type,
@RequestBody ReorderEvent reorderEvent) {
- log.debug("reorder indicators of type: "+type);
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
+ log.debug("reorder indicators of type: " + type);
+ log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
List indicators = reorderEvent.getIds();
String actionType = reorderEvent.getAction();
@@ -596,9 +571,9 @@ public class IndicatorController {
section.setIndicators(indicators);
List indicatorsFull = new ArrayList<>();
- for(String indicatorId : indicators) {
+ for (String indicatorId : indicators) {
Indicator indicator = indicatorDAO.findById(indicatorId);
- if(indicator == null) {
+ if (indicator == null) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException("Reorder indicators: Indicator with id: " + indicatorId + " not found");
}
@@ -614,14 +589,14 @@ public class IndicatorController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @PathVariable("subcategoryId") String subcategoryId,
- @PathVariable("sectionId") String sectionId,
- @PathVariable("indicatorId") String indicatorId,
- @RequestParam("visibility") Visibility visibility) {
- log.debug("change indicator visibility: "+visibility);
- log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
+ @PathVariable("topicId") String topicId,
+ @PathVariable("categoryId") String categoryId,
+ @PathVariable("subcategoryId") String subcategoryId,
+ @PathVariable("sectionId") String sectionId,
+ @PathVariable("indicatorId") String indicatorId,
+ @RequestParam("visibility") Visibility visibility) {
+ log.debug("change indicator visibility: " + visibility);
+ log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId + " - Indicator: " + indicatorId);
Indicator indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) {
@@ -632,16 +607,16 @@ public class IndicatorController {
Section section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
List indicators = section.getIndicators();
- if(indicators.contains(indicatorId)) {
+ if (indicators.contains(indicatorId)) {
return changeVisibilityTree(indicatorId, indicator, visibility);
} else {
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle();
- throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicatorId+" not found in Section: "+sectionId);
+ throw new PathNotValidException("Toggle indicators: Indicator with id: " + indicatorId + " not found in Section: " + sectionId);
}
}
public Indicator changeVisibilityTree(String indicatorId, Indicator indicator, Visibility visibility) {
- if(indicator == null) {
+ if (indicator == null) {
indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) {
// EXCEPTION - Indicator not found
@@ -660,79 +635,79 @@ public class IndicatorController {
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
- if(stakeholder == null) {
+ if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found");
}
- if(!rolesUtils.hasUpdateAuthority(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);
+ throw new ForbiddenException("CheckForExceptions Indicator: You are not authorized to update stakeholder with id: " + stakeholderId);
}
Topic topic = topicDAO.findById(topicId);
- if(topic == null) {
+ if (topic == null) {
// EXCEPTION - Topic not found
- throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found");
+ throw new EntityNotFoundException("Save indicator: Topic with id: " + topicId + " not found");
}
- if(!stakeholder.getTopics().contains(topicId)) {
+ if (!stakeholder.getTopics().contains(topicId)) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
}
Category category = categoryDAO.findById(categoryId);
- if(category == null) {
+ if (category == null) {
// EXCEPTION - Category not found
- throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found");
+ throw new EntityNotFoundException("Save indicator: Category with id: " + categoryId + " not found");
}
- if(!topic.getCategories().contains(categoryId)) {
+ if (!topic.getCategories().contains(categoryId)) {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
- throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId);
+ throw new PathNotValidException("Save indicator: Category with id: " + categoryId + " not found in Topic: " + topicId);
}
SubCategory subcategory = subCategoryDAO.findById(subcategoryId);
- if(subcategory == null) {
+ if (subcategory == null) {
// EXCEPTION - SubCategory not found
- throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found");
+ throw new EntityNotFoundException("Save indicator: SubCategory with id: " + subcategoryId + " not found");
}
if (!category.getSubCategories().contains(subcategoryId)) {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
- throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
+ throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
}
Section section = sectionDAO.findById(sectionId);
- if(section == null) {
+ if (section == null) {
// EXCEPTION - Section not found
- throw new EntityNotFoundException("Save indicator: Section with id: "+sectionId+" not found");
+ throw new EntityNotFoundException("Save indicator: Section with id: " + sectionId + " not found");
}
- if(indicatorType.equals("chart")) {
+ if (indicatorType.equals("chart")) {
if (!subcategory.getCharts().contains(sectionId)) {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
}
- } else if(indicatorType.equals("number")) {
+ } else if (indicatorType.equals("number")) {
if (!subcategory.getNumbers().contains(sectionId)) {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
}
}
- return section;
+ return section;
}
public void deleteTree(Section section) {
List indicators = section.getIndicators();
- for(String indicatorId : indicators) {
+ for (String indicatorId : indicators) {
indicatorDAO.delete(indicatorId);
}
}
public void disConnectTree(Section section) {
List indicators = section.getIndicators();
- for(String indicatorId : indicators) {
+ for (String indicatorId : indicators) {
Indicator indicator = indicatorDAO.findById(indicatorId);
indicator.setDefaultId(null);
indicatorDAO.save(indicator);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java
index fed3a16..b8d4db0 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Category;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface CategoryDAO {
+@Repository
+public interface CategoryDAO extends MongoRepository {
List findAll();
List findByDefaultId(String DefaultId);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java
index 0ac32bd..8940da8 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface IndicatorDAO {
+@Repository
+public interface IndicatorDAO extends MongoRepository {
List findAll();
List findByDefaultId(String DefaultId);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java
deleted file mode 100644
index fc71604..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBCategoryDAO.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.Category;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBCategoryDAO extends CategoryDAO, MongoRepository {
- List findAll();
- List findByDefaultId(String DefaultId);
-
- Category findBySubCategoriesContaining(String subCategory);
-
- Category findById(String Id);
-
- void delete(String Id);
-
- Category save(Category category);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBIndicatorDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBIndicatorDAO.java
deleted file mode 100644
index f35ee01..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBIndicatorDAO.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.Indicator;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBIndicatorDAO extends IndicatorDAO, MongoRepository {
- List findAll();
- List findByDefaultId(String DefaultId);
-
- Indicator findById(String Id);
-
- void delete(String Id);
-
- Indicator save(Indicator indicator);
- //List saveAll(List indicators);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSectionDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSectionDAO.java
deleted file mode 100644
index 51eeb6c..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSectionDAO.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.Section;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBSectionDAO extends SectionDAO, MongoRepository {
- List findAll();
- List findByDefaultId(String DefaultId);
-
- Section findById(String Id);
-
- void delete(String Id);
-
- Section save(Section indicator);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java
deleted file mode 100644
index 0258a37..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBStakeholderDAO.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBStakeholderDAO extends StakeholderDAO, MongoRepository {
- List findAll();
- List findByType(String Type);
-
- List findByDefaultId(String DefaultId);
- List findByDefaultIdAndType(String DefaultId, String Type);
-
- List findByDefaultIdNot(String DefaultId);
- List findByDefaultIdNotAndType(String DefaultId, String Type);
-
- Stakeholder findByTopicsContaining(String topic);
-
- Stakeholder findById(String Id);
- Stakeholder findByAlias(String Alias);
-
- void delete(String Id);
-
- Stakeholder save(Stakeholder stakeholder);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSubCategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSubCategoryDAO.java
deleted file mode 100644
index 375085e..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSubCategoryDAO.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.SubCategory;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBSubCategoryDAO extends SubCategoryDAO, MongoRepository {
- List findAll();
- List findByDefaultId(String DefaultId);
-
- SubCategory findById(String Id);
-
- void delete(String Id);
-
- SubCategory save(SubCategory subCategory);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java
deleted file mode 100644
index 1f7e967..0000000
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBTopicDAO.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package eu.dnetlib.uoamonitorservice.dao;
-
-import eu.dnetlib.uoamonitorservice.entities.Topic;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.List;
-
-public interface MongoDBTopicDAO extends TopicDAO, MongoRepository {
- List findAll();
- List findByDefaultId(String DefaultId);
-
- Topic findByCategoriesContaining(String category);
-
- Topic findById(String Id);
-
- void delete(String Id);
-
- Topic save(Topic topic);
-}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java
index 7a75e99..cd24e5a 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Section;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface SectionDAO {
+@Repository
+public interface SectionDAO extends MongoRepository {
List findAll();
List findByDefaultId(String DefaultId);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java
index d5daaad..113c105 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface StakeholderDAO {
+@Repository
+public interface StakeholderDAO extends MongoRepository {
List findAll();
List findByType(String Type);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java
index 8a9f406..2e22285 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.SubCategory;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface SubCategoryDAO {
+@Repository
+public interface SubCategoryDAO extends MongoRepository {
List findAll();
List findByDefaultId(String DefaultId);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java
index b57f8ce..f6a36fc 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java
@@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Topic;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
import java.util.List;
-public interface TopicDAO {
+@Repository
+public interface TopicDAO extends MongoRepository {
List findAll();
List findByDefaultId(String DefaultId);
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java
index ca6947c..a4aa824 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java
@@ -1,23 +1,14 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
+import eu.dnetlib.uoamonitorservice.primitives.IndicatorPath;
+import eu.dnetlib.uoamonitorservice.primitives.IndicatorSize;
+import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import org.springframework.data.annotation.Id;
import java.util.Date;
import java.util.List;
-enum IndicatorType {
- // Do not rename or remove existring values. This may cause problems with already stored values in DB
- number, chart,
- NUMBER, CHART;
-}
-
-enum IndicatorSize {
- // Do not rename or remove existring values. This may cause problems with already stored values in DB
- small, medium, large,
- SMALL, MEDIUM, LARGE;
-}
-
public class Indicator {
@Id
@JsonProperty("_id")
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java
index 1f0f064..c0664af 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java
@@ -1,18 +1,13 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
+import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import org.springframework.data.annotation.Id;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-enum SectionType {
- // Do not rename or remove existring values. This may cause problems with already stored values in DB
- number, chart,
- NUMBER, CHART;
-}
-
public class Section {
@Id
@JsonProperty("_id")
@@ -21,7 +16,7 @@ public class Section {
private String title;
private String defaultId;
private String stakeholderAlias;
- private SectionType type;
+ private IndicatorType type;
private Date creationDate;
private Date updateDate;
private List indicators;
@@ -90,8 +85,7 @@ public class Section {
if(type == null) {
this.type = null;
} else {
- SectionType sectionType = SectionType.valueOf(type);
- this.type = sectionType;
+ this.type = IndicatorType.valueOf(type);
}
}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java
index 089e459..4d72840 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java
@@ -1,32 +1,14 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
+import eu.dnetlib.uoamonitorservice.primitives.Locale;
+import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import org.springframework.data.annotation.Id;
import java.util.Date;
import java.util.List;
-enum StakeholderType
-{
- // Do not rename or remove existing values. This may cause problems with already stored values in DB
- funder, ri, project, organization,
- country, researcher, datasource,
- FUNDER, RI, PROJECT, ORGANIZATION,
- COUNTRY, RESEARCHER, DATASOURCE;
-}
-
-enum Locale {
- EN("en"), EU("eu");
-
- public final String label;
-
- Locale(String label) {
- this.label = label;
- }
-}
-
-
public class Stakeholder {
@Id
@JsonProperty("_id")
@@ -84,14 +66,6 @@ public class Stakeholder {
this.id = id;
}
-// public StakeholderType getType() {
-// return type;
-// }
-//
-// public void setType(StakeholderType type) {
-// this.type = type;
-// }
-
public String getType() {
if(type == null) {
return null;
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Format.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Format.java
new file mode 100644
index 0000000..7e2a0f1
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Format.java
@@ -0,0 +1,5 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum Format {
+ NUMBER, PERCENTAGE
+}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPath.java
similarity index 88%
rename from src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java
rename to src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPath.java
index 63bc04a..60ed5f4 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPath.java
@@ -1,22 +1,8 @@
-package eu.dnetlib.uoamonitorservice.entities;
+package eu.dnetlib.uoamonitorservice.primitives;
import java.util.List;
import java.util.Map;
-enum IndicatorPathType {
- // Do not rename or remove existring values. This may cause problems with already stored values in DB
- table, bar, column, pie, line, other,
- TABLE, BAR, COLUMN, PIE, LINE, OTHER;
-}
-
-//enum SourceType {
-// 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
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPathType.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPathType.java
new file mode 100644
index 0000000..72ef0ba
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorPathType.java
@@ -0,0 +1,7 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum IndicatorPathType {
+ // Do not rename or remove existing values. This may cause problems with already stored values in DB
+ table, bar, column, pie, line, other,
+ TABLE, BAR, COLUMN, PIE, LINE, OTHER;
+}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorSize.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorSize.java
new file mode 100644
index 0000000..3228307
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorSize.java
@@ -0,0 +1,7 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum IndicatorSize {
+ // Do not rename or remove existring values. This may cause problems with already stored values in DB
+ small, medium, large,
+ SMALL, MEDIUM, LARGE;
+}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorType.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorType.java
new file mode 100644
index 0000000..1e5019f
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/IndicatorType.java
@@ -0,0 +1,7 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum IndicatorType {
+ // Do not rename or remove existing values. This may cause problems with already stored values in DB
+ number, chart,
+ NUMBER, CHART;
+}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Locale.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Locale.java
new file mode 100644
index 0000000..49adf2b
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Locale.java
@@ -0,0 +1,11 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum Locale {
+ EN("en"), EU("eu");
+
+ public final String label;
+
+ Locale(String label) {
+ this.label = label;
+ }
+}
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/ReorderEvent.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/ReorderEvent.java
similarity index 94%
rename from src/main/java/eu/dnetlib/uoamonitorservice/entities/ReorderEvent.java
rename to src/main/java/eu/dnetlib/uoamonitorservice/primitives/ReorderEvent.java
index 9818c8f..caba8e8 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/ReorderEvent.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/ReorderEvent.java
@@ -1,4 +1,4 @@
-package eu.dnetlib.uoamonitorservice.entities;
+package eu.dnetlib.uoamonitorservice.primitives;
import java.util.List;
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java
new file mode 100644
index 0000000..8e58b2b
--- /dev/null
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java
@@ -0,0 +1,9 @@
+package eu.dnetlib.uoamonitorservice.primitives;
+
+public enum StakeholderType {
+ // Do not rename or remove existing values. This may cause problems with already stored values in DB
+ funder, ri, project, organization,
+ country, researcher, datasource,
+ FUNDER, RI, PROJECT, ORGANIZATION,
+ COUNTRY, RESEARCHER, DATASOURCE;
+}
diff --git a/src/main/resources/monitorservice.properties b/src/main/resources/monitorservice.properties
index 82627cb..86a31d4 100644
--- a/src/main/resources/monitorservice.properties
+++ b/src/main/resources/monitorservice.properties
@@ -24,32 +24,4 @@ monitorservice.globalVars.version=@version@
#production
#monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
-#monitorservice.originServer = .openaire.eu
-
-# Monitor
-monitorservice.mongodb.host=localhost
-monitorservice.mongodb.port=27017
-monitorservice.mongodb.database=production
-
-# Notification
-notification.mongodb.host = localhost
-notification.mongodb.port = 27017
-notification.mongodb.database = openaire_notification
-
-# Admin Tools Library
-admintoolslibrary.mail.from = openaire.test@gmail.com
-admintoolslibrary.mail.username = openaire.test@gmail.com
-admintoolslibrary.mail.password = koujreltgjduicjp
-admintoolslibrary.mail.host = smtp.gmail.com
-admintoolslibrary.mail.port = 587
-admintoolslibrary.mail.auth = true
-admintoolslibrary.mail.sslProtocols = TLSv1.2
-admintoolslibrary.mail.defaultEncoding=UTF-8
-admintoolslibrary.mail.protocol=smtp
-admintoolslibrary.mail.testConnection=false
-admintoolslibrary.google.secret = 6LcVtFIUAAAAAIlEaz6Am2PBC3j5lHG7vBo6uW4_
-
-# Authorization
-authorization.security.userInfoUrl = http://mpagasas.di.uoa.gr:19080/login-service/userInfo
-
-server.port=8888
\ No newline at end of file
+#monitorservice.originServer = .openaire.eu
\ No newline at end of file
From e345f5b689f02e8655b1abbf1092b34cf98f890a Mon Sep 17 00:00:00 2001
From: "k.triantafyllou"
Date: Fri, 8 Mar 2024 20:55:51 +0200
Subject: [PATCH 04/11] [new-model | WIP]: Refactoring the code in order to
improve performance and code.
---
.../controllers/CategoryController.java | 11 +-
.../controllers/IndicatorController.java | 11 +-
.../controllers/SectionController.java | 108 +-----
.../controllers/StakeholderController.java | 359 ++++--------------
.../controllers/SubCategoryController.java | 17 +-
.../controllers/TopicController.java | 21 +-
.../uoamonitorservice/dao/CategoryDAO.java | 5 +-
.../uoamonitorservice/dao/IndicatorDAO.java | 3 +-
.../uoamonitorservice/dao/SectionDAO.java | 3 +-
.../uoamonitorservice/dao/StakeholderDAO.java | 7 +-
.../uoamonitorservice/dao/SubCategoryDAO.java | 3 +-
.../uoamonitorservice/dao/TopicDAO.java | 5 +-
.../uoamonitorservice/dto/CategoryFull.java | 18 +
.../uoamonitorservice/dto/SectionFull.java | 19 +
.../dto/StakeholderFull.java | 15 +
.../dto/SubCategoryFull.java | 18 +
.../uoamonitorservice/dto/TopicFull.java | 18 +
.../uoamonitorservice/entities/Category.java | 127 +------
.../uoamonitorservice/entities/Indicator.java | 43 +--
.../uoamonitorservice/entities/Section.java | 118 +-----
.../entities/Stakeholder.java | 222 +----------
.../entities/SubCategory.java | 137 +------
.../uoamonitorservice/entities/Topic.java | 130 +------
.../entities/Visibility.java | 38 --
.../generics/CategoryGeneric.java | 88 +++++
.../uoamonitorservice/generics/Common.java | 42 ++
.../generics/SectionGeneric.java | 119 ++++++
.../generics/StakeholderGeneric.java | 193 ++++++++++
.../generics/SubCategoryGeneric.java | 107 ++++++
.../generics/TopicGeneric.java | 100 +++++
.../primitives/Visibility.java | 5 +
.../service/CategoryService.java | 52 +++
.../service/CommonService.java | 37 ++
.../service/IndicatorService.java | 38 ++
.../service/SectionService.java | 71 ++++
.../service/StakeholderService.java | 59 ++-
.../service/SubCategoryService.java | 55 +++
.../service/TopicService.java | 53 +++
38 files changed, 1286 insertions(+), 1189 deletions(-)
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/CategoryFull.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/SectionFull.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/StakeholderFull.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/SubCategoryFull.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/TopicFull.java
delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/entities/Visibility.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/CategoryGeneric.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/Common.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/SectionGeneric.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/StakeholderGeneric.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/SubCategoryGeneric.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/generics/TopicGeneric.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/Visibility.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/CommonService.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/IndicatorService.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java
create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
index ea5110e..cc91eab 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java
@@ -1,3 +1,4 @@
+/*
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
@@ -9,6 +10,7 @@ import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
+import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -77,7 +79,7 @@ public class CategoryController {
log.debug("save category");
log.debug("Alias: " + categoryFull.getAlias() + " - Id: " + categoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@@ -227,7 +229,7 @@ public class CategoryController {
log.debug("delete category");
log.debug("Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@@ -370,7 +372,7 @@ public class CategoryController {
log.debug("change category visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@@ -430,7 +432,7 @@ public class CategoryController {
private Topic checkForExceptions(String stakeholderId, String topicId) {
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
@@ -486,3 +488,4 @@ public class CategoryController {
}
}
}
+*/
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
index f8746a5..d1fc52b 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
@@ -1,3 +1,4 @@
+/*
package eu.dnetlib.uoamonitorservice.controllers;
@@ -9,6 +10,7 @@ import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorPath;
import eu.dnetlib.uoamonitorservice.primitives.ReorderEvent;
+import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -60,7 +62,7 @@ public class IndicatorController {
log.debug("save bulk indicators");
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
Date date = new Date();
@@ -171,7 +173,7 @@ public class IndicatorController {
String indicatorId = indicator.getId();
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
// this indicator belongs in default profile and it is new or it is updated
if (stakeholder.getDefaultId() == null) {
if (indicatorId == null) {
@@ -477,7 +479,7 @@ public class IndicatorController {
if (indicator != null) {
Section section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
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);
@@ -633,7 +635,7 @@ public class IndicatorController {
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) {
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
@@ -714,3 +716,4 @@ public class IndicatorController {
}
}
}
+*/
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
index 90b47b0..05720fa 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java
@@ -1,11 +1,16 @@
+/*
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoamonitorservice.dao.*;
+import eu.dnetlib.uoamonitorservice.dto.SectionFull;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
+import eu.dnetlib.uoamonitorservice.primitives.Visibility;
+import eu.dnetlib.uoamonitorservice.service.SectionService;
+import eu.dnetlib.uoamonitorservice.service.SubCategoryService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
@RestController
@@ -22,71 +26,22 @@ import java.util.List;
public class SectionController {
private final Logger log = LogManager.getLogger(this.getClass());
- @Autowired
- private RolesUtils rolesUtils;
-
- @Autowired
- private StakeholderDAO stakeholderDAO;
-
- @Autowired
- private TopicDAO topicDAO;
-
- @Autowired
- private CategoryDAO categoryDAO;
-
- @Autowired
- private SubCategoryDAO subCategoryDAO;
-
- @Autowired
- private SectionDAO sectionDAO;
-
- @Autowired
- private IndicatorDAO indicatorDAO;
-
- @Autowired
- private IndicatorController indicatorController;
-
- public Section buildSection(Section sectionFull) {
- Section section = new Section<>(sectionFull);
-
- List indicators = new ArrayList<>();
- List indicatorsFull = new ArrayList<>();
- for(Indicator chart : sectionFull.getIndicators()) {
- Indicator chartSaved = indicatorDAO.save(chart);
- chart.setId(chartSaved.getId());
- indicatorsFull.add(chart);
- indicators.add(chartSaved.getId());
- }
- sectionFull.setIndicators(indicatorsFull);
- section.setIndicators(indicators);
-
- Date date = new Date();
- section.setCreationDate(date);
- section.setUpdateDate(date);
-
- sectionFull.setCreationDate(date);
- sectionFull.setUpdateDate(date);
-
- sectionDAO.save(section);
-
- sectionFull.setId(section.getId());
- return sectionFull;
- }
+ private SectionService service;
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save/{index}", method = RequestMethod.POST)
- public Section saveSection(@PathVariable("stakeholderId") String stakeholderId,
- @PathVariable("topicId") String topicId,
- @PathVariable("categoryId") String categoryId,
- @PathVariable("subcategoryId") String subcategoryId,
- @PathVariable("index") String index,
- @RequestBody Section sectionFull) {
+ public SectionFull saveSection(@PathVariable("stakeholderId") String stakeholderId,
+ @PathVariable("topicId") String topicId,
+ @PathVariable("categoryId") String categoryId,
+ @PathVariable("subcategoryId") String subcategoryId,
+ @PathVariable("index") String index,
+ @RequestBody SectionFull sectionFull) {
log.debug("save section");
log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
- SubCategory subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
+ SubCategory subCategory = this.subCategoryService.checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, "Save Section");
- Section section = new Section<>(sectionFull);
+ Section section = new Section(sectionFull);
Date date = new Date();
section.setUpdateDate(date);
@@ -123,7 +78,7 @@ public class SectionController {
section.setIndicators(indicators);
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
// this section belongs in default profile and it is new or it is updated
if(stakeholder.getDefaultId() == null) {
if(sectionId == null) {
@@ -200,23 +155,13 @@ public class SectionController {
private SubCategory checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId) {
- Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
-
- if(stakeholder == null) {
- // EXCEPTION - Stakeholder not found
- throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found");
- }
+ Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"));
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);
}
- Topic topic = topicDAO.findById(topicId);
- if(topic == null) {
- // EXCEPTION - Topic not found
- throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found");
- }
-
+ Topic topic = topicDAO.findById(topicId).orElseThrow(() -> new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"));
if(!stakeholder.getTopics().contains(topicId)) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
@@ -304,22 +249,5 @@ public class SectionController {
sectionDAO.save(section);
}
}
-
- public Section changeVisibilityTree(String sectionId, Visibility visibility) {
- Section section = sectionDAO.findById(sectionId);
- if (section == null) {
- // EXCEPTION - Section not found
- throw new EntityNotFoundException("Change section visibility: Section with id: " + sectionId + " not found");
- }
-
- Section sectionFull = new Section(section);
- List indicatorsFull = new ArrayList();
-
- for (String indicatorId : section.getIndicators()) {
- indicatorsFull.add(indicatorController.changeVisibilityTree(indicatorId, null, visibility));
- }
-
- sectionFull.setIndicators(indicatorsFull);
- return sectionFull;
- }
}
+*/
diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
index 8e2a33f..cb1f8ba 100644
--- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
+++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java
@@ -1,57 +1,33 @@
package eu.dnetlib.uoamonitorservice.controllers;
-import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
-import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
-import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
-import eu.dnetlib.uoamonitorservice.dao.*;
-import eu.dnetlib.uoamonitorservice.entities.*;
-import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
+import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
+import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
+import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
-
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
-import java.util.*;
+import java.util.List;
+import java.util.stream.Collectors;
@RestController
@CrossOrigin(origins = "*")
public class StakeholderController {
private final Logger log = LogManager.getLogger(this.getClass());
- @Autowired
- private RolesUtils rolesUtils;
-
- @Autowired
+ private PortalService portalService;
private StakeholderService stakeholderService;
@Autowired
- private StakeholderDAO stakeholderDAO;
-
- @Autowired
- private TopicDAO topicDAO;
-
- @Autowired
- private CategoryDAO categoryDAO;
-
- @Autowired
- private SubCategoryDAO subCategoryDAO;
-
- @Autowired
- private SectionDAO sectionDAO;
-
- @Autowired
- private IndicatorDAO indicatorDAO;
-
- @Autowired
- private TopicController topicController;
-
- @Autowired
- private PortalService portalService;
+ public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
+ this.portalService = portalService;
+ this.stakeholderService = stakeholderService;
+ }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
@@ -63,221 +39,46 @@ public class StakeholderController {
return stakeholderAlias;
}
-// @PreAuthorize("isAuthenticated()")
- @PreAuthorize("hasAnyAuthority(" +
- "@AuthorizationService.PORTAL_ADMIN, " +
- "@AuthorizationService.curator(#stakeholderFull.getType()))")
+ /* @PreAuthorize("hasAnyAuthority(" +
+ "@AuthorizationService.PORTAL_ADMIN, " +
+ "@AuthorizationService.curator(#stakeholderFull.getType()))")
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
- public Stakeholder>>>> buildFullStakeholder(@RequestBody Stakeholder