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 --- cds-ui/pom.xml | 2 +- .../blueprint-model/test-blueprint/pom.xml | 1 - .../BlueprintDatabaseConfiguration.kt | 4 +- .../BlueprintProcessorApplication.kt | 2 +- .../BlueprintProcessorExceptionHandler.kt | 4 +- .../src/main/resources/application.properties | 2 +- .../uat/ErrorCatalogTestConfiguration.kt | 2 +- .../uat/error/ErrorCatalogServiceTest.kt | 10 +- .../functions/message-prioritizaion/pom.xml | 1 - .../core/BluePrintProcessorException.kt | 9 +- ms/blueprintsprocessor/modules/blueprints/pom.xml | 1 - .../modules/commons/nats-lib/pom.xml | 1 - .../selfservice/api/ExecutionServiceController.kt | 2 +- ms/error-catalog/application/pom.xml | 1 - 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 ----- ms/error-catalog/pom.xml | 1 - ms/error-catalog/services/pom.xml | 1 - .../catalog/services/ErrorCatalogConfiguration.kt | 34 +++++ .../catalog/services/ErrorCatalogDBService.kt | 98 ++++++++++++++ .../services/ErrorCatalogExceptionHandler.kt | 31 +++++ .../catalog/services/ErrorCatalogLoadService.kt | 147 +++++++++++++++++++++ .../error/catalog/services/ErrorCatalogService.kt | 91 +++++++++++++ .../services/ErrorCatalogServiceExtensions.kt | 25 ++++ .../cds/error/catalog/services/domain/Domain.kt | 76 +++++++++++ .../catalog/services/domain/ErrorMessageModel.kt | 69 ++++++++++ .../services/repository/DomainRepository.kt | 45 +++++++ .../repository/ErrorMessageModelRepository.kt | 36 +++++ .../catalog/services/utils/ErrorCatalogUtils.kt | 39 ++++++ .../catalog/services/ErrorCatalogConfiguration.kt | 34 ----- .../catalog/services/ErrorCatalogDBService.kt | 98 -------------- .../services/ErrorCatalogExceptionHandler.kt | 31 ----- .../catalog/services/ErrorCatalogLoadService.kt | 145 -------------------- .../error/catalog/services/ErrorCatalogService.kt | 91 ------------- .../services/ErrorCatalogServiceExtensions.kt | 25 ---- .../ccsdk/error/catalog/services/domain/Domain.kt | 76 ----------- .../catalog/services/domain/ErrorMessageModel.kt | 69 ---------- .../services/repository/DomainRepository.kt | 45 ------- .../repository/ErrorMessageModelRepository.kt | 36 ----- .../catalog/services/utils/ErrorCatalogUtils.kt | 39 ------ pom.xml | 8 +- 50 files changed, 1070 insertions(+), 1076 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 create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt create mode 100755 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt create mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt delete mode 100755 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt delete mode 100644 ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt diff --git a/cds-ui/pom.xml b/cds-ui/pom.xml index 122823419..4a9f0fdad 100644 --- a/cds-ui/pom.xml +++ b/cds-ui/pom.xml @@ -24,7 +24,7 @@ limitations under the License. org.onap.ccsdk.parent spring-boot-starter-parent - 1.5.1 + 1.5.2 diff --git a/components/model-catalog/blueprint-model/test-blueprint/pom.xml b/components/model-catalog/blueprint-model/test-blueprint/pom.xml index 3b44eb105..29daa768e 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/pom.xml +++ b/components/model-catalog/blueprint-model/test-blueprint/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/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt index 2e268c356..e9557aed9 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt @@ -32,7 +32,7 @@ import javax.sql.DataSource @Import(BluePrintDBLibConfiguration::class) @EnableJpaRepositories( basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.error.catalog"], + "org.onap.ccsdk.cds.error.catalog"], entityManagerFactoryRef = "primaryEntityManager", transactionManagerRef = "primaryTransactionManager" ) @@ -45,7 +45,7 @@ open class BlueprintDatabaseConfiguration(primaryDataSourceProperties: PrimaryDa return primaryEntityManager( "org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.error.catalog" + "org.onap.ccsdk.cds.error.catalog" ) } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt index 7a888f95c..97b7d28b0 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt @@ -31,7 +31,7 @@ import org.springframework.context.annotation.ComponentScan @SpringBootApplication @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class]) @ComponentScan( - basePackages = ["org.onap.ccsdk.error.catalog", + basePackages = ["org.onap.ccsdk.cds.error.catalog", "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"] ) open class BlueprintProcessorApplication diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt index 6fcbdfdb7..f241e3f42 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt @@ -16,8 +16,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor -import org.onap.ccsdk.error.catalog.services.ErrorCatalogExceptionHandler -import org.onap.ccsdk.error.catalog.services.ErrorCatalogService +import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler +import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService import org.springframework.web.bind.annotation.RestControllerAdvice @RestControllerAdvice("org.onap.ccsdk.cds") diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index eb15c5a7e..74549b0ae 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -63,7 +63,7 @@ security.user.name: ccsdkapps # Error Managements error.catalog.applicationId=cds error.catalog.type=properties -error.catalog.errorDefinitionDir=/opt/app/onap/config +error.catalog.errorDefinitionDir=/opt/app/onap/config/ # Used in Health Check #endpoints.user.name=ccsdkapps diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt index 74a17fa1d..c9d55c18a 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration @Configuration @ComponentScan( - basePackages = ["org.onap.ccsdk.error.catalog"] + basePackages = ["org.onap.ccsdk.cds.error.catalog"] ) @EnableAutoConfiguration open class ErrorCatalogTestConfiguration diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt index 8e399fd1a..4f7ef0ec2 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt @@ -20,11 +20,11 @@ import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.uat.ErrorCatalogTestConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.grpcProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException -import org.onap.ccsdk.error.catalog.core.ErrorCatalog -import org.onap.ccsdk.error.catalog.core.ErrorCatalogCodes -import org.onap.ccsdk.error.catalog.core.ErrorMessage -import org.onap.ccsdk.error.catalog.core.ErrorPayload -import org.onap.ccsdk.error.catalog.services.ErrorCatalogService +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalog +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage +import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload +import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource diff --git a/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml b/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml index ac46b3635..c7dbaf174 100644 --- a/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml +++ b/ms/blueprintsprocessor/functions/message-prioritizaion/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/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt index 50b6614ad..acb158d89 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt @@ -17,9 +17,9 @@ package org.onap.ccsdk.cds.controllerblueprints.core -import org.onap.ccsdk.error.catalog.core.ErrorCatalogException -import org.onap.ccsdk.error.catalog.core.ErrorCatalogExceptionFluent -import org.onap.ccsdk.error.catalog.core.ErrorMessage +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage /** * @@ -134,5 +134,6 @@ private fun BluePrintProcessorException.addDomainAndErrorMessage( message: String, cause: Throwable = Throwable() ): BluePrintProcessorException { - return this.addSubError(ErrorMessage(domain, message, cause.message ?: "")).domain(domain) + return this.addSubError(ErrorMessage(domain, message, cause.message + ?: "")).domain(domain) } diff --git a/ms/blueprintsprocessor/modules/blueprints/pom.xml b/ms/blueprintsprocessor/modules/blueprints/pom.xml index cd6a17e88..527a5bf98 100644 --- a/ms/blueprintsprocessor/modules/blueprints/pom.xml +++ b/ms/blueprintsprocessor/modules/blueprints/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/blueprintsprocessor/modules/commons/nats-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml index f4e7f4d98..f28a7132e 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/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/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 908c04607..e5daecede 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -29,7 +29,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHtt import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.error.catalog.core.ErrorCatalogCodes +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity diff --git a/ms/error-catalog/application/pom.xml b/ms/error-catalog/application/pom.xml index a22ea2cc6..4e1a6f3f1 100644 --- a/ms/error-catalog/application/pom.xml +++ b/ms/error-catalog/application/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/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" -} diff --git a/ms/error-catalog/pom.xml b/ms/error-catalog/pom.xml index 0b5220b3a..1e6707a75 100644 --- a/ms/error-catalog/pom.xml +++ b/ms/error-catalog/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/services/pom.xml b/ms/error-catalog/services/pom.xml index 8ed8052a1..6fcf158f5 100644 --- a/ms/error-catalog/services/pom.xml +++ b/ms/error-catalog/services/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/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt new file mode 100644 index 000000000..f0a75e087 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt @@ -0,0 +1,34 @@ +/* + * 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.services + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Configuration +import org.springframework.stereotype.Component + +@Configuration +@EnableConfigurationProperties(ErrorCatalogProperties::class) +open class ErrorCatalogConfiguration + +@Component +@ConfigurationProperties(prefix = "error.catalog") +open class ErrorCatalogProperties { + lateinit var type: String + lateinit var applicationId: String + var errorDefinitionDir: String? = null +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt new file mode 100644 index 000000000..95b44e683 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt @@ -0,0 +1,98 @@ +/* + * 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.services + +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants +import org.onap.ccsdk.cds.error.catalog.services.domain.Domain +import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel +import org.onap.ccsdk.cds.error.catalog.services.repository.DomainRepository +import org.onap.ccsdk.cds.error.catalog.services.repository.ErrorMessageModelRepository +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable +import org.springframework.stereotype.Service + +@Service +@ConditionalOnProperty( + name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE], + havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_DB +) +open class ErrorCatalogDBService( + private val domainRepository: DomainRepository, + private val errorMessageModelRepository: ErrorMessageModelRepository +) { + + /** + * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database by pages + * + * @return Page list of the domains by page + */ + open fun getAllDomains(pageRequest: Pageable): Page { + return domainRepository.findAll(pageRequest) + } + + /** + * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database + * + * @return List list of the domains + */ + open fun getAllDomains(): List { + return domainRepository.findAll() + } + + /** + * This is a getAllDomainsByApplication method to retrieve all the Domain that belong to an application in Error Catalog Database + * + * @return List list of the domains + */ + open fun getAllDomainsByApplication(applicationId: String): List { + return domainRepository.findAllByApplicationId(applicationId) + } + + /** + * This is a getAllErrorMessagesByApplication method to retrieve all the Messages that belong to an application in Error Catalog Database + * + * @return MutableMap list of the abstractErrorModel + */ + open fun getAllErrorMessagesByApplication(applicationId: String): MutableMap { + val domains = domainRepository.findAllByApplicationId(applicationId) + val errorMessages = mutableMapOf() + for (domain in domains) { + val errorMessagesFound = errorMessageModelRepository.findByDomainsId(domain.id) + for (errorMessageFound in errorMessagesFound) { + errorMessages["${domain.name}$MESSAGE_KEY_SEPARATOR${errorMessageFound.messageID}"] = errorMessageFound + } + } + return errorMessages + } + + open fun saveDomain( + domain: String, + applicationId: String, + description: String = "", + errorMessageList: List + ) { + val domainModel = Domain(domain, applicationId, description) + domainModel.errorMessages.addAll(errorMessageList) + domainRepository.saveAndFlush(domainModel) + } + + companion object { + private const val MESSAGE_KEY_SEPARATOR = "." + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt new file mode 100644 index 000000000..88e2f4522 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.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.services + +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException +import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.ExceptionHandler + +abstract class ErrorCatalogExceptionHandler(private val errorCatalogService: ErrorCatalogService) { + + @ExceptionHandler(ErrorCatalogException::class) + fun errorCatalogException(e: ErrorCatalogException): ResponseEntity { + val errorPayload = errorCatalogService.errorPayload(e) + return errorPayload.toResponseEntity() + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt new file mode 100644 index 000000000..ca7d72b50 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt @@ -0,0 +1,147 @@ +/* + * 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.services + +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants +import org.onap.ccsdk.cds.error.catalog.core.logger +import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.stereotype.Service +import java.io.File +import java.io.FileNotFoundException +import java.io.IOException +import java.io.InputStream +import java.nio.file.Paths +import java.util.Properties + +interface ErrorCatalogLoadService { + + suspend fun loadErrorCatalog() + + fun getErrorMessage(domain: String, key: String): String? + + fun getErrorMessage(attribute: String): String? +} + +/** + * Representation of Blueprint Error Message lib from database service to load the properties + */ +@Service +@ConditionalOnBean(ErrorCatalogDBService::class) +open class ErrorCatalogLoadDBService( + private var errorCatalogProperties: ErrorCatalogProperties, + private var errorCatalogDBService: ErrorCatalogDBService +) : ErrorCatalogLoadService { + + private var log = logger(ErrorCatalogLoadDBService::class) + + lateinit var errorMessageInDB: Map + + override suspend fun loadErrorCatalog() { + log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from database...") + errorMessageInDB = getErrorMessagesFromDB() + } + + override fun getErrorMessage(domain: String, key: String): String? { + return getErrorMessage("$domain.${key.toLowerCase()}") + } + + override fun getErrorMessage(attribute: String): String? { + val errorMessage = findErrorMessage(attribute) + return prepareErrorMessage(errorMessage) + } + + /** + * Parses the error-messages.properties file which contains error messages + */ + private suspend fun getErrorMessagesFromDB(): Map { + return errorCatalogDBService.getAllErrorMessagesByApplication(errorCatalogProperties.applicationId) + } + + private fun findErrorMessage(attribute: String): ErrorMessageModel? { + return if (errorMessageInDB.containsKey(attribute)) { + errorMessageInDB[attribute] + } else { + null + } + } + + private fun prepareErrorMessage(errorMessage: ErrorMessageModel?): String? { + return if (errorMessage != null) { + "cause=${errorMessage.cause}, action=${errorMessage.action}" + } else { + null + } + } +} + +/** + * Representation of Blueprint Error Message lib property service to load the properties + */ +@Service +@ConditionalOnProperty( + name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE], + havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_PROPERTIES +) +open class ErrorCatalogLoadPropertyService(private var errorCatalogProperties: ErrorCatalogProperties) : + ErrorCatalogLoadService { + + private val propertyFileName = ErrorMessageLibConstants.ERROR_CATALOG_PROPERTIES_FILENAME + private lateinit var propertyFile: File + + private var log = logger(ErrorCatalogLoadPropertyService::class) + + lateinit var properties: Properties + + override suspend fun loadErrorCatalog() { + log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from properties...") + val propertyDir = errorCatalogProperties.errorDefinitionDir ?: ErrorMessageLibConstants.ERROR_CATALOG_PROPERTIES_DIRECTORY + propertyFile = Paths.get(propertyDir, propertyFileName).toFile().normalize() + properties = parseErrorMessagesProps() + } + + override fun getErrorMessage(domain: String, key: String): String? { + return getErrorMessage("$domain.${key.toLowerCase()}") + } + + override fun getErrorMessage(attribute: String): String? { + return properties.getProperty(attribute) + } + + /** + * Parses the error-messages.properties file which contains error messages + */ + private fun parseErrorMessagesProps(): Properties { + var inputStream: InputStream? = null + val props = Properties() + try { + inputStream = propertyFile.inputStream() + props.load(inputStream) + } catch (e: FileNotFoundException) { + log.error("Application ID: ${errorCatalogProperties.applicationId} > Property File '$propertyFileName' " + + "not found in the application directory.") + } catch (e: IOException) { + log.error("Application ID: ${errorCatalogProperties.applicationId} > Fail to load property file " + + "'$propertyFileName' for message errors.") + } finally { + inputStream!!.close() + } + return props + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt new file mode 100644 index 000000000..91f817133 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt @@ -0,0 +1,91 @@ +/* + * 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.services + +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalog +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException +import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants +import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload +import org.onap.ccsdk.cds.error.catalog.core.GrpcErrorCodes +import org.onap.ccsdk.cds.error.catalog.core.HttpErrorCodes +import org.onap.ccsdk.cds.error.catalog.services.utils.ErrorCatalogUtils +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean +import org.springframework.stereotype.Service +import javax.annotation.PostConstruct + +@Service +@ConditionalOnBean(ErrorCatalogLoadService::class) +open class ErrorCatalogService(private var errorCatalogLoadService: ErrorCatalogLoadService) { + + @PostConstruct + open fun init() = runBlocking { + errorCatalogLoadService.loadErrorCatalog() + } + + fun errorPayload(errorCatalogException: ErrorCatalogException): ErrorPayload { + val errorCatalog = getErrorCatalog(errorCatalogException) + val errorPayload = ErrorPayload(errorCatalog.code, errorCatalog.errorId, errorCatalog.getMessage()) + errorPayload.subErrors.addAll(errorCatalogException.errorPayload!!.subErrors) + if (errorCatalogException.cause != null) { + errorPayload.debugMessage = errorCatalogException.cause!!.printStackTrace().toString() + } + return errorPayload + } + + fun getErrorCatalog(errorCatalogException: ErrorCatalogException): ErrorCatalog { + val errorMessage = getMessage(errorCatalogException.domain, errorCatalogException.name) + val errorCode = + if (errorCatalogException.code == -1) { + getProtocolErrorCode( + errorCatalogException.protocol, + errorCatalogException.name + ) + } else { + errorCatalogException.code + } + val action: String + val errorCause: String + if (errorMessage.isNullOrEmpty()) { + action = errorCatalogException.action + errorCause = errorCatalogException.message ?: "" + } else { + action = ErrorCatalogUtils.readErrorActionFromMessage(errorMessage) + errorCause = errorCatalogException.message ?: ErrorCatalogUtils.readErrorCauseFromMessage(errorMessage) + } + + return ErrorCatalog( + errorCatalogException.name, + errorCatalogException.domain, + errorCode, + action, + errorCause + ) + } + + private fun getProtocolErrorCode(protocol: String, type: String): Int { + return when (protocol) { + ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC -> GrpcErrorCodes.code(type) + else -> HttpErrorCodes.code(type) + } + } + + private fun getMessage(domain: String, key: String): String? { + return errorCatalogLoadService.getErrorMessage(domain, key) + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt new file mode 100644 index 000000000..bb4a8f15e --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt @@ -0,0 +1,25 @@ +/* + * 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.services + +import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity + +fun ErrorPayload.toResponseEntity(): ResponseEntity { + return ResponseEntity(this, HttpStatus.resolve(this.code)!!) +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt new file mode 100755 index 000000000..7ade1c2a2 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt @@ -0,0 +1,76 @@ +/* + * 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.services.domain + +import java.io.Serializable +import javax.persistence.CascadeType +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.FetchType +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.ManyToMany +import javax.persistence.Table +import javax.persistence.UniqueConstraint +import java.util.UUID +import javax.persistence.JoinTable +import javax.persistence.JoinColumn + +/** + * Provide ErrorCode Entity + * + * @author Steve Siani + * @version 1.0 + */ + +@Entity +@Table(name = "ERROR_DOMAINS", uniqueConstraints = [UniqueConstraint(columnNames = ["name", "application_id"])]) +class Domain : Serializable { + @Id + var id: String = UUID.randomUUID().toString() + + @Column(name = "name") + lateinit var name: String + + @Column(name = "application_id") + lateinit var applicationId: String + + @Lob + @Column(name = "description") + var description: String = "" + + @ManyToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL]) + @JoinTable( + name = "ERROR_DOMAINS_ERROR_MESSAGES", + joinColumns = [JoinColumn(name = "domain_id", referencedColumnName = "id")], + inverseJoinColumns = [JoinColumn(name = "message_id", referencedColumnName = "id")] + ) + @Column(name = "error_msg") + val errorMessages: MutableSet = mutableSetOf() + + constructor() + + constructor(name: String, applicationId: String, description: String) { + this.name = name + this.description = description + this.applicationId = applicationId + } + + companion object { + private const val serialVersionUID = 1L + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt new file mode 100644 index 000000000..a4e92af48 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt @@ -0,0 +1,69 @@ +/* + * 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.services.domain + +import java.io.Serializable +import java.util.UUID +import javax.persistence.CascadeType +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.FetchType +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.ManyToMany +import javax.persistence.Table +import javax.persistence.UniqueConstraint + +/** + * Provide Error Message Model Entity + * + * @author Steve Siani + * @version 1.0 + */ +@Entity +@Table(name = "ERROR_MESSAGES", uniqueConstraints = [UniqueConstraint(columnNames = ["message_id"])]) +class ErrorMessageModel : Serializable { + + @Id + var id: String = UUID.randomUUID().toString() + + @Column(name = "message_id", nullable = false) + lateinit var messageID: String + + @Lob + @Column(name = "cause") + var cause: String = "" + + @Lob + @Column(name = "action") + lateinit var action: String + + @ManyToMany(mappedBy = "errorMessages", fetch = FetchType.EAGER, cascade = [CascadeType.PERSIST]) + val domains: MutableSet = mutableSetOf() + + companion object { + private const val serialVersionUID = 1L + } + + constructor() + + constructor(messageId: String, cause: String, action: String) { + this.messageID = messageId + this.cause = cause + this.action = action + } +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt new file mode 100644 index 000000000..197e385e0 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt @@ -0,0 +1,45 @@ +/* + * 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.services.repository + +import org.onap.ccsdk.cds.error.catalog.services.domain.Domain +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +/** + * @param Model + */ +@Repository +interface DomainRepository : JpaRepository { + + /** + * This is a findByNameAndApplicationId method + * + * @param name name + * @param applicationId applicationId + * @return Optional + */ + fun findByNameAndApplicationId(name: String, applicationId: String): Domain? + + /** + * This is a findAllByApplicationId method + * + * @param applicationId applicationId + * @return List + */ + fun findAllByApplicationId(applicationId: String): List +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt new file mode 100644 index 000000000..4a0f78672 --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt @@ -0,0 +1,36 @@ +/* + * 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.services.repository + +import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +/** + * @param Model + */ +@Repository +interface ErrorMessageModelRepository : JpaRepository { + + /** + * This is a findByDomains method + * + * @param domainId domainId + * @return List + */ + fun findByDomainsId(domainId: String): List +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt new file mode 100644 index 000000000..967d3560c --- /dev/null +++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt @@ -0,0 +1,39 @@ +/* + * 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.services.utils + +object ErrorCatalogUtils { + private const val REGEX_PATTERN = "^cause=(.*),action=(.*)" + private val regex = REGEX_PATTERN.toRegex() + + fun readErrorCauseFromMessage(message: String): String { + val matchResults = regex.matchEntire(message) + return matchResults!!.groupValues[1] + } + + fun readErrorActionFromMessage(message: String): String { + val matchResults = regex.matchEntire(message) + return matchResults!!.groupValues[2] + } +} + +fun Exception.errorCauseOrDefault(): Throwable { + return this.cause ?: Throwable() +} + +fun Exception.errorMessageOrDefault(): String { + return this.message ?: "" +} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt deleted file mode 100644 index a73401724..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt +++ /dev/null @@ -1,34 +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.services - -import org.springframework.boot.context.properties.ConfigurationProperties -import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.context.annotation.Configuration -import org.springframework.stereotype.Component - -@Configuration -@EnableConfigurationProperties(ErrorCatalogProperties::class) -open class ErrorCatalogConfiguration - -@Component -@ConfigurationProperties(prefix = "error.catalog") -open class ErrorCatalogProperties { - lateinit var type: String - lateinit var applicationId: String - var errorDefinitionDir: String = "" -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt deleted file mode 100644 index 841bcf539..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt +++ /dev/null @@ -1,98 +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.services - -import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants -import org.onap.ccsdk.error.catalog.services.domain.Domain -import org.onap.ccsdk.error.catalog.services.domain.ErrorMessageModel -import org.onap.ccsdk.error.catalog.services.repository.DomainRepository -import org.onap.ccsdk.error.catalog.services.repository.ErrorMessageModelRepository -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.data.domain.Page -import org.springframework.data.domain.Pageable -import org.springframework.stereotype.Service - -@Service -@ConditionalOnProperty( - name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE], - havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_DB -) -open class ErrorCatalogDBService( - private val domainRepository: DomainRepository, - private val errorMessageModelRepository: ErrorMessageModelRepository -) { - - /** - * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database by pages - * - * @return Page list of the domains by page - */ - open fun getAllDomains(pageRequest: Pageable): Page { - return domainRepository.findAll(pageRequest) - } - - /** - * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database - * - * @return List list of the domains - */ - open fun getAllDomains(): List { - return domainRepository.findAll() - } - - /** - * This is a getAllDomainsByApplication method to retrieve all the Domain that belong to an application in Error Catalog Database - * - * @return List list of the domains - */ - open fun getAllDomainsByApplication(applicationId: String): List { - return domainRepository.findAllByApplicationId(applicationId) - } - - /** - * This is a getAllErrorMessagesByApplication method to retrieve all the Messages that belong to an application in Error Catalog Database - * - * @return MutableMap list of the abstractErrorModel - */ - open fun getAllErrorMessagesByApplication(applicationId: String): MutableMap { - val domains = domainRepository.findAllByApplicationId(applicationId) - val errorMessages = mutableMapOf() - for (domain in domains) { - val errorMessagesFound = errorMessageModelRepository.findByDomainsId(domain.id) - for (errorMessageFound in errorMessagesFound) { - errorMessages["${domain.name}$MESSAGE_KEY_SEPARATOR${errorMessageFound.messageID}"] = errorMessageFound - } - } - return errorMessages - } - - open fun saveDomain( - domain: String, - applicationId: String, - description: String = "", - errorMessageList: List - ) { - val domainModel = Domain(domain, applicationId, description) - domainModel.errorMessages.addAll(errorMessageList) - domainRepository.saveAndFlush(domainModel) - } - - companion object { - private const val MESSAGE_KEY_SEPARATOR = "." - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt deleted file mode 100644 index 91fa97b77..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt +++ /dev/null @@ -1,31 +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.services - -import org.onap.ccsdk.error.catalog.core.ErrorCatalogException -import org.onap.ccsdk.error.catalog.core.ErrorPayload -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.ExceptionHandler - -abstract class ErrorCatalogExceptionHandler(private val errorCatalogService: ErrorCatalogService) { - - @ExceptionHandler(ErrorCatalogException::class) - fun errorCatalogException(e: ErrorCatalogException): ResponseEntity { - val errorPayload = errorCatalogService.errorPayload(e) - return errorPayload.toResponseEntity() - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt deleted file mode 100644 index b8a649eb0..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt +++ /dev/null @@ -1,145 +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.services - -import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants -import org.onap.ccsdk.error.catalog.core.logger -import org.onap.ccsdk.error.catalog.services.domain.ErrorMessageModel -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service -import java.io.FileNotFoundException -import java.io.IOException -import java.io.InputStream -import java.nio.file.Paths -import java.util.Properties - -interface ErrorCatalogLoadService { - - suspend fun loadErrorCatalog() - - fun getErrorMessage(domain: String, key: String): String? - - fun getErrorMessage(attribute: String): String? -} - -/** - * Representation of Blueprint Error Message lib from database service to load the properties - */ -@Service -@ConditionalOnBean(ErrorCatalogDBService::class) -open class ErrorCatalogLoadDBService( - private var errorCatalogProperties: ErrorCatalogProperties, - private var errorCatalogDBService: ErrorCatalogDBService -) : ErrorCatalogLoadService { - - private var log = logger(ErrorCatalogLoadDBService::class) - - lateinit var errorMessageInDB: Map - - override suspend fun loadErrorCatalog() { - log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from database...") - errorMessageInDB = getErrorMessagesFromDB() - } - - override fun getErrorMessage(domain: String, key: String): String? { - return getErrorMessage("$domain.${key.toLowerCase()}") - } - - override fun getErrorMessage(attribute: String): String? { - val errorMessage = findErrorMessage(attribute) - return prepareErrorMessage(errorMessage) - } - - /** - * Parses the error-messages.properties file which contains error messages - */ - private suspend fun getErrorMessagesFromDB(): Map { - return errorCatalogDBService.getAllErrorMessagesByApplication(errorCatalogProperties.applicationId) - } - - private fun findErrorMessage(attribute: String): ErrorMessageModel? { - return if (errorMessageInDB.containsKey(attribute)) { - errorMessageInDB[attribute] - } else { - null - } - } - - private fun prepareErrorMessage(errorMessage: ErrorMessageModel?): String? { - return if (errorMessage != null) { - "cause=${errorMessage.cause}, action=${errorMessage.action}" - } else { - null - } - } -} - -/** - * Representation of Blueprint Error Message lib property service to load the properties - */ -@Service -@ConditionalOnProperty( - name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE], - havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_PROPERTIES -) -open class ErrorCatalogLoadPropertyService(private var errorCatalogProperties: ErrorCatalogProperties) : - ErrorCatalogLoadService { - - private val propertyFileName = ErrorMessageLibConstants.ERROR_CATALOG_PROPERTIES_FILENAME - private var propertyFileBaseDirectory = Paths.get(errorCatalogProperties.errorDefinitionDir) - private var propertyFilePath = propertyFileBaseDirectory.resolve(propertyFileName) - - private var log = logger(ErrorCatalogLoadPropertyService::class) - - lateinit var properties: Properties - - override suspend fun loadErrorCatalog() { - log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from properties...") - properties = parseErrorMessagesProps() - } - - override fun getErrorMessage(domain: String, key: String): String? { - return getErrorMessage("$domain.${key.toLowerCase()}") - } - - override fun getErrorMessage(attribute: String): String? { - return properties.getProperty(attribute) - } - - /** - * Parses the error-messages.properties file which contains error messages - */ - private fun parseErrorMessagesProps(): Properties { - var inputStream: InputStream? = null - val props = Properties() - try { - inputStream = propertyFilePath.toFile().inputStream() - props.load(inputStream) - } catch (e: FileNotFoundException) { - log.error("Application ID: ${errorCatalogProperties.applicationId} > Property File '$propertyFileName}' " + - "not found in the application directory.") - } catch (e: IOException) { - log.error("Application ID: ${errorCatalogProperties.applicationId} > Fail to load property file " + - "'$propertyFileName}' for message errors.") - } finally { - inputStream!!.close() - } - return props - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt deleted file mode 100644 index e55e552d9..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt +++ /dev/null @@ -1,91 +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.services - -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.error.catalog.core.ErrorCatalog -import org.onap.ccsdk.error.catalog.core.ErrorCatalogException -import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants -import org.onap.ccsdk.error.catalog.core.ErrorPayload -import org.onap.ccsdk.error.catalog.core.GrpcErrorCodes -import org.onap.ccsdk.error.catalog.core.HttpErrorCodes -import org.onap.ccsdk.error.catalog.services.utils.ErrorCatalogUtils -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean -import org.springframework.stereotype.Service -import javax.annotation.PostConstruct - -@Service -@ConditionalOnBean(ErrorCatalogLoadService::class) -open class ErrorCatalogService(private var errorCatalogLoadService: ErrorCatalogLoadService) { - - @PostConstruct - open fun init() = runBlocking { - errorCatalogLoadService.loadErrorCatalog() - } - - fun errorPayload(errorCatalogException: ErrorCatalogException): ErrorPayload { - val errorCatalog = getErrorCatalog(errorCatalogException) - val errorPayload = ErrorPayload(errorCatalog.code, errorCatalog.errorId, errorCatalog.getMessage()) - errorPayload.subErrors.addAll(errorCatalogException.errorPayload!!.subErrors) - if (errorCatalogException.cause != null) { - errorPayload.debugMessage = errorCatalogException.cause!!.printStackTrace().toString() - } - return errorPayload - } - - fun getErrorCatalog(errorCatalogException: ErrorCatalogException): ErrorCatalog { - val errorMessage = getMessage(errorCatalogException.domain, errorCatalogException.name) - val errorCode = - if (errorCatalogException.code == -1) { - getProtocolErrorCode( - errorCatalogException.protocol, - errorCatalogException.name - ) - } else { - errorCatalogException.code - } - val action: String - val errorCause: String - if (errorMessage.isNullOrEmpty()) { - action = errorCatalogException.action - errorCause = errorCatalogException.message ?: "" - } else { - action = ErrorCatalogUtils.readErrorActionFromMessage(errorMessage) - errorCause = errorCatalogException.message ?: ErrorCatalogUtils.readErrorCauseFromMessage(errorMessage) - } - - return ErrorCatalog( - errorCatalogException.name, - errorCatalogException.domain, - errorCode, - action, - errorCause - ) - } - - private fun getProtocolErrorCode(protocol: String, type: String): Int { - return when (protocol) { - ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC -> GrpcErrorCodes.code(type) - else -> HttpErrorCodes.code(type) - } - } - - private fun getMessage(domain: String, key: String): String? { - return errorCatalogLoadService.getErrorMessage(domain, key) - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt deleted file mode 100644 index 41481623a..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt +++ /dev/null @@ -1,25 +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.services - -import org.onap.ccsdk.error.catalog.core.ErrorPayload -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity - -fun ErrorPayload.toResponseEntity(): ResponseEntity { - return ResponseEntity(this, HttpStatus.resolve(this.code)!!) -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt deleted file mode 100755 index 50a05b231..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt +++ /dev/null @@ -1,76 +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.services.domain - -import java.io.Serializable -import javax.persistence.CascadeType -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.FetchType -import javax.persistence.Id -import javax.persistence.Lob -import javax.persistence.ManyToMany -import javax.persistence.Table -import javax.persistence.UniqueConstraint -import java.util.UUID -import javax.persistence.JoinTable -import javax.persistence.JoinColumn - -/** - * Provide ErrorCode Entity - * - * @author Steve Siani - * @version 1.0 - */ - -@Entity -@Table(name = "ERROR_DOMAINS", uniqueConstraints = [UniqueConstraint(columnNames = ["name", "application_id"])]) -class Domain : Serializable { - @Id - var id: String = UUID.randomUUID().toString() - - @Column(name = "name") - lateinit var name: String - - @Column(name = "application_id") - lateinit var applicationId: String - - @Lob - @Column(name = "description") - var description: String = "" - - @ManyToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL]) - @JoinTable( - name = "ERROR_DOMAINS_ERROR_MESSAGES", - joinColumns = [JoinColumn(name = "domain_id", referencedColumnName = "id")], - inverseJoinColumns = [JoinColumn(name = "message_id", referencedColumnName = "id")] - ) - @Column(name = "error_msg") - val errorMessages: MutableSet = mutableSetOf() - - constructor() - - constructor(name: String, applicationId: String, description: String) { - this.name = name - this.description = description - this.applicationId = applicationId - } - - companion object { - private const val serialVersionUID = 1L - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt deleted file mode 100644 index 73e143095..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt +++ /dev/null @@ -1,69 +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.services.domain - -import java.io.Serializable -import java.util.UUID -import javax.persistence.CascadeType -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.FetchType -import javax.persistence.Id -import javax.persistence.Lob -import javax.persistence.ManyToMany -import javax.persistence.Table -import javax.persistence.UniqueConstraint - -/** - * Provide Error Message Model Entity - * - * @author Steve Siani - * @version 1.0 - */ -@Entity -@Table(name = "ERROR_MESSAGES", uniqueConstraints = [UniqueConstraint(columnNames = ["message_id"])]) -class ErrorMessageModel : Serializable { - - @Id - var id: String = UUID.randomUUID().toString() - - @Column(name = "message_id", nullable = false) - lateinit var messageID: String - - @Lob - @Column(name = "cause") - var cause: String = "" - - @Lob - @Column(name = "action") - lateinit var action: String - - @ManyToMany(mappedBy = "errorMessages", fetch = FetchType.EAGER, cascade = [CascadeType.PERSIST]) - val domains: MutableSet = mutableSetOf() - - companion object { - private const val serialVersionUID = 1L - } - - constructor() - - constructor(messageId: String, cause: String, action: String) { - this.messageID = messageId - this.cause = cause - this.action = action - } -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt deleted file mode 100644 index 700340b10..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt +++ /dev/null @@ -1,45 +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.services.repository - -import org.onap.ccsdk.error.catalog.services.domain.Domain -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository - -/** - * @param Model - */ -@Repository -interface DomainRepository : JpaRepository { - - /** - * This is a findByNameAndApplicationId method - * - * @param name name - * @param applicationId applicationId - * @return Optional - */ - fun findByNameAndApplicationId(name: String, applicationId: String): Domain? - - /** - * This is a findAllByApplicationId method - * - * @param applicationId applicationId - * @return List - */ - fun findAllByApplicationId(applicationId: String): List -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt deleted file mode 100644 index 084474970..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt +++ /dev/null @@ -1,36 +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.services.repository - -import org.onap.ccsdk.error.catalog.services.domain.ErrorMessageModel -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository - -/** - * @param Model - */ -@Repository -interface ErrorMessageModelRepository : JpaRepository { - - /** - * This is a findByDomains method - * - * @param domainId domainId - * @return List - */ - fun findByDomainsId(domainId: String): List -} diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt deleted file mode 100644 index 673082eed..000000000 --- a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt +++ /dev/null @@ -1,39 +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.services.utils - -object ErrorCatalogUtils { - private const val REGEX_PATTERN = "^cause=(.*),action=(.*)" - private val regex = REGEX_PATTERN.toRegex() - - fun readErrorCauseFromMessage(message: String): String { - val matchResults = regex.matchEntire(message) - return matchResults!!.groupValues[1] - } - - fun readErrorActionFromMessage(message: String): String { - val matchResults = regex.matchEntire(message) - return matchResults!!.groupValues[2] - } -} - -fun Exception.errorCauseOrDefault(): Throwable { - return this.cause ?: Throwable() -} - -fun Exception.errorMessageOrDefault(): String { - return this.message ?: "" -} diff --git a/pom.xml b/pom.xml index 65de1c54a..da7368259 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.onap.ccsdk.parent spring-boot-starter-parent - 1.5.2-SNAPSHOT + 1.5.2 @@ -111,8 +111,7 @@ limitations under the License. validate - + @@ -128,8 +127,7 @@ limitations under the License. process-sources - + -- cgit 1.2.3-korg