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.BluePrintPropertiesService
21 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
22 import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties
23 import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants
24 import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties
25 import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties
27 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 import org.springframework.stereotype.Service
32 class BluePrintDBLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) {
34 fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
35 val dBConnetionProperties = dBDataSourceProperties(jsonNode)
36 return blueprintDBDataSourceService(dBConnetionProperties)
39 fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
40 val prefix = "blueprintsprocessor.db.$selector"
41 val dBConnetionProperties = dBDataSourceProperties(prefix)
42 return blueprintDBDataSourceService(dBConnetionProperties)
45 private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties {
46 val type = jsonNode.get("type").textValue()
48 DBLibConstants.MYSQL_DB -> {
49 JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!!
51 DBLibConstants.MARIA_DB -> {
52 JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!!
55 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
60 private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
61 val type = bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java)
63 DBLibConstants.MARIA_DB -> {
64 mariaDBConnectionProperties(prefix)
66 DBLibConstants.MYSQL_DB -> {
67 mySqlDBConnectionProperties(prefix)
69 DBLibConstants.ORACLE_DB -> {
70 TODO("not implemented")
72 DBLibConstants.POSTGRES_DB -> {
73 TODO("not implemented")
75 DBLibConstants.PRIMARY_DB -> {
76 primaryDBConnectionProperties(prefix)
79 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
84 private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService {
85 when (dBConnetionProperties) {
86 is MariaDataSourceProperties -> {
87 return MariaDatabaseConfiguration(dBConnetionProperties)
89 is MySqlDataSourceProperties -> {
90 return MySqlDatabaseConfiguration(dBConnetionProperties)
93 throw BluePrintProcessorException("couldn't get rest service for")
98 private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
99 return bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
102 private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
103 return bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
106 private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
107 return bluePrintPropertiesService.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)