Revert properties. Remove some comments. Remove mongodb DAOs. Move primitives classes and enums to new package primitives.

This commit is contained in:
Konstantinos Triantafyllou 2024-03-06 01:48:31 +02:00
parent 76c39d6eb3
commit 1158b676e4
27 changed files with 293 additions and 454 deletions

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.controllers; package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; 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.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -45,7 +48,7 @@ public class CategoryController {
List<String> subCategories = new ArrayList<>(); List<String> subCategories = new ArrayList<>();
List<SubCategory> subCategoriesFull = new ArrayList<>(); List<SubCategory> subCategoriesFull = new ArrayList<>();
for(SubCategory<Section<Indicator>> subCategory : categoryFull.getSubCategories()) { for (SubCategory<Section<Indicator>> subCategory : categoryFull.getSubCategories()) {
SubCategory<Section<Indicator>> subcategoryFull = subCategoryController.buildSubCategory(subCategory); SubCategory<Section<Indicator>> subcategoryFull = subCategoryController.buildSubCategory(subCategory);
subCategoriesFull.add(subcategoryFull); subCategoriesFull.add(subcategoryFull);
subCategories.add(subcategoryFull.getId()); subCategories.add(subcategoryFull.getId());
@ -72,28 +75,28 @@ public class CategoryController {
@PathVariable("topicId") String topicId, @PathVariable("topicId") String topicId,
@RequestBody Category<SubCategory> categoryFull) { @RequestBody Category<SubCategory> categoryFull) {
log.debug("save category"); 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<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) { if (stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
// EXCEPTION - Access denied // 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<String> oldCategory = null; Category<String> oldCategory = null;
if(categoryFull.getId() != null) { if (categoryFull.getId() != null) {
oldCategory = categoryDAO.findById(categoryFull.getId()); oldCategory = categoryDAO.findById(categoryFull.getId());
if(oldCategory == null) { if (oldCategory == null) {
// EXCEPTION - Category not found // EXCEPTION - Category not found
throw new EntityNotFoundException("save category: Category with id: " + categoryFull.getId() + " not found"); throw new EntityNotFoundException("save category: Category with id: " + categoryFull.getId() + " not found");
} }
} }
Topic<String> topic = topicDAO.findById(topicId); Topic<String> topic = topicDAO.findById(topicId);
if(topic != null) { if (topic != null) {
if(stakeholder.getTopics().contains(topicId)) { if (stakeholder.getTopics().contains(topicId)) {
Category<String> category = new Category<>(categoryFull); Category<String> category = new Category<>(categoryFull);
Date date = new Date(); Date date = new Date();
@ -103,7 +106,7 @@ public class CategoryController {
List<String> subCategories = new ArrayList<>(); List<String> subCategories = new ArrayList<>();
// if category not exists (no id), create a new default subcategory, identical to category // 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); category.setCreationDate(date);
categoryFull.setCreationDate(date); categoryFull.setCreationDate(date);
@ -115,15 +118,15 @@ public class CategoryController {
List<SubCategory> subCategoriesFull = categoryFull.getSubCategories(); List<SubCategory> subCategoriesFull = categoryFull.getSubCategories();
subCategoriesFull.add(subCategory); subCategoriesFull.add(subCategory);
for(SubCategory oldSubCategory : subCategoriesFull) { for (SubCategory oldSubCategory : subCategoriesFull) {
subCategories.add(oldSubCategory.getId()); subCategories.add(oldSubCategory.getId());
} }
} else { } else {
for(String subCategoryId : oldCategory.getSubCategories()) { for (String subCategoryId : oldCategory.getSubCategories()) {
SubCategory subCategory = subCategoryDAO.findById(subCategoryId); SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
if (subCategory == null) { if (subCategory == null) {
// EXCEPTION - SubCategory not found // 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()); subCategories.add(subCategory.getId());
} }
@ -131,8 +134,8 @@ public class CategoryController {
category.setSubCategories(subCategories); category.setSubCategories(subCategories);
if(stakeholder.getDefaultId() == null) { if (stakeholder.getDefaultId() == null) {
if(categoryFull.getId() == null) { if (categoryFull.getId() == null) {
categoryDAO.save(category); categoryDAO.save(category);
onSaveDefaultCategory(category, topicId); onSaveDefaultCategory(category, topicId);
} else { } else {
@ -145,27 +148,24 @@ public class CategoryController {
List<String> categories = topic.getCategories(); List<String> categories = topic.getCategories();
int index = categories.indexOf(category.getId()); int index = categories.indexOf(category.getId());
if(index == -1) { if (index == -1) {
categories.add(category.getId()); categories.add(category.getId());
topicDAO.save(topic); topicDAO.save(topic);
log.debug("Category saved!"); log.debug("Category saved!");
categoryFull.setId(category.getId()); categoryFull.setId(category.getId());
} }
subCategories = null;
category = null;
} else { } else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); // 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 { } else {
// EXCEPTION - Topic not found // 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 { } else {
// EXCEPTION - Stakeholder not found // 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; return categoryFull;
} }
@ -174,7 +174,7 @@ public class CategoryController {
log.debug("On save default category"); log.debug("On save default category");
List<Topic> topics = topicDAO.findByDefaultId(topicId); List<Topic> topics = topicDAO.findByDefaultId(topicId);
for(Topic topic : topics) { for (Topic topic : topics) {
Category categoryNew = new Category(); Category categoryNew = new Category();
categoryNew.copyFromDefault(category); categoryNew.copyFromDefault(category);
@ -195,28 +195,24 @@ public class CategoryController {
List<Category> categories = categoryDAO.findByDefaultId(category.getId()); List<Category> categories = categoryDAO.findByDefaultId(category.getId());
boolean changed = false; boolean changed = false;
for(Category categoryBasedOnDefault : categories) { for (Category categoryBasedOnDefault : categories) {
if(category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName()) if (category.getName() != null && !category.getName().equals(categoryBasedOnDefault.getName())
&& (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) { && (oldCategory.getName() == null || oldCategory.getName().equals(categoryBasedOnDefault.getName()))) {
categoryBasedOnDefault.setName(category.getName()); categoryBasedOnDefault.setName(category.getName());
categoryBasedOnDefault.setAlias(category.getAlias()); categoryBasedOnDefault.setAlias(category.getAlias());
changed = true; 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()))) { && (oldCategory.getDescription() == null || oldCategory.getDescription().equals(categoryBasedOnDefault.getDescription()))) {
categoryBasedOnDefault.setDescription(category.getDescription()); categoryBasedOnDefault.setDescription(category.getDescription());
changed = true; changed = true;
} }
if(!changed) { if (!changed) {
// break;
continue; continue;
} }
// categoryBasedOnDefault.setName(category.getName());
// categoryBasedOnDefault.setDescription(category.getDescription());
categoryBasedOnDefault.setUpdateDate(category.getUpdateDate()); categoryBasedOnDefault.setUpdateDate(category.getUpdateDate());
categoryDAO.save(categoryBasedOnDefault); categoryDAO.save(categoryBasedOnDefault);
} }
@ -229,34 +225,34 @@ public class CategoryController {
@PathVariable("categoryId") String categoryId, @PathVariable("categoryId") String categoryId,
@RequestParam(required = false) String children) { @RequestParam(required = false) String children) {
log.debug("delete category"); log.debug("delete category");
log.debug("Id: "+categoryId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId); log.debug("Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) { if (stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
// EXCEPTION - Access denied // 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<String> topic = topicDAO.findById(topicId); Topic<String> topic = topicDAO.findById(topicId);
if(topic != null) { if (topic != null) {
if(stakeholder.getTopics().contains(topicId)) { if (stakeholder.getTopics().contains(topicId)) {
Category<String> category = categoryDAO.findById(categoryId); Category<String> 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 // 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<String> categories = topic.getCategories(); List<String> categories = topic.getCategories();
int index = categories.indexOf(categoryId); int index = categories.indexOf(categoryId);
if(index != -1) { if (index != -1) {
// this category belongs in default profile // this category belongs in default profile
if(topic.getDefaultId() == null && children != null) { if (topic.getDefaultId() == null && children != null) {
onDeleteDefaultCategory(categoryId, topicId, children); onDeleteDefaultCategory(categoryId, topicId, children);
} }
subCategoryController.deleteTree(category); subCategoryController.deleteTree(category);
@ -267,42 +263,42 @@ public class CategoryController {
log.debug("Category deleted!"); log.debug("Category deleted!");
} else { } else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); // 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 { } else {
// EXCEPTION - Category not found // 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 { } else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); // 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 { } else {
// EXCEPTION - Topic not found // 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 { } else {
// EXCEPTION - Stakeholder not found // 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; return true;
} }
public boolean onDeleteDefaultCategory(String defaultCategoryId, String defaultTopicId, String children) { public boolean onDeleteDefaultCategory(String defaultCategoryId, String defaultTopicId, String children) {
if(children.equals("delete")) { if (children.equals("delete")) {
List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId); List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId); List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId);
for(Topic topic : topics) { for (Topic topic : topics) {
Iterator<Category> categoriesIterator = categories.iterator(); Iterator<Category> categoriesIterator = categories.iterator();
while(categoriesIterator.hasNext()) { while (categoriesIterator.hasNext()) {
Category category = categoriesIterator.next(); Category category = categoriesIterator.next();
String categoryId = category.getId(); String categoryId = category.getId();
if(topic.getCategories() != null && topic.getCategories().contains(categoryId)) { if (topic.getCategories() != null && topic.getCategories().contains(categoryId)) {
categoriesIterator.remove(); categoriesIterator.remove();
topic.getCategories().remove(categoryId); topic.getCategories().remove(categoryId);
@ -311,21 +307,21 @@ public class CategoryController {
subCategoryController.deleteTree(category); subCategoryController.deleteTree(category);
categoryDAO.delete(categoryId); categoryDAO.delete(categoryId);
log.debug("Category with id: "+categoryId+" deleted!"); log.debug("Category with id: " + categoryId + " deleted!");
break; break;
} }
} }
} }
} else if(children.equals("disconnect")) { } else if (children.equals("disconnect")) {
List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId); List<Category> categories = categoryDAO.findByDefaultId(defaultCategoryId);
for(Category category : categories) { for (Category category : categories) {
subCategoryController.disConnectTree(category); subCategoryController.disConnectTree(category);
category.setDefaultId(null); category.setDefaultId(null);
categoryDAO.save(category); 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; return true;
@ -337,7 +333,7 @@ public class CategoryController {
@PathVariable("topicId") String topicId, @PathVariable("topicId") String topicId,
@RequestBody List<String> categories) { @RequestBody List<String> categories) {
log.debug("reorder categories"); log.debug("reorder categories");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Topic<String> topic = checkForExceptions(stakeholderId, topicId); Topic<String> topic = checkForExceptions(stakeholderId, topicId);
@ -350,9 +346,9 @@ public class CategoryController {
topic.setCategories(categories); topic.setCategories(categories);
List<Category> categoriesFull = new ArrayList<>(); List<Category> categoriesFull = new ArrayList<>();
for(String categoryId : categories) { for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId); Category category = categoryDAO.findById(categoryId);
if(category == null) { if (category == null) {
// EXCEPTION - Category not found // EXCEPTION - Category not found
throw new EntityNotFoundException("Reorder Categories: Category with id: " + categoryId + " not found"); throw new EntityNotFoundException("Reorder Categories: Category with id: " + categoryId + " not found");
} }
@ -371,15 +367,15 @@ public class CategoryController {
@PathVariable("topicId") String topicId, @PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId, @PathVariable("categoryId") String categoryId,
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) { @RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
log.debug("change category visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false")); log.debug("change category visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId); log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) { if (stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) { if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
// EXCEPTION - Access denied // 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<String> topic = topicDAO.findById(topicId); Topic<String> topic = topicDAO.findById(topicId);
@ -389,19 +385,19 @@ public class CategoryController {
return changeVisibilityTree(categoryId, visibility, propagate); return changeVisibilityTree(categoryId, visibility, propagate);
} else { } else {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); // 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 { } else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); // 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 { } else {
// EXCEPTION - Topic not found // 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 { } else {
// EXCEPTION - Stakeholder not found // 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<String> category = categoryDAO.findById(categoryId); Category<String> category = categoryDAO.findById(categoryId);
if (category == null) { if (category == null) {
// EXCEPTION - Category not found // 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<SubCategory> categoryFull = new Category(category); Category<SubCategory> categoryFull = new Category(category);
List<SubCategory> subCategoriesFull = new ArrayList<>(); List<SubCategory> subCategoriesFull = new ArrayList<>();
if(propagate != null && propagate) { if (propagate != null && propagate) {
for (String subCategoryId : category.getSubCategories()) { for (String subCategoryId : category.getSubCategories()) {
subCategoriesFull.add(subCategoryController.changeVisibilityTree(subCategoryId, visibility, propagate)); subCategoriesFull.add(subCategoryController.changeVisibilityTree(subCategoryId, visibility, propagate));
} }
@ -436,24 +432,24 @@ public class CategoryController {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder == null) { if (stakeholder == null) {
// EXCEPTION - Stakeholder not found // EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("checkForExceptions category: Stakeholder with id: " + stakeholderId + " 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 // 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<String> topic = topicDAO.findById(topicId); Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) { if (topic == null) {
// EXCEPTION - Topic not found // 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(); // 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;
@ -461,11 +457,11 @@ public class CategoryController {
public void deleteTree(Topic topic) { public void deleteTree(Topic topic) {
List<String> categories = topic.getCategories(); List<String> categories = topic.getCategories();
for(String categoryId : categories) { for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId); Category category = categoryDAO.findById(categoryId);
if (category == null) { if (category == null) {
// EXCEPTION - Category not found // 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); subCategoryController.deleteTree(category);
@ -476,11 +472,11 @@ public class CategoryController {
public void disConnectTree(Topic topic) { public void disConnectTree(Topic topic) {
List<String> categories = topic.getCategories(); List<String> categories = topic.getCategories();
for(String categoryId : categories) { for (String categoryId : categories) {
Category category = categoryDAO.findById(categoryId); Category category = categoryDAO.findById(categoryId);
if (category == null) { if (category == null) {
// EXCEPTION - Category not found // 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); subCategoryController.disConnectTree(category);

View File

@ -10,7 +10,10 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; 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 @RestController
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@ -40,17 +43,17 @@ public class EmailController {
String failureString = "failure"; String failureString = "failure";
Map<String, ArrayList<String>> mailResults = new HashMap<>(); Map<String, ArrayList<String>> mailResults = new HashMap<>();
boolean bcc = optional.orElse(true); boolean bcc = optional.orElse(true);
for(String userMail:email.getRecipients()){ for (String userMail : email.getRecipients()) {
ArrayList<String> sendTo = new ArrayList<>(); ArrayList<String> sendTo = new ArrayList<>();
sendTo.add(userMail); sendTo.add(userMail);
boolean success =emailSender.send(sendTo,email.getSubject(),email.getBody(), bcc); boolean success = emailSender.send(sendTo, email.getSubject(), email.getBody(), bcc);
if(success){ if (success) {
if(!mailResults.containsKey(successString)) { if (!mailResults.containsKey(successString)) {
mailResults.put(successString, new ArrayList<>()); mailResults.put(successString, new ArrayList<>());
} }
mailResults.get(successString).add(userMail); mailResults.get(successString).add(userMail);
} else { } else {
if(!mailResults.containsKey(failureString)) { if (!mailResults.containsKey(failureString)) {
mailResults.put(failureString, new ArrayList<>()); mailResults.put(failureString, new ArrayList<>());
} }
mailResults.get(failureString).add(userMail); mailResults.get(failureString).add(userMail);

View File

@ -1,12 +1,14 @@
package eu.dnetlib.uoamonitorservice.controllers; package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoamonitorservice.dao.*; import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.*; import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; 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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -56,22 +58,20 @@ public class IndicatorController {
@PathVariable("subcategoryId") String subcategoryId, @PathVariable("subcategoryId") String subcategoryId,
@RequestBody List<Section<Indicator>> sections) throws UnsupportedEncodingException { @RequestBody List<Section<Indicator>> sections) throws UnsupportedEncodingException {
log.debug("save bulk indicators"); 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<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Date date = new Date(); Date date = new Date();
createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId); createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId);
// createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId);
return stakeholderController.setFullEntities(stakeholder); return stakeholderController.setFullEntities(stakeholder);
} }
private void createSectionsAndSaveBulk(Date date, List<Section<Indicator>> old_sections, private void createSectionsAndSaveBulk(Date date, List<Section<Indicator>> old_sections,
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException { Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
for(Section<Indicator> section : old_sections) { for (Section<Indicator> section : old_sections) {
if(section == null) { if (section == null) {
continue; continue;
} }
@ -81,17 +81,17 @@ public class IndicatorController {
List<String> chart_indicators = null; List<String> chart_indicators = null;
List<String> number_indicators = null; List<String> 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_section = createSection(chart_section, "chart", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
chart_indicators = chart_section.getIndicators(); 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_section = createSection(number_section, "number", section.getTitle(), date, stakeholder, topicId, categoryId, subcategoryId);
number_indicators = number_section.getIndicators(); number_indicators = number_section.getIndicators();
} }
List<Indicator> indicators = section.getIndicators(); List<Indicator> indicators = section.getIndicators();
for (Indicator indicator : indicators) { for (Indicator indicator : indicators) {
if(indicator == null) { if (indicator == null) {
continue; continue;
} }
@ -126,10 +126,6 @@ public class IndicatorController {
return section; return section;
} }
// private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List<String> indicators) throws UnsupportedEncodingException {
// saveIndicatorAndAddInSection(indicator, date, stakeholder, section, indicators);
// }
private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, String subcategoryId, Section section, List<String> indicators) throws UnsupportedEncodingException { private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, String subcategoryId, Section section, List<String> indicators) throws UnsupportedEncodingException {
// indicator does not exist in DB // indicator does not exist in DB
indicator.setCreationDate(date); indicator.setCreationDate(date);
@ -155,7 +151,7 @@ public class IndicatorController {
@PathVariable("sectionId") String sectionId, @PathVariable("sectionId") String sectionId,
@RequestBody Indicator indicator) throws UnsupportedEncodingException { @RequestBody Indicator indicator) throws UnsupportedEncodingException {
log.debug("save indicator"); 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<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
@ -163,9 +159,9 @@ public class IndicatorController {
indicator.setUpdateDate(date); indicator.setUpdateDate(date);
Indicator oldIndicator = null; Indicator oldIndicator = null;
if(indicator.getId() != null) { if (indicator.getId() != null) {
oldIndicator = indicatorDAO.findById(indicator.getId()); oldIndicator = indicatorDAO.findById(indicator.getId());
if(oldIndicator == null) { if (oldIndicator == null) {
// EXCEPTION - Indicator not found // EXCEPTION - Indicator not found
throw new EntityNotFoundException("save indicator: Indicator with id: " + indicator.getId() + " not found"); throw new EntityNotFoundException("save indicator: Indicator with id: " + indicator.getId() + " not found");
} }
@ -177,12 +173,11 @@ public class IndicatorController {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
// this indicator belongs in default profile and it is new or it is updated // this indicator belongs in default profile and it is new or it is updated
if(stakeholder.getDefaultId() == null) { if (stakeholder.getDefaultId() == null) {
if(indicatorId == null) { if (indicatorId == null) {
indicatorDAO.save(indicator); indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, section, subcategoryId); onSaveDefaultIndicator(indicator, section, subcategoryId);
} } else {
else {
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator); onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
indicatorDAO.save(indicator); indicatorDAO.save(indicator);
} }
@ -210,7 +205,7 @@ public class IndicatorController {
for (SubCategory subCategory : subCategories) { for (SubCategory subCategory : subCategories) {
List<String> sections = null; List<String> sections = null;
if(defaultSection.getType().equals("chart")) { if (defaultSection.getType().equals("chart")) {
sections = subCategory.getCharts(); sections = subCategory.getCharts();
} else { } else {
sections = subCategory.getNumbers(); sections = subCategory.getNumbers();
@ -218,7 +213,7 @@ public class IndicatorController {
for (String sectionId : sections) { for (String sectionId : sections) {
Section section = sectionDAO.findById(sectionId); 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(); Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator, subCategory.getVisibility()); indicatorNew.copyFromDefault(indicator, subCategory.getVisibility());
indicatorDAO.save(indicatorNew); indicatorDAO.save(indicatorNew);
@ -238,12 +233,9 @@ public class IndicatorController {
boolean changed; boolean changed;
List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId()); List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
for(Indicator indicatorBasedOnDefault : indicators) { for (Indicator indicatorBasedOnDefault : indicators) {
changed = false; changed = false;
if ((
// if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
// && (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
if((
(indicator.getName() == null && oldIndicator.getName() != null) (indicator.getName() == null && oldIndicator.getName() != null)
|| ||
(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())) (indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName()))
@ -256,16 +248,13 @@ public class IndicatorController {
changed = true; changed = true;
} }
if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription()) if (indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
|| indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) { || indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) {
indicatorBasedOnDefault.setDescription(indicator.getDescription()); indicatorBasedOnDefault.setDescription(indicator.getDescription());
changed = true; changed = true;
} }
if ((
// if(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription())
// && (oldIndicator.getAdditionalDescription() == null || oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))) {
if((
(indicator.getAdditionalDescription() == null && oldIndicator.getAdditionalDescription() != null) (indicator.getAdditionalDescription() == null && oldIndicator.getAdditionalDescription() != null)
|| ||
(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription())) (indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
@ -280,17 +269,17 @@ public class IndicatorController {
int i = 0; int i = 0;
List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths(); List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
if(indicatorPaths == null && indicator.getIndicatorPaths() != null) { if (indicatorPaths == null && indicator.getIndicatorPaths() != null) {
indicatorPaths = new ArrayList<>(); indicatorPaths = new ArrayList<>();
} }
for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) { for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
IndicatorPath indicatorPathBasedOnDefault = null; IndicatorPath indicatorPathBasedOnDefault = null;
if(i < indicatorPaths.size()) { if (i < indicatorPaths.size()) {
indicatorPathBasedOnDefault = indicatorPaths.get(i); indicatorPathBasedOnDefault = indicatorPaths.get(i);
} }
if(indicatorPathBasedOnDefault == null) { if (indicatorPathBasedOnDefault == null) {
// Add new indicator path in existing indicators // Add new indicator path in existing indicators
IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath); IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
indicatorPaths.add(indicatorPathNew); indicatorPaths.add(indicatorPathNew);
@ -299,12 +288,8 @@ public class IndicatorController {
IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i); IndicatorPath oldIndicatorPath = oldIndicator.getIndicatorPaths().get(i);
// Check if there are changes in indicator path and update existing indicators if needed // Check if there are changes in indicator path and update existing indicators if needed
log.debug("update indicator path: "+i + " (indicator id: "+indicatorBasedOnDefault.getId()+")"); log.debug("update indicator path: " + i + " (indicator id: " + indicatorBasedOnDefault.getId() + ")");
if ((
// if(indicatorPath.getType() != null
// && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
// && (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
if((
(indicatorPath.getType() == null && oldIndicatorPath.getType() != null) (indicatorPath.getType() == null && oldIndicatorPath.getType() != null)
|| ||
(indicatorPath.getType() != null && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) (indicatorPath.getType() != null && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
@ -316,9 +301,9 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setType(indicatorPath.getType()); indicatorPathBasedOnDefault.setType(indicatorPath.getType());
changed = true; // parameter "type" needs to be changed as well 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 && oldIndicatorPath.getFormat() != null)
|| ||
(indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat())) (indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
@ -330,12 +315,8 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setFormat(indicatorPath.getFormat()); indicatorPathBasedOnDefault.setFormat(indicatorPath.getFormat());
changed = true; changed = true;
} }
log.debug("After type check: "+changed); log.debug("After type check: " + changed);
if ((
// if(indicatorPath.getSource() != null
// && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
// && (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {
if((
(indicatorPath.getSource() == null && oldIndicatorPath.getSource() != null) (indicatorPath.getSource() == null && oldIndicatorPath.getSource() != null)
|| ||
(indicatorPath.getSource() != null && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) (indicatorPath.getSource() != null && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
@ -347,12 +328,8 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource()); indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
changed = true; changed = true;
} }
log.debug("After source check: "+changed); log.debug("After source check: " + changed);
if ((
// if(indicatorPath.getUrl() != null
// && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
// && (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
if((
(indicatorPath.getUrl() == null && oldIndicatorPath.getUrl() != null) (indicatorPath.getUrl() == null && oldIndicatorPath.getUrl() != null)
|| ||
(indicatorPath.getUrl() != null && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) (indicatorPath.getUrl() != null && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
@ -364,9 +341,9 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl()); indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
changed = true; 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 && oldIndicatorPath.getChartObject() != null)
|| ||
(indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) (indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
@ -379,18 +356,16 @@ public class IndicatorController {
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject()); indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
changed = true; 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) { if (indicatorPathBasedOnDefault.getParameters() == null) {
indicatorPathBasedOnDefault.setParameters(new HashMap<>()); indicatorPathBasedOnDefault.setParameters(new HashMap<>());
} }
//if (indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
//log.debug("Different number of parameters");
for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) { for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
log.debug("\nindicatorPath: parameter.getKey(): "+parameter.getKey()+" - value: "+parameter.getValue() log.debug("\nindicatorPath: parameter.getKey(): " + parameter.getKey() + " - value: " + parameter.getValue()
+"\nindicatorPathBasedOnDefault:parameters:key: "+ indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()) + "\nindicatorPathBasedOnDefault:parameters:key: " + indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())
+"\noldIndicatorPath:parameters:key: "+ (oldIndicatorPath.getParameters() == null ? "null" : oldIndicatorPath.getParameters().get(parameter.getKey()))); + "\noldIndicatorPath:parameters:key: " + (oldIndicatorPath.getParameters() == null ? "null" : oldIndicatorPath.getParameters().get(parameter.getKey())));
if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey()) if (!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())
|| (oldIndicatorPath.getParameters() == null || oldIndicatorPath.getParameters().get(parameter.getKey()) == null || (oldIndicatorPath.getParameters() == null || oldIndicatorPath.getParameters().get(parameter.getKey()) == null
|| (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey())) || (oldIndicatorPath.getParameters().get(parameter.getKey()).equals(indicatorPathBasedOnDefault.getParameters().get(parameter.getKey()))
@ -402,9 +377,9 @@ public class IndicatorController {
} }
// When deleting indicator path parameters in a default profile, delete them also from all children profiles // 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<String, String> parameter : oldIndicatorPath.getParameters().entrySet()) { for (Map.Entry<String, String> parameter : oldIndicatorPath.getParameters().entrySet()) {
if(!indicatorPath.getParameters().containsKey(parameter.getKey())) { if (!indicatorPath.getParameters().containsKey(parameter.getKey())) {
indicatorPathBasedOnDefault.getParameters().remove(parameter.getKey()); indicatorPathBasedOnDefault.getParameters().remove(parameter.getKey());
} }
} }
@ -412,21 +387,21 @@ public class IndicatorController {
} }
log.debug("After parameters check: " + changed); log.debug("After parameters check: " + changed);
if(indicatorPath.getJsonPath() != null) { if (indicatorPath.getJsonPath() != null) {
boolean jsonPathChanged = false; boolean jsonPathChanged = false;
boolean breaked = false; boolean breaked = false;
int oldJsonPathSize = 0; int oldJsonPathSize = 0;
if(oldIndicatorPath.getJsonPath() != null) { if (oldIndicatorPath.getJsonPath() != null) {
oldJsonPathSize = oldIndicatorPath.getJsonPath().size(); oldJsonPathSize = oldIndicatorPath.getJsonPath().size();
} }
int basedOnDefaultJsonPathSize = 0; int basedOnDefaultJsonPathSize = 0;
if(indicatorPathBasedOnDefault.getJsonPath() != null) { if (indicatorPathBasedOnDefault.getJsonPath() != null) {
basedOnDefaultJsonPathSize = indicatorPathBasedOnDefault.getJsonPath().size(); basedOnDefaultJsonPathSize = indicatorPathBasedOnDefault.getJsonPath().size();
} }
log.debug("old: "+oldJsonPathSize+" - based on default: "+basedOnDefaultJsonPathSize+" - new: "+indicatorPath.getJsonPath().size()); log.debug("old: " + oldJsonPathSize + " - based on default: " + basedOnDefaultJsonPathSize + " - new: " + indicatorPath.getJsonPath().size());
if(oldJsonPathSize == basedOnDefaultJsonPathSize) { if (oldJsonPathSize == basedOnDefaultJsonPathSize) {
if(indicatorPathBasedOnDefault.getJsonPath() == null && indicatorPath.getJsonPath().size() > 0) { if (indicatorPathBasedOnDefault.getJsonPath() == null && indicatorPath.getJsonPath().size() > 0) {
indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>()); indicatorPathBasedOnDefault.setJsonPath(new ArrayList<>());
} }
@ -436,12 +411,12 @@ public class IndicatorController {
Iterator<String> jsonStringBasedOnDefaultIterator = indicatorPathBasedOnDefault.getJsonPath().iterator(); Iterator<String> jsonStringBasedOnDefaultIterator = indicatorPathBasedOnDefault.getJsonPath().iterator();
while (jsonStringBasedOnDefaultIterator.hasNext()) { while (jsonStringBasedOnDefaultIterator.hasNext()) {
String jsonStringBasedOnDefault = jsonStringBasedOnDefaultIterator.next(); String jsonStringBasedOnDefault = jsonStringBasedOnDefaultIterator.next();
if(oldIndicatorPath.getJsonPath().get(oldIndex).equals(jsonStringBasedOnDefault)) { if (oldIndicatorPath.getJsonPath().get(oldIndex).equals(jsonStringBasedOnDefault)) {
if(basedOnDefaultIndex >= indicatorPath.getJsonPath().size()) { // string deleted if (basedOnDefaultIndex >= indicatorPath.getJsonPath().size()) { // string deleted
jsonStringBasedOnDefaultIterator.remove(); jsonStringBasedOnDefaultIterator.remove();
jsonPathChanged = true; jsonPathChanged = true;
} else { // check if string changed } 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)); indicatorPathBasedOnDefault.getJsonPath().set(basedOnDefaultIndex, indicatorPath.getJsonPath().get(basedOnDefaultIndex));
jsonPathChanged = true; jsonPathChanged = true;
} }
@ -451,20 +426,20 @@ public class IndicatorController {
} else { } else {
breaked = true; breaked = true;
jsonPathChanged = false; jsonPathChanged = false;
log.debug("not the same: "+oldIndex); log.debug("not the same: " + oldIndex);
break; break;
} }
} }
int index=0; int index = 0;
if(!breaked && indicatorPath.getJsonPath().size() > indicatorPathBasedOnDefault.getJsonPath().size()) { // strings added if (!breaked && indicatorPath.getJsonPath().size() > indicatorPathBasedOnDefault.getJsonPath().size()) { // strings added
jsonPathChanged = true; 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)); indicatorPathBasedOnDefault.getJsonPath().add(indicatorPath.getJsonPath().get(index));
} }
} }
if(jsonPathChanged) { if (jsonPathChanged) {
changed = true; changed = true;
} }
} }
@ -476,7 +451,7 @@ public class IndicatorController {
} }
// TODO when deleting indicator paths... // TODO when deleting indicator paths...
if(!changed) { if (!changed) {
// break; // break;
continue; continue;
} }
@ -496,16 +471,16 @@ public class IndicatorController {
@PathVariable("indicatorId") String indicatorId, @PathVariable("indicatorId") String indicatorId,
@RequestParam(required = false) String children) { @RequestParam(required = false) String children) {
log.debug("delete indicator"); 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); Indicator indicator = indicatorDAO.findById(indicatorId);
if(indicator != null) { if (indicator != null) {
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) { if (indicator.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
// EXCEPTION - Access denied // 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<String> indicators = section.getIndicators(); List<String> indicators = section.getIndicators();
@ -514,7 +489,7 @@ public class IndicatorController {
if (index != -1) { if (index != -1) {
// this indicator belongs in default profile // this indicator belongs in default profile
if(section.getDefaultId() == null && children != null) { if (section.getDefaultId() == null && children != null) {
onDeleteDefaultIndicator(indicatorId, sectionId, children); onDeleteDefaultIndicator(indicatorId, sectionId, children);
} }
@ -526,44 +501,44 @@ public class IndicatorController {
log.debug("Indicator deleted!"); log.debug("Indicator deleted!");
} else { } else {
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle(); // 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 { } else {
// EXCEPTION - Indicator not found // 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; return true;
} }
public boolean onDeleteDefaultIndicator(String defaultIndicatorId, String defaultSectionId, String children) { public boolean onDeleteDefaultIndicator(String defaultIndicatorId, String defaultSectionId, String children) {
if(children.equals("delete")) { if (children.equals("delete")) {
// 2nd way // 2nd way
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId); List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
for(Section section : sections) { for (Section section : sections) {
Iterator<Indicator> indicatorsIterator = indicators.iterator(); Iterator<Indicator> indicatorsIterator = indicators.iterator();
while(indicatorsIterator.hasNext()) { while (indicatorsIterator.hasNext()) {
String indicatorId = indicatorsIterator.next().getId(); String indicatorId = indicatorsIterator.next().getId();
if(section.getIndicators().contains(indicatorId)) { if (section.getIndicators().contains(indicatorId)) {
indicatorsIterator.remove(); indicatorsIterator.remove();
section.getIndicators().remove(indicatorId); section.getIndicators().remove(indicatorId);
sectionDAO.save(section); sectionDAO.save(section);
indicatorDAO.delete(indicatorId); indicatorDAO.delete(indicatorId);
log.debug("Indicator with id: "+indicatorId+" deleted!"); log.debug("Indicator with id: " + indicatorId + " deleted!");
break; break;
} }
} }
} }
} else if(children.equals("disconnect")) { } else if (children.equals("disconnect")) {
List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId); List<Indicator> indicators = indicatorDAO.findByDefaultId(defaultIndicatorId);
for(Indicator indicator : indicators) { for (Indicator indicator : indicators) {
indicator.setDefaultId(null); indicator.setDefaultId(null);
indicatorDAO.save(indicator); 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; return true;
@ -578,8 +553,8 @@ public class IndicatorController {
@PathVariable("sectionId") String sectionId, @PathVariable("sectionId") String sectionId,
@PathVariable("type") String type, @PathVariable("type") String type,
@RequestBody ReorderEvent reorderEvent) { @RequestBody ReorderEvent reorderEvent) {
log.debug("reorder indicators of type: "+type); log.debug("reorder indicators of type: " + type);
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId); log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
List<String> indicators = reorderEvent.getIds(); List<String> indicators = reorderEvent.getIds();
String actionType = reorderEvent.getAction(); String actionType = reorderEvent.getAction();
@ -596,9 +571,9 @@ public class IndicatorController {
section.setIndicators(indicators); section.setIndicators(indicators);
List<Indicator> indicatorsFull = new ArrayList<>(); List<Indicator> indicatorsFull = new ArrayList<>();
for(String indicatorId : indicators) { for (String indicatorId : indicators) {
Indicator indicator = indicatorDAO.findById(indicatorId); Indicator indicator = indicatorDAO.findById(indicatorId);
if(indicator == null) { if (indicator == null) {
// EXCEPTION - Indicator not found // EXCEPTION - Indicator not found
throw new EntityNotFoundException("Reorder indicators: Indicator with id: " + indicatorId + " not found"); throw new EntityNotFoundException("Reorder indicators: Indicator with id: " + indicatorId + " not found");
} }
@ -620,8 +595,8 @@ public class IndicatorController {
@PathVariable("sectionId") String sectionId, @PathVariable("sectionId") String sectionId,
@PathVariable("indicatorId") String indicatorId, @PathVariable("indicatorId") String indicatorId,
@RequestParam("visibility") Visibility visibility) { @RequestParam("visibility") Visibility visibility) {
log.debug("change indicator visibility: "+visibility); log.debug("change indicator visibility: " + visibility);
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId); log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId + " - Indicator: " + indicatorId);
Indicator indicator = indicatorDAO.findById(indicatorId); Indicator indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) { if (indicator == null) {
@ -632,16 +607,16 @@ public class IndicatorController {
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
List<String> indicators = section.getIndicators(); List<String> indicators = section.getIndicators();
if(indicators.contains(indicatorId)) { if (indicators.contains(indicatorId)) {
return changeVisibilityTree(indicatorId, indicator, visibility); return changeVisibilityTree(indicatorId, indicator, visibility);
} else { } else {
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle(); // 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) { public Indicator changeVisibilityTree(String indicatorId, Indicator indicator, Visibility visibility) {
if(indicator == null) { if (indicator == null) {
indicator = indicatorDAO.findById(indicatorId); indicator = indicatorDAO.findById(indicatorId);
if (indicator == null) { if (indicator == null) {
// EXCEPTION - Indicator not found // EXCEPTION - Indicator not found
@ -660,60 +635,60 @@ public class IndicatorController {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder == null) { if (stakeholder == null) {
// EXCEPTION - Stakeholder not found // EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " 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 // 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<String> topic = topicDAO.findById(topicId); Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) { if (topic == null) {
// EXCEPTION - Topic not found // 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(); // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId); throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId);
} }
Category<String> category = categoryDAO.findById(categoryId); Category<String> category = categoryDAO.findById(categoryId);
if(category == null) { if (category == null) {
// EXCEPTION - Category not found // 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(); // 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<String> subcategory = subCategoryDAO.findById(subcategoryId); SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
if(subcategory == null) { if (subcategory == null) {
// EXCEPTION - SubCategory not found // 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)) { if (!category.getSubCategories().contains(subcategoryId)) {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); // 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<String> section = sectionDAO.findById(sectionId); Section<String> section = sectionDAO.findById(sectionId);
if(section == null) { if (section == null) {
// EXCEPTION - Section not found // 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)) { if (!subcategory.getCharts().contains(sectionId)) {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); // 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); 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)) { if (!subcategory.getNumbers().contains(sectionId)) {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); // 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); throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId);
@ -725,14 +700,14 @@ public class IndicatorController {
public void deleteTree(Section section) { public void deleteTree(Section section) {
List<String> indicators = section.getIndicators(); List<String> indicators = section.getIndicators();
for(String indicatorId : indicators) { for (String indicatorId : indicators) {
indicatorDAO.delete(indicatorId); indicatorDAO.delete(indicatorId);
} }
} }
public void disConnectTree(Section section) { public void disConnectTree(Section section) {
List<String> indicators = section.getIndicators(); List<String> indicators = section.getIndicators();
for(String indicatorId : indicators) { for (String indicatorId : indicators) {
Indicator indicator = indicatorDAO.findById(indicatorId); Indicator indicator = indicatorDAO.findById(indicatorId);
indicator.setDefaultId(null); indicator.setDefaultId(null);
indicatorDAO.save(indicator); indicatorDAO.save(indicator);

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Category; import eu.dnetlib.uoamonitorservice.entities.Category;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface CategoryDAO { @Repository
public interface CategoryDAO extends MongoRepository<Category, String> {
List<Category> findAll(); List<Category> findAll();
List<Category> findByDefaultId(String DefaultId); List<Category> findByDefaultId(String DefaultId);

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Indicator; import eu.dnetlib.uoamonitorservice.entities.Indicator;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface IndicatorDAO { @Repository
public interface IndicatorDAO extends MongoRepository<Indicator, String> {
List<Indicator> findAll(); List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId); List<Indicator> findByDefaultId(String DefaultId);

View File

@ -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<Category, String> {
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
Category findBySubCategoriesContaining(String subCategory);
Category findById(String Id);
void delete(String Id);
Category save(Category category);
}

View File

@ -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<Indicator, String> {
List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId);
Indicator findById(String Id);
void delete(String Id);
Indicator save(Indicator indicator);
//List<Indicator> saveAll(List<Indicator> indicators);
}

View File

@ -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<Section, String> {
List<Section> findAll();
List<Section> findByDefaultId(String DefaultId);
Section findById(String Id);
void delete(String Id);
Section save(Section indicator);
}

View File

@ -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<Stakeholder, String> {
List<Stakeholder> findAll();
List<Stakeholder> findByType(String Type);
List<Stakeholder> findByDefaultId(String DefaultId);
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> 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);
}

View File

@ -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<SubCategory, String> {
List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String DefaultId);
SubCategory findById(String Id);
void delete(String Id);
SubCategory save(SubCategory subCategory);
}

View File

@ -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<Topic, String> {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
Topic findByCategoriesContaining(String category);
Topic findById(String Id);
void delete(String Id);
Topic save(Topic topic);
}

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Section; import eu.dnetlib.uoamonitorservice.entities.Section;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface SectionDAO { @Repository
public interface SectionDAO extends MongoRepository<Section, String> {
List<Section> findAll(); List<Section> findAll();
List<Section> findByDefaultId(String DefaultId); List<Section> findByDefaultId(String DefaultId);

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface StakeholderDAO { @Repository
public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
List<Stakeholder> findAll(); List<Stakeholder> findAll();
List<Stakeholder> findByType(String Type); List<Stakeholder> findByType(String Type);

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.SubCategory; import eu.dnetlib.uoamonitorservice.entities.SubCategory;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface SubCategoryDAO { @Repository
public interface SubCategoryDAO extends MongoRepository<SubCategory, String> {
List<SubCategory> findAll(); List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String DefaultId); List<SubCategory> findByDefaultId(String DefaultId);

View File

@ -1,10 +1,13 @@
package eu.dnetlib.uoamonitorservice.dao; package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Topic; import eu.dnetlib.uoamonitorservice.entities.Topic;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public interface TopicDAO { @Repository
public interface TopicDAO extends MongoRepository<Topic, String> {
List<Topic> findAll(); List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId); List<Topic> findByDefaultId(String DefaultId);

View File

@ -1,23 +1,14 @@
package eu.dnetlib.uoamonitorservice.entities; package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty; 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 org.springframework.data.annotation.Id;
import java.util.Date; import java.util.Date;
import java.util.List; 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 { public class Indicator {
@Id @Id
@JsonProperty("_id") @JsonProperty("_id")

View File

@ -1,18 +1,13 @@
package eu.dnetlib.uoamonitorservice.entities; package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; 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<StringOrIndicator> { public class Section<StringOrIndicator> {
@Id @Id
@JsonProperty("_id") @JsonProperty("_id")
@ -21,7 +16,7 @@ public class Section<StringOrIndicator> {
private String title; private String title;
private String defaultId; private String defaultId;
private String stakeholderAlias; private String stakeholderAlias;
private SectionType type; private IndicatorType type;
private Date creationDate; private Date creationDate;
private Date updateDate; private Date updateDate;
private List<StringOrIndicator> indicators; private List<StringOrIndicator> indicators;
@ -90,8 +85,7 @@ public class Section<StringOrIndicator> {
if(type == null) { if(type == null) {
this.type = null; this.type = null;
} else { } else {
SectionType sectionType = SectionType.valueOf(type); this.type = IndicatorType.valueOf(type);
this.type = sectionType;
} }
} }

View File

@ -1,32 +1,14 @@
package eu.dnetlib.uoamonitorservice.entities; package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty; 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 org.springframework.data.annotation.Id;
import java.util.Date; import java.util.Date;
import java.util.List; 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<StringOrTopic> { public class Stakeholder<StringOrTopic> {
@Id @Id
@JsonProperty("_id") @JsonProperty("_id")
@ -84,14 +66,6 @@ public class Stakeholder<StringOrTopic> {
this.id = id; this.id = id;
} }
// public StakeholderType getType() {
// return type;
// }
//
// public void setType(StakeholderType type) {
// this.type = type;
// }
public String getType() { public String getType() {
if(type == null) { if(type == null) {
return null; return null;

View File

@ -0,0 +1,5 @@
package eu.dnetlib.uoamonitorservice.primitives;
public enum Format {
NUMBER, PERCENTAGE
}

View File

@ -1,22 +1,8 @@
package eu.dnetlib.uoamonitorservice.entities; package eu.dnetlib.uoamonitorservice.primitives;
import java.util.List; import java.util.List;
import java.util.Map; 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 { public class IndicatorPath {
private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc} private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc}
private Format format = Format.NUMBER; // for numbers is if number is percentage or not private Format format = Format.NUMBER; // for numbers is if number is percentage or not

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.uoamonitorservice.entities; package eu.dnetlib.uoamonitorservice.primitives;
import java.util.List; import java.util.List;

View File

@ -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;
}

View File

@ -25,31 +25,3 @@ monitorservice.globalVars.version=@version@
#production #production
#monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken= #monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
#monitorservice.originServer = .openaire.eu #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