713bf01249df874511720bc2a9d5cfb01c611d86
[so.git] /
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.VnfPkgConflictException;
27 import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.web.bind.annotation.ControllerAdvice;
31 import org.springframework.web.bind.annotation.ExceptionHandler;
32
33 /**
34  * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
35  * 
36  * @author gareth.roper@est.tech
37  */
38 @ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
39
40 public class Sol003PackageManagementControllerExceptionHandler {
41
42     @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
43     public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
44             EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
45         final ProblemDetails problemDetails = new ProblemDetails();
46         problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
47         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
48     }
49
50     @ExceptionHandler(VnfPkgConflictException.class)
51     public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
52             VnfPkgConflictException vnfPkgConflictException) {
53         final ProblemDetails problemDetails = new ProblemDetails();
54         problemDetails.setDetail(vnfPkgConflictException.getMessage());
55         return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
56     }
57
58     @ExceptionHandler(VnfPkgNotFoundException.class)
59     public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
60             VnfPkgNotFoundException vnfPkgNotFoundException) {
61         final ProblemDetails problemDetails = new ProblemDetails();
62         problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
63         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
64     }
65
66 }