2019-11-22 16:50:59 +01:00
|
|
|
package eu.dnetlib.uoamonitorservice.controllers;
|
|
|
|
|
2024-03-14 18:01:28 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.dto.SubCategoryFull;
|
|
|
|
import eu.dnetlib.uoamonitorservice.entities.Category;
|
|
|
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
|
|
|
import eu.dnetlib.uoamonitorservice.entities.SubCategory;
|
|
|
|
import eu.dnetlib.uoamonitorservice.entities.Topic;
|
2024-03-08 19:55:51 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
2024-03-14 18:01:28 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.service.CategoryService;
|
|
|
|
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
|
|
|
import eu.dnetlib.uoamonitorservice.service.SubCategoryService;
|
|
|
|
import eu.dnetlib.uoamonitorservice.service.TopicService;
|
2022-10-10 14:27:17 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2019-11-22 16:50:59 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-11-11 13:45:59 +01:00
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2019-11-22 16:50:59 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
2024-04-02 13:49:02 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-11-22 16:50:59 +01:00
|
|
|
@RestController
|
|
|
|
@CrossOrigin(origins = "*")
|
|
|
|
public class SubCategoryController {
|
2022-10-10 14:27:17 +02:00
|
|
|
private final Logger log = LogManager.getLogger(this.getClass());
|
2019-11-22 16:50:59 +01:00
|
|
|
|
2024-03-14 18:01:28 +01:00
|
|
|
private final StakeholderService stakeholderService;
|
|
|
|
private final TopicService topicService;
|
|
|
|
private final CategoryService categoryService;
|
|
|
|
private final SubCategoryService subCategoryService;
|
2019-11-22 16:50:59 +01:00
|
|
|
|
|
|
|
@Autowired
|
2024-03-14 18:01:28 +01:00
|
|
|
public SubCategoryController(StakeholderService stakeholderService, TopicService topicService, CategoryService categoryService, SubCategoryService subCategoryService) {
|
|
|
|
this.stakeholderService = stakeholderService;
|
|
|
|
this.topicService = topicService;
|
|
|
|
this.categoryService = categoryService;
|
|
|
|
this.subCategoryService = subCategoryService;
|
2019-11-22 16:50:59 +01:00
|
|
|
}
|
|
|
|
|
2024-03-27 13:07:41 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2019-11-22 16:50:59 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/save", method = RequestMethod.POST)
|
2024-03-27 13:07:41 +01:00
|
|
|
public SubCategoryFull saveSubCategory(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@RequestBody SubCategoryFull subcategoryFull) {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("save subcategory");
|
2024-03-27 13:07:41 +01:00
|
|
|
log.debug("Alias: " + subcategoryFull.getAlias() + " - Id: " + subcategoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
|
|
|
|
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
return this.subCategoryService.save(stakeholder, category, new SubCategory(subcategoryFull));
|
2019-12-19 16:04:25 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2019-11-22 16:50:59 +01:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/delete", method = RequestMethod.DELETE)
|
|
|
|
public boolean deleteSubCategory(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
2020-06-22 21:58:40 +02:00
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
|
|
|
@RequestParam(required = false) String children) {
|
2019-11-22 16:50:59 +01:00
|
|
|
log.debug("delete subcategory");
|
2024-03-14 18:01:28 +01:00
|
|
|
log.debug("Id: " + subcategoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
|
2024-04-02 13:49:02 +02:00
|
|
|
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
2024-03-14 18:01:28 +01:00
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
|
|
|
this.subCategoryService.delete(stakeholder.getType(), subCategory, true);
|
2020-06-22 21:58:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-02 13:49:02 +02:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2020-06-25 11:55:46 +02:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/reorder", method = RequestMethod.POST)
|
2024-04-02 13:49:02 +02:00
|
|
|
public List<SubCategoryFull> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@RequestBody List<String> subCategories) {
|
2020-06-25 11:55:46 +02:00
|
|
|
log.debug("reorder subCategories");
|
2024-04-02 13:49:02 +02:00
|
|
|
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
|
|
|
|
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
return this.categoryService.reorderSubCategories(stakeholder, category, subCategories).getSubCategories();
|
|
|
|
}
|
2020-06-25 11:55:46 +02:00
|
|
|
|
2020-11-11 13:45:59 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
|
2024-03-14 18:01:28 +01:00
|
|
|
public SubCategoryFull changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@PathVariable("subcategoryId") String subcategoryId,
|
|
|
|
@RequestParam("visibility") Visibility visibility,
|
|
|
|
@RequestParam(defaultValue = "false") Boolean propagate) {
|
|
|
|
log.debug("change subCategory visibility: " + visibility + " - toggle propagate: " + propagate);
|
|
|
|
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
|
2024-04-02 13:49:02 +02:00
|
|
|
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
2024-03-14 18:01:28 +01:00
|
|
|
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
|
|
|
Category category = this.categoryService.findByPath(topic, categoryId);
|
|
|
|
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
|
|
|
return this.subCategoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), subCategory, visibility, propagate);
|
2020-06-22 21:58:40 +02:00
|
|
|
}
|
2019-11-22 16:50:59 +01:00
|
|
|
}
|