47577b39ee86a0930107e0422a898cecc86f8e46
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / rest-lib / src / main / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / rest / service / BluePrintRestLibPropertyService.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.apps.blueprintsprocessor.rest.service
19
20 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
21 import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
23 import org.springframework.stereotype.Service
24
25 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
26 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
27
28     @Throws(BluePrintProcessorException::class)
29     fun restClientProperties(prefix: String): RestClientProperties {
30         val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
31         return when (type) {
32             RestLibConstants.TYPE_BASIC_AUTH -> {
33                 basicAuthRestClientProperties(prefix)
34             }
35             RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
36                 sslBasicAuthRestClientProperties(prefix)
37             }
38             RestLibConstants.TYPE_DME2_PROXY -> {
39                 dme2ProxyClientProperties(prefix)
40             }
41             RestLibConstants.TYPE_POLICY_MANAGER -> {
42                 policyManagerRestClientProperties(prefix)
43             }
44             else -> {
45                 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
46             }
47         }
48     }
49
50     @Throws(BluePrintProcessorException::class)
51     fun blueprintWebClientService(selector: String): BlueprintWebClientService {
52         val prefix = "blueprintsprocessor.restclient.$selector"
53         val restClientProperties = restClientProperties(prefix)
54         return blueprintWebClientService(restClientProperties)
55     }
56
57
58     fun blueprintDynamicWebClientService(sourceType: String, selector: String): BlueprintWebClientService {
59         TODO()
60     }
61
62     @Throws(BluePrintProcessorException::class)
63     fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
64         when (restClientProperties) {
65             is BasicAuthRestClientProperties -> {
66                 return BasicAuthRestClientService(restClientProperties)
67             }
68             is SSLBasicAuthRestClientProperties -> {
69                 return SSLBasicAuthRestClientService(restClientProperties)
70             }
71             is DME2RestClientProperties -> {
72                 return DME2ProxyRestClientService(restClientProperties)
73             }
74             else -> {
75                 throw BluePrintProcessorException("couldn't get rest service for")
76             }
77         }
78     }
79
80     fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
81         return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
82     }
83
84     fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
85         return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
86     }
87
88     fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
89         return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
90     }
91
92     fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
93         return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)
94     }
95 }
96
97