[new-model]: Refactor all delete and change visibility methods.
This commit is contained in:
parent
e345f5b689
commit
959d553ca4
|
@ -249,5 +249,23 @@ 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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package eu.dnetlib.uoamonitorservice.controllers;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
||||
import eu.dnetlib.uoamonitorservice.service.TopicService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -20,8 +24,8 @@ import java.util.stream.Collectors;
|
|||
public class StakeholderController {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
|
||||
private PortalService portalService;
|
||||
private StakeholderService stakeholderService;
|
||||
private final PortalService portalService;
|
||||
private final StakeholderService stakeholderService;
|
||||
|
||||
@Autowired
|
||||
public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
|
||||
|
@ -39,33 +43,24 @@ public class StakeholderController {
|
|||
return stakeholderAlias;
|
||||
}
|
||||
|
||||
/* @PreAuthorize("hasAnyAuthority(" +
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator(#stakeholderFull.getType()))")
|
||||
"@AuthorizationService.curator(#stakeholder.getType()))")
|
||||
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
||||
public StakeholderFull buildFullStakeholder(@RequestBody StakeholderFull stakeholderFull) {
|
||||
public StakeholderFull buildFullStakeholder(@RequestBody StakeholderFull stakeholder) {
|
||||
log.debug("build stakeholder");
|
||||
log.debug("Alias: " + stakeholderFull.getAlias());
|
||||
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 = stakeholderDAO.save(stakeholder);
|
||||
stakeholderFull.setId(stakeholder.getId());
|
||||
Portal portal = portalService.getPortal(stakeholderFull.getAlias());
|
||||
log.debug("Alias: " + stakeholder.getAlias());
|
||||
stakeholder = this.stakeholderService.buildStakeholder(stakeholder);
|
||||
Portal portal = portalService.getPortal(stakeholder.getAlias());
|
||||
if (portal == null) {
|
||||
portal = new Portal();
|
||||
portal.setPid(stakeholderFull.getAlias());
|
||||
portal.setName(stakeholderFull.getName());
|
||||
portal.setType(stakeholderFull.getType());
|
||||
portal.setPid(stakeholder.getAlias());
|
||||
portal.setName(stakeholder.getName());
|
||||
portal.setType(stakeholder.getType());
|
||||
portalService.insertPortal(portal);
|
||||
}
|
||||
return stakeholderFull;
|
||||
}*/
|
||||
return stakeholder;
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
||||
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
|
||||
|
@ -77,7 +72,7 @@ public class StakeholderController {
|
|||
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
|
||||
public List<StakeholderFull> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
|
||||
return this.stakeholderService.getAllDefaultByRole(type).stream()
|
||||
.map(stakeholder -> this.stakeholderService.getFullStakeholder(stakeholder))
|
||||
.map(this.stakeholderService::getFullStakeholder)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -102,106 +97,37 @@ public class StakeholderController {
|
|||
return stakeholder;
|
||||
}
|
||||
|
||||
/*@PreAuthorize("hasAnyAuthority("
|
||||
@PreAuthorize("hasAnyAuthority("
|
||||
+ "@AuthorizationService.PORTAL_ADMIN, "
|
||||
+ "@AuthorizationService.curator(#_stakeholder.getType()), "
|
||||
+ "@AuthorizationService.manager(#_stakeholder.getType(), #_stakeholder.getAlias()) "
|
||||
+ "@AuthorizationService.curator(#stakeholder.getType()), "
|
||||
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
|
||||
+ ")")
|
||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||
public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) {
|
||||
public StakeholderFull saveStakeholder(@RequestBody StakeholderFull stakeholder) {
|
||||
log.debug("save 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) {
|
||||
stakeholder.setCreationDate(date);
|
||||
} else {
|
||||
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");
|
||||
}
|
||||
for (String topicId : oldStakeholder.getTopics()) {
|
||||
Topic topic = topicDAO.findById(topicId);
|
||||
if (topic == null) {
|
||||
// EXCEPTION - Topic not found
|
||||
throw new EntityNotFoundException("Save stakeholder: Topic with id: " + topicId + " not found (topic exists in stakeholder: " + stakeholder.getId() + ")");
|
||||
}
|
||||
topics.add(topic.getId());
|
||||
}
|
||||
}
|
||||
stakeholder.setTopics(topics);
|
||||
return stakeholderDAO.save(stakeholder);
|
||||
}*/
|
||||
|
||||
/* @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 stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||
String pid = null;
|
||||
|
||||
if (stakeholder != null) {
|
||||
pid = stakeholder.getAlias();
|
||||
if (!rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
|
||||
// EXCEPTION - Access denied
|
||||
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + stakeholderId);
|
||||
}
|
||||
topicController.deleteTree(stakeholder);
|
||||
stakeholder.setTopics(null);
|
||||
stakeholderDAO.delete(stakeholderId);
|
||||
log.debug("Stakeholder deleted!");
|
||||
Portal portal = portalService.getPortal(pid);
|
||||
if (portal != null) {
|
||||
portalService.deletePortal(portal.getId());
|
||||
}
|
||||
} else {
|
||||
// EXCEPTION - Stakeholder not found
|
||||
throw new EntityNotFoundException("Delete stakeholder: Stakeholder with id: " + stakeholderId + " not found");
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
|
||||
/*@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) {
|
||||
log.debug("change stakeholder visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
|
||||
log.debug("Stakeholder: " + stakeholderId);
|
||||
|
||||
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||
if (stakeholder == null) {
|
||||
// EXCEPTION - Stakeholder not found
|
||||
throw new EntityNotFoundException("Change stakeholder visibility: Stakeholder with id: " + stakeholderId + " not found");
|
||||
}
|
||||
if (!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
|
||||
// EXCEPTION - Access denied
|
||||
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholderId);
|
||||
}
|
||||
|
||||
return changeStakeholderVisibilityTree(stakeholder, visibility, propagate);
|
||||
stakeholder.update(this.stakeholderService.save(new Stakeholder(stakeholder)));
|
||||
return stakeholder;
|
||||
}
|
||||
|
||||
private Stakeholder changeStakeholderVisibilityTree(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {
|
||||
Stakeholder<Topic> stakeholderFull = new Stakeholder<>(stakeholder);
|
||||
List<Topic> topicsFull = new ArrayList<>();
|
||||
|
||||
if (propagate != null && propagate) {
|
||||
for (String topicId : stakeholder.getTopics()) {
|
||||
topicsFull.add(topicController.changeVisibilityTree(topicId, visibility, propagate));
|
||||
}
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/delete", method = RequestMethod.DELETE)
|
||||
public boolean deleteStakeholder(@PathVariable("stakeholderId") String id) {
|
||||
log.debug("delete stakeholder");
|
||||
log.debug("Id: " + id);
|
||||
Portal portal = portalService.getPortal(this.stakeholderService.delete(id));
|
||||
if (portal != null) {
|
||||
portalService.deletePortal(portal.getId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
stakeholder.setVisibility(visibility);
|
||||
stakeholderDAO.save(stakeholder);
|
||||
log.debug("Stakeholder toggled!");
|
||||
|
||||
stakeholderFull.setVisibility(visibility);
|
||||
stakeholderFull.setTopics(topicsFull);
|
||||
|
||||
return stakeholder;
|
||||
}*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
|
||||
public StakeholderFull changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
log.debug("change stakeholder visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
|
||||
log.debug("Stakeholder: " + stakeholderId);
|
||||
return this.stakeholderService.changeVisibility(stakeholderId, visibility, propagate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,71 +1,32 @@
|
|||
/*
|
||||
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.entities.Stakeholder;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Topic;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
||||
import eu.dnetlib.uoamonitorservice.service.TopicService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*")
|
||||
public class TopicController {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private RolesUtils rolesUtils;
|
||||
private TopicService topicService;
|
||||
private StakeholderService stakeholderService;
|
||||
|
||||
@Autowired
|
||||
private StakeholderDAO stakeholderDAO;
|
||||
|
||||
@Autowired
|
||||
private TopicDAO topicDAO;
|
||||
|
||||
@Autowired
|
||||
private CategoryController categoryController;
|
||||
|
||||
@Autowired
|
||||
private CategoryDAO categoryDAO;
|
||||
|
||||
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()) {
|
||||
Category<SubCategory> categoryFull = categoryController.buildCategory(category);
|
||||
categoriesFull.add(categoryFull);
|
||||
categories.add(categoryFull.getId());
|
||||
}
|
||||
topicFull.setCategories(categoriesFull);
|
||||
topic.setCategories(categories);
|
||||
|
||||
Date date = new Date();
|
||||
topic.setCreationDate(date);
|
||||
topic.setUpdateDate(date);
|
||||
|
||||
topicFull.setCreationDate(date);
|
||||
topicFull.setUpdateDate(date);
|
||||
|
||||
topicDAO.save(topic);
|
||||
|
||||
topicFull.setId(topic.getId());
|
||||
return topicFull;
|
||||
public TopicController(TopicService topicService, StakeholderService stakeholderService) {
|
||||
this.topicService = topicService;
|
||||
this.stakeholderService = stakeholderService;
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
/*@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/save", method = RequestMethod.POST)
|
||||
public Topic<Category> saveTopic(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@RequestBody Topic<Category> topicFull) {
|
||||
|
@ -190,7 +151,7 @@ public class TopicController {
|
|||
topicBasedOnDefault.setUpdateDate(topic.getUpdateDate());
|
||||
topicDAO.save(topicBasedOnDefault);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/delete", method = RequestMethod.DELETE)
|
||||
|
@ -198,100 +159,15 @@ public class TopicController {
|
|||
@PathVariable("topicId") String topicId,
|
||||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete topic");
|
||||
log.debug("Id: "+topicId + " - Stakeholder: "+stakeholderId);
|
||||
|
||||
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||
|
||||
if(stakeholder != null) {
|
||||
|
||||
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
|
||||
// EXCEPTION - Access denied
|
||||
throw new ForbiddenException("Delete topic: You are not authorized to update stakeholder with id: "+stakeholderId);
|
||||
}
|
||||
|
||||
Topic<String> topic = topicDAO.findById(topicId);
|
||||
if(topic != null) {
|
||||
|
||||
if(topic.getDefaultId() != null && !rolesUtils.hasCreateAndDeleteAuthority(stakeholder.getType())) {
|
||||
// EXCEPTION - Access denied
|
||||
throw new ForbiddenException("Delete topic: You are not authorized to delete a default Topic in stakeholder with id: "+stakeholderId);
|
||||
}
|
||||
|
||||
List<String> topics = stakeholder.getTopics();
|
||||
int index = topics.indexOf(topicId);
|
||||
if(index != -1) {
|
||||
// this topic belongs in default profile
|
||||
if(stakeholder.getDefaultId() == null && children != null) {
|
||||
onDeleteDefaultTopic(topicId, stakeholderId, children);
|
||||
}
|
||||
categoryController.deleteTree(topic);
|
||||
|
||||
topic.setCategories(null);
|
||||
|
||||
topics.remove(index);
|
||||
stakeholderDAO.save(stakeholder);
|
||||
|
||||
topicDAO.delete(topicId);
|
||||
log.debug("Topic deleted!");
|
||||
} else {
|
||||
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
||||
throw new PathNotValidException("Delete topic: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
||||
}
|
||||
|
||||
} else {
|
||||
// EXCEPTION - Topic not found
|
||||
throw new EntityNotFoundException("Delete topic: Topic with id: "+topicId+" not found");
|
||||
}
|
||||
} else {
|
||||
// EXCEPTION - Stakeholder not found
|
||||
throw new EntityNotFoundException("Delete topic: Stakeholder with id: "+stakeholderId+" not found");
|
||||
}
|
||||
log.debug("Id: " + topicId + " - Stakeholder: " + stakeholderId);
|
||||
Stakeholder stakeholder = stakeholderService.findById(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
this.topicService.delete(stakeholder.getType(), topic, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean onDeleteDefaultTopic(String defaultTopicId, String defaultStakeholderId, String children) {
|
||||
if(children.equals("delete")) {
|
||||
List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholderId);
|
||||
List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
|
||||
|
||||
for(Stakeholder stakeholder : stakeholders) {
|
||||
Iterator<Topic> topicsIterator = topics.iterator();
|
||||
while(topicsIterator.hasNext()) {
|
||||
Topic topic = topicsIterator.next();
|
||||
|
||||
String topicId = topic.getId();
|
||||
|
||||
if(stakeholder.getTopics() != null && stakeholder.getTopics().contains(topicId)) {
|
||||
topicsIterator.remove();
|
||||
|
||||
stakeholder.getTopics().remove(topicId);
|
||||
stakeholderDAO.save(stakeholder);
|
||||
|
||||
categoryController.deleteTree(topic);
|
||||
|
||||
topicDAO.delete(topicId);
|
||||
log.debug("Topic with id: "+topicId+" deleted!");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(children.equals("disconnect")) {
|
||||
List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
|
||||
for(Topic topic : topics) {
|
||||
categoryController.disConnectTree(topic);
|
||||
|
||||
topic.setDefaultId(null);
|
||||
topicDAO.save(topic);
|
||||
|
||||
log.debug("DefaultId for Topic with id: "+topic.getId()+" cleared!");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
/*@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/reorder", method = RequestMethod.POST)
|
||||
public List<Topic> reorderTopics(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@RequestBody List<String> topics) {
|
||||
|
@ -332,73 +208,16 @@ public class TopicController {
|
|||
// EXCEPTION - Stakeholder not found
|
||||
throw new EntityNotFoundException("Reorder topics: Stakeholder with id: "+stakeholderId+" not found");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST)
|
||||
public Topic changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@PathVariable("topicId") String topicId,
|
||||
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||
log.debug("change topic visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
|
||||
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
|
||||
|
||||
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||
|
||||
if (stakeholder != null) {
|
||||
if(!rolesUtils.hasUpdateAuthority(stakeholder.getType(), stakeholder.getAlias())) {
|
||||
// EXCEPTION - Access denied
|
||||
throw new ForbiddenException("Toggle topic: You are not authorized to update stakeholder with id: "+stakeholderId);
|
||||
}
|
||||
|
||||
if (stakeholder.getTopics().contains(topicId)) {
|
||||
return changeVisibilityTree(topicId, visibility, propagate);
|
||||
} else {
|
||||
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
||||
throw new PathNotValidException("Toggle topic: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
||||
}
|
||||
} else {
|
||||
// EXCEPTION - Stakeholder not found
|
||||
throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found");
|
||||
}
|
||||
}
|
||||
|
||||
public Topic changeVisibilityTree(String topicId, Visibility visibility, Boolean propagate) {
|
||||
Topic<String> topic = topicDAO.findById(topicId);
|
||||
if (topic == null) {
|
||||
// EXCEPTION - Topic not found
|
||||
throw new EntityNotFoundException("Change topic visibility: Topic with id: "+topicId+" not found");
|
||||
}
|
||||
|
||||
Topic<Category> topicFull = new Topic(topic);
|
||||
List<Category> categoriesFull = new ArrayList<>();
|
||||
|
||||
if(propagate != null && propagate) {
|
||||
for (String categoryId : topic.getCategories()) {
|
||||
categoriesFull.add(categoryController.changeVisibilityTree(categoryId, visibility, propagate));
|
||||
}
|
||||
}
|
||||
|
||||
topic.setVisibility(visibility);
|
||||
topicDAO.save(topic);
|
||||
log.debug("Topic toggled!");
|
||||
|
||||
topicFull.setVisibility(visibility);
|
||||
topicFull.setCategories(categoriesFull);
|
||||
|
||||
return topicFull;
|
||||
}
|
||||
|
||||
public void deleteTree(Stakeholder stakeholder) {
|
||||
List<String> topics = stakeholder.getTopics();
|
||||
for(String topicId : topics) {
|
||||
Topic topic = topicDAO.findById(topicId);
|
||||
if (topic == null) {
|
||||
// EXCEPTION - Topic not found
|
||||
throw new EntityNotFoundException("Topic delete tree: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")");
|
||||
}
|
||||
categoryController.deleteTree(topic);
|
||||
topicDAO.delete(topicId);
|
||||
}
|
||||
public TopicFull changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@PathVariable("topicId") String topicId,
|
||||
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||
log.debug("change topic visibility: " + visibility + " - toggle propagate: " + ((propagate != null && propagate) ? "true" : "false"));
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findById(stakeholderId);
|
||||
return this.topicService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), topicId, visibility, propagate);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,7 @@ public interface CategoryDAO extends MongoRepository<Category, String> {
|
|||
List<Category> findAll();
|
||||
List<Category> findByDefaultId(String DefaultId);
|
||||
|
||||
Optional<Category> findBySubCategoriesContaining(String subCategory);
|
||||
List<Category> findBySubCategoriesContaining(String subCategory);
|
||||
|
||||
Optional<Category> findById(String Id);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Optional;
|
|||
public interface SectionDAO extends MongoRepository<Section, String> {
|
||||
List<Section> findAll();
|
||||
List<Section> findByDefaultId(String DefaultId);
|
||||
List<Section> findByIndicatorsContaining(String id);
|
||||
|
||||
Optional<Section> findById(String Id);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
|
|||
List<Stakeholder> findByDefaultIdNot(String DefaultId);
|
||||
List<Stakeholder> findByDefaultIdNotAndType(String DefaultId, String Type);
|
||||
|
||||
Optional<Stakeholder> findByTopicsContaining(String topic);
|
||||
List<Stakeholder> findByTopicsContaining(String topic);
|
||||
|
||||
Optional<Stakeholder> findById(String Id);
|
||||
Optional<Stakeholder> findByAlias(String Alias);
|
||||
|
|
|
@ -12,6 +12,9 @@ public interface SubCategoryDAO extends MongoRepository<SubCategory, String> {
|
|||
List<SubCategory> findAll();
|
||||
List<SubCategory> findByDefaultId(String DefaultId);
|
||||
|
||||
List<SubCategory> findByNumbersContaining(String id);
|
||||
List<SubCategory> findByChartsContaining(String id);
|
||||
|
||||
Optional<SubCategory> findById(String Id);
|
||||
|
||||
void delete(String Id);
|
||||
|
|
|
@ -12,7 +12,7 @@ public interface TopicDAO extends MongoRepository<Topic, String> {
|
|||
List<Topic> findAll();
|
||||
List<Topic> findByDefaultId(String DefaultId);
|
||||
|
||||
Optional<Topic> findByCategoriesContaining(String category);
|
||||
List<Topic> findByCategoriesContaining(String category);
|
||||
|
||||
Optional<Topic> findById(String Id);
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ import java.util.Objects;
|
|||
|
||||
public class StakeholderFull extends StakeholderGeneric<TopicFull> {
|
||||
|
||||
public StakeholderFull() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
|
||||
super(stakeholder);
|
||||
topics.removeIf(Objects::isNull);
|
||||
|
|
|
@ -2,10 +2,13 @@ package eu.dnetlib.uoamonitorservice.entities;
|
|||
|
||||
import eu.dnetlib.uoamonitorservice.dto.CategoryFull;
|
||||
import eu.dnetlib.uoamonitorservice.generics.CategoryGeneric;
|
||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.generics.TopicGeneric;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Document
|
||||
public class Category extends CategoryGeneric<String> {
|
||||
|
@ -15,6 +18,8 @@ public class Category extends CategoryGeneric<String> {
|
|||
|
||||
public Category(CategoryFull category) {
|
||||
super(category);
|
||||
this.subCategories = category.getSubCategories().stream().map(Common::getId).collect(Collectors.toList());
|
||||
this.subCategories.removeIf(Objects::isNull);
|
||||
}
|
||||
|
||||
public void copyFromDefault(CategoryGeneric defaultCategory) {
|
||||
|
|
|
@ -14,19 +14,11 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
public class Indicator extends Common {
|
||||
@Id
|
||||
@JsonProperty("_id")
|
||||
private String id;
|
||||
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
|
||||
@CreatedDate
|
||||
private Date creationDate;
|
||||
@LastModifiedDate
|
||||
private Date updateDate;
|
||||
private String defaultId;
|
||||
private List<IndicatorPath> indicatorPaths;
|
||||
|
||||
public void copyFromDefault(Indicator defaultIndicator, Visibility visibility) {
|
||||
|
@ -44,14 +36,6 @@ public class Indicator extends Common {
|
|||
setIndicatorPaths(defaultIndicator.getIndicatorPaths());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAdditionalDescription() {
|
||||
return additionalDescription;
|
||||
}
|
||||
|
@ -100,30 +84,6 @@ public class Indicator extends Common {
|
|||
this.tags = tags;
|
||||
}
|
||||
|
||||
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<IndicatorPath> getIndicatorPaths() {
|
||||
return indicatorPaths;
|
||||
}
|
||||
|
@ -131,8 +91,4 @@ public class Indicator extends Common {
|
|||
public void setIndicatorPaths(List<IndicatorPath> indicatorPaths) {
|
||||
this.indicatorPaths = indicatorPaths;
|
||||
}
|
||||
|
||||
// public String hasType() {
|
||||
// return this.type.name();
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ public class Section extends SectionGeneric<String> {
|
|||
|
||||
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);
|
||||
this.indicators = section.getIndicators().stream().map(Indicator::getId).collect(Collectors.toList());
|
||||
this.indicators.removeIf(Objects::isNull);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package eu.dnetlib.uoamonitorservice.entities;
|
||||
|
||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Document
|
||||
public class Stakeholder extends StakeholderGeneric<String> {
|
||||
|
||||
|
@ -10,7 +15,9 @@ public class Stakeholder extends StakeholderGeneric<String> {
|
|||
super();
|
||||
}
|
||||
|
||||
public Stakeholder(StakeholderGeneric stakeholder) {
|
||||
public Stakeholder(StakeholderFull stakeholder) {
|
||||
super(stakeholder);
|
||||
this.topics = stakeholder.getTopics().stream().map(Common::getId).collect(Collectors.toList());
|
||||
this.topics.removeIf(Objects::isNull);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
package eu.dnetlib.uoamonitorservice.entities;
|
||||
|
||||
import eu.dnetlib.uoamonitorservice.dto.SubCategoryFull;
|
||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.generics.SubCategoryGeneric;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Document
|
||||
public class SubCategory extends SubCategoryGeneric<String> {
|
||||
public SubCategory() {}
|
||||
|
||||
public SubCategory(SubCategoryGeneric subCategory) {
|
||||
public SubCategory(SubCategoryFull subCategory) {
|
||||
super(subCategory);
|
||||
this.numbers = subCategory.getNumbers().stream().map(Common::getId).collect(Collectors.toList());
|
||||
this.charts = subCategory.getCharts().stream().map(Common::getId).collect(Collectors.toList());
|
||||
this.numbers.removeIf(Objects::isNull);
|
||||
this.charts.removeIf(Objects::isNull);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
package eu.dnetlib.uoamonitorservice.entities;
|
||||
|
||||
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.generics.TopicGeneric;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Document
|
||||
public class Topic extends TopicGeneric<String> {
|
||||
|
||||
public Topic() {
|
||||
super();
|
||||
}
|
||||
public Topic(TopicGeneric topic) {
|
||||
|
||||
public Topic(TopicFull topic) {
|
||||
super(topic);
|
||||
this.categories = topic.getCategories().stream().map(Common::getId).collect(Collectors.toList());
|
||||
this.categories.removeIf(Objects::isNull);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,7 @@ 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() {}
|
||||
|
@ -38,30 +30,6 @@ public class CategoryGeneric<StringOrSubcategory> extends Common {
|
|||
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;
|
||||
}
|
||||
|
@ -70,14 +38,6 @@ public class CategoryGeneric<StringOrSubcategory> extends Common {
|
|||
this.isOverview = isOverview;
|
||||
}
|
||||
|
||||
public String getDefaultId() {
|
||||
return defaultId;
|
||||
}
|
||||
|
||||
public void setDefaultId(String defaultId) {
|
||||
this.defaultId = defaultId;
|
||||
}
|
||||
|
||||
public List<StringOrSubcategory> getSubCategories() {
|
||||
return subCategories;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,66 @@
|
|||
package eu.dnetlib.uoamonitorservice.generics;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
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;
|
||||
|
||||
public class Common {
|
||||
@Id
|
||||
@JsonProperty("_id")
|
||||
protected String id;
|
||||
@CreatedDate
|
||||
protected Date creationDate;
|
||||
@LastModifiedDate
|
||||
protected Date updateDate;
|
||||
protected String defaultId;
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected String alias;
|
||||
protected Visibility visibility = Visibility.PRIVATE;
|
||||
|
||||
public void update(Common common) {
|
||||
this.id = common.getId();
|
||||
this.creationDate = common.getCreationDate();
|
||||
this.updateDate = common.getUpdateDate();
|
||||
}
|
||||
|
||||
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 String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,14 @@
|
|||
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;
|
||||
public class SectionGeneric<StringOrIndicator> extends Common {
|
||||
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() {
|
||||
|
@ -46,14 +33,6 @@ public class SectionGeneric<StringOrIndicator> {
|
|||
setIndicators(new ArrayList<>());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
@ -62,14 +41,6 @@ public class SectionGeneric<StringOrIndicator> {
|
|||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDefaultId() {
|
||||
return defaultId;
|
||||
}
|
||||
|
||||
public void setDefaultId(String defaultId) {
|
||||
this.defaultId = defaultId;
|
||||
}
|
||||
|
||||
public String getStakeholderAlias() {
|
||||
return stakeholderAlias;
|
||||
}
|
||||
|
@ -93,22 +64,6 @@ public class SectionGeneric<StringOrIndicator> {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ 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;
|
||||
|
@ -24,13 +21,8 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
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() {
|
||||
|
@ -57,14 +49,6 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
updateDate = stakeholder.getUpdateDate();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
if (type == null) {
|
||||
return null;
|
||||
|
@ -137,14 +121,6 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
this.isUpload = isUpload;
|
||||
}
|
||||
|
||||
public String getDefaultId() {
|
||||
return defaultId;
|
||||
}
|
||||
|
||||
public void setDefaultId(String defaultId) {
|
||||
this.defaultId = defaultId;
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return locale.label;
|
||||
}
|
||||
|
@ -167,22 +143,6 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -12,14 +12,6 @@ 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;
|
||||
|
||||
|
@ -53,40 +45,8 @@ public class SubCategoryGeneric<StringOrSection> extends Common {
|
|||
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;
|
||||
setCharts(new ArrayList<>());
|
||||
setNumbers(new ArrayList<>());
|
||||
}
|
||||
|
||||
public List<StringOrSection> getCharts() {
|
||||
|
|
|
@ -11,15 +11,7 @@ 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() {
|
||||
|
@ -49,14 +41,6 @@ public class TopicGeneric<StringOrCategory> extends Common {
|
|||
setCategories(new ArrayList<>());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
|
@ -66,30 +50,6 @@ public class TopicGeneric<StringOrCategory> extends Common {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
|
||||
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 eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.method.P;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -16,16 +17,18 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class CategoryService {
|
||||
|
||||
private final TopicDAO topicDAO;
|
||||
private final CategoryDAO dao;
|
||||
|
||||
private final SubCategoryService subCategoryService;
|
||||
private final CommonService commonService;
|
||||
|
||||
@Autowired
|
||||
public CategoryService(SubCategoryService subCategoryService, CommonService commonService, CategoryDAO dao) {
|
||||
public CategoryService(TopicDAO topicDAO, CategoryDAO dao, SubCategoryService subCategoryService, CommonService commonService) {
|
||||
this.topicDAO = topicDAO;
|
||||
this.dao = dao;
|
||||
this.subCategoryService = subCategoryService;
|
||||
this.commonService = commonService;
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public Category findByPath(Topic topic, String categoryId, String message) {
|
||||
|
@ -49,4 +52,61 @@ public class CategoryService {
|
|||
public Category find(String id) {
|
||||
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Category with id: " + id + " not found"));
|
||||
}
|
||||
|
||||
public CategoryFull buildCategory(CategoryFull categoryFull) {
|
||||
categoryFull.setSubCategories(categoryFull.getSubCategories().stream().map(this.subCategoryService::buildSubcategory).collect(Collectors.toList()));
|
||||
categoryFull.update(this.save(new Category(categoryFull)));
|
||||
return categoryFull;
|
||||
}
|
||||
|
||||
public Category save(Category category) {
|
||||
category.getSubCategories().forEach(this.subCategoryService::find);
|
||||
return this.dao.save(category);
|
||||
}
|
||||
|
||||
public void delete(String type, Category category, boolean remove) {
|
||||
if(this.commonService.hasDeleteAuthority(type)) {
|
||||
this.dao.findByDefaultId(category.getId()).forEach(child -> {
|
||||
this.delete(type, child.getId(), remove);
|
||||
});
|
||||
category.getSubCategories().forEach(subcategoryId -> {
|
||||
this.subCategoryService.delete(type, subcategoryId, false);
|
||||
});
|
||||
if(remove){
|
||||
this.removeCategory(category.getId());
|
||||
}
|
||||
this.dao.delete(category);
|
||||
} else {
|
||||
throw new ForbiddenException("Delete category: You are not authorized to delete category with id: " + category.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String type, String id, boolean remove) {
|
||||
Category category = this.find(id);
|
||||
this.delete(type, category, remove);
|
||||
}
|
||||
|
||||
public void removeCategory(String id) {
|
||||
this.topicDAO.findByCategoriesContaining(id).forEach(topic -> {
|
||||
topic.getCategories().remove(id);
|
||||
this.topicDAO.save(topic);
|
||||
});
|
||||
}
|
||||
|
||||
public CategoryFull changeVisibility(String type, String alias, String id, Visibility visibility, Boolean propagate) {
|
||||
if(this.commonService.hasEditAuthority(type, alias)) {
|
||||
CategoryFull categoryFull = this.getFullCategory(type, alias, id);
|
||||
categoryFull.setVisibility(visibility);
|
||||
if(propagate) {
|
||||
categoryFull.setSubCategories(categoryFull.getSubCategories().stream()
|
||||
.map(category -> this.subCategoryService.changeVisibility(type, alias, category.getId(), visibility, true))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
Category category = this.save(new Category(categoryFull));
|
||||
categoryFull.update(category);
|
||||
return categoryFull;
|
||||
} else {
|
||||
throw new ForbiddenException("Change category visibility: You are not authorized to update category with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,18 @@ public class CommonService {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean hasDeleteAuthority(String type) {
|
||||
return this.authorizationService.isPortalAdmin() || this.authorizationService.isCurator(type);
|
||||
}
|
||||
|
||||
public boolean hasCreateAuthority(String type) {
|
||||
return this.authorizationService.isPortalAdmin() || this.authorizationService.isCurator(type);
|
||||
}
|
||||
|
||||
public boolean hasEditAuthority(String type, String alias) {
|
||||
return this.authorizationService.isPortalAdmin() || this.authorizationService.isCurator(type) || this.authorizationService.isManager(type, alias);
|
||||
}
|
||||
|
||||
public boolean hasVisibilityAuthority(String type, String alias, Common common) {
|
||||
if(authorizationService.isPortalAdmin() || authorizationService.isCurator(type) || authorizationService.isManager(type, alias)) {
|
||||
return true;
|
||||
|
|
|
@ -1,20 +1,29 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.IndicatorDAO;
|
||||
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.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class IndicatorService {
|
||||
|
||||
private final SectionDAO sectionDAO;
|
||||
private final IndicatorDAO dao;
|
||||
|
||||
private final CommonService commonService;
|
||||
|
||||
@Autowired
|
||||
public IndicatorService(IndicatorDAO dao, CommonService commonService) {
|
||||
public IndicatorService(SectionDAO sectionDAO, IndicatorDAO dao, CommonService commonService) {
|
||||
this.sectionDAO = sectionDAO;
|
||||
this.dao = dao;
|
||||
this.commonService = commonService;
|
||||
}
|
||||
|
@ -35,4 +44,41 @@ public class IndicatorService {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String type, Indicator indicator, boolean remove) {
|
||||
if(this.commonService.hasDeleteAuthority(type)) {
|
||||
this.dao.findByDefaultId(indicator.getId()).forEach(child -> {
|
||||
this.delete(type, child.getId(), remove);
|
||||
});
|
||||
if(remove) {
|
||||
this.removeIndicator(indicator.getId());
|
||||
}
|
||||
this.dao.delete(indicator);
|
||||
} else {
|
||||
throw new ForbiddenException("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void delete(String type, String id, boolean remove) {
|
||||
Indicator indicator = this.find(id);
|
||||
this.delete(type, indicator, remove);
|
||||
}
|
||||
|
||||
public void removeIndicator(String id) {
|
||||
this.sectionDAO.findByIndicatorsContaining(id).forEach(section -> {
|
||||
section.getIndicators().remove(id);
|
||||
this.sectionDAO.save(section);
|
||||
});
|
||||
}
|
||||
|
||||
public Indicator changeVisibility(String type, String alias, String id, Visibility visibility) {
|
||||
if(this.commonService.hasEditAuthority(type, alias)) {
|
||||
Indicator indicator = this.getIndicator(type, alias, id);
|
||||
indicator.setVisibility(visibility);
|
||||
return this.save(indicator);
|
||||
} else {
|
||||
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.SectionDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Indicator;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Section;
|
||||
|
@ -15,25 +17,23 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class SectionService {
|
||||
|
||||
private final SubCategoryDAO subCategoryDAO;
|
||||
private final SectionDAO dao;
|
||||
|
||||
private final IndicatorService indicatorService;
|
||||
private final CommonService commonService;
|
||||
|
||||
@Autowired
|
||||
public SectionService(SectionDAO dao, IndicatorService indicatorService) {
|
||||
public SectionService(SubCategoryDAO subCategoryDAO, SectionDAO dao, IndicatorService indicatorService, CommonService commonService) {
|
||||
this.subCategoryDAO = subCategoryDAO;
|
||||
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());
|
||||
this.commonService = commonService;
|
||||
}
|
||||
|
||||
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 sectionFull = new SectionFull(section, section.getIndicators().stream().map(this.indicatorService::find).collect(Collectors.toList()));
|
||||
sectionFull.setIndicators(sectionFull.getIndicators().stream().map(indicator -> {
|
||||
indicator.setVisibility(visibility);
|
||||
return indicatorService.save(indicator);
|
||||
|
@ -68,4 +68,62 @@ public class SectionService {
|
|||
public List<String> getIndicatorsId(String id) {
|
||||
return this.getIndicators(id).stream().map(Indicator::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public SectionFull buildSection(SectionFull sectionFull) {
|
||||
sectionFull.setIndicators(sectionFull.getIndicators().stream().map(this.indicatorService::save).collect(Collectors.toList()));
|
||||
Section section = this.save(new Section(sectionFull));
|
||||
return new SectionFull(section, sectionFull.getIndicators());
|
||||
}
|
||||
|
||||
public Section save(Section section) {
|
||||
section.getIndicators().forEach(this.indicatorService::find);
|
||||
return this.dao.save(section);
|
||||
}
|
||||
|
||||
public void delete(String type, Section section, boolean remove) {
|
||||
if(this.commonService.hasDeleteAuthority(type)) {
|
||||
this.dao.findByDefaultId(section.getId()).forEach(child -> {
|
||||
this.delete(type, child.getId(), remove);
|
||||
});
|
||||
section.getIndicators().forEach(indicatorId -> {
|
||||
this.indicatorService.delete(type, indicatorId, false);
|
||||
});
|
||||
if (remove) {
|
||||
this.removeSection(section.getId());
|
||||
}
|
||||
this.dao.delete(section);
|
||||
} else {
|
||||
throw new ForbiddenException("Delete section: You are not authorized to delete section with id: " + section.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String type, String id, boolean remove) {
|
||||
Section section = this.find(id);
|
||||
this.delete(type, section, remove);
|
||||
}
|
||||
|
||||
public void removeSection(String id) {
|
||||
this.subCategoryDAO.findByNumbersContaining(id).forEach(subCategory -> {
|
||||
subCategory.getNumbers().remove(id);
|
||||
this.subCategoryDAO.save(subCategory);
|
||||
});
|
||||
this.subCategoryDAO.findByChartsContaining(id).forEach(subCategory -> {
|
||||
subCategory.getCharts().remove(id);
|
||||
this.subCategoryDAO.save(subCategory);
|
||||
});
|
||||
}
|
||||
|
||||
public SectionFull changeVisibility(String type, String alias, String id, Visibility visibility) {
|
||||
if(this.commonService.hasEditAuthority(type, alias)) {
|
||||
SectionFull sectionFull = this.getFullSection(type, alias, id);
|
||||
sectionFull.setIndicators(sectionFull.getIndicators().stream()
|
||||
.map(category -> this.indicatorService.changeVisibility(type, alias, category.getId(), visibility))
|
||||
.collect(Collectors.toList()));
|
||||
Section section = this.save(new Section(sectionFull));
|
||||
sectionFull.update(section);
|
||||
return sectionFull;
|
||||
} else {
|
||||
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
|
@ -27,10 +27,22 @@ public class StakeholderService {
|
|||
this.topicService = topicService;
|
||||
}
|
||||
|
||||
public Stakeholder findById(String id) {
|
||||
return this.dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + id + " not found"));
|
||||
}
|
||||
|
||||
public Stakeholder findByAlias(String alias) {
|
||||
return this.dao.findByAlias(alias).orElseThrow(() -> new EntityNotFoundException("Stakeholder with alias: " + alias + " not found"));
|
||||
}
|
||||
|
||||
public List<Stakeholder> findByDefaultId(String id ){
|
||||
return this.dao.findByDefaultId(id);
|
||||
}
|
||||
|
||||
public Stakeholder findByPath(String stakeholderId) {
|
||||
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
||||
}
|
||||
|
||||
public List<String> getAllAliases() {
|
||||
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -65,10 +77,6 @@ public class StakeholderService {
|
|||
.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))) {
|
||||
|
@ -80,4 +88,49 @@ public class StakeholderService {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StakeholderFull buildStakeholder(StakeholderFull stakeholderFull) {
|
||||
stakeholderFull.setTopics(stakeholderFull.getTopics().stream().map(this.topicService::buildTopic).collect(Collectors.toList()));
|
||||
stakeholderFull.update(this.save(new Stakeholder(stakeholderFull)));
|
||||
return stakeholderFull;
|
||||
}
|
||||
|
||||
public Stakeholder save(Stakeholder stakeholder) {
|
||||
stakeholder.getTopics().forEach(this.topicService::find);
|
||||
return this.dao.save(stakeholder);
|
||||
}
|
||||
|
||||
public String delete(String id) {
|
||||
Stakeholder stakeholder = this.findById(id);
|
||||
if(this.commonService.hasDeleteAuthority(stakeholder.getType())) {
|
||||
this.dao.findByDefaultId(stakeholder.getId()).forEach(child -> {
|
||||
this.delete(child.getId());
|
||||
});
|
||||
stakeholder.getTopics().forEach(topicId -> {
|
||||
this.topicService.delete(stakeholder.getType(), topicId, false);
|
||||
});
|
||||
this.dao.delete(id);
|
||||
return stakeholder.getAlias();
|
||||
} else {
|
||||
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
public StakeholderFull changeVisibility(String id, Visibility visibility, Boolean propagate) {
|
||||
Stakeholder stakeholder = this.findById(id);
|
||||
stakeholder.setVisibility(visibility);
|
||||
if(this.commonService.hasEditAuthority(stakeholder.getType(), stakeholder.getAlias())) {
|
||||
StakeholderFull stakeholderFull = this.getFullStakeholder(stakeholder);
|
||||
if(propagate) {
|
||||
stakeholderFull.setTopics(stakeholder.getTopics().stream().
|
||||
map(topicId -> this.topicService.changeVisibility(stakeholderFull.getType(), stakeholderFull.getAlias(), topicId, visibility, true))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
stakeholder = this.save(stakeholder);
|
||||
stakeholderFull.update(stakeholder);
|
||||
return stakeholderFull;
|
||||
} else {
|
||||
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
|
||||
import eu.dnetlib.uoamonitorservice.dto.CategoryFull;
|
||||
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.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.generics.SectionGeneric;
|
||||
import eu.dnetlib.uoamonitorservice.generics.SubCategoryGeneric;
|
||||
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
|
||||
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -16,15 +24,17 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class SubCategoryService {
|
||||
|
||||
private final CategoryDAO categoryDAO;
|
||||
private final SubCategoryDAO dao;
|
||||
|
||||
private final CommonService commonService;
|
||||
private final SectionService sectionService;
|
||||
|
||||
@Autowired
|
||||
public SubCategoryService( CommonService commonService, SubCategoryDAO dao, SectionService sectionService) {
|
||||
this.commonService = commonService;
|
||||
public SubCategoryService(CategoryDAO categoryDAO, SubCategoryDAO dao,CommonService commonService, SectionService sectionService) {
|
||||
this.categoryDAO = categoryDAO;
|
||||
this.dao = dao;
|
||||
this.commonService = commonService;
|
||||
this.sectionService = sectionService;
|
||||
}
|
||||
|
||||
|
@ -52,4 +62,70 @@ public class SubCategoryService {
|
|||
public SubCategory find(String id) {
|
||||
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("SubCategory with id: " + id + " not found"));
|
||||
}
|
||||
|
||||
public SubCategoryFull buildSubcategory(SubCategoryFull subCategoryFull) {
|
||||
subCategoryFull.setNumbers(subCategoryFull.getNumbers().stream().map(this.sectionService::buildSection).collect(Collectors.toList()));
|
||||
subCategoryFull.setCharts(subCategoryFull.getCharts().stream().map(this.sectionService::buildSection).collect(Collectors.toList()));
|
||||
subCategoryFull.update(this.save(new SubCategory(subCategoryFull)));
|
||||
return subCategoryFull;
|
||||
}
|
||||
|
||||
public SubCategory save(SubCategory subCategory) {
|
||||
subCategory.getNumbers().forEach(this.sectionService::find);
|
||||
subCategory.getCharts().forEach(this.sectionService::find);
|
||||
return this.dao.save(subCategory);
|
||||
}
|
||||
|
||||
public void delete(String type, SubCategory subCategory, boolean remove ) {
|
||||
if(this.commonService.hasDeleteAuthority(type)) {
|
||||
this.dao.findByDefaultId(subCategory.getId()).forEach(child -> {
|
||||
this.delete(type, child.getId(), remove);
|
||||
});
|
||||
|
||||
subCategory.getNumbers().forEach(sectionId -> {
|
||||
this.sectionService.delete(type, sectionId, false);
|
||||
});
|
||||
subCategory.getCharts().forEach(sectionId -> {
|
||||
this.sectionService.delete(type, sectionId, false);
|
||||
});
|
||||
if (remove) {
|
||||
this.removeSubCategory(subCategory.getId());
|
||||
}
|
||||
this.dao.delete(subCategory);
|
||||
} else {
|
||||
throw new ForbiddenException("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String type, String id, boolean remove) {
|
||||
SubCategory subCategory = this.find(id);
|
||||
this.delete(type, subCategory, remove);
|
||||
}
|
||||
|
||||
public void removeSubCategory(String id) {
|
||||
this.categoryDAO.findBySubCategoriesContaining(id).forEach(category -> {
|
||||
category.getSubCategories().remove(id);
|
||||
this.categoryDAO.save(category);
|
||||
});
|
||||
}
|
||||
|
||||
public SubCategoryFull changeVisibility(String type, String alias, String id, Visibility visibility, Boolean propagate) {
|
||||
if(this.commonService.hasEditAuthority(type, alias)) {
|
||||
SubCategoryFull subCategoryFull = this.getFullSubCategory(type, alias, id);
|
||||
subCategoryFull.setVisibility(visibility);
|
||||
if(propagate) {
|
||||
subCategoryFull.setNumbers(subCategoryFull.getNumbers().stream()
|
||||
.map(category -> this.sectionService.changeVisibility(type, alias, category.getId(), visibility))
|
||||
.collect(Collectors.toList()));
|
||||
subCategoryFull.setCharts(subCategoryFull.getCharts().stream()
|
||||
.map(category -> this.sectionService.changeVisibility(type, alias, category.getId(), visibility))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
SubCategory subCategory = this.save(new SubCategory(subCategoryFull));
|
||||
subCategoryFull.update(subCategory);
|
||||
return subCategoryFull;
|
||||
} else {
|
||||
throw new ForbiddenException("Change subCategory visibility: You are not authorized to update subCategory with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package eu.dnetlib.uoamonitorservice.service;
|
||||
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||
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 eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.method.P;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -17,31 +17,33 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class TopicService {
|
||||
|
||||
private final StakeholderDAO stakeholderDAO;
|
||||
private final TopicDAO dao;
|
||||
|
||||
private final CategoryService categoryService;
|
||||
private final CommonService commonService;
|
||||
|
||||
@Autowired
|
||||
public TopicService(TopicDAO dao, CategoryService categoryService, CommonService commonService) {
|
||||
public TopicService(StakeholderDAO stakeholderDAO, TopicDAO dao, CategoryService categoryService, CommonService commonService) {
|
||||
this.stakeholderDAO = stakeholderDAO;
|
||||
this.dao = dao;
|
||||
this.categoryService = categoryService;
|
||||
this.commonService = commonService;
|
||||
}
|
||||
|
||||
public Topic findByPath(Stakeholder stakeholder, String topicId, String message) {
|
||||
public Topic findByPath(Stakeholder stakeholder, String topicId) {
|
||||
if (!stakeholder.getTopics().contains(topicId)) {
|
||||
throw new PathNotValidException(message + ": Topic with id: " + topicId + " not found in Stakeholder: " + stakeholder.getId());
|
||||
throw new PathNotValidException("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"));
|
||||
return this.dao.findById(topicId).orElseThrow(() -> new EntityNotFoundException("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()));
|
||||
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;
|
||||
}
|
||||
|
@ -50,4 +52,61 @@ public class TopicService {
|
|||
public Topic find(String id) {
|
||||
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Topic with id: " + id + " not found"));
|
||||
}
|
||||
|
||||
public TopicFull buildTopic(TopicFull topicFull) {
|
||||
topicFull.setCategories(topicFull.getCategories().stream().map(this.categoryService::buildCategory).collect(Collectors.toList()));
|
||||
topicFull.update(this.save(new Topic(topicFull)));
|
||||
return topicFull;
|
||||
}
|
||||
|
||||
public Topic save(Topic topic) {
|
||||
topic.getCategories().forEach(this.categoryService::find);
|
||||
return this.dao.save(topic);
|
||||
}
|
||||
|
||||
public void delete(String type, Topic topic, boolean remove) {
|
||||
if (this.commonService.hasDeleteAuthority(type)) {
|
||||
this.dao.findByDefaultId(topic.getId()).forEach(child -> {
|
||||
this.delete(type, child.getId(), remove);
|
||||
});
|
||||
topic.getCategories().forEach(categoryId -> {
|
||||
this.categoryService.delete(type, categoryId, false);
|
||||
});
|
||||
if(remove) {
|
||||
this.removeTopic(topic.getId());
|
||||
}
|
||||
this.dao.delete(topic);
|
||||
} else {
|
||||
throw new ForbiddenException("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String type, String id, boolean remove) {
|
||||
Topic topic = this.find(id);
|
||||
this.delete(type, topic, remove);
|
||||
}
|
||||
|
||||
public void removeTopic(String id) {
|
||||
this.stakeholderDAO.findByTopicsContaining(id).forEach(stakeholder -> {
|
||||
stakeholder.getTopics().remove(id);
|
||||
this.stakeholderDAO.save(stakeholder);
|
||||
});
|
||||
}
|
||||
|
||||
public TopicFull changeVisibility(String type, String alias, String id, Visibility visibility, Boolean propagate) {
|
||||
if (this.commonService.hasEditAuthority(type, alias)) {
|
||||
TopicFull topicFull = this.getFullTopic(type, alias, id);
|
||||
topicFull.setVisibility(visibility);
|
||||
if (propagate) {
|
||||
topicFull.setCategories(topicFull.getCategories().stream()
|
||||
.map(category -> this.categoryService.changeVisibility(type, alias, category.getId(), visibility, true))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
Topic topic = this.save(new Topic(topicFull));
|
||||
topicFull.update(topic);
|
||||
return topicFull;
|
||||
} else {
|
||||
throw new ForbiddenException("Change topic visibility: You are not authorized to update topic with id: " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue