2 * Copyright © 2020 IBM, Bell Canada.
3 * Modifications Copyright © 2019-2020 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.error.catalog.services
20 import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants
21 import org.onap.ccsdk.error.catalog.services.domain.Domain
22 import org.onap.ccsdk.error.catalog.services.domain.ErrorMessageModel
23 import org.onap.ccsdk.error.catalog.services.repository.DomainRepository
24 import org.onap.ccsdk.error.catalog.services.repository.ErrorMessageModelRepository
25 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
26 import org.springframework.data.domain.Page
27 import org.springframework.data.domain.Pageable
28 import org.springframework.stereotype.Service
31 @ConditionalOnProperty(
32 name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE],
33 havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_DB
35 open class ErrorCatalogDBService(
36 private val domainRepository: DomainRepository,
37 private val errorMessageModelRepository: ErrorMessageModelRepository
41 * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database by pages
43 * @return Page<Domain> list of the domains by page
45 open fun getAllDomains(pageRequest: Pageable): Page<Domain> {
46 return domainRepository.findAll(pageRequest)
50 * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database
52 * @return List<Domain> list of the domains
54 open fun getAllDomains(): List<Domain> {
55 return domainRepository.findAll()
59 * This is a getAllDomainsByApplication method to retrieve all the Domain that belong to an application in Error Catalog Database
61 * @return List<Domain> list of the domains
63 open fun getAllDomainsByApplication(applicationId: String): List<Domain> {
64 return domainRepository.findAllByApplicationId(applicationId)
68 * This is a getAllErrorMessagesByApplication method to retrieve all the Messages that belong to an application in Error Catalog Database
70 * @return MutableMap<String, ErrorCode> list of the abstractErrorModel
72 open fun getAllErrorMessagesByApplication(applicationId: String): MutableMap<String, ErrorMessageModel> {
73 val domains = domainRepository.findAllByApplicationId(applicationId)
74 val errorMessages = mutableMapOf<String, ErrorMessageModel>()
75 for (domain in domains) {
76 val errorMessagesFound = errorMessageModelRepository.findByDomainsId(domain.id)
77 for (errorMessageFound in errorMessagesFound) {
78 errorMessages["${domain.name}$MESSAGE_KEY_SEPARATOR${errorMessageFound.messageID}"] = errorMessageFound
86 applicationId: String,
87 description: String = "",
88 errorMessageList: List<ErrorMessageModel>
90 val domainModel = Domain(domain, applicationId, description)
91 domainModel.errorMessages.addAll(errorMessageList)
92 domainRepository.saveAndFlush(domainModel)
96 private const val MESSAGE_KEY_SEPARATOR = "."