Remote Script Executor Component
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / data / ErrorCode.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 package org.onap.ccsdk.cds.controllerblueprints.core.data
17
18 import java.util.HashMap
19
20 /**
21  * ErrorCode.java Purpose: Maintain a list of HTTP status codes
22  *
23  * @author Steve Siani
24  * @version 1.0
25  */
26 enum class ErrorCode(val value: Int, val httpCode: Int) {
27
28     // / TODO: Add more attribute for each needed application protocol
29     // TODO: Example: INVALID_FILE_EXTENSION(2, 415, 25)
30     GENERIC_FAILURE(1, 500) {
31
32         override fun message(detailMsg: String): String {
33             return "Generic failure. Details : {$detailMsg}"
34         }
35     },
36     INVALID_FILE_EXTENSION(2, 415) {
37         override fun message(detailMsg: String): String {
38             return "Unexpected file extension. Details : {$detailMsg}"
39         }
40     },
41     BLUEPRINT_PATH_MISSING(3, 503) {
42         override fun message(detailMsg: String): String {
43             return "Blueprint path missing or wrong. Details : {$detailMsg}"
44         }
45     },
46     BLUEPRINT_WRITING_FAIL(4, 503) {
47         override fun message(detailMsg: String): String {
48             return "Fail to write blueprint files. Details : {$detailMsg}"
49         }
50     },
51     IO_FILE_INTERRUPT(5, 503) {
52         override fun message(detailMsg: String): String {
53             return "IO file system interruption. Details : {$detailMsg}"
54         }
55     },
56     INVALID_REQUEST_FORMAT(6, 400) {
57         override fun message(detailMsg: String): String {
58             return "Bad request. Details : {$detailMsg}"
59         }
60     },
61     UNAUTHORIZED_REQUEST(7, 401) {
62         override fun message(detailMsg: String): String {
63             return "The request requires user authentication. Details : {$detailMsg}"
64         }
65     },
66     REQUEST_NOT_FOUND(8, 404) {
67         override fun message(detailMsg: String): String {
68             return "Request mapping doesn't exist. Details : {$detailMsg}"
69         }
70     },
71     RESOURCE_NOT_FOUND(9, 404) {
72         override fun message(detailMsg: String): String {
73             return "No response was found for this request in the server. Details : {$detailMsg}"
74         }
75     },
76     CONFLICT_ADDING_RESOURCE(10, 409) {
77         override fun message(detailMsg: String): String {
78             return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
79         }
80     },
81     DUPLICATE_DATA(11, 409) {
82         override fun message(detailMsg: String): String {
83             return "Duplicated data - was expecting one result, got more than one. Details : {$detailMsg}"
84         }
85     };
86
87     abstract fun message(detailMsg: String): String
88
89     companion object {
90
91         private val map = HashMap<Int, ErrorCode>()
92
93         init {
94             for (errorCode in ErrorCode.values()) {
95                 map[errorCode.value] = errorCode
96             }
97         }
98
99         fun valueOf(value: Int): ErrorCode? {
100             return if (map.containsKey(value)) map[value] else map[1]
101         }
102     }
103 }