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 com.fasterxml.jackson.databind.JsonNode
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
22 import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
24 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
25 import org.springframework.stereotype.Service
27 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
28 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
30 fun restClientProperties(prefix: String): RestClientProperties {
31 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
33 RestLibConstants.TYPE_BASIC_AUTH -> {
34 basicAuthRestClientProperties(prefix)
36 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
37 sslBasicAuthRestClientProperties(prefix)
39 RestLibConstants.TYPE_DME2_PROXY -> {
40 dme2ProxyClientProperties(prefix)
42 RestLibConstants.TYPE_POLICY_MANAGER -> {
43 policyManagerRestClientProperties(prefix)
46 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
51 fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
52 val type = jsonNode.get("type").textValue()
54 RestLibConstants.TYPE_BASIC_AUTH -> {
55 JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
57 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
58 JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
60 RestLibConstants.TYPE_DME2_PROXY -> {
61 JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
63 RestLibConstants.TYPE_POLICY_MANAGER -> {
64 JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
67 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
73 fun blueprintWebClientService(selector: String): BlueprintWebClientService {
74 val prefix = "blueprintsprocessor.restclient.$selector"
75 val restClientProperties = restClientProperties(prefix)
76 return blueprintWebClientService(restClientProperties)
79 fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService {
80 val restClientProperties = restClientProperties(jsonNode)
81 return blueprintWebClientService(restClientProperties)
84 fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
85 when (restClientProperties) {
86 is BasicAuthRestClientProperties -> {
87 return BasicAuthRestClientService(restClientProperties)
89 is SSLBasicAuthRestClientProperties -> {
90 return SSLBasicAuthRestClientService(restClientProperties)
92 is DME2RestClientProperties -> {
93 return DME2ProxyRestClientService(restClientProperties)
96 throw BluePrintProcessorException("couldn't get rest service for")
101 fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
102 return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
105 fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
106 return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
109 fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
110 return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
113 fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
114 return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)