Merge "Add Modify NSSI operation in SO actor"
[policy/models.git] / models-interactions / model-simulators / src / main / java / org / onap / policy / simulators / SoSimulatorJaxRs.java
index 019d6f1..12a523a 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 Wipro Limited.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +22,9 @@
 
 package org.onap.policy.simulators;
 
+import io.swagger.annotations.ApiParam;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
@@ -28,19 +32,20 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import lombok.Setter;
 import org.onap.policy.common.utils.resources.ResourceUtils;
-
+import org.onap.policy.so.SoRequest;
+import org.onap.policy.so.SoRequest3gpp;
 
 @Path("/")
 public class SoSimulatorJaxRs {
 
     private static final String REPLACE_ME = "${replaceMe}";
-
     /**
      * Set of incomplete request IDs. When a POST or DELETE is performed, the new request
      * ID is added to the set. When the request is polled, the ID is removed and a "still
@@ -71,8 +76,15 @@ public class SoSimulatorJaxRs {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId,
-                    @PathParam("vnfInstanceId") final String vnfInstanceId) {
+                    @PathParam("vnfInstanceId") final String vnfInstanceId,
+                    @ApiParam(required = true) SoRequest request) {
 
+        List<Map<String, String>> userParam = null;
+        userParam = request.getRequestDetails().getRequestParameters().getUserParams();
+        if (!userParam.isEmpty() && userParam.toString().contains("FAIL")) {
+            // this will be treated as a failure by the SO actor as it's missing the request ID
+            return "{}";
+        }
         return (requirePolling ? makeStarted() : makeImmediateComplete());
     }
 
@@ -114,6 +126,14 @@ public class SoSimulatorJaxRs {
         }
     }
 
+    @PUT
+    @Path("/3gppservices/v7/modify")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces("application/json")
+    public String soPost3gpp(@ApiParam(required = true) SoRequest3gpp request) {
+        return ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.3gpp.success.json");
+    }
+
     private String makeStarted() {
         String requestId = UUID.randomUUID().toString();