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.rest.exceptions;
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;
35 * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
37 * @author gareth.roper@est.tech
39 @ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
41 public class Sol003PackageManagementControllerExceptionHandler {
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);
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);
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);
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);