2020-01-10 11:48:24 +01:00
package eu.dnetlib.uoamonitorservice.controllers ;
2021-02-24 20:22:19 +01:00
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils ;
2020-01-10 11:48:24 +01:00
import eu.dnetlib.uoamonitorservice.dao.* ;
import eu.dnetlib.uoamonitorservice.entities.* ;
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 ;
2020-01-10 11:48:24 +01:00
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException ;
2022-10-10 14:27:17 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2020-01-10 11:48:24 +01:00
import org.springframework.beans.factory.annotation.Autowired ;
2020-11-11 13:45:59 +01:00
import org.springframework.security.access.prepost.PreAuthorize ;
2020-01-10 11:48:24 +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 ;
2020-01-10 11:48:24 +01:00
import java.util.List ;
@RestController
@CrossOrigin ( origins = " * " )
public class SectionController {
2022-10-10 14:27:17 +02:00
private final Logger log = LogManager . getLogger ( this . getClass ( ) ) ;
2020-01-10 11:48:24 +01:00
2020-11-11 13:45:59 +01:00
@Autowired
private RolesUtils rolesUtils ;
2020-01-10 11:48:24 +01:00
@Autowired
private StakeholderDAO stakeholderDAO ;
@Autowired
private TopicDAO topicDAO ;
@Autowired
private CategoryDAO categoryDAO ;
@Autowired
private SubCategoryDAO subCategoryDAO ;
@Autowired
private SectionDAO sectionDAO ;
@Autowired
private IndicatorDAO indicatorDAO ;
2020-06-22 21:58:40 +02:00
@Autowired
private IndicatorController indicatorController ;
2020-01-10 11:48:24 +01:00
public Section < Indicator > buildSection ( Section < Indicator > sectionFull ) {
Section < String > section = new Section < > ( sectionFull ) ;
List < String > indicators = new ArrayList < > ( ) ;
List < Indicator > indicatorsFull = new ArrayList < > ( ) ;
for ( Indicator chart : sectionFull . getIndicators ( ) ) {
Indicator chartSaved = indicatorDAO . save ( chart ) ;
chart . setId ( chartSaved . getId ( ) ) ;
indicatorsFull . add ( chart ) ;
indicators . add ( chartSaved . getId ( ) ) ;
}
sectionFull . setIndicators ( indicatorsFull ) ;
section . setIndicators ( indicators ) ;
2020-11-11 13:45:59 +01:00
Date date = new Date ( ) ;
section . setCreationDate ( date ) ;
section . setUpdateDate ( date ) ;
sectionFull . setCreationDate ( date ) ;
sectionFull . setUpdateDate ( date ) ;
2020-01-10 11:48:24 +01:00
sectionDAO . save ( section ) ;
sectionFull . setId ( section . getId ( ) ) ;
return sectionFull ;
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2020-01-17 12:43:31 +01:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save/{index} " , method = RequestMethod . POST )
2020-01-10 11:48:24 +01:00
public Section saveSection ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
2020-01-17 12:43:31 +01:00
@PathVariable ( " topicId " ) String topicId ,
@PathVariable ( " categoryId " ) String categoryId ,
@PathVariable ( " subcategoryId " ) String subcategoryId ,
@PathVariable ( " index " ) String index ,
@RequestBody Section < Indicator > sectionFull ) {
2020-01-10 11:48:24 +01:00
log . debug ( " save section " ) ;
log . debug ( " Name: " + sectionFull . getTitle ( ) + " - Id: " + sectionFull . getId ( ) + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId ) ;
SubCategory < String > subCategory = checkForExceptions ( stakeholderId , topicId , categoryId , subcategoryId ) ;
2020-05-18 11:17:05 +02:00
2020-11-11 13:45:59 +01:00
Section < String > section = new Section < > ( sectionFull ) ;
Date date = new Date ( ) ;
section . setUpdateDate ( date ) ;
sectionFull . 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 > indicators = new ArrayList < > ( ) ;
2020-05-18 11:17:05 +02:00
Section < String > oldSection = null ;
if ( sectionFull . getId ( ) ! = null ) {
oldSection = sectionDAO . findById ( sectionFull . 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 ( oldSection = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " save section: Section with id: " + sectionFull . getId ( ) + " not found " ) ;
}
for ( String indicatorId : oldSection . getIndicators ( ) ) {
Indicator indicator = indicatorDAO . findById ( indicatorId ) ;
if ( indicator = = null ) {
// EXCEPTION - Indicator not found
throw new EntityNotFoundException ( " Save section: Indicator with id: " + indicatorId + " not found (indicator exists in section: " + section . getId ( ) + " ) " ) ;
}
indicators . add ( indicator . getId ( ) ) ;
}
2020-11-11 13:45:59 +01:00
} else { // section does not exist in DB
section . setCreationDate ( date ) ;
sectionFull . setCreationDate ( 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
for ( Indicator indicator : sectionFull . getIndicators ( ) ) {
indicators . add ( indicator . getId ( ) ) ;
}
2020-05-18 11:17:05 +02:00
}
2020-01-10 11:48:24 +01:00
String sectionId = sectionFull . 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
2020-01-10 11:48:24 +01:00
section . setIndicators ( indicators ) ;
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
// this section belongs in default profile and it is new or it is updated
if ( stakeholder . getDefaultId ( ) = = null ) {
if ( sectionId = = null ) {
2020-11-11 13:45:59 +01:00
sectionDAO . save ( section ) ;
2020-05-13 15:25:02 +02:00
onSaveDefaultSection ( section , topicId , categoryId , subcategoryId , stakeholder ) ;
2020-01-10 11:48:24 +01:00
}
else {
2020-05-18 11:17:05 +02:00
onUpdateDefaultSection ( section , stakeholder , oldSection ) ;
2020-11-11 13:45:59 +01:00
sectionDAO . save ( section ) ;
2020-01-10 11:48:24 +01:00
}
2020-11-11 13:45:59 +01:00
} else {
sectionDAO . save ( section ) ;
2020-01-10 11:48:24 +01:00
}
List < String > sections = null ;
if ( sectionFull . getType ( ) . equals ( " chart " ) ) {
sections = subCategory . getCharts ( ) ;
} else if ( sectionFull . getType ( ) . equals ( " number " ) ) {
sections = subCategory . getNumbers ( ) ;
}
2020-05-13 15:25:02 +02:00
int existing_index = sections . indexOf ( section . getId ( ) ) ;
2020-01-17 12:43:31 +01:00
if ( existing_index = = - 1 ) {
2020-05-13 15:25:02 +02:00
if ( Integer . parseInt ( index ) ! = - 1 ) {
sections . add ( Integer . parseInt ( index ) , section . getId ( ) ) ;
2020-01-17 12:43:31 +01:00
} else {
2020-05-13 15:25:02 +02:00
sections . add ( section . getId ( ) ) ;
2020-01-17 12:43:31 +01:00
}
2020-01-10 11:48:24 +01:00
subCategoryDAO . save ( subCategory ) ;
log . debug ( " Section saved! " ) ;
sectionFull . setId ( section . getId ( ) ) ;
}
return sectionFull ;
}
public void onSaveDefaultSection ( Section section ,
String defaultTopicId , String defaultCategoryId ,
String defaultSubcategoryId , Stakeholder defaultStakeholder ) {
log . debug ( " On save default section " ) ;
// new section in default profile - add it on profiles of the same type
List < SubCategory > subCategories = subCategoryDAO . findByDefaultId ( defaultSubcategoryId ) ;
for ( SubCategory subCategory : subCategories ) {
2020-05-18 11:17:05 +02:00
Category parentCategory = categoryDAO . findBySubCategoriesContaining ( subCategory . getId ( ) ) ;
Topic parentTopic = topicDAO . findByCategoriesContaining ( parentCategory . getId ( ) ) ;
Stakeholder parentStakeholder = stakeholderDAO . findByTopicsContaining ( parentTopic . getId ( ) ) ;
2020-01-10 11:48:24 +01:00
Section sectionNew = new Section ( ) ;
sectionNew . copyFromDefault ( section ) ;
2020-05-18 11:17:05 +02:00
sectionNew . setStakeholderAlias ( parentStakeholder . getAlias ( ) ) ;
2020-01-10 11:48:24 +01:00
sectionDAO . save ( sectionNew ) ;
List < String > sections = null ;
if ( section . getType ( ) . equals ( " chart " ) ) {
sections = subCategory . getCharts ( ) ;
} else if ( section . getType ( ) . equals ( " number " ) ) {
sections = subCategory . getNumbers ( ) ;
}
sections . add ( sectionNew . getId ( ) ) ;
subCategoryDAO . save ( subCategory ) ;
}
}
2020-05-18 11:17:05 +02:00
public void onUpdateDefaultSection ( Section section , Stakeholder stakeholder , Section oldSection ) {
2020-01-10 11:48:24 +01:00
log . debug ( " On update default section " ) ;
// section already exists - check if changed and update all sections based on it
boolean changed = false ;
List < Section > sections = sectionDAO . findByDefaultId ( section . getId ( ) ) ;
for ( Section sectionBasedOnDefault : sections ) {
2020-05-18 11:17:05 +02:00
if ( section . getTitle ( ) ! = null & & ! section . getTitle ( ) . equals ( sectionBasedOnDefault . getTitle ( ) )
& & ( oldSection . getTitle ( ) = = null | | oldSection . getTitle ( ) . equals ( sectionBasedOnDefault . getTitle ( ) ) ) ) {
sectionBasedOnDefault . setTitle ( section . getTitle ( ) ) ;
2020-01-10 11:48:24 +01:00
changed = true ;
}
if ( ! changed ) {
2020-05-18 11:17:05 +02:00
// break;
continue ;
2020-01-10 11:48:24 +01:00
}
2020-05-18 11:17:05 +02:00
// sectionBasedOnDefault.setTitle(section.getTitle());
2020-11-11 13:45:59 +01:00
sectionBasedOnDefault . setUpdateDate ( section . getUpdateDate ( ) ) ;
2020-01-10 11:48:24 +01:00
sectionDAO . save ( sectionBasedOnDefault ) ;
}
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2020-01-10 11:48:24 +01:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete " , method = RequestMethod . DELETE )
public boolean deleteSection ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
2020-06-22 21:58:40 +02:00
@PathVariable ( " topicId " ) String topicId ,
@PathVariable ( " categoryId " ) String categoryId ,
@PathVariable ( " subcategoryId " ) String subcategoryId ,
@PathVariable ( " sectionId " ) String sectionId ,
@RequestParam ( required = false ) String children ) {
2020-01-10 11:48:24 +01:00
log . debug ( " delete section " ) ;
log . debug ( " Id: " + sectionId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId ) ;
Section section = sectionDAO . findById ( sectionId ) ;
if ( section ! = null ) {
SubCategory < String > subCategory = checkForExceptions ( stakeholderId , topicId , categoryId , subcategoryId ) ;
2020-11-11 13:45:59 +01:00
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
List < String > roles = rolesUtils . getRoles ( ) ;
if ( section . 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 section: You are not authorized to delete a default Section in stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2020-06-22 21:58:40 +02:00
String type = " " ;
2020-01-10 11:48:24 +01:00
List < String > sections = null ;
if ( section . getType ( ) . equals ( " chart " ) ) {
sections = subCategory . getCharts ( ) ;
2020-06-22 21:58:40 +02:00
type = " chart " ;
2020-01-10 11:48:24 +01:00
} else if ( section . getType ( ) . equals ( " number " ) ) {
sections = subCategory . getNumbers ( ) ;
2020-06-22 21:58:40 +02:00
type = " number " ;
2020-01-10 11:48:24 +01:00
}
int index = sections . indexOf ( sectionId ) ;
if ( index ! = - 1 ) {
2020-06-22 21:58:40 +02:00
// this section belongs in default profile
if ( subCategory . getDefaultId ( ) = = null & & children ! = null ) {
onDeleteDefaultSection ( sectionId , subcategoryId , children , type ) ;
}
indicatorController . deleteTree ( section ) ;
2020-01-10 11:48:24 +01:00
sections . remove ( index ) ;
subCategoryDAO . save ( subCategory ) ;
sectionDAO . delete ( sectionId ) ;
log . debug ( " Section deleted! " ) ;
} else {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias();
throw new PathNotValidException ( " Delete section: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId ) ;
}
} else {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Delete section: Section with id: " + sectionId + " not found " ) ;
}
return true ;
}
2020-06-22 21:58:40 +02:00
public boolean onDeleteDefaultSection ( String defaultSectionId , String defaultSubCategoryId , String children , String type ) {
if ( children . equals ( " delete " ) ) {
List < SubCategory > subCategories = subCategoryDAO . findByDefaultId ( defaultSubCategoryId ) ;
List < Section > sections = sectionDAO . findByDefaultId ( defaultSectionId ) ;
for ( SubCategory subCategory : subCategories ) {
Iterator < Section > sectionsIterator = sections . iterator ( ) ;
while ( sectionsIterator . hasNext ( ) ) {
Section section = sectionsIterator . next ( ) ;
String sectionId = section . getId ( ) ;
List < String > subCategorySections = null ;
if ( type . equals ( " chart " ) ) {
subCategorySections = subCategory . getCharts ( ) ;
} else if ( type . equals ( " number " ) ) {
subCategorySections = subCategory . getNumbers ( ) ;
}
if ( subCategorySections ! = null & & subCategorySections . contains ( sectionId ) ) {
sectionsIterator . remove ( ) ;
subCategorySections . remove ( sectionId ) ;
subCategoryDAO . save ( subCategory ) ;
indicatorController . deleteTree ( section ) ;
sectionDAO . delete ( sectionId ) ;
log . debug ( " Section with id: " + sectionId + " deleted! " ) ;
break ;
}
}
}
} else if ( children . equals ( " disconnect " ) ) {
List < Section > sections = sectionDAO . findByDefaultId ( defaultSectionId ) ;
for ( Section section : sections ) {
indicatorController . disConnectTree ( section ) ;
section . setDefaultId ( null ) ;
sectionDAO . save ( section ) ;
log . debug ( " DefaultId for Section with id: " + section . getId ( ) + " empty! " ) ;
}
}
return true ;
}
2020-11-11 13:45:59 +01:00
@PreAuthorize ( " isAuthenticated() " )
2020-01-10 11:48:24 +01:00
@RequestMapping ( value = " /{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder " , method = RequestMethod . POST )
public List < Section > reorderSections ( @PathVariable ( " stakeholderId " ) String stakeholderId ,
@PathVariable ( " topicId " ) String topicId ,
@PathVariable ( " categoryId " ) String categoryId ,
@PathVariable ( " subcategoryId " ) String subcategoryId ,
@PathVariable ( " type " ) String type ,
@RequestBody List < String > sections ) {
log . debug ( " reorder sections of type: " + type ) ;
log . debug ( " Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId ) ;
SubCategory < String > subCategory = checkForExceptions ( stakeholderId , topicId , categoryId , subcategoryId ) ;
if ( type . equals ( " chart " ) ) {
[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 > oldSections = subCategory . getCharts ( ) ;
for ( String sectionId : oldSections ) {
if ( ! sections . contains ( sectionId ) ) {
sections . add ( sectionId ) ;
}
}
2020-01-10 11:48:24 +01:00
subCategory . setCharts ( sections ) ;
} else if ( type . equals ( " number " ) ) {
[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 > oldSections = subCategory . getNumbers ( ) ;
for ( String sectionId : oldSections ) {
if ( ! sections . contains ( sectionId ) ) {
sections . add ( sectionId ) ;
}
}
2020-01-10 11:48:24 +01:00
subCategory . setNumbers ( sections ) ;
}
List < Section > sectionsFull = new ArrayList < > ( ) ;
for ( String sectionId : sections ) {
[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
Section section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Reorder sections: Section with id: " + sectionId + " not found " ) ;
}
sectionsFull . add ( section ) ;
2020-01-10 11:48:24 +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
subCategoryDAO . save ( subCategory ) ;
log . debug ( " Sections reordered! " ) ;
2020-01-10 11:48:24 +01:00
return sectionsFull ;
}
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-status", method = RequestMethod.POST)
// public Boolean toggleSectionStatus(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId,
// @PathVariable("subcategoryId") String subcategoryId,
// @PathVariable("sectionId") String sectionId) {
// log.debug("toggle section status (isActive)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Section: "+sectionId);
//
// Section section = sectionDAO.findById(sectionId);
// if (section == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Toggle section status: Section with id: "+sectionId+" not found");
// }
// section.setIsActive(!section.getIsActive());
//
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId, section);
//
// return section.getIsActive();
// }
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-access", method = RequestMethod.POST)
// public Boolean toggleSectionAccess(@PathVariable("stakeholderId") String stakeholderId,
// @PathVariable("topicId") String topicId,
// @PathVariable("categoryId") String categoryId,
// @PathVariable("subcategoryId") String subcategoryId,
// @PathVariable("sectionId") String sectionId) {
// log.debug("toggle section access (isPublic)");
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
//
// Section section = sectionDAO.findById(sectionId);
// if (section == null) {
// // EXCEPTION - Section not found
// throw new EntityNotFoundException("Toggle section access: Section with id: "+sectionId+" not found");
// }
// section.setIsPublic(!section.getIsPublic());
//
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId);
//
// return section.getIsPublic();
// }
2020-11-11 13:45:59 +01:00
2020-01-10 11:48:24 +01:00
public void toggleSection ( String stakeholderId , String topicId , String categoryId , String subcategoryId , Section section ) {
SubCategory < String > subCategory = checkForExceptions ( stakeholderId , topicId , categoryId , subcategoryId ) ;
List < String > sections = null ;
if ( section . getType ( ) . equals ( " chart " ) ) {
sections = subCategory . getCharts ( ) ;
} else if ( section . getType ( ) . equals ( " number " ) ) {
sections = subCategory . getNumbers ( ) ;
}
if ( sections . contains ( section . getId ( ) ) ) {
sectionDAO . save ( section ) ;
log . debug ( " Section toggled! " ) ;
} else {
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias();
throw new PathNotValidException ( " Toggle section: Section with id: " + section . getId ( ) + " not found in SubCategory: " + subcategoryId ) ;
}
}
private SubCategory checkForExceptions ( String stakeholderId , String topicId , String categoryId , String subcategoryId ) {
Stakeholder < String > stakeholder = stakeholderDAO . findById ( stakeholderId ) ;
if ( stakeholder = = null ) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException ( " Save indicator: Stakeholder with id: " + stakeholderId + " not found " ) ;
}
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 ( " CheckForExceptions Section: You are not authorized to update stakeholder with id: " + stakeholderId ) ;
2020-11-11 13:45:59 +01:00
}
2020-01-10 11:48:24 +01:00
Topic < String > topic = topicDAO . findById ( topicId ) ;
if ( topic = = null ) {
// EXCEPTION - Topic not found
throw new EntityNotFoundException ( " Save indicator: Topic with id: " + topicId + " not found " ) ;
}
if ( ! stakeholder . getTopics ( ) . contains ( topicId ) ) {
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
throw new PathNotValidException ( " Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId ) ;
}
Category < String > category = categoryDAO . findById ( categoryId ) ;
if ( category = = null ) {
// EXCEPTION - Category not found
throw new EntityNotFoundException ( " Save indicator: Category with id: " + categoryId + " not found " ) ;
}
if ( ! topic . getCategories ( ) . contains ( categoryId ) ) {
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
throw new PathNotValidException ( " Save indicator: Category with id: " + categoryId + " not found in Topic: " + topicId ) ;
}
SubCategory < String > subcategory = subCategoryDAO . findById ( subcategoryId ) ;
if ( subcategory = = null ) {
// EXCEPTION - SubCategory not found
throw new EntityNotFoundException ( " Save indicator: SubCategory with id: " + subcategoryId + " not found " ) ;
}
if ( ! category . getSubCategories ( ) . contains ( subcategoryId ) ) {
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
throw new PathNotValidException ( " Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId ) ;
}
return subcategory ;
}
2020-06-22 21:58:40 +02:00
public void deleteTree ( SubCategory subCategory ) {
List < String > sections = subCategory . getCharts ( ) ;
for ( String sectionId : sections ) {
Section section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Section delete tree: Chart Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategory . getId ( ) + " ) " ) ;
}
indicatorController . deleteTree ( section ) ;
sectionDAO . delete ( sectionId ) ;
}
sections = subCategory . getNumbers ( ) ;
for ( String sectionId : sections ) {
Section section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Section delete tree: Number Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategory . getId ( ) + " ) " ) ;
}
indicatorController . deleteTree ( section ) ;
sectionDAO . delete ( sectionId ) ;
}
}
public void disConnectTree ( SubCategory subCategory ) {
List < String > sections = subCategory . getCharts ( ) ;
for ( String sectionId : sections ) {
Section section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Section disconnect tree: Chart Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategory . getId ( ) + " ) " ) ;
}
indicatorController . disConnectTree ( section ) ;
section . setDefaultId ( null ) ;
sectionDAO . save ( section ) ;
}
sections = subCategory . getNumbers ( ) ;
for ( String sectionId : sections ) {
Section section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Section disconnect tree: Number Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategory . getId ( ) + " ) " ) ;
}
indicatorController . disConnectTree ( section ) ;
section . setDefaultId ( null ) ;
sectionDAO . save ( section ) ;
}
}
2022-09-14 17:02:47 +02:00
public Section changeVisibilityTree ( String sectionId , Visibility visibility ) {
Section < String > section = sectionDAO . findById ( sectionId ) ;
if ( section = = null ) {
// EXCEPTION - Section not found
throw new EntityNotFoundException ( " Change section visibility: Section with id: " + sectionId + " not found " ) ;
}
Section < Indicator > sectionFull = new Section ( section ) ;
List < Indicator > indicatorsFull = new ArrayList ( ) ;
for ( String indicatorId : section . getIndicators ( ) ) {
indicatorsFull . add ( indicatorController . changeVisibilityTree ( indicatorId , null , visibility ) ) ;
}
sectionFull . setIndicators ( indicatorsFull ) ;
return sectionFull ;
}
2020-01-10 11:48:24 +01:00
}