bgpvpn: simplify bgpvpn related code
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronBgpvpnsNorthbound.java
index 3f9837b9ec39c7265fd2054b17faca76125f1faa..f85c55595fb240b1f5acf92621d5b1b24fc98188 100644 (file)
@@ -115,7 +115,7 @@ public class NeutronBgpvpnsNorthbound
             // sorting not supported
             ) {
         INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAllBgpvpns();
+        List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
         List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
         Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
         while (i.hasNext()) {
@@ -172,18 +172,7 @@ public class NeutronBgpvpnsNorthbound
             // return fields
             @QueryParam("fields") List<String> fields
             ) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        if (!bgpvpnInterface.bgpvpnExists(bgpvpnUUID)) {
-            throw new ResourceNotFoundException(uuidNoExist());
-        }
-        if (fields.size() > 0) {
-            NeutronBgpvpn ans = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronBgpvpnRequest(extractFields(ans, fields))).build();
-        } else {
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
-        }
+        return show(bgpvpnUUID, fields);
     }
 
     /**
@@ -196,25 +185,20 @@ public class NeutronBgpvpnsNorthbound
         @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
         @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createBgpvpns(final NeutronBgpvpnRequest input) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        if (input.isSingleton()) {
-            NeutronBgpvpn singleton = input.getSingleton();
-
-            // add bgpvpn to MDSAL
-            singleton.initDefaults();
-            bgpvpnInterface.addBgpvpn(singleton);
-        } else {
-            // add items to MDSAL
-            for (NeutronBgpvpn test : input.getBulk()) {
-                test.initDefaults();
-                bgpvpnInterface.addBgpvpn(test);
-            }
-        }
-        return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+        return create(input);
     }
 
     /**
      * Updates a Bgpvpn */
+    @Override
+    protected void updateDelta(String uuid,
+                               NeutronBgpvpn delta, NeutronBgpvpn original) {
+        //Fill in defaults if they're missing in update
+        delta.initDefaults();
+        delta.setID(uuid);
+        delta.setTenantID(original.getTenantID());
+    }
+
     @Path("{bgpvpnUUID}")
     @PUT
     @Produces({ MediaType.APPLICATION_JSON })
@@ -226,28 +210,7 @@ public class NeutronBgpvpnsNorthbound
     public Response updateBgpvpn(
             @PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
             ) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
-        NeutronBgpvpn updatedObject = input.getSingleton();
-        NeutronBgpvpn original = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
-
-        /*
-         *  note: what we get appears to not be a delta but
-         * rather an incomplete updated object.  So we need to set
-         * the ID to complete the object and then send that down
-         * for folks to check
-         */
-
-        updatedObject.setID(bgpvpnUUID);
-        updatedObject.setTenantID(original.getTenantID());
-        //Fill in defaults if they're missing in update
-        updatedObject.initDefaults();
-
-        // update bgpvpn object
-        bgpvpnInterface.updateBgpvpn(bgpvpnUUID, updatedObject);
-
-        return Response.status(HttpURLConnection.HTTP_OK).entity(
-                new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
+        return update(bgpvpnUUID, input);
     }
 
     /**
@@ -260,11 +223,6 @@ public class NeutronBgpvpnsNorthbound
         @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response deleteBgpvpn(
             @PathParam("bgpvpnUUID") String bgpvpnUUID) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
-        if (!bgpvpnInterface.removeBgpvpn(bgpvpnUUID)) {
-            throw new InternalServerErrorException("Could not delete bgpvpn");
-        }
-        return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+        return delete(bgpvpnUUID);
     }
 }