From: Jakub Morvay Date: Mon, 14 Nov 2016 15:41:26 +0000 (+0100) Subject: Bug 7180 - error-severity and error-type values should be lowercase X-Git-Tag: release/carbon~386 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c434a0aa3f0787fb84c280a26ffc65c39a91d5d8;ds=sidebyside Bug 7180 - error-severity and error-type values should be lowercase Add String value fields to ErrorSeverity and ErrorType enums that contain lowercase names of enums. Enums' string value getter methods return these lowercase values. Change-Id: I1509a7bbae4811025a5bbba11e9b2f0c0cc75b50 Signed-off-by: Jakub Morvay --- diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java index bfeb2a69ee..2f18bf0d01 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java @@ -10,6 +10,8 @@ package org.opendaylight.controller.config.util.xml; import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.RPC_REPLY_KEY; import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0; + +import com.google.common.base.Preconditions; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -63,10 +65,19 @@ public class DocumentedException extends Exception { } public enum ErrorType { - TRANSPORT, RPC, PROTOCOL, APPLICATION; + TRANSPORT("transport"), + RPC("rpc"), + PROTOCOL("protocol"), + APPLICATION("application"); + + private final String typeValue; + + ErrorType(String typeValue) { + this.typeValue = Preconditions.checkNotNull(typeValue); + } public String getTypeValue() { - return name(); + return this.typeValue; } /** @@ -74,16 +85,17 @@ public class DocumentedException extends Exception { */ @Deprecated public String getTagValue() { - return name(); + return this.typeValue; } - public static ErrorType from( String text ) { - try { - return valueOf( text.toUpperCase() ); - } - catch( Exception e ) { - return APPLICATION; + public static ErrorType from(String text) { + for (ErrorType e : values()) { + if (e.getTypeValue().equalsIgnoreCase(text)) { + return e; + } } + + return APPLICATION; } } @@ -131,10 +143,17 @@ public class DocumentedException extends Exception { } public enum ErrorSeverity { - ERROR, WARNING; + ERROR("error"), + WARNING("warning"); + + private final String severityValue; + + ErrorSeverity(String severityValue) { + this.severityValue = Preconditions.checkNotNull(severityValue); + } public String getSeverityValue() { - return name(); + return this.severityValue; } /** @@ -142,16 +161,17 @@ public class DocumentedException extends Exception { */ @Deprecated public String getTagValue() { - return name(); + return this.severityValue; } - public static ErrorSeverity from( String text ) { - try { - return valueOf( text.toUpperCase() ); - } - catch( Exception e ) { - return ERROR; + public static ErrorSeverity from(String text) { + for (ErrorSeverity e : values()) { + if (e.getSeverityValue().equalsIgnoreCase(text)) { + return e; + } } + + return ERROR; } }