[new-model | WIP]: Refactoring the code in order to improve performance and code.

This commit is contained in:
Konstantinos Triantafyllou 2024-03-08 20:55:51 +02:00
parent 1158b676e4
commit e345f5b689
38 changed files with 1286 additions and 1189 deletions

View File

@ -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<String> 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<String> 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<String> 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<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
@ -486,3 +488,4 @@ public class CategoryController {
}
}
}
*/

View File

@ -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<String> 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<String> 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<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
Stakeholder<String> 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<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
@ -714,3 +716,4 @@ public class IndicatorController {
}
}
}
*/

View File

@ -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<Indicator> buildSection(Section<Indicator> sectionFull) {
Section<String> section = new Section<>(sectionFull);
List<String> indicators = new ArrayList<>();
List<Indicator> 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,
public SectionFull saveSection(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("index") String index,
@RequestBody Section<Indicator> sectionFull) {
@RequestBody SectionFull sectionFull) {
log.debug("save section");
log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId);
SubCategory subCategory = this.subCategoryService.checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, "Save Section");
Section<String> 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<String> 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<String> 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<String> 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<String> section = sectionDAO.findById(sectionId);
if (section == null) {
// EXCEPTION - Section not found
throw new EntityNotFoundException("Change section visibility: Section with id: " + sectionId + " not found");
}
Section<Indicator> sectionFull = new Section(section);
List<Indicator> indicatorsFull = new ArrayList();
for (String indicatorId : section.getIndicators()) {
indicatorsFull.add(indicatorController.changeVisibilityTree(indicatorId, null, visibility));
}
sectionFull.setIndicators(indicatorsFull);
return sectionFull;
}
}
*/

View File

