2 * Copyright © 2018-2019 Bell Canada Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.ccsdk.cds.controllerblueprints.core.data
18 import java.util.HashMap
21 * ErrorCode.java Purpose: Maintain a list of HTTP status codes
26 enum class ErrorCode(val value: Int, val httpCode: Int) {
28 // / TODO: Add more attribute for each needed application protocol
29 // TODO: Example: INVALID_FILE_EXTENSION(2, 415, 25)
30 GENERIC_FAILURE(1, 500) {
32 override fun message(detailMsg: String): String {
33 return "Generic failure. Details : {$detailMsg}"
36 INVALID_FILE_EXTENSION(2, 415) {
37 override fun message(detailMsg: String): String {
38 return "Unexpected file extension. Details : {$detailMsg}"
41 BLUEPRINT_PATH_MISSING(3, 503) {
42 override fun message(detailMsg: String): String {
43 return "Blueprint path missing or wrong. Details : {$detailMsg}"
46 BLUEPRINT_WRITING_FAIL(4, 503) {
47 override fun message(detailMsg: String): String {
48 return "Fail to write blueprint files. Details : {$detailMsg}"
51 IO_FILE_INTERRUPT(5, 503) {
52 override fun message(detailMsg: String): String {
53 return "IO file system interruption. Details : {$detailMsg}"
56 INVALID_REQUEST_FORMAT(6, 400) {
57 override fun message(detailMsg: String): String {
58 return "Bad request. Details : {$detailMsg}"
61 UNAUTHORIZED_REQUEST(7, 401) {
62 override fun message(detailMsg: String): String {
63 return "The request requires user authentication. Details : {$detailMsg}"
66 REQUEST_NOT_FOUND(8, 404) {
67 override fun message(detailMsg: String): String {
68 return "Request mapping doesn't exist. Details : {$detailMsg}"
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}"
76 CONFLICT_ADDING_RESOURCE(10, 409) {
77 override fun message(detailMsg: String): String {
78 return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
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}"
87 abstract fun message(detailMsg: String): String
91 private val map = HashMap<Int, ErrorCode>()
94 for (errorCode in ErrorCode.values()) {
95 map[errorCode.value] = errorCode
99 fun valueOf(value: Int): ErrorCode? {
100 return if (map.containsKey(value)) map[value] else map[1]