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