2019-11-04 10:03:49 +01:00
|
|
|
package eu.dnetlib.uoamonitorservice.handlers;
|
|
|
|
|
[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.responses.ExceptionResponse;
|
2022-10-10 14:27:17 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2019-11-04 10:03:49 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
@ControllerAdvice
|
|
|
|
@RestController
|
|
|
|
public class ExceptionsHandler {
|
2022-10-10 14:27:17 +02:00
|
|
|
private final Logger log = LogManager.getLogger(this.getClass());
|
2019-11-04 10:03:49 +01:00
|
|
|
|
2019-11-22 16:50:59 +01:00
|
|
|
@ExceptionHandler(EntityNotFoundException.class)
|
|
|
|
public ResponseEntity<ExceptionResponse> entityNotFoundException(Exception ex) {
|
|
|
|
ExceptionResponse response = new ExceptionResponse();
|
|
|
|
response.setErrorCode("Not found Exception");
|
|
|
|
response.setErrorMessage("Entity not found Exception");
|
|
|
|
response.setErrors(ex.getMessage());
|
|
|
|
response.setStatus(HttpStatus.NOT_FOUND);
|
2020-06-17 13:37:42 +02:00
|
|
|
log.error("entityNotFoundException exception : "+ ex.getMessage());
|
2019-11-22 16:50:59 +01:00
|
|
|
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
2024-06-11 16:38:39 +02:00
|
|
|
@ExceptionHandler(BadRequestException.class)
|
|
|
|
public ResponseEntity<ExceptionResponse> conflictException(Exception ex) {
|
|
|
|
ExceptionResponse response = new ExceptionResponse();
|
|
|
|
response.setErrorCode("Not found Exception");
|
|
|
|
response.setErrorMessage("Conflict Exception");
|
|
|
|
response.setErrors(ex.getMessage());
|
|
|
|
response.setStatus(HttpStatus.BAD_REQUEST);
|
|
|
|
log.error("conflictException exception : "+ ex.getMessage());
|
|
|
|
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
2019-11-22 16:50:59 +01:00
|
|
|
@ExceptionHandler(PathNotValidException.class)
|
|
|
|
public ResponseEntity<ExceptionResponse> pathNotValidException(Exception ex) {
|
|
|
|
ExceptionResponse response = new ExceptionResponse();
|
|
|
|
response.setErrorCode("Not found Exception");
|
|
|
|
response.setErrorMessage("Path not valid Exception");
|
|
|
|
response.setErrors(ex.getMessage());
|
|
|
|
response.setStatus(HttpStatus.NOT_FOUND);
|
2020-06-17 13:37:42 +02:00
|
|
|
log.error("pathNotValidException exception : "+ ex.getMessage());
|
2019-11-22 16:50:59 +01:00
|
|
|
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
|
|
|
}
|
2020-11-11 11:52:38 +01:00
|
|
|
|
2019-11-04 10:03:49 +01:00
|
|
|
}
|