8c7e7b1cba4901bc69baa3ffd4abc7edecb7ca7d
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator;
27
28 public class SqlDBConfig implements Configuration {
29
30     private static final String SECTION_MARKER_MARIADB = "mariadb";
31
32     private static final String PROPERTY_KEY_DBURL = "url";
33     private static final String PROPERTY_KEY_USERNAME = "username";
34     private static final String PROPERTY_KEY_PASSWORD = "password";
35     private static final String PROPERTY_KEY_CONTROLLERID = "controllerId";
36     private static final String PROPERTY_KEY_DBSUFFIX = "suffix";
37
38
39     private static final String DEFAULT_VALUE_DBURL = "${SDNRDBURL}";
40     private static final String DEFAULT_VALUE_DBUSERNAME = "${SDNRDBUSERNAME}";
41     private static final String DEFAULT_VALUE_DBPASSWORD = "${SDNRDBPASSWORD}";
42     private static final String DEFAULT_VALUE_CONTROLLERID = DatabaseIdGenerator.getControllerId();
43     private static final String DEFAULT_VALUE_DBSUFFIX = "-v6";
44
45     private final ConfigurationFileRepresentation configuration;
46
47     public SqlDBConfig(ConfigurationFileRepresentation configuration) {
48
49         this.configuration = configuration;
50         this.configuration.addSection(SECTION_MARKER_MARIADB);
51         defaults();
52     }
53
54
55     /*
56      * Getter
57      */
58
59     public String getUrl() {
60         return configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL);
61     }
62
63     public void setUrl(String url) {
64         configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL, url);
65
66     }
67
68     public String getUsername() {
69         return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_USERNAME);
70     }
71
72     public String getPassword() {
73         return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_PASSWORD);
74     }
75
76     public String getControllerId() {
77         String v = this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID);
78         return (v == null || v.equals("null") || v.isEmpty()) ? null : v;
79     }
80
81     public String getDbSuffix() {
82         return this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX);
83     }
84
85     @Override
86     public String getSectionName() {
87         return SECTION_MARKER_MARIADB;
88     }
89
90     @Override
91     public synchronized void defaults() {
92         // Add default if not available
93         configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBURL, DEFAULT_VALUE_DBURL);
94         configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_USERNAME,
95                 DEFAULT_VALUE_DBUSERNAME);
96         configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_PASSWORD,
97                 DEFAULT_VALUE_DBPASSWORD);
98         configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID,
99                 DEFAULT_VALUE_CONTROLLERID);
100         configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX, DEFAULT_VALUE_DBSUFFIX);
101
102     }
103
104
105     public void setControllerId(String id) {
106         configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID, id);
107     }
108
109     public void setDbSuffix(String suffix) {
110         configuration.setProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX, suffix);
111     }
112 }