Refactor SOL003 Adapter to organize its modules
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-pkgm / etsi-sol003-pkgm-adapter / src / main / java / org / onap / so / adapters / etsisol003adapter / pkgm / rest / exceptions / Sol003PackageManagementControllerExceptionHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions;
22
23 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails;
24 import org.onap.so.adapters.etsisol003adapter.pkgm.rest.Sol003PackageManagementController;
25 import org.springframework.http.HttpStatus;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.web.bind.annotation.ControllerAdvice;
28 import org.springframework.web.bind.annotation.ExceptionHandler;
29
30 /**
31  * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
32  * 
33  * @author gareth.roper@est.tech
34  */
35 @ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
36
37 public class Sol003PackageManagementControllerExceptionHandler {
38
39     @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
40     public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
41             final EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
42         final ProblemDetails problemDetails = new ProblemDetails();
43         problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
44         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
45     }
46
47     @ExceptionHandler(EtsiCatalogManagerBadRequestException.class)
48     public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerBadRequestFailureException(
49             final EtsiCatalogManagerBadRequestException etsiCatalogManagerBadRequestException) {
50         final ProblemDetails problemDetails = new ProblemDetails();
51         problemDetails.setDetail(etsiCatalogManagerBadRequestException.getMessage());
52         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
53     }
54
55     @ExceptionHandler(SubscriptionNotFoundException.class)
56     public ResponseEntity<ProblemDetails> handleSubscriptionNotFoundException(
57             final SubscriptionNotFoundException subscriptionNotFoundException) {
58         final ProblemDetails problemDetails = new ProblemDetails();
59         problemDetails.setDetail(subscriptionNotFoundException.getMessage());
60         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
61     }
62
63     @ExceptionHandler(ConversionFailedException.class)
64     public ResponseEntity<ProblemDetails> handleConversionFailedException(
65             final ConversionFailedException conversionFailedException) {
66         final ProblemDetails problemDetails = new ProblemDetails();
67         problemDetails.setDetail(conversionFailedException.getMessage());
68         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
69     }
70
71     @ExceptionHandler(VnfPkgConflictException.class)
72     public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
73             final VnfPkgConflictException vnfPkgConflictException) {
74         final ProblemDetails problemDetails = new ProblemDetails();
75         problemDetails.setDetail(vnfPkgConflictException.getMessage());
76         return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
77     }
78
79     @ExceptionHandler(VnfPkgNotFoundException.class)
80     public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
81             final VnfPkgNotFoundException vnfPkgNotFoundException) {
82         final ProblemDetails problemDetails = new ProblemDetails();
83         problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
84         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
85     }
86
87     @ExceptionHandler(VnfPkgBadRequestException.class)
88     public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException(
89             final VnfPkgBadRequestException vnfPkgBadRequestException) {
90         final ProblemDetails problemDetails = new ProblemDetails();
91         problemDetails.setDetail(vnfPkgBadRequestException.getMessage());
92         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
93     }
94 }