2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.impl;
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;
30 public class DataProviderConfig implements Configuration {
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 final EsConfig esConfig;
36 private final SqlDBConfig maridadbConfig;
37 private ConfigurationFileRepresentation configuration;
39 public DataProviderConfig(ConfigurationFileRepresentation configuration) {
40 this.configuration = configuration;
42 this.esConfig = new EsConfig(configuration);
43 this.maridadbConfig = new SqlDBConfig(configuration);
46 public EsConfig getEsConfig() {
50 public SqlDBConfig getMariadbConfig() {
51 return this.maridadbConfig;
55 public void defaults() {
57 configuration.setPropertyIfNotAvailable(this.getSectionName(), PROPERTY_KEY_DBTYPE, DEFAULT_DBTYPE);
61 public String getSectionName() {
62 return ConfigurationFileRepresentation.SECTIONNAME_ROOT;
65 public SdnrDbType getDbType() {
66 String value = this.configuration.getProperty(this.getSectionName(), PROPERTY_KEY_DBTYPE);
67 if (value.isEmpty()) {
68 return DEFAULT_DBTYPE_VALUE;
70 return SdnrDbType.valueOf(value);