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(EtsiCatalogManagerBadRequestException.class)
 
  52     public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerBadRequestFailureException(
 
  53             final EtsiCatalogManagerBadRequestException etsiCatalogManagerBadRequestException) {
 
  54         final ProblemDetails problemDetails = new ProblemDetails();
 
  55         problemDetails.setDetail(etsiCatalogManagerBadRequestException.getMessage());
 
  56         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
 
  59     @ExceptionHandler(SubscriptionNotFoundException.class)
 
  60     public ResponseEntity<ProblemDetails> handleSubscriptionNotFoundException(
 
  61             final SubscriptionNotFoundException subscriptionNotFoundException) {
 
  62         final ProblemDetails problemDetails = new ProblemDetails();
 
  63         problemDetails.setDetail(subscriptionNotFoundException.getMessage());
 
  64         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
 
  67     @ExceptionHandler(SubscriptionRequestConversionException.class)
 
  68     public ResponseEntity<ProblemDetails> handleSubscriptionRequestConversionException(
 
  69             final SubscriptionRequestConversionException subscriptionRequestConversionException) {
 
  70         final ProblemDetails problemDetails = new ProblemDetails();
 
  71         problemDetails.setDetail(subscriptionRequestConversionException.getMessage());
 
  72         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
 
  75     @ExceptionHandler(VnfPkgConflictException.class)
 
  76     public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
 
  77             final VnfPkgConflictException vnfPkgConflictException) {
 
  78         final ProblemDetails problemDetails = new ProblemDetails();
 
  79         problemDetails.setDetail(vnfPkgConflictException.getMessage());
 
  80         return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
 
  83     @ExceptionHandler(VnfPkgNotFoundException.class)
 
  84     public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
 
  85             final VnfPkgNotFoundException vnfPkgNotFoundException) {
 
  86         final ProblemDetails problemDetails = new ProblemDetails();
 
  87         problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
 
  88         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
 
  91     @ExceptionHandler(VnfPkgBadRequestException.class)
 
  92     public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException(
 
  93             final VnfPkgBadRequestException vnfPkgBadRequestException) {
 
  94         final ProblemDetails problemDetails = new ProblemDetails();
 
  95         problemDetails.setDetail(vnfPkgBadRequestException.getMessage());
 
  96         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);