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.CategoryFull ;
import eu.dnetlib.uoamonitorservice.entities.Category ;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder ;
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.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 CategoryController {
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 ;
2019-11-22 16:50:59 +01:00
@Autowired
2024-03-14 18:01:28 +01:00
public CategoryController ( StakeholderService stakeholderService , TopicService topicService , CategoryService categoryService ) {
this . stakeholderService = stakeholderService ;
this . topicService = topicService ;
this . categoryService = categoryService ;
2019-11-22 16:50:59 +01:00
}
2024-03-14 18:01:28 +01:00
/ * @PreAuthorize ( " isAuthenticated() " )
2019-11-22 16:50:59 +01:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/save " , method = RequestMethod . POST )
public Category < SubCategory > saveCategory ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@PathVariable ( " topicId " ) String topicId ,
@RequestBody Category < SubCategory > categoryFull ) {
log . debug ( " save category " ) ;
2024-03-06 00:48:31 +01:00
log . debug ( " Alias: " + categoryFull . getAlias ( ) + " - Id: " + categoryFull . getId ( ) + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId ) ;
2019-11-22 16:50:59 +01:00
2024-03-08 19:55:51 +01:00
Stakeholder stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
2019-11-22 16:50:59 +01:00
2024-03-06 00:48:31 +01:00
if ( stakeholder ! = null ) {
if ( ! rolesUtils . hasUpdateAuthority ( stakeholder . getType ( ) , stakeholder . getAlias ( ) ) ) {
2020-11-11 13:45:59 +01:00
// EXCEPTION - Access denied
2024-03-06 00:48:31 +01:00
throw new ForbiddenException ( " Save Category: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2020-05-18 11:17:05 +02:00
Category < String > oldCategory = null ;
2024-03-06 00:48:31 +01:00
if ( categoryFull . getId ( ) ! = null ) {
2020-05-18 11:17:05 +02:00
oldCategory = categoryDAO . findById ( categoryFull . getId ( ) ) ;
2024-03-06 00:48:31 +01:00
if ( oldCategory = = null ) {
[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
// EXCEPTION - Category not found
throw new EntityNotFoundException ( " save category: Category with id: " + categoryFull . getId ( ) + " not found " ) ;
}
2020-05-18 11:17:05 +02:00
}
2019-11-22 16:50:59 +01:00
Topic < String > topic = topicDAO . findById ( topicId ) ;
2024-03-06 00:48:31 +01:00
if ( topic ! = null ) {
if ( stakeholder . getTopics ( ) . contains ( topicId ) ) {
2020-11-11 13:45:59 +01:00
Category < String > category = new Category < > ( categoryFull ) ;
Date date = new Date ( ) ;
category . setUpdateDate ( date ) ;
categoryFull . setUpdateDate ( date ) ;
[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 > subCategories = new ArrayList < > ( ) ;
2019-11-22 16:50:59 +01:00
// if category not exists (no id), create a new default subcategory, identical to category
2024-03-06 00:48:31 +01:00
if ( categoryFull . getId ( ) = = null ) {
2020-11-11 13:45:59 +01:00
category . setCreationDate ( date ) ;
categoryFull . setCreationDate ( date ) ;
2019-11-22 16:50:59 +01:00
SubCategory < String > subCategory = new SubCategory < > ( ) ;
2019-12-19 16:04:25 +01:00
subCategory . createOverviewSubCategory ( categoryFull ) ;
subCategoryDAO . save ( subCategory ) ;
2019-11-22 16:50:59 +01: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
List < SubCategory > subCategoriesFull = categoryFull . getSubCategories ( ) ;
subCategoriesFull . add ( subCategory ) ;
2024-03-06 00:48:31 +01:00
for ( SubCategory oldSubCategory : subCategoriesFull ) {
[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
subCategories . add ( oldSubCategory . getId ( ) ) ;
}
} else {
2024-03-06 00:48:31 +01:00
for ( String subCategoryId : oldCategory . getSubCategories ( ) ) {
[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
2024-03-06 00:48:31 +01:00
throw new EntityNotFoundException ( " Save category: SubCategory with id: " + subCategoryId + " not found (subcategory exists in category: " + category . getId ( ) + " ) " ) ;
[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
}
subCategories . add ( subCategory . getId ( ) ) ;
}
2019-11-22 16:50:59 +01: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
2019-11-22 16:50:59 +01:00
category . setSubCategories ( subCategories ) ;
2024-03-06 00:48:31 +01:00
if ( stakeholder . getDefaultId ( ) = = null ) {
if ( categoryFull . getId ( ) = = null ) {
2020-11-11 13:45:59 +01:00
categoryDAO . save ( category ) ;
2019-12-19 16:04:25 +01:00
onSaveDefaultCategory ( category , topicId ) ;
} else {
2020-05-18 11:17:05 +02:00
onUpdateDefaultCategory ( category , oldCategory ) ;
2020-11-11 13:45:59 +01:00
categoryDAO . save ( category ) ;
2019-12-19 16:04:25 +01:00
}
2020-11-11 13:45:59 +01:00
} else {
categoryDAO . save ( category ) ;
2019-12-19 16:04:25 +01:00
}
2019-11-22 16:50:59 +01:00
List < String > categories = topic . getCategories ( ) ;
2019-12-19 16:04:25 +01:00
int index = categories . indexOf ( category . getId ( ) ) ;
2024-03-06 00:48:31 +01:00
if ( index = = - 1 ) {
2019-12-19 16:04:25 +01:00
categories . add ( category . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
topicDAO . save ( topic ) ;
log . debug ( " Category saved! " ) ;
2019-12-19 16:04:25 +01:00
categoryFull . setId ( category . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
}
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
2024-03-06 00:48:31 +01:00
throw new PathNotValidException ( " Save category: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId ) ;
2019-11-22 16:50:59 +01:00
}
} else {
// EXCEPTION - Topic not found
2024-03-06 00:48:31 +01:00
throw new EntityNotFoundException ( " Save category: Topic with id: " + topicId + " not found " ) ;
2019-11-22 16:50:59 +01:00
}
} else {
// EXCEPTION - Stakeholder not found
2024-03-06 00:48:31 +01:00
throw new EntityNotFoundException ( " Save category: Stakeholder with id: " + stakeholderId + " not found " ) ;
2019-11-22 16:50:59 +01:00
}
return categoryFull ;
2024-03-14 18:01:28 +01:00
} * /
2019-11-22 16:50:59 +01:00
2024-03-14 18:01:28 +01:00
/ * public void onSaveDefaultCategory ( Category < String > category , String topicId ) {
2019-12-19 16:04:25 +01:00
log . debug ( " On save default category " ) ;
List < Topic > topics = topicDAO . findByDefaultId ( topicId ) ;
2024-03-06 00:48:31 +01:00
for ( Topic topic : topics ) {
2019-12-19 16:04:25 +01:00
Category categoryNew = new Category ( ) ;
categoryNew . copyFromDefault ( category ) ;
categoryDAO . save ( categoryNew ) ;
List < String > categories = topic . getCategories ( ) ;
categories . add ( categoryNew . getId ( ) ) ;
topicDAO . save ( topic ) ;
}
String subCategoryOverviewId = category . getSubCategories ( ) . get ( 0 ) ;
SubCategory subCategoryOverview = subCategoryDAO . findById ( subCategoryOverviewId ) ;
subCategoryController . onSaveDefaultSubCategory ( subCategoryOverview , category . getId ( ) ) ;
2024-03-14 18:01:28 +01:00
} * /
2019-12-19 16:04:25 +01:00
2024-03-14 18:01:28 +01:00
/ * public void onUpdateDefaultCategory ( Category category , Category oldCategory ) {
2019-12-19 16:04:25 +01:00
log . debug ( " On update default category " ) ;
List < Category > categories = categoryDAO . findByDefaultId ( category . getId ( ) ) ;
boolean changed = false ;
2024-03-06 00:48:31 +01:00
for ( Category categoryBasedOnDefault : categories ) {
if ( category . getName ( ) ! = null & & ! category . getName ( ) . equals ( categoryBasedOnDefault . getName ( ) )
2020-05-18 11:17:05 +02:00
& & ( oldCategory . getName ( ) = = null | | oldCategory . getName ( ) . equals ( categoryBasedOnDefault . getName ( ) ) ) ) {
categoryBasedOnDefault . setName ( category . getName ( ) ) ;
2020-09-28 13:59:00 +02:00
categoryBasedOnDefault . setAlias ( category . getAlias ( ) ) ;
2019-12-19 16:04:25 +01:00
changed = true ;
}
2024-03-06 00:48:31 +01:00
if ( category . getDescription ( ) ! = null & & ! category . getDescription ( ) . equals ( categoryBasedOnDefault . getDescription ( ) )
2020-05-18 11:17:05 +02:00
& & ( oldCategory . getDescription ( ) = = null | | oldCategory . getDescription ( ) . equals ( categoryBasedOnDefault . getDescription ( ) ) ) ) {
categoryBasedOnDefault . setDescription ( category . getDescription ( ) ) ;
2019-12-19 16:04:25 +01:00
changed = true ;
}
2024-03-06 00:48:31 +01:00
if ( ! changed ) {
2020-05-18 11:17:05 +02:00
continue ;
2019-12-19 16:04:25 +01:00
}
2020-11-11 13:45:59 +01:00
categoryBasedOnDefault . setUpdateDate ( category . getUpdateDate ( ) ) ;
2019-12-19 16:04:25 +01:00
categoryDAO . save ( categoryBasedOnDefault ) ;
}
2024-03-14 18:01:28 +01:00
} * /
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}/delete " , method = RequestMethod . DELETE )
public boolean deleteCategory ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@PathVariable ( " topicId " ) String topicId ,
2020-06-22 21:58:40 +02:00
@PathVariable ( " categoryId " ) String categoryId ,
@RequestParam ( required = false ) String children ) {
2019-11-22 16:50:59 +01:00
log . debug ( " delete category " ) ;
2024-03-06 00:48:31 +01:00
log . debug ( " Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId ) ;
2024-03-14 18:01:28 +01:00
Stakeholder stakeholder = this . stakeholderService . findById ( stakeholderId ) ;
Topic topic = this . topicService . findByPath ( stakeholder , topicId ) ;
Category category = this . categoryService . findByPath ( topic , categoryId ) ;
this . categoryService . delete ( stakeholder . getType ( ) , category , true ) ;
2019-11-22 16:50:59 +01:00
return true ;
}
2019-12-23 12:45:07 +01:00
2024-03-14 18:01:28 +01:00
/ * @PreAuthorize ( " isAuthenticated() " )
2020-06-25 11:55:46 +02:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/reorder " , method = RequestMethod . POST )
public List < Category > reorderCategories ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
2024-03-06 00:48:31 +01:00
@PathVariable ( " topicId " ) String topicId ,
@RequestBody List < String > categories ) {
2020-06-25 11:55:46 +02:00
log . debug ( " reorder categories " ) ;
2024-03-06 00:48:31 +01:00
log . debug ( " Stakeholder: " + stakeholderId + " - Topic: " + topicId ) ;
2020-06-25 11:55:46 +02:00
Topic < String > topic = checkForExceptions ( stakeholderId , topicId ) ;
[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 > oldCategories = topic . getCategories ( ) ;
for ( String categoryId : oldCategories ) {
if ( ! categories . contains ( categoryId ) ) {
categories . add ( categoryId ) ;
}
}
2020-06-25 11:55:46 +02:00
topic . setCategories ( categories ) ;
List < Category > categoriesFull = new ArrayList < > ( ) ;
2024-03-06 00:48:31 +01:00
for ( String categoryId : categories ) {
[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
Category category = categoryDAO . findById ( categoryId ) ;
2024-03-06 00:48:31 +01:00
if ( category = = null ) {
[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
// EXCEPTION - Category not found
throw new EntityNotFoundException ( " Reorder Categories: Category with id: " + categoryId + " not found " ) ;
}
categoriesFull . add ( category ) ;
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
topicDAO . save ( topic ) ;
log . debug ( " Categories reordered! " ) ;
2020-06-25 11:55:46 +02:00
return categoriesFull ;
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}/change-visibility " , method = RequestMethod . POST )
2024-03-14 18:01:28 +01:00
public CategoryFull changeCategoryVisibility ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@PathVariable ( " topicId " ) String topicId ,
@PathVariable ( " categoryId " ) String categoryId ,
@RequestParam ( " visibility " ) Visibility visibility , @RequestParam ( defaultValue = " false " ) Boolean propagate ) {
log . debug ( " change category visibility: " + visibility + " - toggle propagate: " + propagate ) ;
2024-03-06 00:48:31 +01:00
log . debug ( " Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId ) ;
2024-03-14 18:01:28 +01:00
Stakeholder stakeholder = this . stakeholderService . findById ( stakeholderId ) ;
Topic topic = this . topicService . findByPath ( stakeholder , topicId ) ;
Category category = this . categoryService . findByPath ( topic , categoryId ) ;
return this . categoryService . changeVisibility ( stakeholder . getType ( ) , stakeholder . getAlias ( ) , category , visibility , propagate ) ;
2020-06-22 21:58:40 +02:00
}
2019-11-22 16:50:59 +01:00
}