Fix groupId for error-catalog
[ccsdk/cds.git] / ms / error-catalog / core / src / main / kotlin / org / onap / ccsdk / error / catalog / core / ErrorCodes.kt
1 /*
2  * Copyright © 2018-2019 AT&T 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.error.catalog.core
18
19 object ErrorCatalogCodes {
20     const val GENERIC_FAILURE = "GENERIC_FAILURE"
21     const val GENERIC_PROCESS_FAILURE = "GENERIC_PROCESS_FAILURE"
22     const val INVALID_FILE_EXTENSION = "INVALID_FILE_EXTENSION"
23     const val RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"
24     const val RESOURCE_PATH_MISSING = "RESOURCE_PATH_MISSING"
25     const val RESOURCE_WRITING_FAIL = "RESOURCE_WRITING_FAIL"
26     const val IO_FILE_INTERRUPT = "IO_FILE_INTERRUPT"
27     const val INVALID_REQUEST_FORMAT = "INVALID_REQUEST_FORMAT"
28     const val UNAUTHORIZED_REQUEST = "UNAUTHORIZED_REQUEST"
29     const val REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND"
30     const val CONFLICT_ADDING_RESOURCE = "CONFLICT_ADDING_RESOURCE"
31     const val DUPLICATE_DATA = "DUPLICATE_DATA"
32 }
33
34 object HttpErrorCodes {
35     private val store: MutableMap<String, Int> = mutableMapOf()
36
37     init {
38         store[ErrorCatalogCodes.GENERIC_FAILURE] = 500
39         store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 500
40         store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 415
41         store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 404
42         store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 503
43         store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 503
44         store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 503
45         store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 400
46         store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 401
47         store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 404
48         store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 409
49         store[ErrorCatalogCodes.DUPLICATE_DATA] = 409
50     }
51
52     fun register(type: String, code: Int) {
53         store[type] = code
54     }
55
56     fun code(type: String): Int {
57         // FIXME("Return Default Error Code , If missing")
58         return store[type]!!
59     }
60 }
61
62 object GrpcErrorCodes {
63     private val store: MutableMap<String, Int> = mutableMapOf()
64
65     init {
66         store[ErrorCatalogCodes.GENERIC_FAILURE] = 2
67         store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 2
68         store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 3
69         store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 5
70         store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 3
71         store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 9
72         store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 3
73         store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 3
74         store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 16
75         store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 8
76         store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 10
77         store[ErrorCatalogCodes.DUPLICATE_DATA] = 11
78     }
79
80     fun register(type: String, code: Int) {
81         store[type] = code
82     }
83
84     fun code(type: String): Int {
85         // FIXME("Return Default Error Code , If missing")
86         return store[type]!!
87     }
88 }