Bug 164 59/3059/2
authormsunal <msunal@cisco.com>
Mon, 25 Nov 2013 12:14:57 +0000 (13:14 +0100)
committermsunal <msunal@cisco.com>
Mon, 25 Nov 2013 12:20:53 +0000 (13:20 +0100)
- if URI has bad format then error status 400 is returned
- corrected xtend conventions: triple equals for null

Change-Id: Idfa58e21942506b7483ca6ecf19aedfd1c1de827
Signed-off-by: Martin Sunal <msunal@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java

index f5b913253201ee3d045bfbc00d3af994fdf8cba0..eb1f6165ca23c5bb17deac73f575a06bfc57fc57 100644 (file)
@@ -22,7 +22,7 @@ class BrokerFacade implements DataReader<InstanceIdentifier, CompositeNode> {
     private DataBrokerService dataService;
     
     private new() {
-        if (INSTANCE != null) {
+        if (INSTANCE !== null) {
             throw new IllegalStateException("Already instantiated");
         }
     }
@@ -32,7 +32,7 @@ class BrokerFacade implements DataReader<InstanceIdentifier, CompositeNode> {
     }
 
     private def void checkPreconditions() {
-        if (context == null || dataService == null) {
+        if (context === null || dataService === null) {
             throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
                     .entity(RestconfProvider::NOT_INITALIZED_MSG).build())
         }
index c1ee611e07c77241b1346f0683387d503111e1e9..c2b0ae8bdbb716580b1197108d0e91168b3d6ef0 100644 (file)
@@ -46,7 +46,7 @@ class ControllerContext implements SchemaServiceListener {
     
 
     private new() {
-        if (INSTANCE != null) {
+        if (INSTANCE !== null) {
             throw new IllegalStateException("Already instantiated");
         }
     }
@@ -56,7 +56,7 @@ class ControllerContext implements SchemaServiceListener {
     }
     
     private def void checkPreconditions() {
-        if (schemas == null) {
+        if (schemas === null) {
             throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
                     .entity(RestconfProvider::NOT_INITALIZED_MSG).build())
         }
@@ -72,7 +72,7 @@ class ControllerContext implements SchemaServiceListener {
             pathArgs.remove(0)
         }
         val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule);
-        if (schemaNode == null) {
+        if (schemaNode === null) {
             return null
         }
         new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
@@ -92,7 +92,7 @@ class ControllerContext implements SchemaServiceListener {
 
     private def getLatestModule(SchemaContext schema, String moduleName) {
         checkNotNull(schema)
-        checkArgument(moduleName != null && !moduleName.empty)
+        checkArgument(moduleName !== null && !moduleName.empty)
         val modules = schema.modules.filter[m|m.name == moduleName]
         var latestModule = modules.head
         for (module : modules) {
@@ -134,9 +134,9 @@ class ControllerContext implements SchemaServiceListener {
     def CharSequence toRestconfIdentifier(QName qname) {
         checkPreconditions
         var module = uriToModuleName.get(qname.namespace)
-        if (module == null) {
+        if (module === null) {
             val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision);
-            if(moduleSchema == null) throw new IllegalArgumentException()
+            if(moduleSchema === null) throw new IllegalArgumentException()
             uriToModuleName.put(qname.namespace, moduleSchema.name)
             module = moduleSchema.name;
         }
@@ -189,7 +189,7 @@ class ControllerContext implements SchemaServiceListener {
     }
 
     private def toUriString(Object object) {
-        if(object == null) return "";
+        if(object === null) return "";
         return URLEncoder.encode(object.toString)
     }
 
@@ -203,14 +203,14 @@ class ControllerContext implements SchemaServiceListener {
 
         val nodeName = nodeRef.toNodeName();
         val targetNode = parentNode.getDataChildByName(nodeName);
-        if (targetNode == null) {
+        if (targetNode === null) {
             val children = parentNode.childNodes
             for (child : children) {
                 if (child instanceof ChoiceNode) {
                     val choice = child as ChoiceNode
                     for (caze : choice.cases) {
                         val result = builder.collectPathArguments(strings, caze as DataNodeContainer);
-                        if (result != null)
+                        if (result !== null)
                             return result
                     }
                 }
index d9ac53589fa5415bcba3e59467576fcbb98d069e..a4587fa787fdff3af7b5dedab4b22505375fe37c 100644 (file)
@@ -7,6 +7,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus
+import javax.ws.rs.WebApplicationException
 
 class RestconfImpl implements RestconfService {
     
@@ -19,7 +20,7 @@ class RestconfImpl implements RestconfService {
     extension ControllerContext controllerContext
     
     private new() {
-        if (INSTANCE != null) {
+        if (INSTANCE !== null) {
             throw new IllegalStateException("Already instantiated");
         }
     }
@@ -42,13 +43,13 @@ class RestconfImpl implements RestconfService {
     }
 
     override readData(String identifier) {
-        val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier
+        val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
         return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode)
     }
 
     override createConfigurationData(String identifier, CompositeNode payload) {
-        val identifierWithSchemaNode = identifier.toInstanceIdentifier
+        val identifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
         val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
         switch status.result {
@@ -58,7 +59,7 @@ class RestconfImpl implements RestconfService {
     }
 
     override updateConfigurationData(String identifier, CompositeNode payload) {
-        val identifierWithSchemaNode = identifier.toInstanceIdentifier
+        val identifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
         val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
         switch status.result {
@@ -76,13 +77,13 @@ class RestconfImpl implements RestconfService {
     }
     
     override readConfigurationData(String identifier) {
-        val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier
+        val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
         return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode)
     }
     
     override readOperationalData(String identifier) {
-        val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier
+        val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
         return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode)
     }
@@ -96,7 +97,7 @@ class RestconfImpl implements RestconfService {
     }
     
     override createOperationalData(String identifier, CompositeNode payload) {
-        val identifierWithSchemaNode = identifier.toInstanceIdentifier
+        val identifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
         val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
         switch status.result {
@@ -106,7 +107,7 @@ class RestconfImpl implements RestconfService {
     }
     
     override updateOperationalData(String identifier, CompositeNode payload) {
-        val identifierWithSchemaNode = identifier.toInstanceIdentifier
+        val identifierWithSchemaNode = identifier.resolveInstanceIdentifier
         val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
         val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
         switch status.result {
@@ -115,6 +116,15 @@ class RestconfImpl implements RestconfService {
         }
     }
     
+    private def InstanceIdWithSchemaNode resolveInstanceIdentifier(String identifier) {
+        val identifierWithSchemaNode = identifier.toInstanceIdentifier
+        if (identifierWithSchemaNode === null) {
+            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("URI has bad format")
+                    .build());
+        }
+        return identifierWithSchemaNode
+    }
+    
     private def CompositeNode resolveNodeNamespaceBySchema(CompositeNode node, DataSchemaNode schema) {
         if (node instanceof CompositeNodeWrapper) {
             addNamespaceToNodeFromSchemaRecursively(node as CompositeNodeWrapper, schema)
@@ -124,7 +134,7 @@ class RestconfImpl implements RestconfService {
     }
 
     private def void addNamespaceToNodeFromSchemaRecursively(NodeWrapper<?> nodeBuilder, DataSchemaNode schema) {
-        if (nodeBuilder.namespace == null) {
+        if (nodeBuilder.namespace === null) {
             nodeBuilder.namespace = schema.QName.namespace
         }
         if (nodeBuilder instanceof CompositeNodeWrapper) {
index 7b63c5fd9422e5bb3abd0060be1ba57dc9643389..015dfc8ad99b022c61cf3f705fb2adf9e13a5d9d 100644 (file)
@@ -106,6 +106,16 @@ public class XmlProvidersTest extends JerseyTest {
         assertEquals(404, response.getStatus());
     }
     
+    @Test
+    public void testXmlToCompositeNode400() throws UnsupportedEncodingException, URISyntaxException {
+        String uri = createUri("/datastore/", "simple-nodes:user/name");
+        
+        when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null);
+        
+        Response response = target(uri).request(MediaTypes.API+RestconfService.XML).get();
+        assertEquals(400, response.getStatus());
+    }
+    
     @Test
     public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException {
         InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");