2ad5431be17796686c832d1bb72b6270995eb624
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
19
20 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
21 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
22
23 /**
24  * Configuration of mountpoint-registrar, general section<br>
25  * - dmaapEnabled : Boolean disable/enable service depending on whether DMaaP is running or not Generates default
26  * Configuration properties if none exist or exist partially Generates Consumer properties only for
27  * TransportType=HTTPNOAUTH. Other TransportTypes like HTTP, AUTH_KEY and DME2 have additional properties and are not
28  * generated by default. For a list of applicable properties for the different TranportType values, please see -
29  * https://wiki.onap.org/display/DW/Feature+configuration+requirements
30  */
31 public class GeneralConfig implements Configuration {
32
33     private static final String SECTION_MARKER = "general";
34
35     private static final String PROPERTY_KEY_ENABLED = "dmaapEnabled"; //"enabled";
36
37     private static final String PROPERTY_KEY_USER = "sdnrUser";
38     private static final String DEFAULT_VALUE_USER = "${SDNRUSERNAME}";
39
40     private static final String PROPERTY_KEY_USERPASSWD = "sdnrPasswd";
41     private static final String DEFAULT_VALUE_USERPASSWD = "${SDNRPASSWORD}";
42
43     private static final String PROPERTY_KEY_BASEURL = "baseUrl";
44     private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181";
45
46
47     private ConfigurationFileRepresentation configuration;
48
49     public GeneralConfig(ConfigurationFileRepresentation configuration) {
50         this.configuration = configuration;
51         configuration.addSection(SECTION_MARKER);
52         defaults();
53     }
54
55     public Boolean getEnabled() {
56         Boolean enabled = configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED);
57         return enabled;
58     }
59
60     public String getBaseUrl() {
61         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL);
62     }
63
64     public String getSDNRUser() {
65         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER);
66     }
67
68     public String getSDNRPasswd() {
69         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD);
70     }
71
72     @Override
73     public String getSectionName() {
74         return SECTION_MARKER;
75     }
76
77     @Override
78     public void defaults() {
79         // The default value should be "false" given that SDNR can be run in environments where DMaaP is not used
80         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, Boolean.FALSE);
81         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BASEURL, DEFAULT_VALUE_BASEURL);
82         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USER, DEFAULT_VALUE_USER);
83         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USERPASSWD, DEFAULT_VALUE_USERPASSWD);
84     }
85
86
87
88 }