2019-11-22 16:50:59 +01:00
package eu.dnetlib.uoamonitorservice.controllers ;
2021-02-24 20:22:19 +01:00
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils ;
2019-11-22 16:50:59 +01:00
import eu.dnetlib.uoamonitorservice.dao.* ;
2020-01-10 11:48:24 +01:00
import eu.dnetlib.uoamonitorservice.entities.* ;
2019-11-22 16:50:59 +01:00
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException ;
[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
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException ;
2019-11-22 16:50:59 +01:00
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException ;
import org.apache.log4j.Logger ;
import org.springframework.beans.factory.annotation.Autowired ;
2020-11-11 13:45:59 +01:00
import org.springframework.security.access.AccessDeniedException ;
import org.springframework.security.access.prepost.PreAuthorize ;
2019-11-22 16:50:59 +01:00
import org.springframework.web.bind.annotation.* ;
import java.util.ArrayList ;
2020-11-11 13:45:59 +01:00
import java.util.Date ;
2020-06-22 21:58:40 +02:00
import java.util.Iterator ;
2019-11-22 16:50:59 +01:00
import java.util.List ;
@RestController
@CrossOrigin ( origins = " * " )
public class TopicController {
private final Logger log = Logger . getLogger ( this . getClass ( ) ) ;
@Autowired
2020-11-11 13:45:59 +01:00
private RolesUtils rolesUtils ;
2019-11-22 16:50:59 +01:00
@Autowired
2020-11-11 13:45:59 +01:00
private StakeholderDAO stakeholderDAO ;
2020-01-10 11:48:24 +01:00
2019-11-22 16:50:59 +01:00
@Autowired
2020-11-11 13:45:59 +01:00
private TopicDAO topicDAO ;
2019-11-22 16:50:59 +01:00
@Autowired
private CategoryController categoryController ;
[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
@Autowired
private CategoryDAO categoryDAO ;
2019-11-22 16:50:59 +01:00
public Topic < Category > buildTopic ( Topic < Category > topicFull ) {
Topic < String > 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 ) ;
2020-11-11 13:45:59 +01:00
Date date = new Date ( ) ;
topic . setCreationDate ( date ) ;
topic . setUpdateDate ( date ) ;
topicFull . setCreationDate ( date ) ;
topicFull . setUpdateDate ( date ) ;
2019-12-19 16:04:25 +01:00
topicDAO . save ( topic ) ;
2019-11-22 16:50:59 +01:00
2019-12-19 16:04:25 +01:00
topicFull . setId ( topic . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
return topicFull ;
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2019-11-22 16:50:59 +01:00
@RequestMapping ( value = " /{stakeholderId}/save " , method = RequestMethod . POST )
public Topic < Category > saveTopic ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@RequestBody Topic < Category > topicFull ) {
log . debug ( " save topic " ) ;
2019-12-19 16:04:25 +01:00
log . debug ( " Alias: " + topicFull . getAlias ( ) + " - Id: " + topicFull . getId ( ) + " - Stakeholder: " + stakeholderId ) ;
2019-11-22 16:50:59 +01:00
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
if ( stakeholder ! = null ) {
2020-11-11 13:45:59 +01:00
List < String > roles = rolesUtils . getRoles ( ) ;
if ( ! rolesUtils . hasUpdateAuthority ( roles , stakeholder . getType ( ) , stakeholder . getAlias ( ) ) ) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException ( " Save Topic: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
Topic < String > topic = new Topic < > ( topicFull ) ;
Date date = new Date ( ) ;
topic . setUpdateDate ( date ) ;
topicFull . 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 > categories = new ArrayList < > ( ) ;
2020-05-18 11:17:05 +02:00
Topic < String > oldTopic = null ;
if ( topicFull . getId ( ) ! = null ) {
oldTopic = topicDAO . findById ( topicFull . 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
if ( oldTopic = = null ) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException ( " save topic: Topic with id: " + topicFull . getId ( ) + " not found " ) ;
}
for ( String categoryId : oldTopic . getCategories ( ) ) {
Category category = categoryDAO . findById ( categoryId ) ;
if ( category = = null ) {
// EXCEPTION - Category not found
throw new EntityNotFoundException ( " Save topic: Category with id: " + categoryId + " not found (category exists in topic: " + topic . getId ( ) + " ) " ) ;
}
categories . add ( category . getId ( ) ) ;
}
2020-11-11 13:45:59 +01:00
} else { // topic does not exist in DB
topic . setCreationDate ( date ) ;
topicFull . setCreationDate ( date ) ;
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
for ( Category category : topicFull . getCategories ( ) ) {
categories . add ( category . 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
topic . setCategories ( categories ) ;
2019-12-19 16:04:25 +01:00
if ( stakeholder . getDefaultId ( ) = = null ) {
if ( topicFull . getId ( ) = = null ) {
2020-11-11 13:45:59 +01:00
topicDAO . save ( topic ) ;
2019-12-19 16:04:25 +01:00
onSaveDefaultTopic ( topic , stakeholderId ) ;
} else {
2020-05-18 11:17:05 +02:00
onUpdateDefaultTopic ( topic , oldTopic ) ;
2020-11-11 13:45:59 +01:00
topicDAO . save ( topic ) ;
2019-12-19 16:04:25 +01:00
}
2020-11-11 13:45:59 +01:00
} else {
topicDAO . save ( topic ) ;
2019-12-19 16:04:25 +01:00
}
2019-11-22 16:50:59 +01:00
List < String > topics = stakeholder . getTopics ( ) ;
2019-12-19 16:04:25 +01:00
int index = topics . indexOf ( topic . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
if ( index = = - 1 ) {
2019-12-19 16:04:25 +01:00
topics . add ( topic . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
stakeholderDAO . save ( stakeholder ) ;
log . debug ( " Topic saved! " ) ;
2019-12-19 16:04:25 +01:00
topicFull . setId ( topic . getId ( ) ) ;
2019-11-22 16:50:59 +01:00
}
categories = null ;
topic = null ;
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException ( " Save topic: Stakeholder with id: " + stakeholderId + " not found " ) ;
}
return topicFull ;
}
2019-12-19 16:04:25 +01:00
public void onSaveDefaultTopic ( Topic topic , String stakeholderId ) {
log . debug ( " On save default topic " ) ;
List < Stakeholder > stakeholders = stakeholderDAO . findByDefaultId ( stakeholderId ) ;
for ( Stakeholder _stakeholder : stakeholders ) {
Topic topicNew = new Topic ( ) ;
topicNew . copyFromDefault ( topic ) ;
topicDAO . save ( topicNew ) ;
List < String > topics = _stakeholder . getTopics ( ) ;
topics . add ( topicNew . getId ( ) ) ;
stakeholderDAO . save ( _stakeholder ) ;
}
}
2020-05-18 11:17:05 +02:00
public void onUpdateDefaultTopic ( Topic topic , Topic oldTopic ) {
2019-12-19 16:04:25 +01:00
log . debug ( " On update default topic " ) ;
List < Topic > topics = topicDAO . findByDefaultId ( topic . getId ( ) ) ;
boolean changed = false ;
for ( Topic topicBasedOnDefault : topics ) {
2020-05-18 11:17:05 +02:00
if ( topic . getName ( ) ! = null & & ! topic . getName ( ) . equals ( topicBasedOnDefault . getName ( ) )
& & ( oldTopic . getName ( ) = = null | | oldTopic . getName ( ) . equals ( topicBasedOnDefault . getName ( ) ) ) ) {
topicBasedOnDefault . setName ( topic . getName ( ) ) ;
2020-09-28 13:59:00 +02:00
topicBasedOnDefault . setAlias ( topic . getAlias ( ) ) ;
2019-12-19 16:04:25 +01:00
changed = true ;
}
2020-05-18 11:17:05 +02:00
if ( topic . getDescription ( ) ! = null & & ! topic . getDescription ( ) . equals ( topicBasedOnDefault . getDescription ( ) )
& & ( oldTopic . getDescription ( ) = = null | | oldTopic . getDescription ( ) . equals ( topicBasedOnDefault . getDescription ( ) ) ) ) {
topicBasedOnDefault . setDescription ( topic . getDescription ( ) ) ;
2019-12-19 16:04:25 +01:00
changed = true ;
}
2020-06-17 13:37:42 +02:00
if ( topic . getIcon ( ) ! = null & & ! topic . getIcon ( ) . equals ( topicBasedOnDefault . getIcon ( ) )
& & ( oldTopic . getIcon ( ) = = null | | oldTopic . getIcon ( ) . equals ( topicBasedOnDefault . getIcon ( ) ) ) ) {
topicBasedOnDefault . setIcon ( topic . getIcon ( ) ) ;
changed = true ;
}
2019-12-19 16:04:25 +01:00
if ( ! changed ) {
2020-05-18 11:17:05 +02:00
// break;
continue ;
2019-12-19 16:04:25 +01:00
}
2020-05-18 11:17:05 +02:00
// topicBasedOnDefault.setName(topic.getName());
// topicBasedOnDefault.setDescription(topic.getDescription());
2020-11-11 13:45:59 +01:00
topicBasedOnDefault . setUpdateDate ( topic . getUpdateDate ( ) ) ;
2019-12-19 16:04:25 +01:00
topicDAO . save ( topicBasedOnDefault ) ;
}
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2019-11-22 16:50:59 +01:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/delete " , method = RequestMethod . DELETE )
public boolean deleteTopic ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
2020-06-22 21:58:40 +02:00
@PathVariable ( " topicId " ) String topicId ,
@RequestParam ( required = false ) String children ) {
2019-11-22 16:50:59 +01:00
log . debug ( " delete topic " ) ;
2019-12-19 16:04:25 +01:00
log . debug ( " Id: " + topicId + " - Stakeholder: " + stakeholderId ) ;
2019-11-22 16:50:59 +01:00
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
if ( stakeholder ! = null ) {
2020-11-11 13:45:59 +01:00
List < String > roles = rolesUtils . getRoles ( ) ;
if ( ! rolesUtils . hasUpdateAuthority ( roles , stakeholder . getType ( ) , stakeholder . getAlias ( ) ) ) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException ( " Delete topic: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2019-11-22 16:50:59 +01:00
Topic < String > topic = topicDAO . findById ( topicId ) ;
if ( topic ! = null ) {
2020-11-11 13:45:59 +01:00
if ( topic . getDefaultId ( ) ! = null & & ! rolesUtils . hasCreateAndDeleteAuthority ( roles , stakeholder . getType ( ) ) ) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException ( " Delete topic: You are not authorized to delete a default Topic in stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2019-11-22 16:50:59 +01:00
List < String > topics = stakeholder . getTopics ( ) ;
int index = topics . indexOf ( topicId ) ;
if ( index ! = - 1 ) {
2020-06-22 21:58:40 +02:00
// this topic belongs in default profile
if ( stakeholder . getDefaultId ( ) = = null & & children ! = null ) {
onDeleteDefaultTopic ( topicId , stakeholderId , children ) ;
2019-11-22 16:50:59 +01:00
}
2020-06-22 21:58:40 +02:00
// for(String categoryId : topic.getCategories()) {
// Category<String> category = categoryDAO.findById(categoryId);
// if(category == null) {
// // EXCEPTION - Category not found
// throw new EntityNotFoundException("Delete topic: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
// }
//
// for(String subCategoryId : category.getSubCategories()) {
// SubCategory<String> subcategory = subCategoryDAO.findById(subCategoryId);
// if (subcategory == null) {
// // EXCEPTION - SubCategory not found
// throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
// }
//
// for(String chartSectionId : subcategory.getCharts()) {
// Section<String> chartSection = sectionDAO.findById(chartSectionId);
// if (chartSection == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
// }
//
// for (String chartId : chartSection.getIndicators()) {
// indicatorDAO.delete(chartId);
// }
// subcategory.setCharts(null);
// sectionDAO.delete(chartSectionId);
// }
//
// for(String numberSectionId : subcategory.getNumbers()) {
// Section<String> numberSection = sectionDAO.findById(numberSectionId);
// if (numberSection == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
// }
//
// for (String numberId : numberSection.getIndicators()) {
// indicatorDAO.delete(numberId);
// }
// subcategory.setNumbers(null);
// sectionDAO.delete(numberSectionId);
// }
//
// subCategoryDAO.delete(subCategoryId);
// }
// category.setSubCategories(null);
// categoryDAO.delete(categoryId);
// }
categoryController . deleteTree ( topic ) ;
2019-11-22 16:50:59 +01:00
topic . setCategories ( null ) ;
topics . remove ( index ) ;
stakeholderDAO . save ( stakeholder ) ;
topicDAO . delete ( 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
log . debug ( " Topic deleted! " ) ;
2019-11-22 16:50:59 +01:00
} 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 " ) ;
}
return true ;
}
2019-12-23 12:45:07 +01:00
2020-06-22 21:58:40 +02:00
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 ) ;
[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
log . debug ( " DefaultId for Topic with id: " + topic . getId ( ) + " cleared! " ) ;
2020-06-22 21:58:40 +02:00
}
}
return true ;
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2020-06-25 11:55:46 +02:00
@RequestMapping ( value = " /{stakeholderId}/reorder " , method = RequestMethod . POST )
public List < Topic > reorderTopics ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@RequestBody List < String > topics ) {
log . debug ( " reorder topics " ) ;
log . debug ( " Stakeholder: " + stakeholderId ) ;
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
if ( stakeholder ! = null ) {
2020-11-11 13:45:59 +01:00
List < String > roles = rolesUtils . getRoles ( ) ;
if ( ! rolesUtils . hasUpdateAuthority ( roles , stakeholder . getType ( ) , stakeholder . getAlias ( ) ) ) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException ( " Reorder topics: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45: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 < String > oldTopics = stakeholder . getTopics ( ) ;
for ( String topicId : oldTopics ) {
if ( ! topics . contains ( topicId ) ) {
topics . add ( topicId ) ;
}
}
2020-06-25 11:55:46 +02:00
stakeholder . setTopics ( topics ) ;
List < Topic > topicsFull = new ArrayList < > ( ) ;
for ( String topicId : topics ) {
[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
Topic topic = topicDAO . findById ( topicId ) ;
if ( topic = = null ) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException ( " Reorder Topics: Topic with id: " + topicId + " not found " ) ;
}
topicsFull . add ( topic ) ;
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
stakeholderDAO . save ( stakeholder ) ;
log . debug ( " Topics reordered! " ) ;
2020-06-25 11:55:46 +02:00
return topicsFull ;
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException ( " Reorder topics: Stakeholder with id: " + stakeholderId + " not found " ) ;
}
}
2020-11-11 13:45:59 +01:00
// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST)
// public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId) {
// log.debug("toggle topic status (isActive)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
//
// Topic topic = topicDAO.findById(topicId);
// if (topic == null) {
// // EXCEPTION - Topic not found
// throw new EntityNotFoundException("Toggle topic status: Topic with id: "+topicId+" not found");
// }
// topic.setIsActive(!topic.getIsActive());
//
// this.toggleTopic(stakeholderId, topic);
//
// return topic.getIsActive();
// }
//
// @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-access", method = RequestMethod.POST)
// public Boolean toggleTopicAccess(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId) {
// log.debug("toggle topic access (isPublic)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId);
//
// Topic topic = topicDAO.findById(topicId);
// if (topic == null) {
// // EXCEPTION - Topic not found
// throw new EntityNotFoundException("Toggle topic access: Topic with id: "+topicId+" not found");
// }
// topic.setIsPublic(!topic.getIsPublic());
//
// this.toggleTopic(stakeholderId, topic);
//
// return topic.getIsPublic();
// }
@PreAuthorize ( " isAuthenticated() " )
@RequestMapping ( value = " /{stakeholderId}/{topicId}/change-visibility " , method = RequestMethod . POST )
public Visibility changeTopicVisibility ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@PathVariable ( " topicId " ) String topicId ,
@RequestParam ( " visibility " ) Visibility visibility ) {
log . debug ( " change topic visibility: " + visibility ) ;
2019-12-23 12:45:07 +01:00
log . debug ( " Stakeholder: " + stakeholderId + " - Topic: " + topicId ) ;
Topic topic = topicDAO . findById ( topicId ) ;
if ( topic = = null ) {
// EXCEPTION - Topic not found
2020-11-11 13:45:59 +01:00
throw new EntityNotFoundException ( " Change topic visibility: Topic with id: " + topicId + " not found " ) ;
2019-12-23 12:45:07 +01:00
}
2020-11-11 13:45:59 +01:00
topic . setVisibility ( visibility ) ;
2019-12-23 12:45:07 +01:00
this . toggleTopic ( stakeholderId , topic ) ;
2020-11-11 13:45:59 +01:00
return topic . getVisibility ( ) ;
2019-12-23 12:45:07 +01:00
}
public void toggleTopic ( String stakeholderId , Topic topic ) {
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
if ( stakeholder ! = null ) {
2020-11-11 13:45:59 +01:00
List < String > roles = rolesUtils . getRoles ( ) ;
if ( ! rolesUtils . hasUpdateAuthority ( roles , stakeholder . getType ( ) , stakeholder . getAlias ( ) ) ) {
// EXCEPTION - Access denied
[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
throw new ForbiddenException ( " Toggle topic: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2019-12-23 12:45:07 +01:00
if ( stakeholder . getTopics ( ) . contains ( topic . getId ( ) ) ) {
topicDAO . save ( topic ) ;
log . debug ( " Topic toggled! " ) ;
} else {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException ( " Toggle topic: Topic with id: " + topic . getId ( ) + " not found in Stakeholder: " + stakeholderId ) ;
}
} else {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException ( " Toggle topic: Stakeholder with id: " + stakeholderId + " not found " ) ;
}
}
2020-06-22 21:58:40 +02:00
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 ) ;
}
}
2019-11-22 16:50:59 +01:00
}