Project

General

Profile

« Previous | Next » 

Revision 57671

1. Schema changes: Move each entity on its own collection - each entity keeps ids for its sub-entities.
2. New controllers for each entity: TopicController.java, CategoryController.java, SubCategoryController.java, IndicatorController.java.
3. New DAOs for each entity: TopicDAO.java, MongoDBTopicDAO.java, CategoryDAO.java, MongoDBCategoryDAO.java, SubCategoryDAO.java, MongoDBSubCategoryDAO.java.
4. New custom Exceptions: EntityNotFoundException.java, PathNotValidException.java.
5. ExceptionsHandler.java: Handle new EntityNotFoundException (id not in db) and PathNotValidException (id exists in db but not in path given).

View differences:

ExceptionsHandler.java
19 19
    public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
20 20
        ExceptionResponse response = new ExceptionResponse();
21 21
        response.setErrorCode("Validation Error");
22
        response.setErrorMessage("Invalid inputs.");
22
        response.setErrorMessage("Invalid inputs");
23 23
        response.setErrors(ex.getMessage());
24 24
        response.setStatus(HttpStatus.BAD_REQUEST);
25 25
        log.debug("invalidInput exception");
......
47 47
        log.debug("notFoundException exception");
48 48
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
49 49
    }
50

  
51
    @ExceptionHandler(EntityNotFoundException.class)
52
    public ResponseEntity<ExceptionResponse> entityNotFoundException(Exception ex) {
53
        ExceptionResponse response = new ExceptionResponse();
54
        response.setErrorCode("Not found Exception");
55
        response.setErrorMessage("Entity not found Exception");
56
        response.setErrors(ex.getMessage());
57
        response.setStatus(HttpStatus.NOT_FOUND);
58
        log.debug("entityNotFoundException exception");
59
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
60
    }
61

  
62
    @ExceptionHandler(PathNotValidException.class)
63
    public ResponseEntity<ExceptionResponse> pathNotValidException(Exception ex) {
64
        ExceptionResponse response = new ExceptionResponse();
65
        response.setErrorCode("Not found Exception");
66
        response.setErrorMessage("Path not valid Exception");
67
        response.setErrors(ex.getMessage());
68
        response.setStatus(HttpStatus.NOT_FOUND);
69
        log.debug("pathNotValidException exception");
70
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
71
    }
50 72
}

Also available in: Unified diff