Refactor to remove empty catch exception.
[controller.git] / opendaylight / northbound / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / northbound / NeutronSubnetsNorthbound.java
index d2d7a5a671c62325ce1a0d2f8966901867357878..699aee9fc3a7d3503e7b1a6d464926da1aefd24f 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
 import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
 import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
 import org.opendaylight.controller.northbound.commons.RestMessages;\r
+import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;\r
 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;\r
 import org.opendaylight.controller.sal.utils.ServiceHelper;\r
 \r
@@ -107,10 +108,11 @@ public class NeutronSubnetsNorthbound {
                     (queryGatewayIP == null || queryGatewayIP.equals(oSS.getGatewayIP())) &&\r
                     (queryEnableDHCP == null || queryEnableDHCP.equals(oSS.getEnableDHCP())) &&\r
                     (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {\r
-                if (fields.size() > 0)\r
+                if (fields.size() > 0) {\r
                     ans.add(extractFields(oSS,fields));\r
-                else\r
+                } else {\r
                     ans.add(oSS);\r
+                }\r
             }\r
         }\r
         //TODO: apply pagination to results\r
@@ -139,15 +141,17 @@ public class NeutronSubnetsNorthbound {
             throw new ServiceUnavailableException("Subnet CRUD Interface "\r
                     + RestMessages.SERVICEUNAVAILABLE.toString());\r
         }\r
-        if (!subnetInterface.subnetExists(subnetUUID))\r
+        if (!subnetInterface.subnetExists(subnetUUID)) {\r
             return Response.status(404).build();\r
+        }\r
         if (fields.size() > 0) {\r
             NeutronSubnet ans = subnetInterface.getSubnet(subnetUUID);\r
             return Response.status(200).entity(\r
                     new NeutronSubnetRequest(extractFields(ans, fields))).build();\r
-        } else\r
+        } else {\r
             return Response.status(200).entity(\r
                     new NeutronSubnetRequest(subnetInterface.getSubnet(subnetUUID))).build();\r
+        }\r
     }\r
 \r
     /**\r
@@ -185,22 +189,29 @@ public class NeutronSubnetsNorthbound {
              *  and that the gateway IP doesn't overlap with the allocation pools\r
              *  *then* add the subnet to the cache\r
              */\r
-            if (subnetInterface.subnetExists(singleton.getID()))\r
+            if (subnetInterface.subnetExists(singleton.getID())) {\r
                 return Response.status(400).build();\r
-            if (!networkInterface.networkExists(singleton.getNetworkUUID()))\r
+            }\r
+            if (!networkInterface.networkExists(singleton.getNetworkUUID())) {\r
                 return Response.status(404).build();\r
-            if (!singleton.isValidCIDR())\r
+            }\r
+            if (!singleton.isValidCIDR()) {\r
                 return Response.status(400).build();\r
-            singleton.initDefaults();\r
-            if (singleton.gatewayIP_Pool_overlap())\r
+            }\r
+            if (!singleton.initDefaults()) {\r
+                throw new InternalServerErrorException("subnet object could not be initialized properly");\r
+            }\r
+            if (singleton.gatewayIP_Pool_overlap()) {\r
                 return Response.status(409).build();\r
+            }\r
             Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
             if (instances != null) {\r
                 for (Object instance : instances) {\r
                     INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
                     int status = service.canCreateSubnet(singleton);\r
-                    if (status < 200 || status > 299)\r
+                    if (status < 200 || status > 299) {\r
                         return Response.status(status).build();\r
+                    }\r
                 }\r
             }\r
             subnetInterface.addSubnet(singleton);\r
@@ -225,24 +236,32 @@ public class NeutronSubnetsNorthbound {
                  *  and that the bulk request doesn't already contain a subnet with this id\r
                  */\r
 \r
-                test.initDefaults();\r
-                if (subnetInterface.subnetExists(test.getID()))\r
+                if (!test.initDefaults()) {\r
+                    throw new InternalServerErrorException("subnet object could not be initialized properly");\r
+                }\r
+                if (subnetInterface.subnetExists(test.getID())) {\r
                     return Response.status(400).build();\r
-                if (testMap.containsKey(test.getID()))\r
+                }\r
+                if (testMap.containsKey(test.getID())) {\r
                     return Response.status(400).build();\r
+                }\r
                 testMap.put(test.getID(), test);\r
-                if (!networkInterface.networkExists(test.getNetworkUUID()))\r
+                if (!networkInterface.networkExists(test.getNetworkUUID())) {\r
                     return Response.status(404).build();\r
-                if (!test.isValidCIDR())\r
+                }\r
+                if (!test.isValidCIDR()) {\r
                     return Response.status(400).build();\r
-                if (test.gatewayIP_Pool_overlap())\r
+                }\r
+                if (test.gatewayIP_Pool_overlap()) {\r
                     return Response.status(409).build();\r
+                }\r
                 if (instances != null) {\r
                     for (Object instance : instances) {\r
                         INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
                         int status = service.canCreateSubnet(test);\r
-                        if (status < 200 || status > 299)\r
+                        if (status < 200 || status > 299) {\r
                             return Response.status(status).build();\r
+                        }\r
                     }\r
                 }\r
             }\r
@@ -292,10 +311,12 @@ public class NeutronSubnetsNorthbound {
         /*\r
          * verify the subnet exists and there is only one delta provided\r
          */\r
-        if (!subnetInterface.subnetExists(subnetUUID))\r
+        if (!subnetInterface.subnetExists(subnetUUID)) {\r
             return Response.status(404).build();\r
-        if (!input.isSingleton())\r
+        }\r
+        if (!input.isSingleton()) {\r
             return Response.status(400).build();\r
+        }\r
         NeutronSubnet delta = input.getSingleton();\r
         NeutronSubnet original = subnetInterface.getSubnet(subnetUUID);\r
 \r
@@ -304,16 +325,18 @@ public class NeutronSubnetsNorthbound {
          */\r
         if (delta.getID() != null || delta.getTenantID() != null ||\r
                 delta.getIpVersion() != null || delta.getCidr() != null ||\r
-                delta.getAllocationPools() != null)\r
+                delta.getAllocationPools() != null) {\r
             return Response.status(400).build();\r
+        }\r
 \r
         Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
         if (instances != null) {\r
             for (Object instance : instances) {\r
                 INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
                 int status = service.canUpdateSubnet(delta, original);\r
-                if (status < 200 || status > 299)\r
+                if (status < 200 || status > 299) {\r
                     return Response.status(status).build();\r
+                }\r
             }\r
         }\r
 \r
@@ -354,18 +377,21 @@ public class NeutronSubnetsNorthbound {
         /*\r
          * verify the subnet exists and it isn't currently in use\r
          */\r
-        if (!subnetInterface.subnetExists(subnetUUID))\r
+        if (!subnetInterface.subnetExists(subnetUUID)) {\r
             return Response.status(404).build();\r
-        if (subnetInterface.subnetInUse(subnetUUID))\r
+        }\r
+        if (subnetInterface.subnetInUse(subnetUUID)) {\r
             return Response.status(409).build();\r
+        }\r
         NeutronSubnet singleton = subnetInterface.getSubnet(subnetUUID);\r
         Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
         if (instances != null) {\r
             for (Object instance : instances) {\r
                 INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
                 int status = service.canDeleteSubnet(singleton);\r
-                if (status < 200 || status > 299)\r
+                if (status < 200 || status > 299) {\r
                     return Response.status(status).build();\r
+                }\r
             }\r
         }\r
 \r