| 1 | package edu.ucsb.cs.scaffold.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs.scaffold.errors.EntityNotFoundException; | |
| 4 | import edu.ucsb.cs.scaffold.errors.ForbiddenException; | |
| 5 | import edu.ucsb.cs.scaffold.model.CurrentUser; | |
| 6 | import edu.ucsb.cs.scaffold.services.CurrentUserService; | |
| 7 | import java.util.Map; | |
| 8 | import lombok.extern.slf4j.Slf4j; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.http.HttpStatus; | |
| 11 | import org.springframework.http.ResponseEntity; | |
| 12 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 13 | import org.springframework.web.bind.annotation.ResponseStatus; | |
| 14 | ||
| 15 | @Slf4j | |
| 16 | public abstract class ApiController { | |
| 17 | ||
| 18 | @Autowired private CurrentUserService currentUserService; | |
| 19 | ||
| 20 | protected CurrentUser getCurrentUser() { | |
| 21 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::getCurrentUser → KILLED |
return currentUserService.getCurrentUser(); |
| 22 | } | |
| 23 | ||
| 24 | protected Object genericMessage(String message) { | |
| 25 |
1
1. genericMessage : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::genericMessage → KILLED |
return Map.of("message", message); |
| 26 | } | |
| 27 | ||
| 28 | @ExceptionHandler({EntityNotFoundException.class}) | |
| 29 | @ResponseStatus(HttpStatus.NOT_FOUND) | |
| 30 | public Object handleEntityNotFoundException(Throwable e) { | |
| 31 |
1
1. handleEntityNotFoundException : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::handleEntityNotFoundException → KILLED |
return Map.of( |
| 32 | "type", e.getClass().getSimpleName(), | |
| 33 | "message", e.getMessage()); | |
| 34 | } | |
| 35 | ||
| 36 | @ExceptionHandler({ForbiddenException.class}) | |
| 37 | @ResponseStatus(HttpStatus.FORBIDDEN) | |
| 38 | public Object handleForbiddenException(Throwable e) { | |
| 39 |
1
1. handleForbiddenException : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::handleForbiddenException → KILLED |
return Map.of( |
| 40 | "type", e.getClass().getSimpleName(), | |
| 41 | "message", e.getMessage()); | |
| 42 | } | |
| 43 | ||
| 44 | @ExceptionHandler(UnsupportedOperationException.class) | |
| 45 | public ResponseEntity<Map<String, String>> handleUnsupportedOperation( | |
| 46 | UnsupportedOperationException ex) { | |
| 47 |
1
1. handleUnsupportedOperation : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::handleUnsupportedOperation → KILLED |
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("message", ex.getMessage())); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * This method handles the IllegalArgumentException. This maps to a 400/Bad Request. | |
| 52 | * | |
| 53 | * @param e the exception | |
| 54 | * @return a map with the type and message of the exception | |
| 55 | */ | |
| 56 | @ExceptionHandler({IllegalArgumentException.class}) | |
| 57 | @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 58 | public Object handleIllegalArgument(Throwable e) { | |
| 59 |
1
1. handleIllegalArgument : replaced return value with null for edu/ucsb/cs/scaffold/controller/ApiController::handleIllegalArgument → KILLED |
return Map.of( |
| 60 | "type", e.getClass().getSimpleName(), | |
| 61 | "message", e.getMessage()); | |
| 62 | } | |
| 63 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 25 |
1.1 |
|
| 31 |
1.1 |
|
| 39 |
1.1 |
|
| 47 |
1.1 |
|
| 59 |
1.1 |