Migrate ccsdk/apps to ccsdk/cds
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / data / BlueprintErrorCode.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         override fun message(detailMsg: String): String {
32             return "Generic failure. Details : {$detailMsg}"
33         }
34     },
35     INVALID_FILE_EXTENSION(2, 415) {
36         override fun message(detailMsg: String): String {
37             return "Unexpected file extension. Details : {$detailMsg}"
38         }
39     },
40     BLUEPRINT_PATH_MISSING(3, 503) {
41         override fun message(detailMsg: String): String {
42             return "Blueprint path missing or wrong. Details : {$detailMsg}"
43         }
44     },
45     BLUEPRINT_WRITING_FAIL(4, 503) {
46         override fun message(detailMsg: String): String {
47             return "Fail to write blueprint files. Details : {$detailMsg}"
48         }
49     },
50     IO_FILE_INTERRUPT(5, 503) {
51         override fun message(detailMsg: String): String {
52             return "IO file system interruption. Details : {$detailMsg}"
53         }
54     },
55     INVALID_REQUEST_FORMAT(6, 400) {
56         override fun message(detailMsg: String): String {
57             return "Bad request. Details : {$detailMsg}"
58         }
59     },
60     UNAUTHORIZED_REQUEST(7, 401) {
61         override fun message(detailMsg: String): String {
62             return "The request requires user authentication. Details : {$detailMsg}"
63         }
64     },
65     REQUEST_NOT_FOUND(8, 404) {
66         override fun message(detailMsg: String): String {
67             return "Request mapping doesn't exist. Details : {$detailMsg}"
68         }
69     },
70     RESOURCE_NOT_FOUND(9, 404) {
71         override fun message(detailMsg: String): String {
72             return "No response was found for this request in the server. Details : {$detailMsg}"
73         }
74     },
75     CONFLICT_ADDING_RESOURCE(10, 409) {
76         override fun message(detailMsg: String): String {
77             return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
78         }
79     };
80
81     abstract fun message(detailMsg: String): String
82
83     companion object {
84
85         private val map = HashMap<Int, ErrorCode>()
86
87         init {
88             for (errorCode in ErrorCode.values()) {
89                 map[errorCode.value] = errorCode
90             }
91         }
92
93         fun valueOf(value: Int): ErrorCode? {
94             return if (map.containsKey(value)) map[value] else map[1]
95         }
96     }
97 }