Bug 6903 - Implement Query parameters - fields
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / restful / services / impl / RestconfDataServiceImpl.java
index cb17434392c1870ce602082d4719e8366a671abf..b15a00aa8683d5a5b1c8a57dff0bef4377b45ff0 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
 import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.netconf.sal.restconf.impl.WriterParameters;
 import org.opendaylight.restconf.RestConnectorProvider;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
@@ -62,16 +63,21 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         this.mountPointServiceHandler = mountPointServiceHandler;
     }
 
+    @Override
+    public Response readData(final UriInfo uriInfo) {
+        return readData(null, uriInfo);
+    }
+
     @Override
     public Response readData(final String identifier, final UriInfo uriInfo) {
-        Preconditions.checkNotNull(identifier);
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
-
         final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(
                 identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get()));
-        final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
-        final String value = uriInfo.getQueryParameters().getFirst(RestconfDataServiceConstant.CONTENT);
 
+        final WriterParameters parameters = ReadDataTransactionUtil.parseUriParameters(
+                instanceIdentifier, uriInfo);
+
+        final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
         final DOMTransactionChain transactionChain;
         if (mountPoint == null) {
             transactionChain = this.transactionChainHandler.get();
@@ -79,9 +85,9 @@ public class RestconfDataServiceImpl implements RestconfDataService {
             transactionChain = transactionChainOfMountPoint(mountPoint);
         }
 
-        final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
-                transactionChain);
-        final NormalizedNode<?, ?> node = ReadDataTransactionUtil.readData(value, transactionNode);
+        final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
+                instanceIdentifier, mountPoint, transactionChain);
+        final NormalizedNode<?, ?> node = ReadDataTransactionUtil.readData(parameters.getContent(), transactionNode);
         if (node == null) {
             throw new RestconfDocumentedException(
                     "Request could not be completed because the relevant data model content does not exist",
@@ -94,12 +100,19 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 + node.getNodeType().getLocalName() + '"';
         final Response resp;
 
-        if ((value == null) || value.contains(RestconfDataServiceConstant.ReadData.CONFIG)) {
-            resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).header("ETag", etag)
-                    .header("Last-Modified", dateFormatGmt.format(new Date())).build();
+        if ((parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL))
+                    || parameters.getContent().equals(RestconfDataServiceConstant.ReadData.CONFIG)) {
+            resp = Response.status(200)
+                    .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
+                    .header("ETag", etag)
+                    .header("Last-Modified", dateFormatGmt.format(new Date()))
+                    .build();
         } else {
-            resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).build();
+            resp = Response.status(200)
+                    .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
+                    .build();
         }
+
         return resp;
     }