northbound: code clean up
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSubnetsNorthbound.java
index 7e05b7c8e7659fcf67235a0e9ffbd8d6b79fc126..561c4ca10470c75530b20e82360a7e22e84f1120 100644 (file)
@@ -9,11 +9,9 @@
 package org.opendaylight.neutron.northbound.api;
 
 import java.net.HttpURLConnection;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
@@ -28,11 +26,8 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
-
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
-import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
-import org.opendaylight.neutron.spi.INeutronSubnetAware;
 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronSubnet;
@@ -56,8 +51,8 @@ import org.opendaylight.neutron.spi.NeutronSubnet;
  */
 
 @Path("/subnets")
-public class NeutronSubnetsNorthbound
-    extends AbstractNeutronNorthboundIAware<NeutronSubnet, NeutronSubnetRequest, INeutronSubnetCRUD, INeutronSubnetAware> {
+public final class NeutronSubnetsNorthbound
+        extends AbstractNeutronNorthbound<NeutronSubnet, NeutronSubnetRequest, INeutronSubnetCRUD> {
     private static final String RESOURCE_NAME = "Subnet";
 
     @Override
@@ -65,11 +60,6 @@ public class NeutronSubnetsNorthbound
         return RESOURCE_NAME;
     }
 
-    @Override
-    protected NeutronSubnet extractFields(NeutronSubnet o, List<String> fields) {
-        return o.extractFields(fields);
-    }
-
     private NeutronCRUDInterfaces getNeutronInterfaces(boolean needNetwork) {
         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSubnetCRUD(this);
         if (answer.getSubnetInterface() == null) {
@@ -78,8 +68,8 @@ public class NeutronSubnetsNorthbound
         if (needNetwork) {
             answer = answer.fetchINeutronNetworkCRUD(this);
             if (answer.getNetworkInterface() == null) {
-                throw new ServiceUnavailableException("Network CRUD Interface "
-                    + RestMessages.SERVICEUNAVAILABLE.toString());
+                throw new ServiceUnavailableException(
+                        "Network CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString());
             }
         }
         return answer;
@@ -90,52 +80,6 @@ public class NeutronSubnetsNorthbound
         return getNeutronInterfaces(false).getSubnetInterface();
     }
 
-    @Override
-    protected NeutronSubnetRequest newNeutronRequest(NeutronSubnet o) {
-        return new NeutronSubnetRequest(o);
-    }
-
-    @Override
-    protected Object[] getInstances() {
-        return NeutronUtil.getInstances(INeutronSubnetAware.class, this);
-    }
-
-    @Override
-    protected int canCreate(Object instance, NeutronSubnet singleton) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        return service.canCreateSubnet(singleton);
-    }
-
-    @Override
-    protected void created(Object instance, NeutronSubnet singleton) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        service.neutronSubnetCreated(singleton);
-    }
-
-    @Override
-    protected int canUpdate(Object instance, NeutronSubnet delta, NeutronSubnet original) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        return service.canUpdateSubnet(delta, original);
-    }
-
-    @Override
-    protected void updated(Object instance, NeutronSubnet updated) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        service.neutronSubnetUpdated(updated);
-    }
-
-    @Override
-    protected int canDelete(Object instance, NeutronSubnet singleton) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        return service.canDeleteSubnet(singleton);
-    }
-
-    @Override
-    protected void deleted(Object instance, NeutronSubnet singleton) {
-        INeutronSubnetAware service = (INeutronSubnetAware) instance;
-        service.neutronSubnetDeleted(singleton);
-    }
-
     @Context
     UriInfo uriInfo;
 
@@ -144,8 +88,7 @@ public class NeutronSubnetsNorthbound
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
     //@TypeHint(OpenStackSubnets.class)
