Merge "Update ETSI Catalog Swagger to latest and Add Notification Swagger"
[so.git] / adapters / mso-vnfm-adapter / mso-vnfm-etsi-adapter / src / main / java / org / onap / so / adapters / vnfmadapter / 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.vnfmadapter;
22
23 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
24 import org.onap.so.adapters.vnfmadapter.rest.Sol003PackageManagementController;
25 import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
26 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
27 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
28 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.web.bind.annotation.ControllerAdvice;
32 import org.springframework.web.bind.annotation.ExceptionHandler;
33
34 /**
35  * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
36  * 
37  * @author gareth.roper@est.tech
38  */
39 @ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
40
41 public class Sol003PackageManagementControllerExceptionHandler {
42
43     @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
44     public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
45             final EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
46         final ProblemDetails problemDetails = new ProblemDetails();
47         problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
48         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
49     }
50
51     @ExceptionHandler(VnfPkgConflictException.class)
52     public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
53             final VnfPkgConflictException vnfPkgConflictException) {
54         final ProblemDetails problemDetails = new ProblemDetails();
55         problemDetails.setDetail(vnfPkgConflictException.getMessage());
56         return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
57     }
58
59     @ExceptionHandler(VnfPkgNotFoundException.class)
60     public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
61             final VnfPkgNotFoundException vnfPkgNotFoundException) {
62         final ProblemDetails problemDetails = new ProblemDetails();
63         problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
64         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
65     }
66
67     @ExceptionHandler(VnfPkgBadRequestException.class)
68     public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException(
69             final VnfPkgBadRequestException vnfPkgBadRequestException) {
70         final ProblemDetails problemDetails = new ProblemDetails();
71         problemDetails.setDetail(vnfPkgBadRequestException.getMessage());
72         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
73     }
74 }