Remove DocumentedException.ErrorType
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / ops / AbstractConfigOperation.java
index 9a57a2ecad0d49d2570925f4d48e359d60b154e1..81899f208d63fd066d75ff21e7caf27a377507fa 100644 (file)
@@ -5,12 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import java.io.IOException;
 import java.io.InputStream;
@@ -19,11 +17,14 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.util.Base64;
+import java.util.Optional;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -56,19 +57,17 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
         final Optional<XmlElement> configElement = parent.getOnlyChildElementOptionally(CONFIG_KEY);
         if (configElement.isPresent()) {
             return configElement.get();
-        } else {
-            final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
-            if (!urlElement.isPresent()) {
-                throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
-                    DocumentedException.ErrorType.PROTOCOL,
-                    DocumentedException.ErrorTag.MISSING_ELEMENT,
-                    DocumentedException.ErrorSeverity.ERROR);
-            }
+        }
 
-            final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
-            return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY,
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
+        if (urlElement.isEmpty()) {
+            throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
+                ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
         }
+
+        final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
+        return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY,
+            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
 
     /**
@@ -85,19 +84,13 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
             return XmlUtil.readXmlToDocument(input);
         } catch (MalformedURLException e) {
             throw new DocumentedException(url + " URL is invalid or unsupported", e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.INVALID_VALUE,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         } catch (IOException e) {
-            throw new DocumentedException("Could not open URL:" + url, e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.ERROR);
+            throw new DocumentedException("Could not open URL " + url, e,
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         } catch (SAXException e) {
             throw new DocumentedException("Could not parse XML at" + url, e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }