2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.apps.blueprintsprocessor.rest.service
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
25 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
27 @Throws(BluePrintProcessorException::class)
28 fun restClientProperties(prefix: String): RestClientProperties {
29 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
31 RestLibConstants.TYPE_BASIC_AUTH -> {
32 basicAuthRestClientProperties(prefix)
34 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
35 sslBasicAuthRestClientProperties(prefix)
37 RestLibConstants.TYPE_DME2_PROXY -> {
38 dme2ProxyClientProperties(prefix)
40 RestLibConstants.TYPE_POLICY_MANAGER -> {
41 policyManagerRestClientProperties(prefix)
44 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
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)
57 is SSLBasicAuthRestClientProperties -> {
58 return SSLBasicAuthRestClientService(beanProperties)
60 is DME2RestClientProperties -> {
61 return DME2ProxyRestClientService(beanProperties)
64 throw BluePrintProcessorException("couldn't get rest service for selector($selector)")
70 fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
71 return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
74 fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
75 return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
78 fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
79 return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
82 fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
83 return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)