Integrate netconf-mapping-api into netconf-server
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / rpc / SimulatedGetConfig.java
index 51976445c2c3cba5feb6189d9b9189364c391f00..83dc1006013c42bb241ec764798c1419708ee4d3 100644 (file)
@@ -5,69 +5,62 @@
  * 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.test.tool.rpc;
 
-import com.google.common.base.Optional;
 import java.io.File;
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
-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 java.util.Optional;
+import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
+import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.server.api.operations.AbstractLastNetconfOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-public class SimulatedGetConfig extends AbstractConfigNetconfOperation {
+public class SimulatedGetConfig extends AbstractLastNetconfOperation {
+    private static final Logger LOG = LoggerFactory.getLogger(SimulatedGetConfig.class);
 
     private final DataList storage;
-    private static final Logger LOG = LoggerFactory
-            .getLogger(SimulatedGetConfig.class);
 
-    public SimulatedGetConfig(final String netconfSessionIdForReporting, final DataList storage, final Optional<File> initialConfigXMLFile) {
-        super(null, netconfSessionIdForReporting);
+    public SimulatedGetConfig(final String netconfSessionIdForReporting, final DataList storage,
+                              final Optional<File> initialConfigXMLFile) {
+        super(netconfSessionIdForReporting);
 
-        if(initialConfigXMLFile.isPresent()) {
-            LOG.info("File is present: {}", initialConfigXMLFile.get()
-                    .getName());
-            this.storage = loadInitialConfigXMLFile(initialConfigXMLFile.get());
-        }
-        else {
+        if (initialConfigXMLFile.isPresent()) {
+            final var file = initialConfigXMLFile.orElseThrow();
+            LOG.info("File is present: {}", file.getName());
+            this.storage = loadInitialConfigXMLFile(file);
+        } else {
             this.storage = storage;
         }
     }
 
-    private final DataList loadInitialConfigXMLFile( final File file ) {
+    private static DataList loadInitialConfigXMLFile(final File file) {
         LOG.info("Loading initial config xml file: {}", file.getName());
         DataList configData = new DataList();
-        List<XmlElement> xmlElementList = Collections.emptyList();
         try {
             Element element = XmlUtil.readXmlToElement(file);
             XmlElement xmlElement = XmlElement.fromDomElement(element);
-            xmlElementList = xmlElement.getChildElements();
+            List<XmlElement> xmlElementList = xmlElement.getChildElements();
             configData.setConfigList(xmlElementList);
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             LOG.info("IO exception loading xml file: {} ", e.getMessage());
 
-        }
-        catch (SAXException e) {
+        } catch (SAXException e) {
             LOG.info("SAXException {}", e.getMessage());
         }
         return configData;
     }
 
     @Override
-    protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
-        final Element element = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.<String>absent());
+    protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
+        final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
 
-        for(final XmlElement e : storage.getConfigList()) {
+        for (final XmlElement e : storage.getConfigList()) {
             final Element domElement = e.getDomElement();
             element.appendChild(element.getOwnerDocument().importNode(domElement, true));
         }