ORAN A1 Adapter YANG Model Update
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / util / InternalSeverity.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 /**
19  * @author herbert
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util;
23
24
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
27
28 public enum InternalSeverity {
29
30         NonAlarmed,
31         Warning,
32         Minor,
33         Major,
34         Critical;
35
36     public boolean isNoAlarmIndication() {
37         return this == NonAlarmed;
38     }
39
40     public String getValueAsString() {
41         return this.name();
42     }
43
44     @Override
45     public String toString() {
46         return this.name();
47     }
48
49     public String toNetconfString() {
50         switch (this) {
51         case NonAlarmed:
52             return "non-alarmed";
53         case Warning:
54             return "warning";
55         case Minor:
56             return "minor";
57         case Major:
58             return "major";
59         case Critical:
60             return "critical";
61         }
62         return "not-specified";
63     }
64
65     public SeverityType toDataProviderSeverityType() {
66         switch (this) {
67         case NonAlarmed:
68             return SeverityType.NonAlarmed;
69         case Warning:
70             return SeverityType.Warning;
71         case Minor:
72             return SeverityType.Minor;
73         case Major:
74             return SeverityType.Major;
75         case Critical:
76             return SeverityType.Critical;
77         }
78         return null; //Should never happen
79     }
80
81     /**
82      * convert ONF 1.2 Severity
83      * @param severity as input
84      * @return String with related output
85      */
86     public static InternalSeverity valueOf(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.SeverityType severity ) {
87         switch( severity ) {
88             case NonAlarmed:
89                 return InternalSeverity.NonAlarmed;
90             case Warning:
91                 return InternalSeverity.Warning;
92             case Minor:
93                 return InternalSeverity.Minor;
94             case Major:
95                 return InternalSeverity.Major;
96             case Critical:
97                 return InternalSeverity.Critical;
98         }
99         return null;
100     }
101
102     /**
103      * convert ONF 1.2.1.1 Severity
104      * @param severity as input
105      * @return String with related output
106      */
107     public static InternalSeverity valueOf(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev180907.SeverityType severity ) {
108         switch( severity ) {
109             case NonAlarmed:
110                 return InternalSeverity.NonAlarmed;
111             case Warning:
112                 return InternalSeverity.Warning;
113             case Minor:
114                 return InternalSeverity.Minor;
115             case Major:
116                 return InternalSeverity.Major;
117             case Critical:
118                 return InternalSeverity.Critical;
119         }
120         return null;
121     }
122
123     /**
124      * convert ONF 1.2.1.1p Severity
125      * @param severity as input
126      * @return String with related output
127      */
128     public static InternalSeverity valueOf(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.SeverityType severity ) {
129         switch( severity ) {
130             case NonAlarmed:
131                 return InternalSeverity.NonAlarmed;
132             case Warning:
133                 return InternalSeverity.Warning;
134             case Minor:
135                 return InternalSeverity.Minor;
136             case Major:
137                 return InternalSeverity.Major;
138             case Critical:
139                 return InternalSeverity.Critical;
140         }
141         return null;
142     }
143
144
145
146     /**
147      * convert a text string into Severity
148      * @param severityString with textes: warning minor major critical  non[-]alarmed. (Capital or lowercase)
149      * @return related enum. Unknown oe illegal are converted to NonAlarm
150      */
151     public static @Nullable InternalSeverity valueOfString(String severityString) {
152
153         switch( severityString.toLowerCase().trim() ) {
154         case "warning":
155             return InternalSeverity.Warning;
156         case "minor":
157             return InternalSeverity.Minor;
158         case "major":
159             return InternalSeverity.Major;
160         case "critical":
161             return InternalSeverity.Critical;
162         }
163         return InternalSeverity.NonAlarmed;
164
165     }
166
167     /**
168      * Convert to InternalSeverity
169      * @param severity to be converted
170      * @return InternalSeverity, null converted to NonAlarmed
171      */
172     public static InternalSeverity valueOf(@org.eclipse.jdt.annotation.Nullable SeverityType severity) {
173         if (severity != null) {
174             switch (severity) {
175             case NonAlarmed:
176                 return InternalSeverity.NonAlarmed;
177             case Warning:
178                 return InternalSeverity.Warning;
179             case Minor:
180                 return InternalSeverity.Minor;
181             case Major:
182                 return InternalSeverity.Major;
183             case Critical:
184                 return InternalSeverity.Critical;
185             }
186         }
187         return InternalSeverity.NonAlarmed;
188     }
189
190
191 }