2019-11-22 16:50:59 +01:00
|
|
|
package eu.dnetlib.uoamonitorservice.controllers;
|
|
|
|
|
2024-03-27 13:07:41 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.dto.CategoryFull;
|
2024-03-14 18:01:28 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.dto.SubCategoryFull;
|
2024-03-27 13:07:41 +01:00
|
|
|
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
2024-03-14 18:01:28 +01:00
|
|
|
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.*;
|
|
|
|
|
|
|
|
@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);
|
|
|
|
Stakeholder stakeholder = this.stakeholderService.findById(stakeholderId);
|
|
|
|
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-03-14 18:01:28 +01:00
|
|
|
/*@PreAuthorize("isAuthenticated()")
|
2020-06-25 11:55:46 +02:00
|
|
|
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/reorder", method = RequestMethod.POST)
|
|
|
|
public List<SubCategory> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
|
|
|
|
@PathVariable("topicId") String topicId,
|
|
|
|
@PathVariable("categoryId") String categoryId,
|
|
|
|
@RequestBody List<String> subCategories) {
|
|
|
|
log.debug("reorder subCategories");
|
|
|
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId);
|
|
|
|
|
|
|
|
Category<String> category = checkForExceptions(stakeholderId, topicId, categoryId);
|
|
|
|
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
List<String> oldSubcategories = category.getSubCategories();
|
|
|
|
for (String subcategoryId : oldSubcategories) {
|
|
|
|
if (!subCategories.contains(subcategoryId)) {
|
|
|
|
subCategories.add(subcategoryId);
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 11:55:46 +02:00
|
|
|
category.setSubCategories(subCategories);
|
|
|
|
|
|
|
|
List<SubCategory> subCategoriesFull = new ArrayList<>();
|
|
|
|
for(String subCategoryId : subCategories) {
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
SubCategory subCategory = subCategoryDAO.findById(subCategoryId);
|
|
|
|
if(subCategory == null) {
|
|
|
|
// EXCEPTION - SubCategory not found
|
|
|
|
throw new EntityNotFoundException("Reorder subCategories: subCategory with id: " + subCategoryId + " not found");
|
|
|
|
}
|
|
|
|
subCategoriesFull.add(subCategory);
|
2020-06-25 11:55:46 +02:00
|
|
|
}
|
[Trunk | Monitor Service]:
1. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java && SectionController.java && IndicatorController.java:
a. Comment logs for get requests.
b. Use "ForbiddenException" instead of "AccessDeniedException"
c. On /save, if full entity has id (already in DB), if not found in DB throw EntityNotFoundException.
d. Get children (e.g. when saving a Topic, get its categories) from DB.
2. TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java:
In /reorder, if there are in DB, ids that are missing from reordered list, do reordering and add in the end of list the missing ids.
3. ReorderEvent.java: [NEW] Added class ReorderEvent with fields "action" (String), "target" (String), "ids" (List<String>) (used in IndicatorController.java).
4. IndicatorController.java:
a. In /reorder, @RequestBody changed from List<String> indicators to ReorderEvent reorderEvent.
b. If there are in DB, ids that are missing from reordered list AND missing id is not moved to other section (action = removed and target = missing id), do reordering and add in the end of list the missing ids.
5. ExceptionsHandler.java: exception handler methods "invalidInput()", "nullPointerException()", "notFoundException()" moved to "Admin Tools Library" - "accessDeniedException()" is removed.
6. responses/ExceptionResponse.java: File and folder deleted (moved to "Admin Tools Library").
7. RolesUtils.java: Added method "isLoggedIn()" (checks if no roles for user, or user has role "ROLE_ANONYMOUS").
2020-12-09 15:24:27 +01:00
|
|
|
|
|
|
|
categoryDAO.save(category);
|
|
|
|
log.debug("SubCategories reordered!");
|
|
|
|
|
2020-06-25 11:55:46 +02:00
|
|
|
return subCategoriesFull;
|
2024-03-14 18:01:28 +01:00
|
|
|
}*/
|
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);
|
|
|
|
Stakeholder stakeholder = this.stakeholderService.findById(stakeholderId);
|
|
|
|
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
|
|
|
}
|