[Trunk | Monitor Service]: StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java & IndicatorController.java: Updated /change-visibility methods and added @RequestParam(required = false) Boolean propagate, to allow changing visibility of all contents of the updated entity too & updated return type to return the entity instead its visibility & added everywhere method "changeVisibilityTree()".
This commit is contained in:
parent
902a666c8e
commit
82a8f8ad56
|
@ -450,26 +450,13 @@ public class CategoryController {
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
|
||||||
public Visibility changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
public Category changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||||
@PathVariable("topicId") String topicId,
|
@PathVariable("topicId") String topicId,
|
||||||
@PathVariable("categoryId") String categoryId,
|
@PathVariable("categoryId") String categoryId,
|
||||||
@RequestParam("visibility") Visibility visibility) {
|
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||||
log.debug("change category visibility: "+visibility);
|
log.debug("change category visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
|
||||||
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
|
||||||
|
|
||||||
Category category = categoryDAO.findById(categoryId);
|
|
||||||
if (category == null) {
|
|
||||||
// EXCEPTION - Category not found
|
|
||||||
throw new EntityNotFoundException("Change topic visibility: Category with id: "+categoryId+" not found");
|
|
||||||
}
|
|
||||||
category.setVisibility(visibility);
|
|
||||||
|
|
||||||
this.toggleCategory(stakeholderId, topicId, category);
|
|
||||||
|
|
||||||
return category.getVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleCategory(String stakeholderId, String topicId, Category category) {
|
|
||||||
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||||
|
|
||||||
if (stakeholder != null) {
|
if (stakeholder != null) {
|
||||||
|
@ -483,12 +470,11 @@ public class CategoryController {
|
||||||
Topic<String> topic = topicDAO.findById(topicId);
|
Topic<String> topic = topicDAO.findById(topicId);
|
||||||
if (topic != null) {
|
if (topic != null) {
|
||||||
if (stakeholder.getTopics().contains(topicId)) {
|
if (stakeholder.getTopics().contains(topicId)) {
|
||||||
if (topic.getCategories().contains(category.getId())) {
|
if (topic.getCategories().contains(categoryId)) {
|
||||||
categoryDAO.save(category);
|
return changeVisibilityTree(categoryId, visibility, propagate);
|
||||||
log.debug("Category toggled!");
|
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
|
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
|
||||||
throw new PathNotValidException("Toggle category: Category with id: "+category.getId()+" not found in Topic: "+topicId);
|
throw new PathNotValidException("Toggle category: Category with id: "+categoryId+" not found in Topic: "+topicId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
||||||
|
@ -504,6 +490,32 @@ public class CategoryController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Category changeVisibilityTree(String categoryId, Visibility visibility, Boolean propagate) {
|
||||||
|
Category<String> category = categoryDAO.findById(categoryId);
|
||||||
|
if (category == null) {
|
||||||
|
// EXCEPTION - Category not found
|
||||||
|
throw new EntityNotFoundException("Change category visibility: Category with id: "+categoryId+" not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Category<SubCategory> categoryFull = new Category(category);
|
||||||
|
List<SubCategory> subCategoriesFull = new ArrayList<>();
|
||||||
|
|
||||||
|
if(propagate != null && propagate) {
|
||||||
|
for (String subCategoryId : category.getSubCategories()) {
|
||||||
|
subCategoriesFull.add(subCategoryController.changeVisibilityTree(subCategoryId, visibility, propagate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
category.setVisibility(visibility);
|
||||||
|
categoryDAO.save(category);
|
||||||
|
log.debug("Category toggled!");
|
||||||
|
|
||||||
|
categoryFull.setVisibility(visibility);
|
||||||
|
categoryFull.setSubCategories(subCategoriesFull);
|
||||||
|
|
||||||
|
return categoryFull;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Topic checkForExceptions(String stakeholderId, String topicId) {
|
private Topic checkForExceptions(String stakeholderId, String topicId) {
|
||||||
|
|
||||||
|
|
|
@ -797,7 +797,7 @@ public class IndicatorController {
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
|
||||||
public Visibility changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||||
@PathVariable("topicId") String topicId,
|
@PathVariable("topicId") String topicId,
|
||||||
@PathVariable("categoryId") String categoryId,
|
@PathVariable("categoryId") String categoryId,
|
||||||
@PathVariable("subcategoryId") String subcategoryId,
|
@PathVariable("subcategoryId") String subcategoryId,
|
||||||
|
@ -810,27 +810,34 @@ public class IndicatorController {
|
||||||
Indicator indicator = indicatorDAO.findById(indicatorId);
|
Indicator indicator = indicatorDAO.findById(indicatorId);
|
||||||
if (indicator == null) {
|
if (indicator == null) {
|
||||||
// EXCEPTION - Indicator not found
|
// EXCEPTION - Indicator not found
|
||||||
throw new EntityNotFoundException("Change indicator visibility: Indicator with id: "+indicatorId+" not found");
|
throw new EntityNotFoundException("Change indicator visibility: Indicator with id: " + indicatorId + " not found");
|
||||||
}
|
}
|
||||||
indicator.setVisibility(visibility);
|
|
||||||
|
|
||||||
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
|
||||||
|
|
||||||
return indicator.getVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, Indicator indicator) {
|
|
||||||
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType());
|
||||||
List<String> indicators = section.getIndicators();
|
List<String> indicators = section.getIndicators();
|
||||||
|
|
||||||
if(indicators.contains(indicator.getId())) {
|
if(indicators.contains(indicatorId)) {
|
||||||
indicatorDAO.save(indicator);
|
return changeVisibilityTree(indicatorId, indicator, visibility);
|
||||||
log.debug("Indicator toggled!");
|
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle();
|
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle();
|
||||||
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in Section: "+sectionId);
|
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicatorId+" not found in Section: "+sectionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Indicator changeVisibilityTree(String indicatorId, Indicator indicator, Visibility visibility) {
|
||||||
|
if(indicator == null) {
|
||||||
|
indicator = indicatorDAO.findById(indicatorId);
|
||||||
|
if (indicator == null) {
|
||||||
|
// EXCEPTION - Indicator not found
|
||||||
|
throw new EntityNotFoundException("Change indicator visibility: Indicator with id: " + indicatorId + " not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indicator.setVisibility(visibility);
|
||||||
|
indicatorDAO.save(indicator);
|
||||||
|
log.debug("Indicator toggled!");
|
||||||
|
|
||||||
|
return indicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) {
|
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) {
|
||||||
|
|
|
@ -542,4 +542,22 @@ public class SectionController {
|
||||||
sectionDAO.save(section);
|
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,7 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.controllers;
|
package eu.dnetlib.uoamonitorservice.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.PortalType;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.*;
|
import eu.dnetlib.uoamonitorservice.dao.*;
|
||||||
|
@ -12,7 +11,6 @@ import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.access.AuthorizationServiceException;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -690,9 +688,9 @@ public class StakeholderController {
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
|
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
|
||||||
public Visibility toggleStakeholderAccess(@PathVariable("stakeholderId") String stakeholderId,
|
public Visibility changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||||
@RequestParam("visibility") Visibility visibility) {
|
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||||
log.debug("change stakeholder visibility: "+visibility);
|
log.debug("change stakeholder visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
|
||||||
log.debug("Stakeholder: "+stakeholderId);
|
log.debug("Stakeholder: "+stakeholderId);
|
||||||
|
|
||||||
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||||
|
@ -711,11 +709,20 @@ public class StakeholderController {
|
||||||
// EXCEPTION - Access denied
|
// EXCEPTION - Access denied
|
||||||
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: "+stakeholderId);
|
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: "+stakeholderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return changeStakeholderVisibilityTree(stakeholder, visibility, propagate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Visibility changeStakeholderVisibilityTree(Stakeholder<String> stakeholder, Visibility visibility, Boolean propagate) {
|
||||||
|
if(propagate != null && propagate) {
|
||||||
|
for (String topicId : stakeholder.getTopics()) {
|
||||||
|
topicController.changeVisibilityTree(topicId, visibility, propagate);
|
||||||
|
}
|
||||||
|
}
|
||||||
stakeholder.setVisibility(visibility);
|
stakeholder.setVisibility(visibility);
|
||||||
|
|
||||||
stakeholderDAO.save(stakeholder);
|
stakeholderDAO.save(stakeholder);
|
||||||
log.debug("Stakeholder toggled!");
|
log.debug("Stakeholder toggled!");
|
||||||
|
|
||||||
return stakeholder.getVisibility();
|
return stakeholder.getVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -436,12 +436,12 @@ public class SubCategoryController {
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
|
||||||
public Visibility changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
public SubCategory changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||||
@PathVariable("topicId") String topicId,
|
@PathVariable("topicId") String topicId,
|
||||||
@PathVariable("categoryId") String categoryId,
|
@PathVariable("categoryId") String categoryId,
|
||||||
@PathVariable("subcategoryId") String subcategoryId,
|
@PathVariable("subcategoryId") String subcategoryId,
|
||||||
@RequestParam("visibility") Visibility visibility) {
|
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||||
log.debug("change subCategory visibility: "+visibility);
|
log.debug("change subCategory visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
|
||||||
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
||||||
|
|
||||||
SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
|
SubCategory subCategory = subCategoryDAO.findById(subcategoryId);
|
||||||
|
@ -449,25 +449,45 @@ public class SubCategoryController {
|
||||||
// EXCEPTION - SubCategory not found
|
// EXCEPTION - SubCategory not found
|
||||||
throw new EntityNotFoundException("Change subCategory visibility: SubCategory with id: "+subcategoryId+" not found");
|
throw new EntityNotFoundException("Change subCategory visibility: SubCategory with id: "+subcategoryId+" not found");
|
||||||
}
|
}
|
||||||
subCategory.setVisibility(visibility);
|
|
||||||
|
|
||||||
this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory);
|
|
||||||
|
|
||||||
return subCategory.getVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleSubCategory(String stakeholderId, String topicId, String categoryId, SubCategory subcategory) {
|
|
||||||
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
|
Category category = checkForExceptions(stakeholderId, topicId, categoryId);
|
||||||
|
|
||||||
if (category.getSubCategories().contains(subcategory.getId())) {
|
if (category.getSubCategories().contains(subcategoryId)) {
|
||||||
subCategoryDAO.save(subcategory);
|
return changeVisibilityTree(subcategoryId, visibility, propagate);
|
||||||
log.debug("SubCategory toggled!");
|
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
|
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
|
||||||
throw new PathNotValidException("Toggle subCategory: SubCategory with id: "+subcategory.getId()+" not found in Category: "+categoryId);
|
throw new PathNotValidException("Toggle subCategory: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubCategory changeVisibilityTree(String subCategoryId, Visibility visibility, Boolean propagate) {
|
||||||
|
SubCategory<String> subCategory = subCategoryDAO.findById(subCategoryId);
|
||||||
|
if (subCategory == null) {
|
||||||
|
// EXCEPTION - SubCategory not found
|
||||||
|
throw new EntityNotFoundException("Change subCategory visibility: SubCategory with id: " + subCategoryId + " not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
SubCategory<Section> subCategoryFull = new SubCategory(subCategory);
|
||||||
|
List<Section> chartsFull = new ArrayList();
|
||||||
|
List<Section> numbersFull = new ArrayList();
|
||||||
|
|
||||||
|
if (propagate != null && propagate) {
|
||||||
|
for (String sectionId : subCategory.getCharts()) {
|
||||||
|
chartsFull.add(sectionController.changeVisibilityTree(sectionId, visibility));
|
||||||
|
}
|
||||||
|
for (String sectionId : subCategory.getNumbers()) {
|
||||||
|
numbersFull.add(sectionController.changeVisibilityTree(sectionId, visibility));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subCategory.setVisibility(visibility);
|
||||||
|
subCategoryDAO.save(subCategory);
|
||||||
|
log.debug("SubCategory toggled!");
|
||||||
|
|
||||||
|
subCategoryFull.setVisibility(visibility);
|
||||||
|
subCategoryFull.setCharts(chartsFull);
|
||||||
|
subCategoryFull.setNumbers(numbersFull);
|
||||||
|
|
||||||
|
return subCategoryFull;
|
||||||
|
}
|
||||||
|
|
||||||
private Category checkForExceptions(String stakeholderId, String topicId, String categoryId) {
|
private Category checkForExceptions(String stakeholderId, String topicId, String categoryId) {
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -429,25 +428,12 @@ public class TopicController {
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST)
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST)
|
||||||
public Visibility changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
public Topic changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||||
@PathVariable("topicId") String topicId,
|
@PathVariable("topicId") String topicId,
|
||||||
@RequestParam("visibility") Visibility visibility) {
|
@RequestParam("visibility") Visibility visibility, @RequestParam(required = false) Boolean propagate) {
|
||||||
log.debug("change topic visibility: "+visibility);
|
log.debug("change topic visibility: "+visibility + " - toggle propagate: "+((propagate != null && propagate) ? "true" : "false"));
|
||||||
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
|
||||||
|
|
||||||
Topic topic = topicDAO.findById(topicId);
|
|
||||||
if (topic == null) {
|
|
||||||
// EXCEPTION - Topic not found
|
|
||||||
throw new EntityNotFoundException("Change topic visibility: Topic with id: "+topicId+" not found");
|
|
||||||
}
|
|
||||||
topic.setVisibility(visibility);
|
|
||||||
|
|
||||||
this.toggleTopic(stakeholderId, topic);
|
|
||||||
|
|
||||||
return topic.getVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleTopic(String stakeholderId, Topic topic) {
|
|
||||||
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
||||||
|
|
||||||
if (stakeholder != null) {
|
if (stakeholder != null) {
|
||||||
|
@ -458,17 +444,46 @@ public class TopicController {
|
||||||
throw new ForbiddenException("Toggle topic: You are not authorized to update stakeholder with id: "+stakeholderId);
|
throw new ForbiddenException("Toggle topic: You are not authorized to update stakeholder with id: "+stakeholderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stakeholder.getTopics().contains(topic.getId())) {
|
if (stakeholder.getTopics().contains(topicId)) {
|
||||||
topicDAO.save(topic);
|
return changeVisibilityTree(topicId, visibility, propagate);
|
||||||
log.debug("Topic toggled!");
|
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
|
||||||
throw new PathNotValidException("Toggle topic: Topic with id: "+topic.getId()+" not found in Stakeholder: "+stakeholderId);
|
throw new PathNotValidException("Toggle topic: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// EXCEPTION - Stakeholder not found
|
// EXCEPTION - Stakeholder not found
|
||||||
throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found");
|
throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this.toggleTopic(stakeholderId, topic);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Topic changeVisibilityTree(String topicId, Visibility visibility, Boolean propagate) {
|
||||||
|
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) {
|
public void deleteTree(Stakeholder stakeholder) {
|
||||||
|
|
Loading…
Reference in New Issue