aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db-repositories
ModeNameSize
-rw-r--r--pom.xml1757logstatsplain
d---------src62logstatsplain
736c9cce3a8ef0de'>rest/service/BluePrintRestLibPropertyService.kt
blob: 705caa2e28182f739dd1fc079004bb2ef3d21542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Copyright © 2017-2018 AT&T Intellectual Property.
 * Modifications Copyright © 2019 IBM.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onap.ccsdk.apps.blueprintsprocessor.rest.service

import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.springframework.stereotype.Service

@Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {

    fun restClientProperties(prefix: String): RestClientProperties {
        val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
        return when (type) {
            RestLibConstants.TYPE_BASIC_AUTH -> {
                basicAuthRestClientProperties(prefix)
            }
            RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
                sslBasicAuthRestClientProperties(prefix)
            }
            RestLibConstants.TYPE_DME2_PROXY -> {
                dme2ProxyClientProperties(prefix)
            }
            RestLibConstants.TYPE_POLICY_MANAGER -> {
                policyManagerRestClientProperties(prefix)
            }
            else -> {
                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
            }
        }
    }

    fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
        val type = jsonNode.get("type").textValue()
        return when (type) {
            RestLibConstants.TYPE_BASIC_AUTH -> {
                JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
            }
            RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
                JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
            }
            RestLibConstants.TYPE_DME2_PROXY -> {
                JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
            }
            RestLibConstants.TYPE_POLICY_MANAGER -> {
                JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
            }
            else -> {
                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
            }
        }
    }


    fun blueprintWebClientService(selector: String): BlueprintWebClientService {
        val prefix = "blueprintsprocessor.restclient.$selector"
        val restClientProperties = restClientProperties(prefix)
        return blueprintWebClientService(restClientProperties)
    }

    fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService {
        val restClientProperties = restClientProperties(jsonNode)
        return blueprintWebClientService(restClientProperties)
    }

    fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
        when (restClientProperties) {
            is BasicAuthRestClientProperties -> {
                return BasicAuthRestClientService(restClientProperties)
            }
            is SSLBasicAuthRestClientProperties -> {
                return SSLBasicAuthRestClientService(restClientProperties)
            }
            is DME2RestClientProperties -> {
                return DME2ProxyRestClientService(restClientProperties)
            }
            else -> {
                throw BluePrintProcessorException("couldn't get rest service for")
            }
        }
    }

    fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
        return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
    }

    fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
        return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
    }

    fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
        return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
    }

    fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
        return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)
    }
}