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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnfmadapter;
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;
34 * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
36 * @author gareth.roper@est.tech
38 @ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
40 public class Sol003PackageManagementControllerExceptionHandler {
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);
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);
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);