Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / health-api-common / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / healthapi / configuration / HealthCheckProperties.kt
1 /*
2  * Copyright © 2019-2020 Orange.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint
20 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceName
21 import org.springframework.beans.factory.annotation.Value
22 import org.springframework.context.annotation.Configuration
23 import org.springframework.context.annotation.PropertySource
24
25 @Configuration
26 @PropertySource("classpath:application.properties")
27 open class HealthCheckProperties {
28
29     @Value("\${blueprintprocessor.healthcheck.baseUrl:}")
30     private val bluePrintProcessorBaseURL: String? = null
31
32     @Value("#{'\${blueprintprocessor.healthcheck.mapping-service-name-with-service-link:}'.split(']')}")
33     private val blueprintprocessorServiceMapping: List<String>? = null
34
35     @Value("\${cdslistener.healthcheck.baseUrl:}")
36     private val cdsListenerBaseURL: String? = null
37
38     @Value("#{'\${cdslistener.healthcheck.mapping-service-name-with-service-link:}'.split(']')}")
39     private val cdsListenerServiceMapping: List<String>? = null
40
41     open fun getBlueprintBaseURL(): String? {
42         return bluePrintProcessorBaseURL
43     }
44
45     open fun getCDSListenerBaseURL(): String? {
46         return cdsListenerBaseURL
47     }
48
49     open fun getBlueprintServiceInformation(): List<ServiceEndpoint> {
50         val serviceName = ServiceName.BLUEPRINT
51         return getListOfServiceEndPoints(blueprintprocessorServiceMapping, serviceName)
52     }
53
54     open fun getCDSListenerServiceInformation(): List<ServiceEndpoint> {
55         val serviceName = ServiceName.CDSLISTENER
56         return getListOfServiceEndPoints(cdsListenerServiceMapping, serviceName)
57     }
58
59     private fun getListOfServiceEndPoints(serviceMapping: List<String>?, serviceName: ServiceName): MutableList<ServiceEndpoint> {
60         val serviceEndpoints = mutableListOf<ServiceEndpoint>()
61         if (serviceMapping != null) {
62             for (element in serviceMapping) {
63                 fillListOfService(serviceName, element, serviceEndpoints)
64             }
65         }
66         return serviceEndpoints
67     }
68
69     private fun fillListOfService(serviceName: ServiceName, element: String, listOfCDSListenerServiceEndpoint: MutableList<ServiceEndpoint>) {
70         val serviceEndpointInfo = element.split(",/")
71         val serviceEndpoint = getServiceEndpoint(serviceEndpointInfo)
72         if (serviceName.equals(ServiceName.CDSLISTENER))
73             serviceEndpoint.serviceLink = cdsListenerBaseURL + serviceEndpoint.serviceLink
74         else if (serviceName.equals(ServiceName.BLUEPRINT))
75             serviceEndpoint.serviceLink = bluePrintProcessorBaseURL + serviceEndpoint.serviceLink
76         listOfCDSListenerServiceEndpoint.add(serviceEndpoint)
77     }
78
79     private fun getServiceEndpoint(serviceEndpointInfo: List<String>): ServiceEndpoint {
80         return ServiceEndpoint(
81             removeSpecialCharacter(serviceEndpointInfo[0]), removeSpecialCharacter(serviceEndpointInfo[1])
82         )
83     }
84
85     private fun removeSpecialCharacter(value: String): String {
86         return value.replaceFirst(",[", "")
87             .replace("[", "")
88             .replace("]", "")
89     }
90 }