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