2 * Copyright © 2019 Bell Canada 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.cds.blueprintsprocessor.db.primary
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
21 import org.onap.ccsdk.cds.blueprintsprocessor.db.*
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
23 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
24 import org.springframework.stereotype.Service
27 class BluePrintDBLibPropertySevice(private var bluePrintProperties: BluePrintProperties) {
29 fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
30 val dBConnetionProperties = dBDataSourceProperties(jsonNode)
31 return blueprintDBDataSourceService(dBConnetionProperties)
34 fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
35 val prefix = "blueprintsprocessor.database.$selector"
36 val dBConnetionProperties = dBDataSourceProperties(prefix)
37 return blueprintDBDataSourceService(dBConnetionProperties)
40 private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties {
41 val type = jsonNode.get("type").textValue()
43 DBLibConstants.MYSQL_DB -> {
44 JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!!
46 DBLibConstants.MARIA_DB -> {
47 JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!!
50 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
55 private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
56 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
58 DBLibConstants.MARIA_DB -> {
59 mariaDBConnectionProperties(prefix)
61 DBLibConstants.MYSQL_DB -> {
62 mySqlDBConnectionProperties(prefix)
64 DBLibConstants.ORACLE_DB -> {
65 TODO("not implemented")
67 DBLibConstants.POSTGRES_DB -> {
68 TODO("not implemented")
70 DBLibConstants.PRIMARY_DB -> {
71 primaryDBConnectionProperties(prefix)
74 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
79 private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService {
80 when (dBConnetionProperties) {
81 is MariaDataSourceProperties -> {
82 return MariaDatabaseConfiguration(dBConnetionProperties)
84 is MySqlDataSourceProperties -> {
85 return MySqlDatabaseConfiguration(dBConnetionProperties)
88 throw BluePrintProcessorException("couldn't get rest service for")
93 private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
94 return bluePrintProperties.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
97 private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
98 return bluePrintProperties.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
101 private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
102 return bluePrintProperties.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)