Fix for SO-2617
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / sdnc-simulator / src / main / java / org / onap / so / sdncsimulator / controller / OperationsController.java
index 9696beb..2f24ef6 100644 (file)
@@ -21,12 +21,15 @@ package org.onap.so.sdncsimulator.controller;
 
 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE;
 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE;
+import static org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration.DELETE;
 import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.MediaType;
 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration;
 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
 import org.onap.so.sdncsimulator.models.InputRequest;
 import org.onap.so.sdncsimulator.models.Output;
@@ -49,6 +52,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 @Controller
 @RequestMapping(path = OPERATIONS_URL)
 public class OperationsController {
+    private static final String HTTP_STATUS_OK = HttpStatus.OK.value() + "";
 
     private static final Logger LOGGER = LoggerFactory.getLogger(OperationsController.class);
 
@@ -77,7 +81,7 @@ public class OperationsController {
         final Output output = getOutput(apiServiceOperationInformation);
         final OutputRequest outputRequest = new OutputRequest(output);
 
-        if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
+        if (output.getResponseCode().equals(HTTP_STATUS_OK)) {
             LOGGER.info("Sucessfully executed service request sending response: {}", outputRequest);
             return ResponseEntity.ok(outputRequest);
         }
@@ -103,7 +107,7 @@ public class OperationsController {
         final Output output = getOutput(apiVnfOperationInformation);
         final OutputRequest outputRequest = new OutputRequest(output);
 
-        if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
+        if (output.getResponseCode().equals(HTTP_STATUS_OK)) {
             LOGGER.info("Sucessfully executed request vnf sending response: {}", outputRequest);
             return ResponseEntity.ok(outputRequest);
         }
@@ -116,10 +120,14 @@ public class OperationsController {
     private Output getOutput(final GenericResourceApiServiceOperationInformation serviceOperationInformation) {
         final GenericResourceApiRequestinformationRequestInformation requestInformation =
                 serviceOperationInformation.getRequestInformation();
-        if (requestInformation != null) {
+        final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader =
+                serviceOperationInformation.getSdncRequestHeader();
+        if (requestInformation != null && sdncRequestHeader != null) {
             final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction();
-            if (DELETESERVICEINSTANCE.equals(requestAction)) {
-                LOGGER.info("RequestAction: {} will delete service instance from cache ...", requestAction);
+            final GenericResourceApiSvcActionEnumeration svcAction = sdncRequestHeader.getSvcAction();
+            if (DELETESERVICEINSTANCE.equals(requestAction) && DELETE.equals(svcAction)) {
+                LOGGER.info("RequestAction: {} and SvcAction: {} will delete service instance from cache ...",
+                        requestAction, svcAction);
                 return cacheServiceProvider.deleteServiceOperationInformation(serviceOperationInformation);
             }
         }