-    @StatusCodes({
-            @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+    @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
@@ -167,26 +110,26 @@ public class NeutronSubnetsNorthbound
             @QueryParam("limit") Integer limit,
             @QueryParam("marker") String marker,
             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
-            // sorting not supported
-            ) {
+    // sorting not supported
+    ) {
         INeutronSubnetCRUD subnetInterface = getNeutronInterfaces(false).getSubnetInterface();
-        List<NeutronSubnet> allNetworks = subnetInterface.getAllSubnets();
-        List<NeutronSubnet> ans = new ArrayList<NeutronSubnet>();
+        List<NeutronSubnet> allNetworks = subnetInterface.getAll();
+        List<NeutronSubnet> ans = new ArrayList<>();
         Iterator<NeutronSubnet> i = allNetworks.iterator();
         while (i.hasNext()) {
             NeutronSubnet oSS = i.next();
-            if ((queryID == null || queryID.equals(oSS.getID())) &&
-                    (queryNetworkID == null || queryNetworkID.equals(oSS.getNetworkUUID())) &&
-                    (queryName == null || queryName.equals(oSS.getName())) &&
-                    (queryIPVersion == null || queryIPVersion.equals(oSS.getIpVersion())) &&
-                    (queryCIDR == null || queryCIDR.equals(oSS.getCidr())) &&
-                    (queryGatewayIP == null || queryGatewayIP.equals(oSS.getGatewayIP())) &&
-                    (queryEnableDHCP == null || queryEnableDHCP.equals(oSS.getEnableDHCP())) &&
-                    (queryTenantID == null || queryTenantID.equals(oSS.getTenantID())) &&
-                    (queryIpV6AddressMode == null || queryIpV6AddressMode.equals(oSS.getIpV6AddressMode())) &&
-                    (queryIpV6RaMode == null || queryIpV6RaMode.equals(oSS.getIpV6RaMode()))){
+            if ((queryID == null || queryID.equals(oSS.getID()))
+                    && (queryNetworkID == null || queryNetworkID.equals(oSS.getNetworkUUID()))
+                    && (queryName == null || queryName.equals(oSS.getName()))
+                    && (queryIPVersion == null || queryIPVersion.equals(oSS.getIpVersion()))
+                    && (queryCIDR == null || queryCIDR.equals(oSS.getCidr()))
+                    && (queryGatewayIP == null || queryGatewayIP.equals(oSS.getGatewayIP()))
+                    && (queryEnableDHCP == null || queryEnableDHCP.equals(oSS.getEnableDHCP()))
+                    && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))
+                    && (queryIpV6AddressMode == null || queryIpV6AddressMode.equals(oSS.getIpV6AddressMode()))
+                    && (queryIpV6RaMode == null || queryIpV6RaMode.equals(oSS.getIpV6RaMode()))) {
                 if (fields.size() > 0) {
-                    ans.add(extractFields(oSS,fields));
+                    ans.add(oSS.extractFields(fields));
                 } else {
                     ans.add(oSS);
                 }
@@ -195,13 +138,12 @@ public class NeutronSubnetsNorthbound
 
         if (limit != null && ans.size() > 1) {
             // Return a paginated request
-            NeutronSubnetRequest request = (NeutronSubnetRequest) PaginatedRequestFactory.createRequest(limit,
-                    marker, pageReverse, uriInfo, ans, NeutronSubnet.class);
+            NeutronSubnetRequest request = (NeutronSubnetRequest) PaginatedRequestFactory.createRequest(limit, marker,
+                    pageReverse, uriInfo, ans, NeutronSubnet.class);
             return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
         }
 
-        return Response.status(HttpURLConnection.HTTP_OK).entity(
-                new NeutronSubnetRequest(ans)).build();
+        return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSubnetRequest(ans)).build();
     }
 
     /**
@@ -211,14 +153,12 @@ public class NeutronSubnetsNorthbound
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
     //@TypeHint(OpenStackSubnets.class)
-    @StatusCodes({
-            @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+    @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
-    public Response showSubnet(
-            @PathParam("subnetUUID") String subnetUUID,
+    public Response showSubnet(@PathParam("subnetUUID") String subnetUUID,
             // return fields
             @QueryParam("fields") List<String> fields) {
         return show(subnetUUID, fields);
@@ -231,8 +171,7 @@ public class NeutronSubnetsNorthbound
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
     //@TypeHint(OpenStackSubnets.class)
-    @StatusCodes({
-            @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
+    @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createSubnets(final NeutronSubnetRequest input) {
         getNeutronInterfaces(true); // Ensure that network service is loaded
@@ -262,13 +201,10 @@ public class NeutronSubnetsNorthbound
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
     //@TypeHint(OpenStackSubnets.class)
-    @StatusCodes({
-            @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+    @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
-    public Response updateSubnet(
-            @PathParam("subnetUUID") String subnetUUID, final NeutronSubnetRequest input
-            ) {
+    public Response updateSubnet(@PathParam("subnetUUID") String subnetUUID, final NeutronSubnetRequest input) {
         return update(subnetUUID, input);
     }
 
@@ -277,12 +213,10 @@ public class NeutronSubnetsNorthbound
 
     @Path("{subnetUUID}")
     @DELETE
-    @StatusCodes({
-            @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
+    @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
-    public Response deleteSubnet(
-            @PathParam("subnetUUID") String subnetUUID) {
+    public Response deleteSubnet(@PathParam("subnetUUID") String subnetUUID) {
         return delete(subnetUUID);
     }
 }