Merge "Add -noprompt to keytool import ONAP Root CA"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / DesignerBlueprintExceptionHandler.kt
1 /*
2  * Copyright © 2018-2019 Bell Canada Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
18
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
21 import org.slf4j.LoggerFactory
22 import org.springframework.http.HttpStatus
23 import org.springframework.http.ResponseEntity
24 import org.springframework.web.bind.annotation.ExceptionHandler
25 import org.springframework.web.bind.annotation.RestControllerAdvice
26
27 /**
28  * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right
29  * HTTP code status
30  *
31  * @author Vinal Patel
32  * @version 1.0
33  */
34 @RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints")
35 open class DesignerBlueprintExceptionHandler {
36
37     companion object ControllerBlueprintExceptionHandler {
38         val LOG = LoggerFactory.getLogger(DesignerBlueprintExceptionHandler::class.java)
39     }
40
41     @ExceptionHandler
42     fun ControllerBlueprintExceptionHandler(e: BluePrintException): ResponseEntity<ErrorMessage> {
43         val errorCode = ErrorCode.valueOf(e.code)
44         val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
45         LOG.error("Error: $errorCode ${e.message}")
46         return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
47     }
48
49     @ExceptionHandler
50     fun ControllerBlueprintExceptionHandler(e: Exception): ResponseEntity<ErrorMessage> {
51         val errorCode = ErrorCode.GENERIC_FAILURE
52         val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
53         LOG.error("Error: $errorCode ${e.message}")
54         return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
55     }
56 }