Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / OofUtils.groovy
index 040fc26..0e6cb64 100644 (file)
 
 package org.onap.so.bpmn.common.scripts
 
+import com.google.gson.GsonBuilder
+import org.onap.so.beans.nsmf.oof.NsiReqBody
+import org.onap.so.beans.nsmf.oof.NssiReqBody
+import org.onap.so.beans.nsmf.oof.RequestInfo
+import org.onap.so.beans.nsmf.oof.SubnetCapability
+import org.onap.so.beans.nsmf.oof.TemplateInfo
+
 import static org.onap.so.bpmn.common.scripts.GenericUtils.*
 
 import javax.ws.rs.core.UriBuilder
@@ -43,7 +50,7 @@ import org.onap.so.db.catalog.beans.HomingInstance
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import com.google.gson.JsonObject
-
+import com.google.gson.JsonParser
 import com.fasterxml.jackson.databind.ObjectMapper
 
 class OofUtils {
@@ -534,14 +541,36 @@ class OofUtils {
                         "    \"timeout\": 600,\n" +
                         "    \"callbackUrl\": \"${callbackUrl}\"\n" +
                         "    },\n")
-        response.append(" \"serviceProfile\": {\n" +
-                "   \"serviceProfileParameters\": ")
-        response.append(json);
-        response.append("\n }\n")
+        response.append(" \"serviceProfile\":")
+        response.append(json)
         response.append("\n}\n")
         return response.toString()
     }
 
+    public String buildSelectNSSTRequest(String requestId,String messageType, Map<String, Object> profileInfo) {
+        def transactionId = requestId
+        logger.debug( "transactionId is: " + transactionId)
+        String correlator = requestId
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+        ObjectMapper objectMapper = new ObjectMapper()
+        String json = objectMapper.writeValueAsString(profileInfo)
+        StringBuilder response = new StringBuilder()
+        response.append(
+                "{\n" +
+                        "  \"requestInfo\": {\n" +
+                        "    \"transactionId\": \"${transactionId}\",\n" +
+                        "    \"requestId\": \"${requestId}\",\n" +
+                        "    \"sourceId\": \"so\",\n" +
+                        "    \"timeout\": 600,\n" +
+                        "    \"callbackUrl\": \"${callbackUrl}\"\n" +
+                        "    },\n")
+        response.append(" \"SliceProfile\":")
+        response.append(json)
+        response.append("\n}\n")
+        return response.toString()
+    }
+
+
     public String buildSelectNSIRequest(String requestId, String nstInfo,String messageType, Map<String, Object> profileInfo){
 
         def transactionId = requestId
@@ -591,6 +620,7 @@ String correlator = requestId
 String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
 ObjectMapper objectMapper = new ObjectMapper();
 String profileJson = objectMapper.writeValueAsString(profileInfo);
+JsonParser parser = new JsonParser()
 
 //Prepare requestInfo object
 JsonObject requestInfo = new JsonObject()
@@ -610,9 +640,11 @@ nsstInfo.addProperty("name", name)
 JsonObject json = new JsonObject()
 json.add("requestInfo", requestInfo)
 json.add("NSSTInfo", nsstInfo)
-json.addProperty("sliceProfile", profileJson)
+json.add("sliceProfile", (JsonObject) parser.parse(profileJson))
+
 return json.toString()
 }
+
 /**
 * Method to create NSI/NSSI termination request
 * (OOF response will be synchronous in G-Release)
@@ -650,4 +682,64 @@ json.add("requestInfo", requestInfo)
 return json.toString()
  
 }
+
+    public String buildSelectNSIRequest(String requestId, TemplateInfo nstInfo, List<TemplateInfo> nsstInfo,
+                                        String messageType, Map<String, Object> serviceProfile,
+                                        List<SubnetCapability> subnetCapabilities, Integer timeOut, boolean preferReuse){
+
+        def transactionId = requestId
+        String correlator = requestId
+        logger.debug( "transactionId is: " + transactionId)
+
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+
+        NsiReqBody nsiReqBody = new NsiReqBody()
+
+        RequestInfo requestInfo = new RequestInfo()
+        requestInfo.setRequestId(requestId)
+        requestInfo.setTransactionId(transactionId)
+        requestInfo.setCallbackUrl(callbackUrl)
+        requestInfo.setSourceId("so")
+        requestInfo.setTimeout(timeOut)
+        requestInfo.setNumSolutions(1)
+
+        nsiReqBody.setRequestInfo(requestInfo)
+        nsiReqBody.setNSTInfo(nstInfo)
+        nsiReqBody.setServiceProfile(serviceProfile)
+        nsiReqBody.setSubnetCapabilities(subnetCapabilities)
+        nsiReqBody.setNSSTInfo(nsstInfo)
+        nsiReqBody.setPreferReuse(preferReuse)
+
+        return bean2JsonStr(nsiReqBody)
+    }
+
+    public <T> String buildSelectNSSIRequest(String requestId, TemplateInfo nsstInfo, String messageType,
+                                             T sliceProfile, Integer timeOut){
+
+        def transactionId = requestId
+        String correlator = requestId
+        logger.debug( "transactionId is: " + transactionId)
+
+        String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator
+
+        NssiReqBody nssiReqBody = new NssiReqBody()
+
+        RequestInfo requestInfo = new RequestInfo()
+        requestInfo.setRequestId(requestId)
+        requestInfo.setTransactionId(transactionId)
+        requestInfo.setCallbackUrl(callbackUrl)
+        requestInfo.setSourceId("so")
+        requestInfo.setTimeout(timeOut)
+        requestInfo.setNumSolutions(100)
+
+        nssiReqBody.setRequestInfo(requestInfo)
+        nssiReqBody.setSliceProfile(sliceProfile)
+        nssiReqBody.setNSSTInfo(nsstInfo)
+
+        return bean2JsonStr(nssiReqBody)
+    }
+
+    private static <T> String bean2JsonStr(T t) {
+        return new GsonBuilder().setPrettyPrinting().create().toJson(t)
+    }
 }