Merge "YANG Model update for A1 Adapter"
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / devicemonitor / impl / config / DmConfig.java
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.devicemanager.devicemonitor.impl.config;
19
20 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
21 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorProblems;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
24
25 /**
26  * Configuration of devicemonitor, section [devicemonitor]
27  *   SeverityConnectionlossNeOAM=minor
28  *   SeverityConnectionlossOAM=major
29  *   SeverityConnectionlossMediator=critical
30  */
31 public class DmConfig implements Configuration {
32
33     private static final String SECTION_MARKER_TA = "devicemonitor";
34
35     private static final String PROPERTY_KEY_PREFIX_Severity = "Severity";
36
37         private final ConfigurationFileRepresentation configuration;
38
39         public DmConfig(ConfigurationFileRepresentation configuration) {
40                 this.configuration = configuration;
41         this.configuration.addSection(SECTION_MARKER_TA);
42                 defaults();
43         }
44
45         public InternalSeverity getSeverity(DeviceMonitorProblems problem) {
46                 String severityString = configuration.getProperty(SECTION_MARKER_TA, getPropertyName(problem));
47                 InternalSeverity result = InternalSeverity.valueOfString(severityString);
48                 return result != null ? result : InternalSeverity.Major;
49         }
50
51         @Override
52         public String getSectionName() {
53                 return SECTION_MARKER_TA;
54         }
55
56         @Override
57         public void defaults() {
58         for (DeviceMonitorProblems problem : DeviceMonitorProblems.values()) {
59                 configuration.setPropertyIfNotAvailable(SECTION_MARKER_TA, getPropertyName(problem), problem.getSeverity().name());
60         }
61         }
62
63         private String getPropertyName(DeviceMonitorProblems problem) {
64                 return PROPERTY_KEY_PREFIX_Severity+problem.name();
65         }
66
67 }