Update features for Argon release
[ccsdk/features.git] / sdnr / wt / data-provider / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / dataprovider / impl / DataProviderConfig.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 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.impl;
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.elasticsearch.EsConfig;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType;
29
30 public class DataProviderConfig implements Configuration {
31
32     private static final String PROPERTY_KEY_DBTYPE = "dbType";
33     private static final Object DEFAULT_DBTYPE = "${SDNRDBTYPE}";
34     private static final SdnrDbType DEFAULT_DBTYPE_VALUE = SdnrDbType.ELASTICSEARCH;
35     private static final String PROPERTY_KEY_DBENABLED = "enabled";
36     private static final String DEFAULT_ISENABLED = "${SDNRDBENABLED}";
37     private static final boolean DEFAULT_ISENABLED_IFNOTSET = true;
38     private static final String PROPERTY_KEY_GUICUTTHROUGH_OVERWRITE = "GUICUTTHROUGH_PROXY_OVERWRITE";
39     private static final String DEFAULT_GUICUTTHROUGH_OVERWRITE = "${GUICUTTHROUGH_PROXY_OVERWRITE}";
40     private final EsConfig esConfig;
41     private final SqlDBConfig maridadbConfig;
42     private ConfigurationFileRepresentation configuration;
43
44     public DataProviderConfig(ConfigurationFileRepresentation configuration) {
45         this.configuration = configuration;
46         defaults();
47         this.esConfig = new EsConfig(configuration);
48         this.maridadbConfig = new SqlDBConfig(configuration);
49     }
50
51     public EsConfig getEsConfig() {
52         return this.esConfig;
53     }
54
55     public SqlDBConfig getMariadbConfig() {
56         return this.maridadbConfig;
57     }
58
59     public boolean isEnabled() {
60         final String s = this.configuration.getProperty(ConfigurationFileRepresentation.SECTIONNAME_ROOT,
61                 PROPERTY_KEY_DBENABLED);
62         if (s != null && !s.isBlank()) {
63             return Boolean.getBoolean(s);
64         }
65         return DEFAULT_ISENABLED_IFNOTSET;
66     }
67
68     @Override
69     public void defaults() {
70
71         configuration.setPropertyIfNotAvailable(this.getSectionName(), PROPERTY_KEY_DBTYPE, DEFAULT_DBTYPE);
72         configuration.setPropertyIfNotAvailable(this.getSectionName(), PROPERTY_KEY_DBENABLED, DEFAULT_ISENABLED);
73         configuration.setPropertyIfNotAvailable(this.getSectionName(), PROPERTY_KEY_GUICUTTHROUGH_OVERWRITE,
74                 DEFAULT_GUICUTTHROUGH_OVERWRITE);
75     }
76
77     @Override
78     public String getSectionName() {
79         return ConfigurationFileRepresentation.SECTIONNAME_ROOT;
80     }
81
82     public SdnrDbType getDbType() {
83         String value = this.configuration.getProperty(this.getSectionName(), PROPERTY_KEY_DBTYPE);
84         if (value.isEmpty()) {
85             return DEFAULT_DBTYPE_VALUE;
86         }
87         return SdnrDbType.valueOf(value);
88     }
89
90     public String getGuicutthroughOverride() {
91         return this.configuration.getProperty(this.getSectionName(), PROPERTY_KEY_GUICUTTHROUGH_OVERWRITE);
92     }
93
94 }