Error Catalog Management Core Library. 98/103298/16
authorBrinda Santh <bs2796@att.com>
Fri, 6 Mar 2020 18:04:37 +0000 (13:04 -0500)
committerKAPIL SINGAL <ks220y@att.com>
Wed, 11 Mar 2020 17:55:28 +0000 (17:55 +0000)
Issue-ID: CCSDK-2076
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I9e8e67bdee77fb359a791f4ef4c2963aa78ab93a
Signed-off-by: Steve Siani <alphonse.steve.siani.djissitchi@ibm.com>
42 files changed:
ms/blueprintsprocessor/application/pom.xml
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt [new file with mode: 0644]
ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
ms/blueprintsprocessor/application/src/main/resources/application.properties
ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties [new file with mode: 0644]
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/application/src/test/resources/application-test.properties
ms/blueprintsprocessor/application/src/test/resources/application.properties
ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties [new file with mode: 0644]
ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt
ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
ms/blueprintsprocessor/parent/pom.xml
ms/error-catalog/README.md [new file with mode: 0755]
ms/error-catalog/application/pom.xml [new file with mode: 0644]
ms/error-catalog/core/pom.xml [new file with mode: 0644]
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogException.kt [new file with mode: 0644]
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCatalogExtensions.kt [new file with mode: 0644]
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorCodes.kt [new file with mode: 0644]
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorLibData.kt [new file with mode: 0644]
ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/error/catalog/core/ErrorMessageLibConstants.kt [new file with mode: 0644]
ms/error-catalog/pom.xml [new file with mode: 0644]
ms/error-catalog/services/pom.xml [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt [new file with mode: 0755]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt [new file with mode: 0644]
ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt [new file with mode: 0644]
ms/pom.xml

index b75e161..d17425c 100755 (executable)
@@ -46,9 +46,9 @@
 
     <dependencies>
         <dependency>
-           <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
-           <artifactId>blueprint-core</artifactId>
-           <exclusions>
+            <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
+            <artifactId>blueprint-core</artifactId>
+            <exclusions>
                 <exclusion>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-logging</artifactId>
             </exclusions>
         </dependency>
 
+        <!-- Error Catalog Services -->
+        <dependency>
+            <groupId>org.onap.ccsdk.error.catalog</groupId>
+            <artifactId>error-catalog-services</artifactId>
+        </dependency>
+
         <!-- North Bound -->
         <dependency>
             <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
index 58464cb..2e268c3 100644 (file)
@@ -31,7 +31,8 @@ import javax.sql.DataSource
 @Configuration
 @Import(BluePrintDBLibConfiguration::class)
 @EnableJpaRepositories(
-    basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor"],
+    basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor",
+        "org.onap.ccsdk.error.catalog"],
     entityManagerFactoryRef = "primaryEntityManager",
     transactionManagerRef = "primaryTransactionManager"
 )
