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.apps.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) {
31 override fun message(detailMsg: String): String {
32 return "Generic failure. Details : {$detailMsg}"
35 INVALID_FILE_EXTENSION(2, 415) {
36 override fun message(detailMsg: String): String {
37 return "Unexpected file extension. Details : {$detailMsg}"
40 BLUEPRINT_PATH_MISSING(3, 503) {
41 override fun message(detailMsg: String): String {
42 return "Blueprint path missing or wrong. Details : {$detailMsg}"
45 BLUEPRINT_WRITING_FAIL(4, 503) {
46 override fun message(detailMsg: String): String {
47 return "Fail to write blueprint files. Details : {$detailMsg}"
50 IO_FILE_INTERRUPT(5, 503) {
51 override fun message(detailMsg: String): String {
52 return "IO file system interruption. Details : {$detailMsg}"
55 INVALID_REQUEST_FORMAT(6, 400) {
56 override fun message(detailMsg: String): String {
57 return "Bad request. Details : {$detailMsg}"
60 UNAUTHORIZED_REQUEST(7, 401) {
61 override fun message(detailMsg: String): String {
62 return "The request requires user authentication. Details : {$detailMsg}"
65 REQUEST_NOT_FOUND(8, 404) {
66 override fun message(detailMsg: String): String {
67 return "Request mapping doesn't exist. Details : {$detailMsg}"
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}"
75 CONFLICT_ADDING_RESOURCE(10, 409) {
76 override fun message(detailMsg: String): String {
77 return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
81 abstract fun message(detailMsg: String): String
85 private val map = HashMap<Int, ErrorCode>()
88 for (errorCode in ErrorCode.values()) {
89 map[errorCode.value] = errorCode
93 fun valueOf(value: Int): ErrorCode? {
94 return if (map.containsKey(value)) map[value] else map[1]