@ -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,37 +39,23 @@ public class StakeholderController {
return stakeholderAlias;
}
// @PreAuthorize("isAuthenticated()")
@PreAuthorize("hasAnyAuthority(" +
/* @PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator(#stakeholderFull.getType()))")
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
public Stakeholder<Topic<Category<SubCategory<Section<Indicator>>>>> buildFullStakeholder(@RequestBody Stakeholder<Topic<Category<SubCategory<Section<Indicator>>>>> stakeholderFull) {
public StakeholderFull buildFullStakeholder(@RequestBody StakeholderFull stakeholderFull) {
log.debug("build stakeholder");
log.debug("Alias: " + stakeholderFull.getAlias());
Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
List<String> topics = new ArrayList<>();
List<Topic<Category<SubCategory<Section<Indicator>>>>> topicsFull = new ArrayList<>();
for(Topic topic : stakeholderFull.getTopics()) {
Topic<Category<SubCategory<Section<Indicator>>>> topicFull = topicController.buildTopic(topic);
topicsFull.add(topicFull);
topics.add(topicFull.getId());
}
stakeholderFull.setTopics(topicsFull);
stakeholder.setTopics(topics);
Stakeholder stakeholder = new Stakeholder(stakeholderFull);
stakeholderFull.setTopics(stakeholderFull.getTopics().stream().map(topic -> topicController.buildTopic(topic)));
stakeholder.setTopics(stakeholderFull.getTopics().stream().map(TopicFull::getId).collect(Collectors.toList()));
Date date = new Date();
stakeholder.setCreationDate(date);
stakeholder.setUpdateDate(date);
stakeholderFull.setCreationDate(date);
stakeholderFull.setUpdateDate(date);
Stakeholder<String> stakeholderSaved = stakeholderDAO.save(stakeholder);
stakeholderFull.setId(stakeholderSaved.getId());
stakeholder = stakeholderDAO.save(stakeholder);
stakeholderFull.setId(stakeholder.getId());
Portal portal = portalService.getPortal(stakeholderFull.getAlias());
if (portal == null) {
portal = new Portal();
@ -102,182 +64,21 @@ public class StakeholderController {
portal.setType(stakeholderFull.getType());
portalService.insertPortal(portal);
}
return stakeholderFull;
//return null;
}
}*/
public Stakeholder setFullEntities(Stakeholder<String> stakeholder) {
boolean addAll = false;
boolean addPublicAndRestricted = false;
if(rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
addAll = true;
addPublicAndRestricted = true;
} else if(rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())) {
addPublicAndRestricted = true;
}
Stakeholder<Topic> stakeholderFull = new Stakeholder<>(stakeholder);
List<Topic> topics = new ArrayList<>();
for (String topicId: (List<String>)stakeholder.getTopics()) {
Topic<String> topic = topicDAO.findById(topicId);
if(topic == null) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException("Get stakeholder: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")");
}
if((!addAll && topic.getVisibility() == Visibility.PRIVATE)
|| (!addPublicAndRestricted && topic.getVisibility() == Visibility.RESTRICTED)) {
continue;
}
Topic<Category> topicFull = new Topic<Category>(topic);
List<Category> categories = new ArrayList<>();
for(String categoryId : topic.getCategories()) {
Category<String> category = categoryDAO.findById(categoryId);
if(category == null) {
// EXCEPTION - Category not found
throw new EntityNotFoundException("Get stakeholder: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
}
if((!addAll && category.getVisibility() == Visibility.PRIVATE)
|| (!addPublicAndRestricted && category.getVisibility() == Visibility.RESTRICTED)) {
continue;
}
Category<SubCategory> categoryFull = new Category<SubCategory>(category);
List<SubCategory> subCategories = new ArrayList<>();
for(String subCategoryId : category.getSubCategories()) {
SubCategory<String> subCategory = subCategoryDAO.findById(subCategoryId);
if(subCategory == null) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException("Get stakeholder: SubCategory with id: "+subCategoryId+" not found (subCategory exists in category: "+categoryId+")");
}
if((!addAll && subCategory.getVisibility() == Visibility.PRIVATE)
|| (!addPublicAndRestricted && subCategory.getVisibility() == Visibility.RESTRICTED)) {
continue;
}
SubCategory subCategoryFull = new SubCategory<Section<Indicator>>(subCategory);
List<Section> sectionsCharts = new ArrayList<>();
for(String sectionId : subCategory.getCharts()) {
sectionsCharts.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted));
}
subCategoryFull.setCharts(sectionsCharts);
List<Section> sectionsNumbers = new ArrayList<>();
for(String sectionId : subCategory.getNumbers()) {
sectionsNumbers.add(getSectionFull(sectionId, subCategoryId, addAll, addPublicAndRestricted));
}
subCategoryFull.setNumbers(sectionsNumbers);
subCategories.add(subCategoryFull);
}
categoryFull.setSubCategories(subCategories);
categories.add(categoryFull);
}
topicFull.setCategories(categories);
topics.add(topicFull);
}
stakeholderFull.setTopics(topics);
return stakeholderFull;
}
private Section getSectionFull(String sectionId, String subCategoryId, boolean addAll, boolean addPublicAndRestricted) {
Section<String> section = sectionDAO.findById(sectionId);
if (section == null) {
// EXCEPTION - Section not found
throw new EntityNotFoundException("Get stakeholder: Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategoryId + ")");
}
Section sectionFull = new Section<Indicator>(section);
List<Indicator> indicators = new ArrayList<>();
for (String indicatorId : section.getIndicators()) {
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 section: " + sectionId + ")");
}
if((!addAll && indicator.getVisibility() == Visibility.PRIVATE)
|| (!addPublicAndRestricted && indicator.getVisibility() == Visibility.RESTRICTED)) {
continue;
}
indicators.add(indicator);
}
sectionFull.setIndicators(indicators);
return sectionFull;
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN)")
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) {
// log.debug("get all stakeholders" + (type != null ? " with type: "+type : ""));
List<Stakeholder> stakeholders;
if(type == null) {
stakeholders = stakeholderDAO.findAll();
} else {
stakeholders = stakeholderDAO.findByType(type);
}
List<Stakeholder> stakeholdersFull = new ArrayList<>();
for(Stakeholder stakeholder : stakeholders) {
stakeholdersFull.add(this.setFullEntities(stakeholder));
}
return stakeholdersFull;
return this.stakeholderService.getAll(type);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
public List<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
// log.debug("get all default stakeholders" + (type != null ? " with type: "+type : ""));
List<Stakeholder> stakeholders;
if(type == null) {
stakeholders = stakeholderDAO.findByDefaultId(null);
} else {
stakeholders = stakeholderDAO.findByDefaultIdAndType(null, type);
}
List<Stakeholder> stakeholdersFull = new ArrayList<>();
// Remove stakeholders for which i do not have authority
if(stakeholders != null && stakeholders.size() > 0) {
if (rolesUtils.isPortalAdmin()) {
for(Stakeholder stakeholder : stakeholders) {
stakeholdersFull.add(this.setFullEntities(stakeholder));
}
return stakeholdersFull;
}
Iterator<Stakeholder> stakeholderIterator = stakeholders.iterator();
while(stakeholderIterator.hasNext()) {
Stakeholder stakeholder = stakeholderIterator.next();
if(rolesUtils.isCurator(stakeholder.getType())) {
stakeholdersFull.add(this.setFullEntities(stakeholder));
continue;
}
stakeholderIterator.remove();
}
}
return stakeholdersFull;
public List<StakeholderFull> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
return this.stakeholderService.getAllDefaultByRole(type).stream()
.map(stakeholder -> this.stakeholderService.getFullStakeholder(stakeholder))
.collect(Collectors.toList());
}
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
@ -293,57 +94,33 @@ public class StakeholderController {
}
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
public Stakeholder getStakeholder(@PathVariable("alias") String alias) {
Stakeholder<String> stakeholder = stakeholderDAO.findByAlias(alias);
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
if (stakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("Get stakeholder: Stakeholder with alias: "+alias+" not found");
}
if(stakeholder.getDefaultId() == null && !rolesUtils.isLoggedIn()) {
// EXCEPTION - Unauthorized
throw new AccessDeniedException("Get stakeholder: You are not authorized (not logged in) to access stakeholder with alias: "+alias);
}
if(stakeholder.getDefaultId() == null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
// EXCEPTION - Access denied
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
}
if((stakeholder.getVisibility() == Visibility.PRIVATE && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())
|| (stakeholder.getVisibility() == Visibility.RESTRICTED && !rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias()) && !rolesUtils.isMember(stakeholder.getType(), stakeholder.getAlias())))) {
// // EXCEPTION - Access denied
List<String> topicsEmpty = stakeholder.getTopics();
topicsEmpty.clear();
stakeholder.setTopics(topicsEmpty);
stakeholder.setVisibility(Visibility.PRIVATE);
return stakeholder;
}
return this.setFullEntities(stakeholder);
}
@PreAuthorize("hasAnyAuthority("
/*@PreAuthorize("hasAnyAuthority("
+ "@AuthorizationService.PORTAL_ADMIN, "
+ "@AuthorizationService.curator(#_stakeholder.getType()), "
+ "@AuthorizationService.manager(#_stakeholder.getType(), #_stakeholder.getAlias()) "
+ ")")
@RequestMapping(value = "/save", method = RequestMethod.POST)
public Stakeholder saveStakeholder(@RequestBody Stakeholder _stakeholder) {
public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) {
log.debug("save stakeholder");
log.debug("Alias: "+_stakeholder.getAlias() + " - Id: "+_stakeholder.getId());
Stakeholder<String> stakeholder = new Stakeholder<>(_stakeholder);
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
Date date = new Date();
stakeholder.setUpdateDate(date);
List<String> topics = new ArrayList<>();
if(_stakeholder.getId() == null) {
if (stakeholder.getId() == null) {
stakeholder.setCreationDate(date);
} else {
Stakeholder<String> oldStakeholder = stakeholderDAO.findById(_stakeholder.getId());
Stakeholder oldStakeholder = stakeholderDAO.findById(stakeholder.getId());
if (oldStakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("save stakeholder: Stakeholder with id: "+_stakeholder.getId()+" not found");
throw new EntityNotFoundException("save stakeholder: Stakeholder with id: " + stakeholder.getId() + " not found");
}
for (String topicId : oldStakeholder.getTopics()) {
Topic topic = topicDAO.findById(topicId);
@ -355,20 +132,16 @@ public class StakeholderController {
}
}
stakeholder.setTopics(topics);
Stakeholder<String> stakeholderSaved = stakeholderDAO.save(stakeholder);
_stakeholder.setId(stakeholderSaved.getId());
_stakeholder.setCreationDate(stakeholderSaved.getCreationDate());
_stakeholder.setUpdateDate(stakeholderSaved.getUpdateDate());
return _stakeholder;
}
return stakeholderDAO.save(stakeholder);
}*/
@PreAuthorize("isAuthenticated()")
/* @PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/delete", method = RequestMethod.DELETE)
public boolean deleteStakeholder(@PathVariable("stakeholderId") String stakeholderId) {
log.debug("delete stakeholder");
log.debug("Id: " + stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
String pid = null;
if (stakeholder != null) {
@ -390,9 +163,9 @@ public class StakeholderController {
throw new EntityNotFoundException("Delete stakeholder: Stakeholder with id: " + stakeholderId + " not found");
}
return true;
}
}*/
@PreAuthorize("isAuthenticated()")
/*@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
public Stakeholder changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
@ -412,7 +185,7 @@ public class StakeholderController {
return changeStakeholderVisibilityTree(stakeholder, visibility, propagate);
}
private Stakeholder changeStakeholderVisibilityTree(Stakeholder<String> stakeholder, Visibility visibility, Boolean propagate) {
private Stakeholder changeStakeholderVisibilityTree(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {
Stakeholder<Topic> stakeholderFull = new Stakeholder<>(stakeholder);
List<Topic> topicsFull = new ArrayList<>();
@ -430,5 +203,5 @@ public class StakeholderController {
stakeholderFull.setTopics(topicsFull);
return stakeholder;
}
}*/
}