@@ -43,7 +44,8 @@ open class BlueprintDatabaseConfiguration(primaryDataSourceProperties: PrimaryDa
     open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean {
         return primaryEntityManager(
             "org.onap.ccsdk.cds.controllerblueprints",
-            "org.onap.ccsdk.cds.blueprintsprocessor"
+            "org.onap.ccsdk.cds.blueprintsprocessor",
+            "org.onap.ccsdk.error.catalog"
         )
     }
 
index 1d1baee..7a888f9 100644 (file)
@@ -30,7 +30,10 @@ import org.springframework.context.annotation.ComponentScan
  */
 @SpringBootApplication
 @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
+@ComponentScan(
+    basePackages = ["org.onap.ccsdk.error.catalog",
+        "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]
+)
 open class BlueprintProcessorApplication
 
 fun main(args: Array<String>) {
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
new file mode 100644 (file)
index 0000000..6fcbdfd
--- /dev/null
@@ -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.blueprintsprocessor
+
+import org.onap.ccsdk.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.error.catalog.services.ErrorCatalogService
+import org.springframework.web.bind.annotation.RestControllerAdvice
+
+@RestControllerAdvice("org.onap.ccsdk.cds")
+open class BlueprintProcessorExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+        ErrorCatalogExceptionHandler(errorCatalogService)
index fffc2f4..6710009 100755 (executable)
@@ -27,6 +27,11 @@ server.port=8081
 security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
 security.user.name: ccsdkapps
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.defaultDirectory=/opt/app/onap/config
+
 ### START -Controller Blueprints Properties
 # Load Resource Source Mappings
 resourceSourceMappings=processor-db=source-db,input=source-input,default=source-default,sdnc=source-rest,aai-data=source-rest,capability=source-capability,vault-data=source-rest,rest=source-rest,script=source-capability
@@ -137,4 +142,4 @@ blueprintsprocessor.messageproducer.self-service-api.topic=producer.t
 #blueprintsprocessor.messageconsumer.prioritize-input.type=kafka-streams-basic-auth
 #blueprintsprocessor.messageconsumer.prioritize-input.bootstrapServers=127.0.0.1:9092
 #blueprintsprocessor.messageconsumer.prioritize-input.applicationId=cds-controller
-#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic
\ No newline at end of file
+#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic
index d6082bf..2a16b3e 100755 (executable)
@@ -60,6 +60,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts
 security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
 security.user.name: ccsdkapps
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.defaultDirectory=/opt/app/onap/config
+
 # Used in Health Check
 #endpoints.user.name=ccsdkapps
 #endpoints.user.password=ccsdkapps
@@ -130,5 +135,3 @@ cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener ser
 #Actuator properties
 management.endpoints.web.exposure.include=*
 management.endpoint.health.show-details=always
-
-
diff --git a/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties
new file mode 100644 (file)
index 0000000..246a1d5
--- /dev/null
@@ -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.
+#
+org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resolution_failure=cause=Fail to process Resource Resolution.,action=Verify the resource definitions.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
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
new file mode 100644 (file)
index 0000000..74a17fa
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  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.blueprintsprocessor.uat
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+        basePackages = ["org.onap.ccsdk.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
new file mode 100644 (file)
index 0000000..8e399fd
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  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.blueprintsprocessor.uat.error
+
+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.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.BeforeTest
+import kotlin.test.Test
+import kotlin.test.assertTrue
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(
+        classes = [ErrorCatalogTestConfiguration::class]
+)
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class ErrorCatalogServiceTest {
+    @Autowired
+    lateinit var errorCatalogService: ErrorCatalogService
+
+    private val domain = "org.onap.ccsdk.cds.blueprintsprocessor"
+    private lateinit var errorType: String
+    private lateinit var errorCatalogHttp: ErrorCatalog
+    private lateinit var errorCatalogGrpc: ErrorCatalog
+    private lateinit var errorPayloadHttp: ErrorPayload
+    private lateinit var errorPayloadGrpc: ErrorPayload
+
+    @BeforeTest
+    fun setup() {
+        errorType = ErrorCatalogCodes.GENERIC_FAILURE
+        errorCatalogHttp = ErrorCatalog(errorType, domain, 500,
+                "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.")
+        errorCatalogGrpc = ErrorCatalog(errorType, domain, 2,
+                "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.")
+
+        errorPayloadHttp = ErrorPayload(500, ErrorCatalogCodes.GENERIC_FAILURE,
+                "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.",
+                errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor",
+                        "Internal error in Blueprint Processor run time.", ""))
+        errorPayloadGrpc = ErrorPayload(2, ErrorCatalogCodes.GENERIC_FAILURE,
+                "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.",
+                errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor",
+                        "Internal error in Blueprint Processor run time.", ""))
+    }
+
+    @Test
+    fun errorPayloadHttp() {
+        val errorPayload = errorCatalogService.errorPayload(httpProcessorException(errorType, domain,
+                "Internal error in Blueprint Processor run time."))
+        assertTrue { errorPayload.isEqualTo(errorPayloadHttp) }
+    }
+
+    @Test
+    fun errorPayloadGrpc() {
+        val errorPayload = errorCatalogService.errorPayload(grpcProcessorException(errorType, domain,
+                "Internal error in Blueprint Processor run time."))
+        assertTrue { errorPayload.isEqualTo(errorPayloadGrpc) }
+    }
+
+    @Test
+    fun getErrorCatalogHttp() {
+        val errorCatalog = errorCatalogService.getErrorCatalog(httpProcessorException(errorType, domain,
+                "Internal error in Blueprint Processor run time."))
+        assertTrue { errorCatalog == errorCatalogHttp }
+    }
+
+    @Test
+    fun getErrorCatalogGrpc() {
+        val errorCatalog = errorCatalogService.getErrorCatalog(grpcProcessorException(errorType, domain,
+                "Internal error in Blueprint Processor run time."))
+        assertTrue { errorCatalog == errorCatalogGrpc }
+    }
+}
index 1d2565b..8358940 100644 (file)
 
 spring.http.log-request-details=true
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.defaultDirectory=./src/test/resources/
+
 blueprintsprocessor.httpPort=0
 blueprintsprocessor.grpcEnable=true
 blueprintsprocessor.grpcPort=0
@@ -61,4 +66,3 @@ blueprintprocessor.healthcheck.mapping-service-name-with-service-link=[Execution
 #BaseUrls for health check Cds Listener services
 cdslistener.healthcheck.baseUrl=http://cds-sdc-listener:8080/
 cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener service,/api/v1/sdclistener/healthcheck]
-
index ea14c49..eabc141 100644 (file)
@@ -61,6 +61,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts
 security.user.password:{bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
 security.user.name:ccsdkapps
 
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.defaultDirectory=/opt/app/onap/config
+
 # Executor Options
 blueprintsprocessor.resourceResolution.enabled=true
 blueprintsprocessor.netconfExecutor.enabled=true
diff --git a/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties
new file mode 100644 (file)
index 0000000..246a1d5
--- /dev/null
@@ -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.
+#
+org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resolution_failure=cause=Fail to process Resource Resolution.,action=Verify the resource definitions.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
index a2435da..74e6bb6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 - 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.
@@ -21,29 +22,13 @@ package org.onap.ccsdk.cds.controllerblueprints.core
  *
  * @author Brinda Santh
  */
-class BluePrintException : Exception {
-
-    var code: Int = 100
+class BluePrintException : BluePrintProcessorException {
 
     constructor(cause: Throwable) : super(cause)
     constructor(message: String) : super(message)
     constructor(message: String, cause: Throwable) : super(message, cause)
-    constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.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
-    }
+    constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
+    constructor(code: Int, cause: Throwable) : super(code, cause)
+    constructor(code: Int, message: String) : super(code, message)
+    constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
 }
index b0b2170..50b6614 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * Modifications Copyright © 2018 - 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.
 
 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
+
 /**
  *
  *
  * @author Brinda Santh
  */
-class BluePrintProcessorException : RuntimeException {
-
-    var code: Int = 100
+open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> {
 
     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(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
+    constructor(code: Int, cause: Throwable) : super(code, cause)
+    constructor(code: Int, message: String) : super(code, message)
+    constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
+
+    override fun code(code: Int): BluePrintProcessorException {
+        return this.updateCode(code)
+    }
+
+    override fun domain(domain: String): BluePrintProcessorException {
+        return this.updateDomain(domain)
+    }
+
+    override fun action(action: String): BluePrintProcessorException {
+        return this.updateAction(action)
+    }
 
-    constructor(code: Int, cause: Throwable) : super(cause) {
-        this.code = code
+    override fun http(type: String): BluePrintProcessorException {
+        return this.updateHttp(type)
     }
 
-    constructor(code: Int, message: String) : super(message) {
-        this.code = code
+    override fun grpc(type: String): BluePrintProcessorException {
+        return this.updateGrpc(type)
     }
 
-    constructor(code: Int, message: String, cause: Throwable) : super(message, cause) {
-        this.code = code
+    override fun payloadMessage(message: String): BluePrintProcessorException {
+        return this.updatePayloadMessage(message)
     }
 
-    constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) :
-            super(String.format(message, *args), cause) {
-        this.code = code
+    override fun addErrorPayloadMessage(message: String): BluePrintProcessorException {
+        return this.updateErrorPayloadMessage(message)
+    }
+
+    override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException {
+        return this.updateSubError(errorMessage)
     }
 }
 
@@ -55,3 +75,64 @@ class BluePrintRetryException : RuntimeException {
     constructor(cause: Throwable) : super(cause)
     constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
 }
+
+/** Extension Functions */
+
+fun processorException(message: String): BluePrintProcessorException {
+    return BluePrintProcessorException(message)
+}
+
+fun processorException(code: Int, message: String): BluePrintProcessorException {
+    return processorException(message).code(code)
+}
+
+fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
+    return processorException(message).http(type)
+}
+
+fun grpcProcessorException(type: String, message: String): BluePrintProcessorException {
+    return processorException(message).grpc(type)
+}
+
+fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(message).http(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
+}
+
+fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(message).grpc(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
+}
+
+fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
+        BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(message).http(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+}
+
+fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
+        BluePrintProcessorException {
+    val bluePrintProcessorException = processorException(message).grpc(type)
+    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+}
+
+fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: Throwable):
+        BluePrintProcessorException {
+    return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
+            .addErrorPayloadMessage(message)
+            .payloadMessage(message)
+}
+
+fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException {
+    return this.addDomainAndErrorMessage(domain, message).domain(domain)
+            .addErrorPayloadMessage(message)
+            .payloadMessage(message)
+}
+
+private fun BluePrintProcessorException.addDomainAndErrorMessage(
+    domain: String,
+    message: String,
+    cause: Throwable = Throwable()
+): BluePrintProcessorException {
+    return this.addSubError(ErrorMessage(domain, message, cause.message ?: "")).domain(domain)
+}
index ff9aed6..1f01d1c 100644 (file)
@@ -211,24 +211,28 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     }
 
     @PostMapping(
-            path = arrayOf("/workflow-spec"), produces = arrayOf(MediaType
-            .APPLICATION_JSON_VALUE),
-            consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+        path = arrayOf("/workflow-spec"), produces = arrayOf(
+            MediaType
+                .APPLICATION_JSON_VALUE
+        ),
+        consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
     )
     @ResponseBody
     @Throws(BluePrintException::class)
     @PreAuthorize("hasRole('USER')")
     suspend fun workflowSpec(@RequestBody workFlowSpecReq: WorkFlowSpecRequest):
-            ResponseEntity<String> = mdcWebCoroutineScope {
+        ResponseEntity<String> = mdcWebCoroutineScope {
         var json = bluePrintModelHandler.prepareWorkFlowSpec(workFlowSpecReq)
-                .asJsonString()
+            .asJsonString()
         ResponseEntity(json, HttpStatus.OK)
     }
 
     @GetMapping(
-            path = arrayOf("/workflows/blueprint-name/{name}/version/{version" +
-                    "}"),
-            produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+        path = arrayOf(
+            "/workflows/blueprint-name/{name}/version/{version" +
+                "}"
+        ),
+        produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)
     )
     @ResponseBody
     @Throws(BluePrintException::class)
@@ -240,7 +244,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
         @PathVariable(value = "version") version: String
     ): ResponseEntity<String> = mdcWebCoroutineScope {
         var json = bluePrintModelHandler.getWorkflowNames(name, version)
-                .asJsonString()
+            .asJsonString()
         ResponseEntity(json, HttpStatus.OK)
     }
 }
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt
new file mode 100644 (file)
index 0000000..ae91246
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.blueprintsprocessor.designer.api
+
+object DesignerApiDomains {
+    // Designer Api Domains Constants
+    const val DESIGNER_API = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api"
+    const val DESIGNER_API_ENHANCER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer"
+    const val DESIGNER_API_HANDLER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler"
+    const val DESIGNER_API_LOAD = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load"
+    const val DESIGNER_API_SERVICE = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service"
+}
+
+object DesignerApiHttpErrorCodes {
+    init {
+        // Register HttpErrorCodes
+        // HttpErrorCodes.register("", 200)
+    }
+}
+
+object DesignerGrpcErrorCodes {
+    init {
+        // Register GrpcErrorCodes
+        // GrpcErrorCodes.register("", 3)
+    }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt
new file mode 100644 (file)
index 0000000..b37cd0e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.blueprintsprocessor.resource.api
+
+object ResourceApiDomains {
+    // Resource Api Domains Constants
+    const val RESOURCE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api"
+}
+
+object ResourceApiHttpErrorCodes {
+    init {
+        // Register HttpErrorCodes
+        // HttpErrorCodes.register("", 200)
+    }
+}
+
+object ResourceGrpcErrorCodes {
+    init {
+        // Register GrpcErrorCodes
+        // GrpcErrorCodes.register("", 3)
+    }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt
new file mode 100644 (file)
index 0000000..b76bc26
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.blueprintsprocessor.selfservice.api
+
+object SelfServiceApiDomains {
+    // SelfServiceApi Domains Constants
+    const val BLUEPRINT_PROCESSOR = "org.onap.ccsdk.cds.blueprintsprocessor"
+    const val SELF_SERVICE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api"
+    const val SELF_SERVICE_API_VALIDATOR = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api.validator"
+    const val NETCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor"
+    const val RESOURCE_RESOLUTION = "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution"
+    const val RESTCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor"
+    const val CLI_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor"
+    const val PYTHON_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor"
+    const val SDC_LISTENER = "org.onap.ccsdk.cds.sdclistener"
+}
+
+object SelfServiceApiHttpErrorCodes {
+    init {
+        // Register HttpErrorCodes
+        // HttpErrorCodes.register("", 200)
+    }
+}
+
+object SelfServiceGrpcErrorCodes {
+    init {
+        // Register GrpcErrorCodes
+        // GrpcErrorCodes.register("", 3)
+    }
+}
index 8b268d6..908c046 100644 (file)
@@ -27,7 +27,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutp
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
 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.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
@@ -81,7 +83,9 @@ open class ExecutionServiceController {
     ): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope {
 
         if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
-            throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
+            throw httpProcessorException(ErrorCatalogCodes.GENERIC_FAILURE,
+                    SelfServiceApiDomains.BLUEPRINT_PROCESSOR,
+                    "Can't process async request through the REST endpoint. Use gRPC for async processing.")
         }
         ph.register()
         val processResult = executionServiceHandler.doProcess(executionServiceInput)
index d1de108..8349fa7 100755 (executable)
@@ -35,6 +35,7 @@
         <sli.version>${ccsdk.sli.core.version}</sli.version>
         <!-- Override CDS version from parent to be project.version -->
         <ccsdk.cds.version>${project.version}</ccsdk.cds.version>
+        <error.catalog.version>${project.version}</error.catalog.version>
         <dmaap.client.version>1.1.5</dmaap.client.version>
         <!-- Should be using released artifact as soon as available: -->
         <!-- https://github.com/springfox/springfox/milestone/44 -->
                 <version>${kafka.version}</version>
             </dependency>
 
+            <!-- Error Catalog -->
+            <dependency>
+                <groupId>org.onap.ccsdk.error.catalog</groupId>
+                <artifactId>error-catalog-core</artifactId>
+                <version>${error.catalog.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>*</groupId>
+                        <artifactId>*</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.onap.ccsdk.error.catalog</groupId>
+                <artifactId>error-catalog-services</artifactId>
+                <version>${error.catalog.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>*</groupId>
+                        <artifactId>*</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+
             <!-- SLI Version -->
             <dependency>
                 <groupId>org.onap.ccsdk.sli.core</groupId>
             <groupId>io.netty</groupId>
             <artifactId>netty-tcnative-boringssl-static</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.onap.ccsdk.error.catalog</groupId>
+            <artifactId>error-catalog-core</artifactId>
+        </dependency>
     </dependencies>
 
     <repositories>
diff --git a/ms/error-catalog/README.md b/ms/error-catalog/README.md
new file mode 100755 (executable)
index 0000000..d6ae56d
--- /dev/null
@@ -0,0 +1,36 @@
+## How to use library
+
+##### 1. Set Error Catalog service type (Database or properties file service) in application.properties file
+
+```
+##### Error Managements #####
+## For database service type ##
+#    error.catalog.type=DB
+## For database service type ##
+#    error.catalog.type=properties
+error.catalog.applicationId=cds
+error.catalog.type=properties
+```
+
+##### 2. Generate exception
+
+- HTTP Error Exception
+```
+errorCatalogException: ErrorCatalogException = httpProcessorException(ErrorCatalogCodes.ERROR_TYPE, 
+"Error message here...")
+```
+
+- GRPC Error Exception
+```
+errorCatalogException: ErrorCatalogException = grpcProcessorException(ErrorCatalogCodes.ERROR_TYPE, 
+"Error message here...")
+```
+
+##### 3. Update an existing exception
+```
+e = errorCatalogException.code(500)
+e = errorCatalogException.action("message")
+...
+```
+
+##### 4. Add a HTTP REST Exception handler
\ No newline at end of file
diff --git a/ms/error-catalog/application/pom.xml b/ms/error-catalog/application/pom.xml
new file mode 100644 (file)
index 0000000..dc9d312
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.ccsdk.error.catalog</groupId>
+        <artifactId>error-catalog</artifactId>
+        <version>0.7.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>error-catalog-application</artifactId>
+
+    <name>Error Catalog Application</name>
+    <description>Error Catalog Application</description>
+</project>
diff --git a/ms/error-catalog/core/pom.xml b/ms/error-catalog/core/pom.xml
new file mode 100644 (file)
index 0000000..7a46dbc
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.ccsdk.error.catalog</groupId>
+        <artifactId>error-catalog</artifactId>
+        <version>0.7.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>error-catalog-core</artifactId>
+
+    <name>Error Catalog Core</name>
+    <description>Error Catalog Core</description>
+</project>
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
new file mode 100644 (file)
index 0000000..76f9cc0
--- /dev/null
@@ -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.error.catalog.core
+
+interface ErrorCatalogExceptionFluent<T> {
+    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<String>? = 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 <T : ErrorCatalogException> updateCode(code: Int): T {
+        this.code = code
+        return this as T
+    }
+
+    open fun <T : ErrorCatalogException> updateDomain(domain: String): T {
+        this.domain = domain
+        return this as T
+    }
+
+    open fun <T : ErrorCatalogException> updateAction(action: String): T {
+        this.action = action
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> updateHttp(type: String): T {
+        this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP
+        this.code = HttpErrorCodes.code(type)
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> updateGrpc(type: String): T {
+        this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC
+        this.code = GrpcErrorCodes.code(type)
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> updatePayloadMessage(message: String): T {
+        if (this.errorPayloadMessages == null) this.errorPayloadMessages = arrayListOf()
+        this.errorPayloadMessages!!.add(message)
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> updateErrorPayloadMessage(message: String): T {
+        if (errorPayload == null) {
+            errorPayload = ErrorPayload()
+        }
+        errorPayload!!.message = "${errorPayload!!.message} $messageSeparator $message"
+        return this as T
+    }
+
+    fun <T : ErrorCatalogException> 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
new file mode 100644 (file)
index 0000000..76011b2
--- /dev/null
@@ -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.error.catalog.core
+
+import org.slf4j.LoggerFactory
+import org.slf4j.helpers.MessageFormatter
+import kotlin.reflect.KClass
+
+fun <T : Any> logger(clazz: T) = LoggerFactory.getLogger(clazz.javaClass)!!
+
+fun <T : KClass<*>> 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
new file mode 100644 (file)
index 0000000..241e9d2
--- /dev/null
@@ -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.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<String, Int> = 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<String, Int> = 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
new file mode 100644 (file)
index 0000000..b33c118
--- /dev/null
@@ -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.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<ErrorMessage> = 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
new file mode 100644 (file)
index 0000000..ef56e7b
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  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
new file mode 100644 (file)
index 0000000..91e13c2
--- /dev/null
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.ccsdk.cds</groupId>
+        <artifactId>ms</artifactId>
+        <version>0.7.0-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+
+    <groupId>org.onap.ccsdk.error.catalog</groupId>
+    <artifactId>error-catalog</artifactId>
+    <packaging>pom</packaging>
+
+    <name>Error Catalog Lib</name>
+    <description>Error Catalog Lib for ONAP Components</description>
+
+    <modules>
+        <module>application</module>
+        <module>core</module>
+        <module>services</module>
+    </modules>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.onap.ccsdk.error.catalog</groupId>
+                <artifactId>error-catalog-core</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.onap.ccsdk.error.catalog</groupId>
+                <artifactId>error-catalog-services</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+    <dependencies>
+        <!-- Kotlin Dependencies -->
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-script-util</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-reactor</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.module</groupId>
+            <artifactId>jackson-module-kotlin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-compiler-embeddable</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-scripting-jvm-host</artifactId>
+            <!--Use kotlin-compiler-embeddable as koltin-compiler wrap-->
+            <!--guava dependency creating classpath issues at runtime-->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.jetbrains.kotlin</groupId>
+                    <artifactId>kotlin-compiler</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-webflux</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.persistence</groupId>
+            <artifactId>javax.persistence-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-maven-plugin</artifactId>
+                <version>${kotlin.maven.version}</version>
+                <executions>
+                    <execution>
+                        <id>compile</id>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirs>
+                                <sourceDir>src/main/kotlin</sourceDir>
+                            </sourceDirs>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>test-compile</id>
+                        <goals>
+                            <goal>test-compile</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirs>
+                                <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
+                            </sourceDirs>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/ms/error-catalog/services/pom.xml b/ms/error-catalog/services/pom.xml
new file mode 100644 (file)
index 0000000..1adbc40
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.ccsdk.error.catalog</groupId>
+        <artifactId>error-catalog</artifactId>
+        <version>0.7.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>error-catalog-services</artifactId>
+
+    <name>Error Catalog Service</name>
+    <description>Error Catalog Service</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onap.ccsdk.error.catalog</groupId>
+            <artifactId>error-catalog-core</artifactId>
+        </dependency>
+    </dependencies>
+</project>
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
new file mode 100644 (file)
index 0000000..8f2440e
--- /dev/null
@@ -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.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 defaultDirectory: 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
new file mode 100644 (file)
index 0000000..841bcf5
--- /dev/null
@@ -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.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<Domain> list of the domains by page
+    </Domain> */
+    open fun getAllDomains(pageRequest: Pageable): Page<Domain> {
+        return domainRepository.findAll(pageRequest)
+    }
+
+    /**
+     * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database
+     *
+     * @return List<Domain> list of the domains
+    </Domain> */
+    open fun getAllDomains(): List<Domain> {
+        return domainRepository.findAll()
+    }
+
+    /**
+     * This is a getAllDomainsByApplication method to retrieve all the Domain that belong to an application in Error Catalog Database
+     *
+     * @return List<Domain> list of the domains
+    </Domain> */
+    open fun getAllDomainsByApplication(applicationId: String): List<Domain> {
+        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<String, ErrorCode> list of the abstractErrorModel
+    </Domain> */
+    open fun getAllErrorMessagesByApplication(applicationId: String): MutableMap<String, ErrorMessageModel> {
+        val domains = domainRepository.findAllByApplicationId(applicationId)
+        val errorMessages = mutableMapOf<String, ErrorMessageModel>()
+        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<ErrorMessageModel>
+    ) {
+        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
new file mode 100644 (file)
index 0000000..91fa97b
--- /dev/null
@@ -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.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<ErrorPayload> {
+        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
new file mode 100644 (file)
index 0000000..d1af5fe
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ *  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<String, ErrorMessageModel>
+
+    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<String, ErrorMessageModel> {
+        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.defaultDirectory)
+    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
new file mode 100644 (file)
index 0000000..e55e552
--- /dev/null
@@ -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.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
new file mode 100644 (file)
index 0000000..4148162
--- /dev/null
@@ -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.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<ErrorPayload> {
+    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
new file mode 100755 (executable)
index 0000000..50a05b2
--- /dev/null
@@ -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.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<ErrorMessageModel> = 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
new file mode 100644 (file)
index 0000000..73e1430
--- /dev/null
@@ -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.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<Domain> = 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
new file mode 100644 (file)
index 0000000..700340b
--- /dev/null
@@ -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.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 <T> Model
+ */
+@Repository
+interface DomainRepository : JpaRepository<Domain, String> {
+
+    /**
+     * This is a findByNameAndApplicationId method
+     *
+     * @param name name
+     * @param applicationId applicationId
+     * @return Optional<T>
+     */
+    fun findByNameAndApplicationId(name: String, applicationId: String): Domain?
+
+    /**
+     * This is a findAllByApplicationId method
+     *
+     * @param applicationId applicationId
+     * @return List<T>
+     */
+    fun findAllByApplicationId(applicationId: String): List<Domain>
+}
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
new file mode 100644 (file)
index 0000000..0844749
--- /dev/null
@@ -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.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 <T> Model
+ */
+@Repository
+interface ErrorMessageModelRepository : JpaRepository<ErrorMessageModel, String> {
+
+    /**
+     * This is a findByDomains method
+     *
+     * @param domainId domainId
+     * @return List<T>
+     */
+    fun findByDomainsId(domainId: String): List<ErrorMessageModel>
+}
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
new file mode 100644 (file)
index 0000000..673082e
--- /dev/null
@@ -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.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 ?: ""
+}
index 7ec3f39..9386150 100644 (file)
@@ -32,6 +32,7 @@
     <description>Micro-services</description>
 
     <modules>
+        <module>error-catalog</module>
         <module>blueprintsprocessor</module>
         <module>py-executor</module>
         <module>command-executor</module>