aboutsummaryrefslogtreecommitdiffstats
path: root/ms/error-catalog/services/src
diff options
context:
space:
mode:
authorBrinda Santh <bs2796@att.com>2020-03-06 13:04:37 -0500
committerKAPIL SINGAL <ks220y@att.com>2020-03-11 17:55:28 +0000
commit91b3a6477c4d5136bea02d3c1284a51b2f2ec1b1 (patch)
treefc8fe811f14dced88bc7e7296b60d1ce2990452d /ms/error-catalog/services/src
parent55ec3c71441abda7c6058f4c2cc569c129f635ba (diff)
Error Catalog Management Core Library.
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>
Diffstat (limited to 'ms/error-catalog/services/src')
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt34
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt98
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt31
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt145
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt91
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt25
-rwxr-xr-xms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt76
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt69
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt45
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt36
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt39
11 files changed, 689 insertions, 0 deletions
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
index 000000000..8f2440e34
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogConfiguration.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.ccsdk.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
index 000000000..841bcf539
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogDBService.kt
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..91fa97b77
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogExceptionHandler.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..d1af5fe55
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogLoadService.kt
@@ -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
index 000000000..e55e552d9
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogService.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..41481623a
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/ErrorCatalogServiceExtensions.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2018-2019 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..50a05b231
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/Domain.kt
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..73e143095
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/domain/ErrorMessageModel.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..700340b10
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/DomainRepository.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..084474970
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/repository/ErrorMessageModelRepository.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.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
index 000000000..673082eed
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/error/catalog/services/utils/ErrorCatalogUtils.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.ccsdk.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 ?: ""
+}