View File

@ -1,3 +1,4 @@
/*
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
@ -6,6 +7,7 @@ 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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@ -145,7 +147,7 @@ public class SubCategoryController {
subCategory.setCharts(chartSections);
subCategory.setNumbers(numberSections);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder.getDefaultId() == null) {
if(subcategoryFull.getId() == null) {
subCategoryDAO.save(subCategory);
@ -230,7 +232,7 @@ public class SubCategoryController {
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
if(subcategory != null) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(subcategory.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
// EXCEPTION - Access denied
throw new ForbiddenException("Delete subcategory: You are not authorized to delete a default SubCategory in stakeholder with id: "+stakeholderId);
@ -398,7 +400,7 @@ public class SubCategoryController {
private Category checkForExceptions(String stakeholderId, String topicId, String categoryId) {
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder == null) {
// EXCEPTION - Stakeholder not found
@ -464,3 +466,4 @@ public class SubCategoryController {
}
}
}
*/

View File

@ -1,11 +1,14 @@
/*
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,9 +40,8 @@ public class TopicController {
@Autowired
private CategoryDAO categoryDAO;
public Topic<Category> buildTopic(Topic<Category> topicFull) {
Topic<String> topic = new Topic<>(topicFull);
public TopicFull buildTopic(TopicFull topicFull) {
Topic topic = new Topic(topicFull);
List<String> categories = new ArrayList<>();
List<Category> categoriesFull = new ArrayList<>();
for(Category<SubCategory> category : topicFull.getCategories()) {
@ -70,7 +72,7 @@ public class TopicController {
log.debug("save topic");
log.debug("Alias: "+topicFull.getAlias() + " - Id: "+topicFull.getId()+ " - Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@ -198,7 +200,7 @@ public class TopicController {
log.debug("delete topic");
log.debug("Id: "+topicId + " - Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
@ -296,7 +298,7 @@ public class TopicController {
log.debug("reorder topics");
log.debug("Stakeholder: "+stakeholderId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if(stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@ -340,7 +342,7 @@ public class TopicController {
log.debug("change topic visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
if (stakeholder != null) {
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
@ -399,3 +401,4 @@ public class TopicController {
}
}
}
*/

View File

