Remove DocumentedException.ErrorType
[netconf.git] / netconf / netconf-impl / src / main / java / org / opendaylight / netconf / impl / mapping / operations / DefaultCloseSession.java
index 3666c4ad1b618f3f10c61aab32129f4638a94c0c..b0092519d875f3d6580b02b58d76f7e910b534d6 100644 (file)
@@ -5,18 +5,18 @@
  * 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.impl.mapping.operations;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
+import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.impl.NetconfServerSession;
+import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -30,7 +30,7 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
     private final AutoCloseable sessionResources;
     private NetconfServerSession session;
 
-    public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) {
+    public DefaultCloseSession(final String netconfSessionIdForReporting, final AutoCloseable sessionResources) {
         super(netconfSessionIdForReporting);
         this.sessionResources = sessionResources;
     }
@@ -43,27 +43,26 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
     /**
      * Close netconf operation router associated to this session, which in turn
      * closes NetconfOperationServiceSnapshot with all NetconfOperationService
-     * instances
+     * instances.
      */
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
+    protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
             throws DocumentedException {
         try {
             sessionResources.close();
-            Preconditions.checkNotNull(session, "Session was not set").delayedClose();
+            requireNonNull(session, "Session was not set").delayedClose();
             LOG.info("Session {} closing", session.getSessionId());
-        } catch (Exception e) {
-            throw new DocumentedException("Unable to properly close session "
-                    + getNetconfSessionIdForReporting(), DocumentedException.ErrorType.application,
-                    DocumentedException.ErrorTag.operation_failed,
-                    DocumentedException.ErrorSeverity.error, Collections.singletonMap(
-                    DocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
+        } catch (final Exception e) {
+            throw new DocumentedException("Unable to properly close session " + getNetconfSessionIdForReporting(), e,
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                    Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
         }
-        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
+        return document.createElement(XmlNetconfConstants.OK);
     }
 
     @Override
-    public void setNetconfSession(final NetconfServerSession s) {
-        this.session = s;
+    public void setNetconfSession(final NetconfServerSession netconfServerSession) {
+        this.session = netconfServerSession;
     }
 }