21d080d5a5cb85f10e4d64d669197f52feeeb469
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
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.apps.blueprintsprocessor.rest.service
18
19 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
20 import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
22 import org.springframework.stereotype.Service
23
24 @Service
25 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
26
27     @Throws(BluePrintProcessorException::class)
28     fun restClientProperties(prefix: String): RestClientProperties {
29         val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
30         return when (type) {
31             RestLibConstants.TYPE_BASIC_AUTH -> {
32                 basicAuthRestClientProperties(prefix)
33             }
34             RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
35                 sslBasicAuthRestClientProperties(prefix)
36             }
37             RestLibConstants.TYPE_DME2_PROXY -> {
38                 dme2ProxyClientProperties(prefix)
39             }
40             RestLibConstants.TYPE_POLICY_MANAGER -> {
41                 policyManagerRestClientProperties(prefix)
42             }
43             else -> {
44                 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
45             }
46         }
47     }
48
49     @Throws(BluePrintProcessorException::class)
50     fun blueprintWebClientService(selector: String): BlueprintWebClientService {
51         val prefix = "blueprintsprocessor.restclient.$selector"
52         val beanProperties = restClientProperties(prefix)
53         when (beanProperties) {
54             is BasicAuthRestClientProperties -> {
55                 return BasicAuthRestClientService(beanProperties)
56             }
57             is SSLBasicAuthRestClientProperties -> {
58                 return SSLBasicAuthRestClientService(beanProperties)
59             }
60             is DME2RestClientProperties -> {
61                 return DME2ProxyRestClientService(beanProperties)
62             }
63             else -> {
64                 throw BluePrintProcessorException("couldn't get rest service for selector($selector)")
65             }
66         }
67
68     }
69
70     fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
71         return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
72     }
73
74     fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
75         return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
76     }
77
78     fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
79         return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
80     }
81
82     fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
83         return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)
84     }
85 }
86
87