2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
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.apps.blueprintsprocessor.rest.service
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
25 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
26 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
28 @Throws(BluePrintProcessorException::class)
29 fun restClientProperties(prefix: String): RestClientProperties {
30 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
32 RestLibConstants.TYPE_BASIC_AUTH -> {
33 basicAuthRestClientProperties(prefix)
35 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
36 sslBasicAuthRestClientProperties(prefix)
38 RestLibConstants.TYPE_DME2_PROXY -> {
39 dme2ProxyClientProperties(prefix)
41 RestLibConstants.TYPE_POLICY_MANAGER -> {
42 policyManagerRestClientProperties(prefix)
45 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
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)
58 fun blueprintDynamicWebClientService(sourceType: String, selector: String): BlueprintWebClientService {
62 @Throws(BluePrintProcessorException::class)
63 fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
64 when (restClientProperties) {
65 is BasicAuthRestClientProperties -> {
66 return BasicAuthRestClientService(restClientProperties)
68 is SSLBasicAuthRestClientProperties -> {
69 return SSLBasicAuthRestClientService(restClientProperties)
71 is DME2RestClientProperties -> {
72 return DME2ProxyRestClientService(restClientProperties)
75 throw BluePrintProcessorException("couldn't get rest service for")
80 fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
81 return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
84 fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
85 return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
88 fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
89 return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
92 fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
93 return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)