Adding delete endpoint for vnf
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / main / java / org / onap / so / aaisimulator / controller / GenericVnfsController.java
index 67e1c4b..43fe47d 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.onap.so.aaisimulator.controller;
 
+import static org.onap.so.aaisimulator.utils.Constants.APPLICATION_MERGE_PATCH_JSON;
 import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
 import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
 import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNFS_URL;
@@ -44,6 +45,7 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -152,7 +154,8 @@ public class GenericVnfsController {
         return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF);
     }
 
-    @PostMapping(value = "/generic-vnf/{vnf-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+    @PostMapping(value = "/generic-vnf/{vnf-id}",
+            consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, APPLICATION_MERGE_PATCH_JSON},
             produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public ResponseEntity<?> patchGenericVnf(@RequestBody final GenericVnf genericVnf,
             @PathVariable("vnf-id") final String vnfId,
@@ -192,4 +195,21 @@ public class GenericVnfsController {
         return ResponseEntity.ok(genericVnfs);
     }
 
+    @DeleteMapping(value = "/generic-vnf/{vnf-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> deleteGenericVnf(@PathVariable("vnf-id") final String vnfId,
+            @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) {
+        LOGGER.info("Will delete GenericVnf for 'vnf-id': {} and 'resource-version': {}", vnfId, resourceVersion);
+
+        if (cacheServiceProvider.deleteGenericVnf(vnfId, resourceVersion)) {
+            LOGGER.info("Successfully delete GenericVnf from cache for 'vnf-id': {} and 'resource-version': {}", vnfId,
+                    resourceVersion);
+            return ResponseEntity.noContent().build();
+        }
+
+        LOGGER.error("Unable to delete GenericVnf for 'vnf-id': {} and 'resource-version': {} ...", vnfId,
+                resourceVersion);
+        return getRequestErrorResponseEntity(request, GENERIC_VNF);
+
+    }
+
 }