@ -5,15 +5,16 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface CategoryDAO extends MongoRepository<Category, String> {
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
Category findBySubCategoriesContaining(String subCategory);
Optional<Category> findBySubCategoriesContaining(String subCategory);
Category findById(String Id);
Optional<Category> findById(String Id);
void delete(String Id);

View File

@ -5,13 +5,14 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface IndicatorDAO extends MongoRepository<Indicator, String> {
List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId);
Indicator findById(String Id);
Optional<Indicator> findById(String Id);
void delete(String Id);

View File

@ -5,13 +5,14 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface SectionDAO extends MongoRepository<Section, String> {
List<Section> findAll();
List<Section> findByDefaultId(String DefaultId);
Section findById(String Id);
Optional<Section> findById(String Id);
void delete(String Id);

View File

@ -5,6 +5,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
@ -17,10 +18,10 @@ public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
List<Stakeholder> findByDefaultIdNot(String DefaultId);
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
Stakeholder findByTopicsContaining(String topic);
Optional<Stakeholder> findByTopicsContaining(String topic);
Stakeholder findById(String Id);
Stakeholder findByAlias(String Alias);
Optional<Stakeholder> findById(String Id);
Optional<Stakeholder> findByAlias(String Alias);
void delete(String Id);

View File

@ -5,13 +5,14 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface SubCategoryDAO extends MongoRepository<SubCategory, String> {
List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String DefaultId);
SubCategory findById(String Id);
Optional<SubCategory> findById(String Id);
void delete(String Id);

View File

@ -5,15 +5,16 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface TopicDAO extends MongoRepository<Topic, String> {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
Topic findByCategoriesContaining(String category);
Optional<Topic> findByCategoriesContaining(String category);
Topic findById(String Id);
Optional<Topic> findById(String Id);
void delete(String Id);

View File

@ -0,0 +1,18 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.generics.CategoryGeneric;
import java.util.List;
import java.util.Objects;
public class CategoryFull extends CategoryGeneric<SubCategoryFull> {
public CategoryFull() {
super();
}
public CategoryFull(CategoryGeneric category, List<SubCategoryFull> subCategories) {
super(category);
subCategories.removeIf(Objects::isNull);
this.setSubCategories(subCategories);
}
}

View File

@ -0,0 +1,19 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.dao.IndicatorDAO;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
import eu.dnetlib.uoamonitorservice.generics.SectionGeneric;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import java.util.List;
import java.util.stream.Collectors;
public class SectionFull extends SectionGeneric<Indicator> {
public SectionFull() {}
public SectionFull(Section section, List<Indicator> indicators) {
super(section);
this.setIndicators(indicators);
}
}

View File

@ -0,0 +1,15 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import java.util.List;
import java.util.Objects;
public class StakeholderFull extends StakeholderGeneric<TopicFull> {
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
super(stakeholder);
topics.removeIf(Objects::isNull);
this.setTopics(topics);
}
}

View File

@ -0,0 +1,18 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.generics.SubCategoryGeneric;
import java.util.List;
import java.util.Objects;
public class SubCategoryFull extends SubCategoryGeneric<SectionFull> {
public SubCategoryFull() {}
public SubCategoryFull(SubCategoryGeneric subCategory, List<SectionFull> numbers, List<SectionFull> charts) {
super(subCategory);
numbers.removeIf(Objects::isNull);
charts.removeIf(Objects::isNull);
this.setNumbers(numbers);
this.setCharts(charts);
}
}

View File

@ -0,0 +1,18 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.generics.TopicGeneric;
import java.util.List;
import java.util.Objects;
public class TopicFull extends TopicGeneric<CategoryFull> {
public TopicFull() {
super();
}
public TopicFull(TopicGeneric topic, List<CategoryFull> categories) {
super(topic);
categories.removeIf(Objects::isNull);
this.setCategories(categories);
}
}

View File

@ -1,129 +1,30 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import eu.dnetlib.uoamonitorservice.dto.CategoryFull;
import eu.dnetlib.uoamonitorservice.generics.CategoryGeneric;
import eu.dnetlib.uoamonitorservice.generics.TopicGeneric;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Category<StringOrSubcategory> {
@Id
@JsonProperty("_id")
private String id;
private String name;
private String alias;
private String description;
private Visibility visibility = Visibility.PRIVATE;
private Date creationDate;
private Date updateDate;
private boolean isOverview;
private String defaultId;
private List<StringOrSubcategory> subCategories;
public Category() {}
public Category(Category category) {
id = category.getId();
name = category.getName();
alias = category.getAlias();
description = category.getDescription();
setVisibility(category.getVisibility());
creationDate = category.getCreationDate();
updateDate = category.getUpdateDate();
isOverview = category.getIsOverview();
defaultId = category.getDefaultId();
@Document
public class Category extends CategoryGeneric<String> {
public Category() {
super();
}
public void copyFromDefault(Category defaultCategory) {
public Category(CategoryFull category) {
super(category);
}
public void copyFromDefault(CategoryGeneric defaultCategory) {
setName(defaultCategory.getName());
setAlias(defaultCategory.getAlias());
setDescription(defaultCategory.getDescription());
setVisibility(defaultCategory.getVisibility());
setCreationDate(defaultCategory.getCreationDate());
setUpdateDate(defaultCategory.getUpdateDate());
setIsOverview(defaultCategory.getIsOverview());
setDefaultId(defaultCategory.getId());
setSubCategories(new ArrayList());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public boolean getIsOverview() {
return isOverview;
}
public void setIsOverview(boolean isOverview) {
this.isOverview = isOverview;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrSubcategory> getSubCategories() {
return subCategories;
}
public void setSubCategories(List<StringOrSubcategory> subCategories) {
this.subCategories = subCategories;
setSubCategories(new ArrayList<>());
}
}

View File

@ -1,28 +1,30 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorPath;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorSize;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.Date;
import java.util.List;
public class Indicator {
public class Indicator extends Common {
@Id
@JsonProperty("_id")
private String id;
private String name;
private String description;
private String additionalDescription;
private IndicatorType type; //number,chart
private IndicatorSize width; //small,medium,large
private IndicatorSize height = IndicatorSize.MEDIUM; //small,medium,large
private List<String> tags; // this field is not used anywhere now
private Visibility visibility = Visibility.PRIVATE;
@CreatedDate
private Date creationDate;
@LastModifiedDate
private Date updateDate;
private String defaultId;
private List<IndicatorPath> indicatorPaths;
@ -50,22 +52,6 @@ public class Indicator {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAdditionalDescription() {
return additionalDescription;
}
@ -81,13 +67,6 @@ public class Indicator {
return type.name();
}
// public String getStringType() {
// return type.name();
// }
// public void setType(IndicatorType type) {
// this.type = type;
// }
public void setType(String type) {
if(type == null) {
this.type = null;
@ -121,14 +100,6 @@ public class Indicator {
this.tags = tags;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Date getCreationDate() {
return creationDate;
}

View File

@ -1,115 +1,21 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import org.springframework.data.annotation.Id;
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
import eu.dnetlib.uoamonitorservice.generics.SectionGeneric;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class Section<StringOrIndicator> {
@Id
@JsonProperty("_id")
private String id;
private String title;
private String defaultId;
private String stakeholderAlias;
private IndicatorType type;
private Date creationDate;
private Date updateDate;
private List<StringOrIndicator> indicators;
@Document
public class Section extends SectionGeneric<String> {
public Section() {}
public Section(Section section) {
id = section.getId();
title = section.getTitle();
defaultId = section.getDefaultId();
stakeholderAlias = section.getStakeholderAlias();
setType(section.getType());
creationDate = section.getCreationDate();
updateDate = section.getUpdateDate();
}
public void copyFromDefault(Section defaultSection) {
setTitle(defaultSection.getTitle());
setType(defaultSection.getType());
setDefaultId(defaultSection.id);
setCreationDate(defaultSection.getCreationDate());
setUpdateDate(defaultSection.getUpdateDate());
setIndicators(new ArrayList<>());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public String getStakeholderAlias() {
return stakeholderAlias;
}
public void setStakeholderAlias(String stakeholderAlias) {
this.stakeholderAlias = stakeholderAlias;
}
public String getType() {
if(type == null) {
return null;
}
return type.name();
}
public void setType(String type) {
if(type == null) {
this.type = null;
} else {
this.type = IndicatorType.valueOf(type);
}
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public List<StringOrIndicator> getIndicators() {
return indicators;
}
public void setIndicators(List<StringOrIndicator> indicators) {
this.indicators = indicators;
public Section(SectionFull section) {
super(section);
List<String> indicators = section.getIndicators().stream().map(Indicator::getId).collect(Collectors.toList());
indicators.removeIf(Objects::isNull);
this.setIndicators(indicators);
}
}

View File

@ -1,224 +1,16 @@
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 eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
import java.util.List;
public class Stakeholder<StringOrTopic> {
@Id
@JsonProperty("_id")
private String id;
private StakeholderType type; // private StakeholderType type;
private Date projectUpdateDate = null;
private String index_id;
private String index_name;
private String index_shortName;
private String statsProfile = "monitor";
private String logoUrl;
private boolean isUpload = false;
private String name;
private String alias;
private String description;
private String defaultId = null;
private Locale locale = Locale.EU;
private Visibility visibility = Visibility.PRIVATE;
private String funderType;
private Date creationDate;
private Date updateDate;
private List<StringOrTopic> topics;
@Document
public class Stakeholder extends StakeholderGeneric<String> {
public Stakeholder() {
}
public Stakeholder(Stakeholder stakeholder) {
id = stakeholder.getId();
setType(stakeholder.getType());
projectUpdateDate = stakeholder.getProjectUpdateDate();
index_id = stakeholder.getIndex_id();
index_name = stakeholder.getIndex_name();
index_shortName = stakeholder.getIndex_shortName();
statsProfile = stakeholder.getStatsProfile();
logoUrl = stakeholder.getLogoUrl();
isUpload = stakeholder.getIsUpload();
name = stakeholder.getName();
alias = stakeholder.getAlias();
description = stakeholder.getDescription();
defaultId = stakeholder.getDefaultId();
setLocale(stakeholder.getLocale());
setVisibility(stakeholder.getVisibility());
this.funderType = stakeholder.getFunderType();
creationDate = stakeholder.getCreationDate();
updateDate = stakeholder.getUpdateDate();
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
if(type == null) {
return null;
}
return type.name();
}
public void setType(String type) {
if(type == null) {
this.type = null;
} else {
StakeholderType stakeholderType = StakeholderType.valueOf(type);
this.type = stakeholderType;
}
}
public Date getProjectUpdateDate() {
return projectUpdateDate;
}
public void setProjectUpdateDate(Date projectUpdateDate) {
this.projectUpdateDate = projectUpdateDate;
}
public String getIndex_id() {
return index_id;
}
public void setIndex_id(String index_id) {
this.index_id = index_id;
}
public String getIndex_name() {
return index_name;
}
public void setIndex_name(String index_name) {
this.index_name = index_name;
}
public String getIndex_shortName() {
return index_shortName;
}
public void setIndex_shortName(String index_shortName) {
this.index_shortName = index_shortName;
}
public String getStatsProfile() {
return statsProfile;
}
public void setStatsProfile(String statsProfile) {
this.statsProfile = statsProfile;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public boolean getIsUpload() {
return isUpload;
}
public void setIsUpload(boolean isUpload) {
this.isUpload = isUpload;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public String getLocale() {
return locale.label;
}
public void setLocale(String label) {
Locale locale = null;
for (Locale l : Locale.values()) {
if (l.label.equals(label)) {
locale = l;
}
}
this.locale = locale;
}
public Visibility getVisibility() {
//return visibility.getLabel();
return visibility;
}
public void setVisibility(Visibility visibility) {
//this.visibility = Visibility.get(visibility);
this.visibility = visibility;
}
public String getFunderType() {
return funderType;
}
public void setFunderType(String funderType) {
this.funderType = funderType;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public List<StringOrTopic> getTopics() {
return topics;
}
public void setTopics(List<StringOrTopic> topics) {
this.topics = topics;
public Stakeholder(StakeholderGeneric stakeholder) {
super(stakeholder);
}
}

View File

@ -1,138 +1,13 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class SubCategory<StringOrSection> {
@Id
@JsonProperty("_id")
private String id;
private String name;
private String alias;
private String description;
private Visibility visibility = Visibility.PRIVATE;
private Date creationDate;
private Date updateDate;
private String defaultId;
private List<StringOrSection> charts;
private List<StringOrSection> numbers;
import eu.dnetlib.uoamonitorservice.generics.SubCategoryGeneric;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
public class SubCategory extends SubCategoryGeneric<String> {
public SubCategory() {}
public SubCategory(SubCategory subCategory) {
id = subCategory.getId();
name = subCategory.getName();
alias = subCategory.getAlias();
description = subCategory.getDescription();
setVisibility(subCategory.getVisibility());
creationDate = subCategory.getCreationDate();
updateDate = subCategory.getUpdateDate();
defaultId = subCategory.getDefaultId();
}
public void createOverviewSubCategory(Category category) {
setName("Overview");
setAlias("overview");
setVisibility(category.getVisibility());
setCreationDate(category.getCreationDate());
setUpdateDate(category.getUpdateDate());
setCharts(new ArrayList<>());
setNumbers(new ArrayList<>());
}
public void copyFromDefault(SubCategory defaultSubCategory) {
setName(defaultSubCategory.getName());
setAlias(defaultSubCategory.getAlias());
setDescription(defaultSubCategory.getDescription());
setVisibility(defaultSubCategory.getVisibility());
setCreationDate(defaultSubCategory.getCreationDate());
setUpdateDate(defaultSubCategory.getUpdateDate());
setDefaultId(defaultSubCategory.getId());
setCharts(new ArrayList());
setNumbers(new ArrayList());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrSection> getCharts() {
return charts;
}
public void setCharts(List<StringOrSection> charts) {
this.charts = charts;
}
public List<StringOrSection> getNumbers() {
return numbers;
}
public void setNumbers(List<StringOrSection> numbers) {
this.numbers = numbers;
public SubCategory(SubCategoryGeneric subCategory) {
super(subCategory);
}
}

View File

@ -1,129 +1,15 @@
package eu.dnetlib.uoamonitorservice.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import eu.dnetlib.uoamonitorservice.generics.TopicGeneric;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Document
public class Topic extends TopicGeneric<String> {
public class Topic<StringOrCategory> {
@Id
@JsonProperty("_id")
private String id;
private String name;
private String alias;
private String description;
private String icon;
private Visibility visibility = Visibility.PRIVATE;
private Date creationDate;
private Date updateDate;
private String defaultId;
private List<StringOrCategory> categories;
public Topic() {}
public Topic(Topic topic) {
id = topic.getId();
name = topic.getName();
alias = topic.getAlias();
description = topic.getDescription();
icon = topic.getIcon();
setVisibility(topic.getVisibility());
creationDate = topic.getCreationDate();
updateDate = topic.getUpdateDate();
defaultId = topic.getDefaultId();
public Topic() {
super();
}
public void copyFromDefault(Topic defaultTopic) {
setName(defaultTopic.getName());
setAlias(defaultTopic.getAlias());
setDescription(defaultTopic.getDescription());
setIcon(defaultTopic.getIcon());
setVisibility(defaultTopic.getVisibility());
setCreationDate(defaultTopic.getCreationDate());
setUpdateDate(defaultTopic.getUpdateDate());
setDefaultId(defaultTopic.getId());
setCategories(new ArrayList());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrCategory> getCategories() {
return categories;
}
public void setCategories(List<StringOrCategory> categories) {
this.categories = categories;
public Topic(TopicGeneric topic) {
super(topic);
}
}

View File

@ -1,38 +0,0 @@
package eu.dnetlib.uoamonitorservice.entities;
import java.util.HashMap;
import java.util.Map;
public enum Visibility {
// Do not rename or remove existring values. This may cause problems with already stored values in DB
// PUBLIC("public"), RESTRICTED("restricted"), PRIVATE("private");
PUBLIC, RESTRICTED, PRIVATE
// private String label;
//
// private Visibility(String label) {
// this.label = label;
// }
//
// public String getLabel() {
// return this.label;
// }
//
// //Lookup table
// private static final Map<String, Visibility> lookup = new HashMap<>();
//
// //Populate the lookup table on loading time
// static
// {
// for(Visibility visibility : Visibility.values())
// {
// lookup.put(visibility.getLabel(), visibility);
// }
// }
//
// //This method can be used for reverse lookup purpose
// public static Visibility get(String visibility)
// {
// return lookup.get(visibility);
// }
}

View File

@ -0,0 +1,88 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Document
public class CategoryGeneric<StringOrSubcategory> extends Common {
@Id
@JsonProperty("_id")
protected String id;
@CreatedDate
protected Date creationDate;
@LastModifiedDate
protected Date updateDate;
protected boolean isOverview;
protected String defaultId;
protected List<StringOrSubcategory> subCategories;
public CategoryGeneric() {}
public CategoryGeneric(CategoryGeneric category) {
id = category.getId();
name = category.getName();
alias = category.getAlias();
description = category.getDescription();
setVisibility(category.getVisibility());
creationDate = category.getCreationDate();
updateDate = category.getUpdateDate();
defaultId = category.getDefaultId();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public boolean getIsOverview() {
return isOverview;
}
public void setIsOverview(boolean isOverview) {
this.isOverview = isOverview;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrSubcategory> getSubCategories() {
return subCategories;
}
public void setSubCategories(List<StringOrSubcategory> subCategories) {
this.subCategories = subCategories;
}
}

View File

@ -0,0 +1,42 @@
package eu.dnetlib.uoamonitorservice.generics;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
public class Common {
protected String name;
protected String description;
protected String alias;
protected Visibility visibility = Visibility.PRIVATE;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
}

View File

@ -0,0 +1,119 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class SectionGeneric<StringOrIndicator> {
@Id
@JsonProperty("_id")
protected String id;
protected String title;
protected String defaultId;
protected String stakeholderAlias;
protected IndicatorType type;
@CreatedDate
protected Date creationDate;
@LastModifiedDate
protected Date updateDate;
protected List<StringOrIndicator> indicators;
public SectionGeneric() {
}
public SectionGeneric(SectionGeneric section) {
id = section.getId();
title = section.getTitle();
defaultId = section.getDefaultId();
stakeholderAlias = section.getStakeholderAlias();
setType(section.getType());
creationDate = section.getCreationDate();
updateDate = section.getUpdateDate();
}
public void copyFromDefault(SectionGeneric defaultSection) {
setTitle(defaultSection.getTitle());
setType(defaultSection.getType());
setDefaultId(defaultSection.id);
setCreationDate(defaultSection.getCreationDate());
setUpdateDate(defaultSection.getUpdateDate());
setIndicators(new ArrayList<>());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public String getStakeholderAlias() {
return stakeholderAlias;
}
public void setStakeholderAlias(String stakeholderAlias) {
this.stakeholderAlias = stakeholderAlias;
}
public String getType() {
if (type == null) {
return null;
}
return type.name();
}
public void setType(String type) {
if (type == null) {
this.type = null;
} else {
this.type = IndicatorType.valueOf(type);
}
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public List<StringOrIndicator> getIndicators() {
return indicators;
}
public void setIndicators(List<StringOrIndicator> indicators) {
this.indicators = indicators;
}
}

View File

@ -0,0 +1,193 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.Locale;
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.Date;
import java.util.List;
public class StakeholderGeneric<StringOrTopic> extends Common {
@Id
@JsonProperty("_id")
protected String id;
protected StakeholderType type;
protected Date projectUpdateDate = null;
protected String index_id;
protected String index_name;
protected String index_shortName;
protected String statsProfile = "monitor";
protected String logoUrl;
protected boolean isUpload = false;
protected String defaultId = null;
protected Locale locale = Locale.EU;
protected String funderType;
@CreatedDate
protected Date creationDate;
@LastModifiedDate
protected Date updateDate;
protected List<StringOrTopic> topics;
public StakeholderGeneric() {
}
public StakeholderGeneric(StakeholderGeneric stakeholder) {
id = stakeholder.getId();
setType(stakeholder.getType());
projectUpdateDate = stakeholder.getProjectUpdateDate();
index_id = stakeholder.getIndex_id();
index_name = stakeholder.getIndex_name();
index_shortName = stakeholder.getIndex_shortName();
statsProfile = stakeholder.getStatsProfile();
logoUrl = stakeholder.getLogoUrl();
isUpload = stakeholder.getIsUpload();
name = stakeholder.getName();
alias = stakeholder.getAlias();
description = stakeholder.getDescription();
defaultId = stakeholder.getDefaultId();
setLocale(stakeholder.getLocale());
setVisibility(stakeholder.getVisibility());
this.funderType = stakeholder.getFunderType();
creationDate = stakeholder.getCreationDate();
updateDate = stakeholder.getUpdateDate();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
if (type == null) {
return null;
}
return type.name();
}
public void setType(String type) {
if (type == null) {
this.type = null;
} else {
StakeholderType stakeholderType = StakeholderType.valueOf(type);
this.type = stakeholderType;
}
}
public Date getProjectUpdateDate() {
return projectUpdateDate;
}
public void setProjectUpdateDate(Date projectUpdateDate) {
this.projectUpdateDate = projectUpdateDate;
}
public String getIndex_id() {
return index_id;
}
public void setIndex_id(String index_id) {
this.index_id = index_id;
}
public String getIndex_name() {
return index_name;
}
public void setIndex_name(String index_name) {
this.index_name = index_name;
}
public String getIndex_shortName() {
return index_shortName;
}
public void setIndex_shortName(String index_shortName) {
this.index_shortName = index_shortName;
}
public String getStatsProfile() {
return statsProfile;
}
public void setStatsProfile(String statsProfile) {
this.statsProfile = statsProfile;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public boolean getIsUpload() {
return isUpload;
}
public void setIsUpload(boolean isUpload) {
this.isUpload = isUpload;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public String getLocale() {
return locale.label;
}
public void setLocale(String label) {
Locale locale = null;
for (Locale l : Locale.values()) {
if (l.label.equals(label)) {
locale = l;
}
}
this.locale = locale;
}
public String getFunderType() {
return funderType;
}
public void setFunderType(String funderType) {
this.funderType = funderType;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public List<StringOrTopic> getTopics() {
return topics;
}
public void setTopics(List<StringOrTopic> topics) {
this.topics = topics;
}
}

View File

@ -0,0 +1,107 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class SubCategoryGeneric<StringOrSection> extends Common {
@Id
@JsonProperty("_id")
protected String id;
@CreatedDate
protected Date creationDate;
@LastModifiedDate
protected Date updateDate;
protected String defaultId;
protected List<StringOrSection> charts;
protected List<StringOrSection> numbers;
public SubCategoryGeneric() {}
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
id = subCategory.getId();
name = subCategory.getName();
alias = subCategory.getAlias();
description = subCategory.getDescription();
setVisibility(subCategory.getVisibility());
creationDate = subCategory.getCreationDate();
updateDate = subCategory.getUpdateDate();
defaultId = subCategory.getDefaultId();
}
public void createOverviewSubCategory(Category category) {
setName("Overview");
setAlias("overview");
setVisibility(category.getVisibility());
setCreationDate(category.getCreationDate());
setUpdateDate(category.getUpdateDate());
setCharts(new ArrayList<>());
setNumbers(new ArrayList<>());
}
public void copyFromDefault(SubCategoryGeneric defaultSubCategory) {
setName(defaultSubCategory.getName());
setAlias(defaultSubCategory.getAlias());
setDescription(defaultSubCategory.getDescription());
setVisibility(defaultSubCategory.getVisibility());
setCreationDate(defaultSubCategory.getCreationDate());
setUpdateDate(defaultSubCategory.getUpdateDate());
setDefaultId(defaultSubCategory.getId());
setCharts(new ArrayList());
setNumbers(new ArrayList());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrSection> getCharts() {
return charts;
}
public void setCharts(List<StringOrSection> charts) {
this.charts = charts;
}
public List<StringOrSection> getNumbers() {
return numbers;
}
public void setNumbers(List<StringOrSection> numbers) {
this.numbers = numbers;
}
}

View File

@ -0,0 +1,100 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class TopicGeneric<StringOrCategory> extends Common {
@Id
@JsonProperty("_id")
protected String id;
protected String icon;
@CreatedDate
protected Date creationDate;
@LastModifiedDate
protected Date updateDate;
protected String defaultId;
protected List<StringOrCategory> categories;
public TopicGeneric() {
}
public TopicGeneric(TopicGeneric topic) {
id = topic.getId();
name = topic.getName();
alias = topic.getAlias();
description = topic.getDescription();
icon = topic.getIcon();
setVisibility(topic.getVisibility());
creationDate = topic.getCreationDate();
updateDate = topic.getUpdateDate();
defaultId = topic.getDefaultId();
}
public void copyFromDefault(TopicGeneric defaultTopic) {
setName(defaultTopic.getName());
setAlias(defaultTopic.getAlias());
setDescription(defaultTopic.getDescription());
setIcon(defaultTopic.getIcon());
setVisibility(defaultTopic.getVisibility());
setCreationDate(defaultTopic.getCreationDate());
setUpdateDate(defaultTopic.getUpdateDate());
setDefaultId(defaultTopic.getId());
setCategories(new ArrayList<>());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getDefaultId() {
return defaultId;
}
public void setDefaultId(String defaultId) {
this.defaultId = defaultId;
}
public List<StringOrCategory> getCategories() {
return categories;
}
public void setCategories(List<StringOrCategory> categories) {
this.categories = categories;
}
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.uoamonitorservice.primitives;
public enum Visibility {
PUBLIC, RESTRICTED, PRIVATE
}

View File

@ -0,0 +1,52 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
import eu.dnetlib.uoamonitorservice.dto.CategoryFull;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.entities.Topic;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;
import java.util.stream.Collectors;
@Service
public class CategoryService {
private final CategoryDAO dao;
private final SubCategoryService subCategoryService;
private final CommonService commonService;
@Autowired
public CategoryService(SubCategoryService subCategoryService, CommonService commonService, CategoryDAO dao) {
this.subCategoryService = subCategoryService;
this.commonService = commonService;
this.dao = dao;
}
public Category findByPath(Topic topic, String categoryId, String message) {
if (!topic.getCategories().contains(categoryId)) {
throw new PathNotValidException(message + ": Category with id: " + categoryId + " not found in Topic: " + topic.getId());
}
return this.dao.findById(categoryId).orElseThrow(() -> new EntityNotFoundException(message + ": Category with id: " + categoryId + " not found"));
}
public CategoryFull getFullCategory(String type, String alias, String categoryId) {
Category category = this.find(categoryId);
if(commonService.hasVisibilityAuthority(type, alias, category)) {
return new CategoryFull(category, category.getSubCategories().stream()
.map(subCategoryId -> this.subCategoryService.getFullSubCategory(type, alias, subCategoryId))
.collect(Collectors.toList()));
} else {
return null;
}
}
public Category find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Category with id: " + id + " not found"));
}
}

View File

@ -0,0 +1,37 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CommonService {
AuthorizationService authorizationService;
@Autowired
public CommonService(AuthorizationService authorizationService) {
this.authorizationService = authorizationService;
}
public boolean hasAccessAuthority(String type, String alias, boolean isDefault) {
if(this.authorizationService.isPortalAdmin() || this.authorizationService.isCurator(type)) {
return true;
} else if(!isDefault) {
return this.authorizationService.isManager(type, alias);
}
return false;
}
public boolean hasVisibilityAuthority(String type, String alias, Common common) {
if(authorizationService.isPortalAdmin() || authorizationService.isCurator(type) || authorizationService.isManager(type, alias)) {
return true;
} else if(authorizationService.isMember(type, alias) && common.getVisibility() != Visibility.PRIVATE) {
return true;
} else {
return common.getVisibility() == Visibility.PUBLIC;
}
}
}

View File

@ -0,0 +1,38 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoamonitorservice.dao.IndicatorDAO;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class IndicatorService {
private final IndicatorDAO dao;
private final CommonService commonService;
@Autowired
public IndicatorService(IndicatorDAO dao, CommonService commonService) {
this.dao = dao;
this.commonService = commonService;
}
public Indicator save(Indicator indicator) {
return this.dao.save(indicator);
}
public Indicator find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Indicator with id: " + id + " not found"));
}
public Indicator getIndicator(String type, String alias, String id) {
Indicator indicator = this.find(id);
if(this.commonService.hasVisibilityAuthority(type, alias, indicator)) {
return indicator;
} else {
return null;
}
}
}

View File

@ -0,0 +1,71 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoamonitorservice.dao.SectionDAO;
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class SectionService {
private final SectionDAO dao;
private final IndicatorService indicatorService;
@Autowired
public SectionService(SectionDAO dao, IndicatorService indicatorService) {
this.dao = dao;
this.indicatorService = indicatorService;
}
public SectionFull buildSection(SectionFull sectionFull) {
sectionFull.setIndicators(sectionFull.getIndicators().stream().map(indicator -> this.indicatorService.save(indicator)).collect(Collectors.toList()));
Section section = dao.save(new Section(sectionFull));
return new SectionFull(section, sectionFull.getIndicators());
}
public SectionFull changeVisibilityTree(String sectionId, Visibility visibility) {
Section section = this.find(sectionId);
SectionFull sectionFull = new SectionFull(section, section.getIndicators().stream().map(indicatorId -> this.indicatorService.find(indicatorId)).collect(Collectors.toList()));
sectionFull.setIndicators(sectionFull.getIndicators().stream().map(indicator -> {
indicator.setVisibility(visibility);
return indicatorService.save(indicator);
}).collect(Collectors.toList()));
return sectionFull;
}
public SectionFull saveSection(SectionFull sectionFull) {
Section section = new Section(sectionFull);
if(section.getId() != null) {
section.setIndicators(this.getIndicatorsId(section.getId()));
}
return sectionFull;
}
public Section find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Section with id: " + id + " not found"));
}
public SectionFull getFullSection(String type, String alias, String id) {
Section section = this.find(id);
return new SectionFull(section, section.getIndicators().stream()
.map(indicatorId -> this.indicatorService.getIndicator(type, alias, indicatorId))
.collect(Collectors.toList()));
}
public List<Indicator> getIndicators(String id) {
Section section = this.find(id);
return section.getIndicators().stream().map(this.indicatorService::find).collect(Collectors.toList());
}
public List<String> getIndicatorsId(String id) {
return this.getIndicators(id).stream().map(Indicator::getId).collect(Collectors.toList());
}
}

View File

@ -1,9 +1,11 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.Visibility;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -13,16 +15,39 @@ import java.util.stream.Collectors;
@Service
public class StakeholderService {
@Autowired
StakeholderDAO dao;
private final StakeholderDAO dao;
private final CommonService commonService;
private final TopicService topicService;
@Autowired
RolesUtils rolesUtils;
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService) {
this.dao = dao;
this.commonService = commonService;
this.topicService = topicService;
}
public Stakeholder findByAlias(String alias) {
return this.dao.findByAlias(alias).orElseThrow(() -> new EntityNotFoundException("Stakeholder with alias: " + alias + " not found"));
}
public List<String> getAllAliases() {
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
}
public List<Stakeholder> getAll(String type) {
if(type != null) {
return this.dao.findByType(type);
}
return this.dao.findAll();
}
public List<Stakeholder> getAllDefaultByRole(String type) {
return (type == null?this.dao.findByDefaultId(null):this.dao.findByDefaultIdAndType(null, type)).stream()
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), true))
.collect(Collectors.toList());
}
public List<Stakeholder> getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
List<Stakeholder> stakeholders;
if(type != null && defaultId != null) {
@ -35,12 +60,24 @@ public class StakeholderService {
stakeholders = dao.findByDefaultIdNot(null);
}
return stakeholders.stream().filter(stakeholder ->
(!manage &&
(stakeholder.getVisibility() == Visibility.PUBLIC
|| stakeholder.getVisibility() == Visibility.RESTRICTED))
|| rolesUtils.isPortalAdmin()
|| rolesUtils.isCurator(stakeholder.getType())
|| rolesUtils.isManager(stakeholder.getType(), stakeholder.getId()))
(!manage && (stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED))
|| this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
.collect(Collectors.toList());
}
public Stakeholder findByPath(String stakeholderId) {
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
}
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
if(this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder.getDefaultId() == null) ||
(stakeholder.getDefaultId() != null && this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder))) {
return new StakeholderFull(stakeholder,
stakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
.collect(Collectors.toList()));
} else {
return null;
}
}
}

View File

@ -0,0 +1,55 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
import eu.dnetlib.uoamonitorservice.dto.SubCategoryFull;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.entities.SubCategory;
import eu.dnetlib.uoamonitorservice.entities.Topic;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.stream.Collectors;
@Service
public class SubCategoryService {
private final SubCategoryDAO dao;
private final CommonService commonService;
private final SectionService sectionService;
@Autowired
public SubCategoryService( CommonService commonService, SubCategoryDAO dao, SectionService sectionService) {
this.commonService = commonService;
this.dao = dao;
this.sectionService = sectionService;
}
public SubCategory findByPath(Category category, String subcategoryId, String message) {
if (!category.getSubCategories().contains(subcategoryId)) {
throw new PathNotValidException(message + ": SubCategory with id: " + subcategoryId + " not found in Category: " + category.getId());
}
return this.dao.findById(subcategoryId).orElseThrow(() -> new EntityNotFoundException(message + ": SubCategory with id: " + subcategoryId + " not found"));
}
public SubCategoryFull getFullSubCategory(String type, String alias, String subCategoryId) {
SubCategory subCategory = this.find(subCategoryId);
if(commonService.hasVisibilityAuthority(type, alias, subCategory)) {
return new SubCategoryFull(subCategory, subCategory.getNumbers().stream()
.map(sectionId -> this.sectionService.getFullSection(type, alias, sectionId))
.collect(Collectors.toList()),
subCategory.getCharts().stream()
.map(sectionId -> this.sectionService.getFullSection(type, alias, sectionId))
.collect(Collectors.toList()));
} else {
return null;
}
}
public SubCategory find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("SubCategory with id: " + id + " not found"));
}
}

View File

@ -0,0 +1,53 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.Topic;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;
import java.util.stream.Collectors;
@Service
public class TopicService {
private final TopicDAO dao;
private final CategoryService categoryService;
private final CommonService commonService;
@Autowired
public TopicService(TopicDAO dao, CategoryService categoryService, CommonService commonService) {
this.dao = dao;
this.categoryService = categoryService;
this.commonService = commonService;
}
public Topic findByPath(Stakeholder stakeholder, String topicId, String message) {
if (!stakeholder.getTopics().contains(topicId)) {
throw new PathNotValidException(message + ": Topic with id: " + topicId + " not found in Stakeholder: " + stakeholder.getId());
}
return this.dao.findById(topicId).orElseThrow(() -> new EntityNotFoundException(message + ": Topic with id: " + topicId + " not found"));
}
public TopicFull getFullTopic(String type, String alias, String id) {
Topic topic = this.find(id);
if(commonService.hasVisibilityAuthority(type, alias, topic)) {
return new TopicFull(topic, topic.getCategories().stream()
.map(categoryId -> this.categoryService.getFullCategory(type, alias, categoryId))
.collect(Collectors.toList()));
} else {
return null;
}
}
public Topic find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Topic with id: " + id + " not found"));
}
}