fix some deprecated warnings
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / gnpy / GnpyResult.java
index 0067102503899356f0ccd6202d627613618d5710..a039bfe68721d7fb2e3ff15c4a42cf95bfecf44b 100644 (file)
@@ -11,9 +11,7 @@ package org.opendaylight.transportpce.pce.gnpy;
 import com.google.common.base.Preconditions;
 import com.google.gson.stream.JsonReader;
 
-import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -62,6 +60,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
@@ -84,8 +83,6 @@ public class GnpyResult {
 
     public GnpyResult(String gnpyResponseString) throws Exception {
 
-        // try {
-        // Optional<DataObject> dataObject;
         // Create the schema context
         final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
         Iterable<? extends YangModuleInfo> moduleInfos;
@@ -153,8 +150,9 @@ public class GnpyResult {
                 NoPathCase noPathCase = (NoPathCase) response.getResponseType();
                 String noPathType = noPathCase.getNoPath().getNoPath();
                 LOG.info("GNPy: No path - {}",noPathType);
-                if (((noPathType == "NO_FEASIBLE_BAUDRATE_WITH_SPACING") && (noPathType == "NO_FEASIBLE_MODE"))
-                        && ((noPathType ==  "MODE_NOT_FEASIBLE") && (noPathType == "NO_SPECTRUM"))) {
+                if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
+                        && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
+                        && (noPathType.equals("NO_SPECTRUM")))) {
                     List<PathMetric> pathMetricList = noPathCase.getNoPath().getPathProperties().getPathMetric();
                     LOG.info("GNPy : path is not feasible : {}", noPathType);
                     for (PathMetric pathMetric : pathMetricList) {
@@ -234,7 +232,9 @@ public class GnpyResult {
         NormalizedNodeResult result = new NormalizedNodeResult();
         SchemaContext schemaContext = getSchemaContext(objectClass);
         try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-                JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, schemaContext);) {
+                JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
+                    JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext),
+                    schemaContext);) {
             LOG.debug("GNPy: the path to the reader {}", reader.getPath());
             LOG.debug("GNPy: the reader {}", reader.toString());
             LOG.debug("GNPy: the jsonParser class {} // jsonParser to string {}", jsonParser.getClass(),
@@ -257,28 +257,6 @@ public class GnpyResult {
         return schemaContext;
     }
 
-    private String readResultFromFile(String fileName) {
-        BufferedReader br = null;
-        FileReader fr = null;
-        StringBuilder sb = new StringBuilder();
-        String gnpyResponse;
-
-        try {
-            fr = new FileReader(fileName);
-            br = new BufferedReader(fr);
-            String currentLine;
-            while ((currentLine = br.readLine()) != null) {
-                LOG.info(currentLine);
-                sb.append(currentLine);
-            }
-            fr.close();
-        } catch (IOException e) {
-            LOG.warn("GNPy: exception {} occured during the reading of results", e.getMessage());
-        }
-        gnpyResponse = sb.toString();
-        return gnpyResponse;
-    }
-
     /**
      * Transforms the given input {@link NormalizedNode} into the given
      * {@link DataObject}.
@@ -321,4 +299,8 @@ public class GnpyResult {
         }
         return Optional.ofNullable((T) bindingNodeEntry.getValue());
     }
+
+    public Response getResponse() {
+        return response;
+    }
 }