From 8865ccde1a486e203a3812813f5350ddb726265f Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Wed, 18 Mar 2020 09:59:18 -0400 Subject: Fix GroupId and package name in Error Catalog Issue-ID: CCSDK-2180 Signed-off-by: Steve Siani Change-Id: Ibe00fc1f2a905821b7100ae4f221ea1e0b934894 --- ms/error-catalog/core/pom.xml | 1 - .../error/catalog/core/ErrorCatalogException.kt | 112 +++++++++++++++++++++ .../error/catalog/core/ErrorCatalogExtensions.kt | 32 ++++++ .../ccsdk/cds/error/catalog/core/ErrorCodes.kt | 88 ++++++++++++++++ .../ccsdk/cds/error/catalog/core/ErrorLibData.kt | 94 +++++++++++++++++ .../error/catalog/core/ErrorMessageLibConstants.kt | 31 ++++++ .../error/catalog/core/ErrorCatalogException.kt | 112 --------------------- .../error/catalog/core/ErrorCatalogExtensions.kt | 32 ------ .../onap/ccsdk/error/catalog/core/ErrorCodes.kt | 88 ---------------- .../onap/ccsdk/error/catalog/core/ErrorLibData.kt | 94 ----------------- .../error/catalog/core/ErrorMessageLibConstants.kt | 30 ------ 11 files changed, 357 insertions(+), 357 deletions(-) create mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt create mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt create mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt create mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt create mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt delete mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogException.kt delete mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogExtensions.kt delete mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCodes.kt delete mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorLibData.kt delete mode 100644 ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorMessageLibConstants.kt (limited to 'ms/error-catalog/core') diff --git a/ms/error-catalog/core/pom.xml b/ms/error-catalog/core/pom.xml index 407f10f08..f117aa83f 100644 --- a/ms/error-catalog/core/pom.xml +++ b/ms/error-catalog/core/pom.xml @@ -14,7 +14,6 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - 4.0.0 diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt new file mode 100644 index 000000000..032feb62c --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt @@ -0,0 +1,112 @@ +/* + * Copyright © 2020 IBM, Bell Canada. + * Modifications Copyright © 2019-2020 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.error.catalog.core + +interface ErrorCatalogExceptionFluent { + fun code(code: Int): T + fun domain(domain: String): T + fun action(action: String): T + fun http(type: String): T + fun grpc(type: String): T + fun payloadMessage(message: String): T + fun addErrorPayloadMessage(message: String): T + fun addSubError(errorMessage: ErrorMessage): T +} + +open class ErrorCatalogException : RuntimeException { + var code: Int = -1 + var domain: String = "" + var name: String = ErrorCatalogCodes.GENERIC_FAILURE + var action: String = "" + var errorPayload: ErrorPayload? = null + var protocol: String = "" + var errorPayloadMessages: MutableList? = null + + val messageSeparator = "${System.lineSeparator()} -> " + + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(message: String) : super(message) + constructor(cause: Throwable) : super(cause) + constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) + + constructor(code: Int, cause: Throwable) : super(cause) { + this.code = code + } + + constructor(code: Int, message: String) : super(message) { + this.code = code + } + + constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { + this.code = code + } + + constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) : + super(String.format(message, *args), cause) { + this.code = code + } + + open fun updateCode(code: Int): T { + this.code = code + return this as T + } + + open fun updateDomain(domain: String): T { + this.domain = domain + return this as T + } + + open fun updateAction(action: String): T { + this.action = action + return this as T + } + + fun updateHttp(type: String): T { + this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP + this.code = HttpErrorCodes.code(type) + return this as T + } + + fun updateGrpc(type: String): T { + this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC + this.code = GrpcErrorCodes.code(type) + return this as T + } + + fun updatePayloadMessage(message: String): T { + if (this.errorPayloadMessages == null) this.errorPayloadMessages = arrayListOf() + this.errorPayloadMessages!!.add(message) + return this as T + } + + fun updateErrorPayloadMessage(message: String): T { + if (errorPayload == null) { + errorPayload = ErrorPayload() + } + errorPayload!!.message = "${errorPayload!!.message} $messageSeparator $message" + return this as T + } + + fun updateSubError(errorMessage: ErrorMessage): T { + if (errorPayload == null) { + errorPayload = ErrorPayload() + } + errorPayload!!.subErrors.add(errorMessage) + return this as T + } +} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt new file mode 100644 index 000000000..65c547245 --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt @@ -0,0 +1,32 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.error.catalog.core + +import org.slf4j.LoggerFactory +import org.slf4j.helpers.MessageFormatter +import kotlin.reflect.KClass + +fun logger(clazz: T) = LoggerFactory.getLogger(clazz.javaClass)!! + +fun > logger(clazz: T) = LoggerFactory.getLogger(clazz.java)!! + +fun format(message: String, vararg args: Any?): String { + if (args != null && args.isNotEmpty()) { + return MessageFormatter.arrayFormat(message, args).message + } + return message +} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt new file mode 100644 index 000000000..86483e3e9 --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt @@ -0,0 +1,88 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.error.catalog.core + +object ErrorCatalogCodes { + const val GENERIC_FAILURE = "GENERIC_FAILURE" + const val GENERIC_PROCESS_FAILURE = "GENERIC_PROCESS_FAILURE" + const val INVALID_FILE_EXTENSION = "INVALID_FILE_EXTENSION" + const val RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND" + const val RESOURCE_PATH_MISSING = "RESOURCE_PATH_MISSING" + const val RESOURCE_WRITING_FAIL = "RESOURCE_WRITING_FAIL" + const val IO_FILE_INTERRUPT = "IO_FILE_INTERRUPT" + const val INVALID_REQUEST_FORMAT = "INVALID_REQUEST_FORMAT" + const val UNAUTHORIZED_REQUEST = "UNAUTHORIZED_REQUEST" + const val REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND" + const val CONFLICT_ADDING_RESOURCE = "CONFLICT_ADDING_RESOURCE" + const val DUPLICATE_DATA = "DUPLICATE_DATA" +} + +object HttpErrorCodes { + private val store: MutableMap = mutableMapOf() + + init { + store[ErrorCatalogCodes.GENERIC_FAILURE] = 500 + store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 500 + store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 415 + store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 404 + store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 503 + store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 503 + store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 503 + store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 400 + store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 401 + store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 404 + store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 409 + store[ErrorCatalogCodes.DUPLICATE_DATA] = 409 + } + + fun register(type: String, code: Int) { + store[type] = code + } + + fun code(type: String): Int { + // FIXME("Return Default Error Code , If missing") + return store[type]!! + } +} + +object GrpcErrorCodes { + private val store: MutableMap = mutableMapOf() + + init { + store[ErrorCatalogCodes.GENERIC_FAILURE] = 2 + store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 2 + store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 3 + store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 5 + store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 3 + store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 9 + store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 3 + store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 3 + store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 16 + store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 8 + store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 10 + store[ErrorCatalogCodes.DUPLICATE_DATA] = 11 + } + + fun register(type: String, code: Int) { + store[type] = code + } + + fun code(type: String): Int { + // FIXME("Return Default Error Code , If missing") + return store[type]!! + } +} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt new file mode 100644 index 000000000..2c0772e31 --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt @@ -0,0 +1,94 @@ +/* + * Copyright © 2020 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.error.catalog.core + +import com.fasterxml.jackson.annotation.JsonFormat +import org.slf4j.event.Level +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants.ERROR_CATALOG_DEFAULT_ERROR_CODE +import java.time.LocalDateTime + +open class ErrorPayload { + var code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE + var status: String = "" + @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var timestamp: LocalDateTime = LocalDateTime.now() + var message: String = "" + var debugMessage: String = "" + var logLevel: String = Level.ERROR.name + val subErrors: ArrayList = ArrayList() + + constructor() + + constructor( + code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE, + status: String, + message: String, + logLevel: String = Level.ERROR.name, + debugMessage: String = "" + ) { + this.code = code + this.status = status + this.message = message + this.logLevel = logLevel + this.debugMessage = debugMessage + } + + constructor( + code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE, + status: String, + message: String, + logLevel: String = Level.ERROR.name, + debugMessage: String = "", + errorMessage: ErrorMessage + ) { + this.code = code + this.status = status + this.message = message + this.logLevel = logLevel + this.debugMessage = debugMessage + this.subErrors.add(errorMessage) + } + + fun isEqualTo(errorPayload: ErrorPayload): Boolean { + return (this.code == errorPayload.code && this.status == errorPayload.status && this.message == errorPayload.message && + this.logLevel == errorPayload.logLevel && this.debugMessage == errorPayload.debugMessage && + this.subErrors == errorPayload.subErrors) + } +} + +/** + * + * + * @author Steve Siani + */ +data class ErrorMessage( + val domainId: String, + val message: String, + val cause: String +) + +data class ErrorCatalog( + val errorId: String, + val domainId: String, + val code: Int, + val action: String, + val cause: String +) { + fun getMessage(): String { + return "Cause: $cause ${System.lineSeparator()} Action : $action" + } +} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt new file mode 100644 index 000000000..6570e3e66 --- /dev/null +++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt @@ -0,0 +1,31 @@ +/* + * Copyright © 2020 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.error.catalog.core + +object ErrorMessageLibConstants { + const val ERROR_CATALOG_DOMAIN = "org.onap.ccsdk.cds.error.catalog" + const val ERROR_CATALOG_TYPE = "error.catalog.type" + const val ERROR_CATALOG_TYPE_PROPERTIES = "properties" + const val ERROR_CATALOG_TYPE_DB = "DB" + const val ERROR_CATALOG_PROPERTIES_FILENAME = "error-messages_en.properties" + const val ERROR_CATALOG_PROPERTIES_DIRECTORY = "/opt/app/onap/config/" + const val ERROR_CATALOG_MODELS = "org.onap.ccsdk.cds.error.catalog.domain" + const val ERROR_CATALOG_REPOSITORY = "org.onap.ccsdk.cds.error.catalog.repository" + const val ERROR_CATALOG_DEFAULT_ERROR_CODE = 500 + const val ERROR_CATALOG_PROTOCOL_HTTP = "http" + const val ERROR_CATALOG_PROTOCOL_GRPC = "grpc" +} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogException.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogException.kt deleted file mode 100644 index 76f9cc0f1..000000000 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogException.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2020 IBM, Bell Canada. - * Modifications Copyright © 2019-2020 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.error.catalog.core - -interface ErrorCatalogExceptionFluent { - fun code(code: Int): T - fun domain(domain: String): T - fun action(action: String): T - fun http(type: String): T - fun grpc(type: String): T - fun payloadMessage(message: String): T - fun addErrorPayloadMessage(message: String): T - fun addSubError(errorMessage: ErrorMessage): T -} - -open class ErrorCatalogException : RuntimeException { - var code: Int = -1 - var domain: String = "" - var name: String = ErrorCatalogCodes.GENERIC_FAILURE - var action: String = "" - var errorPayload: ErrorPayload? = null - var protocol: String = "" - var errorPayloadMessages: MutableList? = null - - val messageSeparator = "${System.lineSeparator()} -> " - - constructor(message: String, cause: Throwable) : super(message, cause) - constructor(message: String) : super(message) - constructor(cause: Throwable) : super(cause) - constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause) - - constructor(code: Int, cause: Throwable) : super(cause) { - this.code = code - } - - constructor(code: Int, message: String) : super(message) { - this.code = code - } - - constructor(code: Int, message: String, cause: Throwable) : super(message, cause) { - this.code = code - } - - constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) : - super(String.format(message, *args), cause) { - this.code = code - } - - open fun updateCode(code: Int): T { - this.code = code - return this as T - } - - open fun updateDomain(domain: String): T { - this.domain = domain - return this as T - } - - open fun updateAction(action: String): T { - this.action = action - return this as T - } - - fun updateHttp(type: String): T { - this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP - this.code = HttpErrorCodes.code(type) - return this as T - } - - fun updateGrpc(type: String): T { - this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC - this.code = GrpcErrorCodes.code(type) - return this as T - } - - fun updatePayloadMessage(message: String): T { - if (this.errorPayloadMessages == null) this.errorPayloadMessages = arrayListOf() - this.errorPayloadMessages!!.add(message) - return this as T - } - - fun updateErrorPayloadMessage(message: String): T { - if (errorPayload == null) { - errorPayload = ErrorPayload() - } - errorPayload!!.message = "${errorPayload!!.message} $messageSeparator $message" - return this as T - } - - fun updateSubError(errorMessage: ErrorMessage): T { - if (errorPayload == null) { - errorPayload = ErrorPayload() - } - errorPayload!!.subErrors.add(errorMessage) - return this as T - } -} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogExtensions.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogExtensions.kt deleted file mode 100644 index 76011b27d..000000000 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogExtensions.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2018-2019 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.error.catalog.core - -import org.slf4j.LoggerFactory -import org.slf4j.helpers.MessageFormatter -import kotlin.reflect.KClass - -fun logger(clazz: T) = LoggerFactory.getLogger(clazz.javaClass)!! - -fun > logger(clazz: T) = LoggerFactory.getLogger(clazz.java)!! - -fun format(message: String, vararg args: Any?): String { - if (args != null && args.isNotEmpty()) { - return MessageFormatter.arrayFormat(message, args).message - } - return message -} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCodes.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCodes.kt deleted file mode 100644 index 241e9d238..000000000 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCodes.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2018-2019 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.error.catalog.core - -object ErrorCatalogCodes { - const val GENERIC_FAILURE = "GENERIC_FAILURE" - const val GENERIC_PROCESS_FAILURE = "GENERIC_PROCESS_FAILURE" - const val INVALID_FILE_EXTENSION = "INVALID_FILE_EXTENSION" - const val RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND" - const val RESOURCE_PATH_MISSING = "RESOURCE_PATH_MISSING" - const val RESOURCE_WRITING_FAIL = "RESOURCE_WRITING_FAIL" - const val IO_FILE_INTERRUPT = "IO_FILE_INTERRUPT" - const val INVALID_REQUEST_FORMAT = "INVALID_REQUEST_FORMAT" - const val UNAUTHORIZED_REQUEST = "UNAUTHORIZED_REQUEST" - const val REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND" - const val CONFLICT_ADDING_RESOURCE = "CONFLICT_ADDING_RESOURCE" - const val DUPLICATE_DATA = "DUPLICATE_DATA" -} - -object HttpErrorCodes { - private val store: MutableMap = mutableMapOf() - - init { - store[ErrorCatalogCodes.GENERIC_FAILURE] = 500 - store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 500 - store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 415 - store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 404 - store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 503 - store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 503 - store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 503 - store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 400 - store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 401 - store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 404 - store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 409 - store[ErrorCatalogCodes.DUPLICATE_DATA] = 409 - } - - fun register(type: String, code: Int) { - store[type] = code - } - - fun code(type: String): Int { - // FIXME("Return Default Error Code , If missing") - return store[type]!! - } -} - -object GrpcErrorCodes { - private val store: MutableMap = mutableMapOf() - - init { - store[ErrorCatalogCodes.GENERIC_FAILURE] = 2 - store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 2 - store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 3 - store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 5 - store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 3 - store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 9 - store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 3 - store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 3 - store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 16 - store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 8 - store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 10 - store[ErrorCatalogCodes.DUPLICATE_DATA] = 11 - } - - fun register(type: String, code: Int) { - store[type] = code - } - - fun code(type: String): Int { - // FIXME("Return Default Error Code , If missing") - return store[type]!! - } -} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorLibData.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorLibData.kt deleted file mode 100644 index b33c118de..000000000 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorLibData.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2020 IBM, Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.error.catalog.core - -import com.fasterxml.jackson.annotation.JsonFormat -import org.slf4j.event.Level -import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants.ERROR_CATALOG_DEFAULT_ERROR_CODE -import java.time.LocalDateTime - -open class ErrorPayload { - var code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE - var status: String = "" - @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - var timestamp: LocalDateTime = LocalDateTime.now() - var message: String = "" - var debugMessage: String = "" - var logLevel: String = Level.ERROR.name - val subErrors: ArrayList = ArrayList() - - constructor() - - constructor( - code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE, - status: String, - message: String, - logLevel: String = Level.ERROR.name, - debugMessage: String = "" - ) { - this.code = code - this.status = status - this.message = message - this.logLevel = logLevel - this.debugMessage = debugMessage - } - - constructor( - code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE, - status: String, - message: String, - logLevel: String = Level.ERROR.name, - debugMessage: String = "", - errorMessage: ErrorMessage - ) { - this.code = code - this.status = status - this.message = message - this.logLevel = logLevel - this.debugMessage = debugMessage - this.subErrors.add(errorMessage) - } - - fun isEqualTo(errorPayload: ErrorPayload): Boolean { - return (this.code == errorPayload.code && this.status == errorPayload.status && this.message == errorPayload.message && - this.logLevel == errorPayload.logLevel && this.debugMessage == errorPayload.debugMessage && - this.subErrors == errorPayload.subErrors) - } -} - -/** - * - * - * @author Steve Siani - */ -data class ErrorMessage( - val domainId: String, - val message: String, - val cause: String -) - -data class ErrorCatalog( - val errorId: String, - val domainId: String, - val code: Int, - val action: String, - val cause: String -) { - fun getMessage(): String { - return "Cause: $cause ${System.lineSeparator()} Action : $action" - } -} diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorMessageLibConstants.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorMessageLibConstants.kt deleted file mode 100644 index ef56e7b79..000000000 --- a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorMessageLibConstants.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2020 IBM, Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.error.catalog.core - -object ErrorMessageLibConstants { - const val ERROR_CATALOG_DOMAIN = "org.onap.ccsdk.error.catalog" - const val ERROR_CATALOG_TYPE = "error.catalog.type" - const val ERROR_CATALOG_TYPE_PROPERTIES = "properties" - const val ERROR_CATALOG_TYPE_DB = "DB" - const val ERROR_CATALOG_PROPERTIES_FILENAME = "error-messages_en.properties" - const val ERROR_CATALOG_MODELS = "org.onap.ccsdk.error.catalog.domain" - const val ERROR_CATALOG_REPOSITORY = "org.onap.ccsdk.error.catalog.repository" - const val ERROR_CATALOG_DEFAULT_ERROR_CODE = 500 - const val ERROR_CATALOG_PROTOCOL_HTTP = "http" - const val ERROR_CATALOG_PROTOCOL_GRPC = "grpc" -} -- cgit 1.2.3-korg