Changes in Modify and Deallocate Core NSSI flows 67/123467/1
authorAlex <alexander.borovitzky@guest.telecomitalia.it>
Mon, 23 Aug 2021 16:36:36 +0000 (19:36 +0300)
committerAlex <alexander.borovitzky@guest.telecomitalia.it>
Mon, 23 Aug 2021 16:39:17 +0000 (19:39 +0300)
Issue-ID: SO-3703
Change-Id: I22391ae0ff142fd6923cb62621fb537708a3cd19
Signed-off-by: Alex <alexander.borovitzky@guest.telecomitalia.it>
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy
bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy
bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy
bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn
bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn

index 646861a..67e4b92 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.so.bpmn.infrastructure.scripts
 
 import com.fasterxml.jackson.databind.ObjectMapper
+import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.json.JSONArray
 import org.json.JSONObject
@@ -42,6 +43,7 @@ import org.onap.so.serviceinstancebeans.*
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 
+import javax.ws.rs.NotFoundException
 import javax.ws.rs.core.Response
 
 import static org.apache.commons.lang3.StringUtils.isBlank
@@ -50,6 +52,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
     private final String PREFIX ="DoCommonCoreNSSI"
 
+    private static final String SLICE_PROFILE_TEMPLATE = "{\"sliceProfileId\": \"%s\"}"
+
     private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class)
 
     private JsonUtils jsonUtil = new JsonUtils()
@@ -58,7 +62,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
     @Override
     void preProcessRequest(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start preProcessRequest")
+        LOGGER.debug("${getPrefix()} Start preProcessRequest")
 
         def currentNSSI = execution.getVariable("currentNSSI")
         if (!currentNSSI) {
@@ -89,19 +93,33 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
 
         // Slice Profile
-        String sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile")
-        if (isBlank(sliceProfile)) {
-            String msg = "Slice Profile is null"
-            exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-        } else {
-            currentNSSI['sliceProfile'] = sliceProfile
+        String sliceProfile = execution.getVariable("sliceParams")
+        
+      /*  if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfile")) {
+            sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile")
         }
+        else { // In case of Deallocate flow or Modify flow with deletion of Slice Profile Instance
+            if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfileId")) {
+                sliceProfile = String.format(SLICE_PROFILE_TEMPLATE, jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfileId"))
+            }
+            else {
+                String msg = "Either Slice Profile or Slice Profile Id should be provided"
+                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+            }
+        } */
+
+        LOGGER.debug("sliceProfile=" + sliceProfile)
+        currentNSSI['sliceProfile'] = sliceProfile
 
         // S-NSSAI
-        def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList"))
+        String strList = jsonUtil.getJsonValue(sliceProfile, "snssaiList")
+
+        if(strList != null) {
+            def snssaiList = jsonUtil.StringArrayToList(strList)
 
-        String sNssai = snssaiList.get(0)
-        currentNSSI['S-NSSAI'] = sNssai
+            String sNssai = snssaiList.get(0)
+            currentNSSI['S-NSSAI'] = sNssai
+        }
 
 
         // Slice Profile id
@@ -110,8 +128,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
         execution.setVariable("currentNSSI", currentNSSI)
 
-
-        LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest")
+        LOGGER.debug("***** ${getPrefix()} Exit preProcessRequest")
     }
 
 
@@ -120,7 +137,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void getNetworkServiceInstance(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start getNetworkServiceInstance")
+        LOGGER.debug("${getPrefix()} Start getNetworkServiceInstance")
 
         AAIResourcesClient client = getAAIClient()
 
@@ -144,7 +161,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
         }
 
-        LOGGER.trace("${getPrefix()} Exit getNetworkServiceInstance")
+        LOGGER.debug("${getPrefix()} Exit getNetworkServiceInstance")
     }
 
 
@@ -156,6 +173,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return Network Service Instance
      */
     private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
+        LOGGER.debug("${getPrefix()} Start handleNetworkInstance")
+
         ServiceInstance networkServiceInstance = null
 
         def currentNSSI = execution.getVariable("currentNSSI")
@@ -169,7 +188,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
                 if (networkServiceInstanceOpt.isPresent()) {
                     networkServiceInstance = networkServiceInstanceOpt.get()
 
-                    if (networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
+                    if (networkServiceInstance.getServiceRole() == null /* WorkAround */ ||  networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
                         currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
                         break
                     }
@@ -180,6 +199,12 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
                 }
             }
+
+            if (currentNSSI['networkServiceInstanceUri'] == null) {
+                String msg = String.format("Network Service Instance URI is null")
+                LOGGER.error(msg)
+                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+            }
         }
         else {
             String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
@@ -193,6 +218,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
         }
 
+        LOGGER.debug("${getPrefix()} Exit handleNetworkInstance")
+
         return networkServiceInstance
     }
 
@@ -202,7 +229,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
+        LOGGER.debug("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -211,6 +238,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
         AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
         Optional<Relationships> relationships = wrapper.getRelationships()
+
         if (relationships.isPresent()) {
             for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedUris(Types.GENERIC_VNF)) {
                 currentNSSI['constituteVnfUri'] = constituteVnfUri
@@ -234,126 +262,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
         }
 
-        LOGGER.trace("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
-
-    }
-
-
-    /**
-     * Retrieves NSSI associated profiles from AAI
-     * @param execution
-     */
-    void getNSSIAssociatedProfiles(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles")
-
-        List<SliceProfile> associatedProfiles = new ArrayList<>()
-
-        AAIResourcesClient client = getAAIClient()
-
-        def currentNSSI = execution.getVariable("currentNSSI")
-
-        ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
-
-        String nssiId = currentNSSI['nssiId']
-
-        // NSSI
-        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
-        AAIResultWrapper nssiWrapper = client.get(nssiUri)
-        Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
-
-        if (nssiRelationships.isPresent()) {
-            // Allotted Resource
-            for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
-                AAIResultWrapper arWrapper = client.get(allottedResourceUri)
-                Optional<Relationships> arRelationships = arWrapper.getRelationships()
-
-                boolean isFound = false
-                if(arRelationships.isPresent()) {
-                    // Slice Profile Instance
-                    for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
-                        Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
-
-                        if (sliceProfileInstanceOpt.isPresent()) {
-                            ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
-                            if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
-                                associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile()
-
-                                currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
-
-                                isFound = true
-                                break // Should be only one
-                            }
-                        }
-                        else {
-                            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
-                        }
-                    }
-                }
-                else {
-                    exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
-                }
-
-                if(isFound) {
-                    break
-                }
-            }
-        }
-        else {
-            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships  found for nssi id = " + nssiId)
-        }
-
-        if(associatedProfiles.isEmpty()) {
-            String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
-            LOGGER.error(msg)
-            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
-        }
-        else {
-            currentNSSI['associatedProfiles'] =  associatedProfiles
-        }
-
-        LOGGER.trace("${getPrefix()} Exit getNSSIAssociatedProfiles")
-    }
-
-
-    /**
-     * Calculates a final list of S-NSSAI
-     * @param execution
-     */
-    void calculateSNSSAI(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start calculateSNSSAI")
-
-        def currentNSSI = execution.getVariable("currentNSSI")
-
-        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
-
-        String currentSNSSAI = currentNSSI['S-NSSAI']
-
-        List<String> snssais = new ArrayList<>()
-
-        String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" ) // Not exist in case of Deallocate
-
-        boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
-
-        if(isCreateSliceProfileInstance) { // Slice Profile Instance has to be created
-            for (SliceProfile associatedProfile : associatedProfiles) {
-                snssais.add(associatedProfile.getSNssai())
-            }
-
-            snssais.add(currentSNSSAI)
-        }
-        else { // Slice profile instance has to be deleted
-            for (SliceProfile associatedProfile : associatedProfiles) {
-                if (!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI
-                    snssais.add(associatedProfile.getSNssai())
-                } else {
-                    currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
-                }
-            }
-        }
-
-        currentNSSI['S-NSSAIs'] = snssais
+        LOGGER.debug("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
 
-        LOGGER.trace("${getPrefix()} Exit calculateSNSSAI")
     }
 
 
@@ -362,7 +272,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void invokePUTServiceInstance(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start invokePUTServiceInstance")
+        LOGGER.debug("${getPrefix()} Start invokePUTServiceInstance")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -372,15 +282,18 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
             ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
 
-            String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
+            GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
 
-            currentNSSI['putServiceInstanceURL'] = url
+            // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
+            String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
 
             String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
-            String basicAuth =  UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
 
-            def authHeader = ""
-            String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
+            String basicAuth =  UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
+
+            def authHeader = utils.getBasicAuth(basicAuth, msoKey) // ""
+         /*   String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
+
             String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
 
             String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
@@ -389,11 +302,15 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             }
             else {
                 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
-            }
+            } */
 
             def requestDetails = ""
+
             String prepareRequestDetailsResponse = prepareRequestDetails(execution)
-            errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
+            LOGGER.debug("invokePUTServiceInstance: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse)
+
+            String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
+            LOGGER.debug("invokePUTServiceInstance: errorCode=" + errorCode)
             if(errorCode == null || errorCode.isEmpty()) { // No error
                 requestDetails = prepareRequestDetailsResponse
             }
@@ -402,15 +319,13 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             }
 
             String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
-            String putServiceInstanceResponse = ""
 
-            if(errorCode == null || errorCode.isEmpty()) { // No error
-                putServiceInstanceResponse = callPUTServiceInstanceResponse
-            }
-            else {
-                LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
-                exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
-            }
+            String macroOperationId = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestId")
+            String requestSelfLink = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestSelfLink")
+
+            execution.setVariable("macroOperationId",  macroOperationId)
+            execution.setVariable("requestSelfLink", requestSelfLink)
+            currentNSSI['requestSelfLink'] = requestSelfLink
 
         } catch (any) {
             String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
@@ -418,29 +333,36 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
         }
 
-        LOGGER.trace("${getPrefix()} Exit invokePUTServiceInstance")
+        LOGGER.debug("${getPrefix()} Exit invokePUTServiceInstance")
     }
 
 
     String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
+        LOGGER.debug("${getPrefix()} Start callPUTServiceInstance")
+
         String errorCode = ""
         String errorMessage = ""
         String response
 
+        LOGGER.debug("callPUTServiceInstance: url = " + url)
+        LOGGER.debug("callPUTServiceInstance: authHeader = " + authHeader)
+
         try {
-            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
+            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
             httpClient.addAdditionalHeader("Authorization", authHeader)
             httpClient.addAdditionalHeader("Accept", "application/json")
 
-            Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
-
+            Response httpResponse = httpClient.put(requestDetailsStr)
 
-            if (httpResponse.hasEntity()) {
+            int soResponseCode = httpResponse.getStatus()
+            if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
                 response = httpResponse.readEntity(String.class)
+
+                LOGGER.debug("callPUTServiceInstance: response = " + response)
             }
             else {
                 errorCode = 500
-                errorMessage = "No response received."
+                errorMessage = "Response code is " + soResponseCode
 
                 response =  "{\n" +
                         " \"errorCode\": \"${errorCode}\",\n" +
@@ -461,6 +383,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
         return response
 
+        LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance")
     }
 
 
@@ -471,6 +394,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return ModelInfo
      */
     ModelInfo prepareModelInfo(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareModelInfo")
 
         def currentNSSI = execution.getVariable("currentNSSI")
         ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
@@ -491,6 +415,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareModelInfo")
+
         return modelInfo
     }
 
@@ -501,6 +427,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return SubscriberInfo
      */
     SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareSubscriberInfo")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         String globalSubscriberId = execution.getVariable("globalSubscriberId")
@@ -545,6 +473,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
         } */
 
+        LOGGER.debug("${getPrefix()} Exit prepareSubscriberInfo")
+
         return subscriberInfo
     }
 
@@ -555,6 +485,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return RequestInfo
      */
     RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
+        LOGGER.debug("${getPrefix()} Start prepareRequestInfo")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         String productFamilyId = execution.getVariable("productFamilyId")
@@ -566,6 +498,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         requestInfo.setProductFamilyId(productFamilyId)
         requestInfo.setRequestorId("NBI")
 
+        LOGGER.debug("${getPrefix()} Exit prepareRequestInfo")
+
         return requestInfo
     }
 
@@ -577,6 +511,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return ModelInfo
      */
     ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+        LOGGER.debug("${getPrefix()} Start prepareServiceModelInfo")
 
         ModelInfo serviceModelInfo = new ModelInfo()
         serviceModelInfo.setModelType(ModelType.service)
@@ -586,6 +521,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         serviceModelInfo.setModelName(modelInfo.getModelName())
         serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
 
+        LOGGER.debug("${getPrefix()} Exit prepareServiceModelInfo")
+
         return serviceModelInfo
     }
 
@@ -596,6 +533,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return CloudConfiguration
      */
     CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareCloudConfiguration")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         CloudConfiguration cloudConfiguration = new CloudConfiguration()
@@ -603,6 +542,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         AAIResourcesClient client = getAAIClient()
 
         AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
+
         AAIResultWrapper wrapper = client.get(constituteVnfUri)
         Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
 
@@ -617,9 +557,29 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
                 if (cloudRegionrOpt.isPresent()) {
                     cloudRegion = cloudRegionrOpt.get()
                     cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
-                    for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
-                        cloudConfiguration.setTenantId(tenant.getTenantId())
-                        break // only one is required
+
+                    if(cloudRegion.getTenants() != null && cloudRegion.getTenants().getTenant() != null) {
+                        for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
+                            cloudConfiguration.setTenantId(tenant.getTenantId())
+                            cloudConfiguration.setTenantName(tenant.getTenantName())
+                            break // only one is required
+                        }
+                    }
+                    else {
+                        List<AAIResourceUri> tenantRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.TENANT)
+                        if (!(tenantRelatedAAIUris == null || tenantRelatedAAIUris.isEmpty())) {
+                            Optional<Tenant> tenantOpt = client.get(Tenant.class, tenantRelatedAAIUris.get(0))
+                            Tenant tenant = null
+                            if (tenantOpt.isPresent()) {
+                                tenant = tenantOpt.get()
+
+                                LOGGER.debug("prepareCloudConfiguration: tenantId=" + tenant.getTenantId())
+                                LOGGER.debug("prepareCloudConfiguration: tenantName=" + tenant.getTenantName())
+
+                                cloudConfiguration.setTenantId(tenant.getTenantId())
+                                cloudConfiguration.setTenantName(tenant.getTenantName())
+                            }
+                        }
                     }
 
                     cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
@@ -627,6 +587,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             }
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareCloudConfiguration")
+
         return cloudConfiguration
     }
 
@@ -638,33 +600,100 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return List<VfModules>
      */
     List<org.onap.so.serviceinstancebeans.VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
+        LOGGER.debug("${getPrefix()} Start prepareVfModules")
 
         AAIResourcesClient client = getAAIClient()
 
+        def currentNSSI = execution.getVariable("currentNSSI")
+
         List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
-        for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
-            org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
 
-            ModelInfo vfModuleModelInfo = new ModelInfo()
-            vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
-            vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
+        ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
+
+        String networkServiceModelInvariantUuid = networkServiceInstance.getModelInvariantId()
+
+        String serviceVnfs="";
+        String msg=""
+        try{
+            CatalogDbUtils catalogDbUtils = getCatalogDbUtilsFactory().create()
+
+            String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution, networkServiceModelInvariantUuid)
+            LOGGER.debug("***** JSON IS: "+json)
 
-            AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
+            serviceVnfs = jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs") ?: ""
 
-            Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
+            ObjectMapper mapper = new ObjectMapper()
 
-            if (vfModuleModelVerOpt.isPresent()) {
-                vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
-                vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
-                vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
+            List<Object> vnfList = mapper.readValue(serviceVnfs, List.class)
+            LOGGER.debug("vnfList:  "+vnfList)
+
+            Map vnfMap = vnfList.get(0)
+            ModelInfo vnfModelInfo = vnfMap.get("modelInfo")
+            vnfModelInfo.setModelCustomizationId(vnfModelInfo.getModelCustomizationUuid())
+            vnfModelInfo.setModelVersionId(vnfModelInfo.getModelId())
+            LOGGER.debug("vnfModelInfo "+vnfModelInfo)
+
+            //List of VFModules
+            List<Map<String, Object>> vfModuleList = vnfMap.get("vfModules")
+            LOGGER.debug("vfModuleList "+vfModuleList)
+
+            //List of VfModules
+            List<ModelInfo> vfModelInfoList = new ArrayList<>()
+
+            //Traverse VFModules List and add in vfModelInfoList
+            for (vfModule in vfModuleList) {
+                ModelInfo vfModelInfo = vfModule.get("modelInfo")
+                vfModelInfo.setModelCustomizationId(vfModelInfo.getModelCustomizationUuid())
+                vfModelInfo.setModelVersionId(vfModelInfo.getModelId())
+                LOGGER.debug("vfModelInfo "+vfModelInfo)
+                vfModelInfoList.add(vfModelInfo)
             }
-            vfmodules.setModelInfo(vfModuleModelInfo)
 
-            vfmodules.setInstanceName(vfModule.getVfModuleName())
+            for (ModelInfo vfModuleModelInfo : vfModelInfoList) {
+                org.onap.so.serviceinstancebeans.VfModules vfModules = new org.onap.so.serviceinstancebeans.VfModules()
+                vfModules.setModelInfo(vfModuleModelInfo)
+                vfModules.setInstanceName(vfModuleModelInfo.getModelName())
+
+                List<Map<String, Object>> vfModuleInstanceParams = new ArrayList<>()
+                vfModules.setInstanceParams(vfModuleInstanceParams)
+                vfModuless.add(vfModules)
+            }
 
-            vfModuless.add(vfmodules)
+        } catch (Exception ex){
+            msg = "Exception in prepareVfModules " + ex.getMessage()
+            LOGGER.error(msg)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
         }
 
+        /*
+        List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
+        if(constituteVnf.getVfModules() != null && constituteVnf.getVfModules().getVfModule() != null) {
+            for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
+                org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
+
+                ModelInfo vfModuleModelInfo = new ModelInfo()
+                vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
+                vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
+
+                AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
+
+                Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
+
+                if (vfModuleModelVerOpt.isPresent()) {
+                    vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
+                    vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
+                    vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
+                }
+                vfmodules.setModelInfo(vfModuleModelInfo)
+
+                vfmodules.setInstanceName(vfModule.getVfModuleName())
+
+                vfModuless.add(vfmodules)
+            }
+        } */
+
+        LOGGER.debug("${getPrefix()} Exit prepareVfModules")
+
         return vfModuless
     }
 
@@ -676,6 +705,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return ModelInfo
      */
     ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
+        LOGGER.debug("${getPrefix()} Start prepareVNFModelInfo")
+
         ModelInfo vnfModelInfo = new ModelInfo()
 
         AAIResourcesClient client = getAAIClient()
@@ -694,11 +725,15 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareVNFModelInfo")
+
         return vnfModelInfo
     }
 
 
     List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareInstanceParams")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         List<Map<String, Object>> instanceParams = new ArrayList<>()
@@ -734,6 +769,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr)
         instanceParams.add(instanceParamsMap)
 
+        LOGGER.debug("${getPrefix()} Exit prepareInstanceParams")
+
         return instanceParams
     }
 
@@ -743,6 +780,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return Resources
      */
     Resources prepareResources(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareResources")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         Resources resources = new Resources()
@@ -781,6 +820,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         vnfs.add(vnf)
         resources.setVnfs(vnfs)
 
+        LOGGER.debug("${getPrefix()} Exit prepareResources")
+
         return resources
     }
 
@@ -790,6 +831,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return Service
      */
     org.onap.so.serviceinstancebeans.Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+        LOGGER.debug("${getPrefix()} Start prepareService")
+
         org.onap.so.serviceinstancebeans.Service service = new org.onap.so.serviceinstancebeans.Service()
 
         // Model Info
@@ -800,6 +843,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         // Resources
         service.setResources(prepareResources(execution))
 
+        LOGGER.debug("${getPrefix()} Exit prepareService")
+
         return service
 
     }
@@ -811,6 +856,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return RequestParameters
      */
     RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+        LOGGER.debug("${getPrefix()} Start prepareRequestParameters")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         RequestParameters requestParameters = new RequestParameters()
@@ -834,6 +881,10 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
         userParams.add(serviceMap)
         requestParameters.setUserParams(userParams)
 
+        requestParameters.setaLaCarte(false)
+
+        LOGGER.debug("${getPrefix()} Exit prepareRequestParameters")
+
         return requestParameters
     }
 
@@ -844,6 +895,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return OwningEntity
      */
     org.onap.so.serviceinstancebeans.OwningEntity prepareOwningEntity(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareOwningEntity")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         AAIResourcesClient client = getAAIClient()
@@ -866,6 +919,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             }
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareOwningEntity")
+
         return owningEntity
     }
 
@@ -876,6 +931,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return Project
      */
     org.onap.so.serviceinstancebeans.Project prepareProject(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareProject")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         AAIResourcesClient client = getAAIClient()
@@ -898,6 +955,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             }
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareProject")
+
         return project
     }
 
@@ -908,6 +967,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @return
      */
     String prepareRequestDetails(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start prepareRequestDetails")
+
         String errorCode = ""
         String errorMessage = ""
         String response
@@ -941,9 +1002,12 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             // Project
             requestDetails.setProject(prepareProject(execution))
 
+            Map<String, Object> requestDetailsMap = new LinkedHashMap<>()
+            requestDetailsMap.put("requestDetails", requestDetails)
+
             ObjectMapper mapper = new ObjectMapper()
 
-            response = mapper.writeValueAsString(requestDetails)
+            response = mapper.writeValueAsString(requestDetailsMap)
         }
         catch (any) {
             String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
@@ -956,6 +1020,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
         }
 
+        LOGGER.debug("${getPrefix()} Exit prepareRequestDetails")
+
         return response
     }
 
@@ -990,60 +1056,145 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
 
     /**
-     * Removes Slice Profile association with NSSI
+     * Retrieves NSSI associated profiles from AAI
      * @param execution
      */
-    void removeSPAssociationWithNSSI(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start removeSPAssociationWithNSSI")
+    void getNSSIAssociatedProfiles(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start getNSSIAssociatedProfiles")
+
+        List<SliceProfile> associatedProfiles = new ArrayList<>()
 
         AAIResourcesClient client = getAAIClient()
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
+        ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
+
         String nssiId = currentNSSI['nssiId']
+
+        String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+        // NSSI
         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+        AAIResultWrapper nssiWrapper = client.get(nssiUri)
+        Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
+
+        if (nssiRelationships.isPresent()) {
+            // Allotted Resource
+            for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
+                AAIResultWrapper arWrapper = client.get(allottedResourceUri)
+                Optional<Relationships> arRelationships = arWrapper.getRelationships()
+
+                if(arRelationships.isPresent()) {
+                    // Slice Profile Instance
+                    for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
+                        Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
+
+                        if (sliceProfileInstanceOpt.isPresent()) {
+                            ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+                            if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
 
-        AAIResourceUri sliceProfileInstanceUri = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri']
+                                String globalSubscriberId = execution.getVariable("globalSubscriberId")
+                                String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
 
-        Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
-        if (sliceProfileInstanceOpt.isPresent()) {
-            ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+                                org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
+                                        AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
 
-            List<SliceProfile> associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile()
+                                def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
+                                LOGGER.debug("client.exists(sliceProfilesUri = " + client.exists(sliceProfilesUri))
+                                if (!client.exists(sliceProfilesUri)) {
+                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Slice Profiles URI doesn't exist")
+                                }
 
-            String currentSNSSAI = currentNSSI['S-NSSAI']
+                                AAIResultWrapper sliceProfilesWrapper = client.get(sliceProfilesUri)
+                                Optional<SliceProfiles> sliceProfilesOpt = sliceProfilesWrapper.asBean(SliceProfiles.class)
+                                if(sliceProfilesOpt.isPresent()) {
+                                    SliceProfiles sliceProfiles = sliceProfilesOpt.get()
 
-            if(!(associatedProfiles == null || associatedProfiles.isEmpty())) {
-                // Removes slice profile which contains given S-NSSAI and  updates Slice Profile Instance
-                associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
+                                    LOGGER.debug("getNSSIAssociatedProfiles: sliceProfiles.getSliceProfile().size() = " + sliceProfiles.getSliceProfile().size())
+                                    LOGGER.debug("getNSSIAssociatedProfiles: givenSliceProfileId = " + givenSliceProfileId)
+                                    for(SliceProfile sliceProfile: sliceProfiles.getSliceProfile()) {
+                                        LOGGER.debug("getNSSIAssociatedProfiles: sliceProfile.getProfileId() = " + sliceProfile.getProfileId())
+                                        if(sliceProfile.getProfileId().equals(givenSliceProfileId)) { // Slice profile id equals to received slice profile id
+                                            currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
+                                        }
 
-                try {
-                    client.update(sliceProfileInstanceUri, sliceProfileInstance)
+                                    }
 
-                    currentNSSI['sliceProfileInstance'] = sliceProfileInstance
-                } catch (Exception e) {
-                    exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
+                                    associatedProfiles.addAll(sliceProfiles.getSliceProfile()) // Adds all slice profiles
+                                }
+
+                            }
+                        }
+                        else {
+                            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
+                        }
+                    }
+                }
+                else {
+                    exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
                 }
-            }
-            else {
-                exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profiles found")
-            }
 
+            }
         }
         else {
-            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found")
+            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships  found for nssi id = " + nssiId)
         }
 
-        // Removes SLice Profile Instance association with NSSI
-        try {
-            client.disconnect(nssiUri, sliceProfileInstanceUri)
+        checkAssociatedProfiles(execution, associatedProfiles, nssi)
+
+        currentNSSI['associatedProfiles'] =  associatedProfiles
+
+        LOGGER.debug("${getPrefix()} Exit getNSSIAssociatedProfiles")
+    }
+
+
+    void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {}
+
+
+    /**
+     * Removes Slice Profile association with NSSI
+     * @param execution
+     */
+    void removeSPAssociationWithNSSI(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start removeSPAssociationWithNSSI")
+
+        AAIResourcesClient client = getAAIClient()
+
+        def currentNSSI = execution.getVariable("currentNSSI")
+
+        String nssiId = currentNSSI['nssiId']
+        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+
+        String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
+
+        boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
+
+        AAIResourceUri sliceProfileInstanceUri = null
+        if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
+            def spURI = currentNSSI['sliceProfileInstanceUri']
+            if(spURI != null) {
+                sliceProfileInstanceUri = (AAIResourceUri)spURI
+            }
+            else {
+                String msg = "Slice Profile URI not found"
+                LOGGER.error(msg)
+                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+            }
         }
-        catch (Exception e) {
-            exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
+
+        // Removes SLice Profile Instance association with NSSI
+        if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
+            try {
+                client.disconnect(nssiUri, sliceProfileInstanceUri)
+            }
+            catch (Exception e) {
+                exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
+            }
         }
 
 
-        LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI")
+        LOGGER.debug("${getPrefix()} Exit removeSPAssociationWithNSSI")
     }
 
 
@@ -1052,21 +1203,38 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void deleteSliceProfileInstance(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start deleteSliceProfileInstance")
+        LOGGER.debug("${getPrefix()} Start deleteSliceProfileInstance")
 
         AAIResourcesClient client = getAAIClient()
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
-        AAIResourceUri sliceProfileInstanceURI = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri']
+        String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
 
-        try {
-            client.delete(sliceProfileInstanceURI)
-        }catch(Exception e){
-            exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
+        boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
+
+        AAIResourceUri sliceProfileInstanceUri = null
+        if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
+            def spURI = currentNSSI['sliceProfileInstanceUri']
+            if(spURI != null) {
+                sliceProfileInstanceUri = (AAIResourceUri)spURI
+            }
+            else {
+                String msg = "Slice Profile URI not found"
+                LOGGER.error(msg)
+                exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+            }
         }
 
-        LOGGER.trace("${getPrefix()} Exit deleteSliceProfileInstance")
+        if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
+            try {
+                client.delete(sliceProfileInstanceUri)
+            } catch (Exception e) {
+                exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
+            }
+        }
+
+        LOGGER.debug("${getPrefix()} Exit deleteSliceProfileInstance")
     }
 
 
@@ -1075,7 +1243,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void prepareUpdateResourceOperationStatus(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus")
+        LOGGER.debug("${getPrefix()} Start updateServiceOperationStatus")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -1092,7 +1260,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
         setResourceOperationStatus(execution, "finished", "100", "Core NSSI ${getAction()} successful")
 
-        LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus")
+        LOGGER.debug("${getPrefix()} Exit updateServiceOperationStatus")
     }
 
 
@@ -1102,26 +1270,31 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param operationType
      */
     void setResourceOperationStatus(DelegateExecution execution, String status, String progress, String statusDesc) {
-        LOGGER.trace("${getPrefix()} Start setResourceOperationStatus")
+        LOGGER.debug("${getPrefix()} Start setResourceOperationStatus")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
-        String serviceId = currentNSSI['nssiId']
+        String serviceId = currentNSSI['nsiId']
         String jobId = execution.getVariable("jobId")
         String nsiId = currentNSSI['nsiId']
         String operationType = execution.getVariable("operationType")
+        String resourceInstanceId = currentNSSI['nssiId']
+
+        ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
+        String modelUuid = nssi.getModelVersionId()
 
         ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
         resourceOperationStatus.setServiceId(serviceId)
         resourceOperationStatus.setOperationId(jobId)
-        resourceOperationStatus.setResourceTemplateUUID(nsiId)
+        resourceOperationStatus.setResourceTemplateUUID(modelUuid)
         resourceOperationStatus.setOperType(operationType)
+        resourceOperationStatus.setResourceInstanceID(resourceInstanceId)
         resourceOperationStatus.setStatus(status)
         resourceOperationStatus.setProgress(progress)
         resourceOperationStatus.setStatusDescription(statusDesc)
         requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
 
-        LOGGER.trace("${getPrefix()} Exit setResourceOperationStatus")
+        LOGGER.debug("${getPrefix()} Exit setResourceOperationStatus")
     }
 
 
@@ -1130,11 +1303,11 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void prepareFailedOperationStatusUpdate(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start prepareFailedOperationStatusUpdate")
+        LOGGER.debug("${getPrefix()} Start prepareFailedOperationStatusUpdate")
 
         setResourceOperationStatus(execution, "failed", "0", "Core NSSI ${getAction()} Failed")
 
-        LOGGER.trace("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
+        LOGGER.debug("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
     }
 
 
@@ -1143,42 +1316,58 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     public void getPUTServiceInstanceProgress(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start getPUTServiceInstanceProgress")
+        LOGGER.debug("${getPrefix()} Start getPUTServiceInstanceProgress")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
-        String url = currentNSSI['putServiceInstanceURL']
+        ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
+
+        String url = currentNSSI['requestSelfLink']
+
+        String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
 
-        getProgress(execution, url, "putStatus")
+        String basicAuth =  UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
 
-        LOGGER.trace("${getPrefix()} Exit getPUTServiceInstanceProgress")
+        def authHeader = ""
+        String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
+
+        getProgress(execution, url, basicAuthValue, "putStatus")
+
+        LOGGER.debug("${getPrefix()} Exit getPUTServiceInstanceProgress")
     }
 
 
-    void getProgress(DelegateExecution execution, String url, String statusVariableName) {
+    void getProgress(DelegateExecution execution, String url, String authHeader, String statusVariableName) {
+        LOGGER.debug("${getPrefix()} Start getProgress")
+
+        LOGGER.debug("getProgress: url = " + url)
+        LOGGER.debug("getProgress: authHeader = " + authHeader)
+
         String msg=""
         try {
 
-            ExternalAPIUtil externalAPIUtil = getExternalAPIUtilFactory().create()
-            Response response = externalAPIUtil.executeExternalAPIGetCall(execution, url)
+            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
+            httpClient.addAdditionalHeader("Authorization", authHeader)
+            httpClient.addAdditionalHeader("Accept", "application/json")
+
+            Response response = httpClient.get()
             int responseCode = response.getStatus()
-            execution.setVariable("GetServiceOrderResponseCode", responseCode)
+          //  execution.setVariable("GetServiceOrderResponseCode", responseCode)
             LOGGER.debug("Get ServiceOrder response code is: " + responseCode)
 
-            String extApiResponse = response.readEntity(String.class)
-            JSONObject responseObj = new JSONObject(extApiResponse)
-            execution.setVariable("GetServiceOrderResponse", extApiResponse)
-            LOGGER.debug("Create response body is: " + extApiResponse)
+            String soResponse = ""
+            if(response.hasEntity()) {
+                soResponse = response.readEntity(String.class)
+         //       execution.setVariable("GetServiceOrderResponse", extApiResponse)
+                LOGGER.debug("Create response body is: " + soResponse)
+            }
+
             //Process Response //200 OK 201 CREATED 202 ACCEPTED
-            if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
-            {
+            if (responseCode >= 200 && responseCode < 204) {
                 LOGGER.debug("Get Create ServiceOrder Received a Good Response")
-                String orderState = responseObj.get("state")
-                if("REJECTED".equalsIgnoreCase(orderState)) {
-                    prepareFailedOperationStatusUpdate(execution)
-                    return
-                }
+                String requestState = jsonUtil.getJsonValue(soResponse, "request.requestStatus.requestState")
 
+                /*
                 JSONArray items = responseObj.getJSONArray("orderItem")
                 JSONObject item = items.get(0)
                 JSONObject service = item.get("service")
@@ -1190,21 +1379,25 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
 
                 execution.setVariable("networkServiceId", networkServiceId)
                 String serviceOrderState = item.get("state")
-                execution.setVariable("ServiceOrderState", serviceOrderState)
+                execution.setVariable("ServiceOrderState", serviceOrderState) */
+
                 // Get serviceOrder State and process progress
-                if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
+                if("ACKNOWLEDGED".equalsIgnoreCase(requestState)) {
                     execution.setVariable(statusVariableName, "processing")
                 }
-                else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
+                else if("IN_PROGRESS".equalsIgnoreCase(requestState)) {
                     execution.setVariable(statusVariableName, "processing")
                 }
-                else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
+                else if("COMPLETE".equalsIgnoreCase(requestState)) {
                     execution.setVariable(statusVariableName, "completed")
                 }
-                else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
+                else if("FAILED".equalsIgnoreCase(requestState)) {
                     msg = "ServiceOrder failed"
                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
                 }
+                else if("REJECTED".equalsIgnoreCase(requestState)) {
+                    prepareFailedOperationStatusUpdate(execution)
+                }
                 else {
                     msg = "ServiceOrder failed"
                     exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  msg)
@@ -1219,6 +1412,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000,  e.getMessage())
         }
 
+        LOGGER.debug("${getPrefix()} Exit getProgress")
     }
 
 
@@ -1228,7 +1422,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
      * @param execution
      */
     void timeDelay(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start timeDelay")
+        LOGGER.debug("${getPrefix()} Start timeDelay")
 
         try {
             LOGGER.debug("${getPrefix()} timeDelay going to sleep for 5 sec")
@@ -1240,10 +1434,20 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
             LOGGER.error("${getPrefix()} ::: timeDelay exception" + e)
         }
 
-        LOGGER.trace("${getPrefix()} Exit timeDelay")
+        LOGGER.debug("${getPrefix()} Exit timeDelay")
     }
 
 
+    void postProcessRequest(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start postProcessRequest")
+
+        execution.removeVariable("currentNSSI")
+
+        LOGGER.debug("***** ${getPrefix()} Exit postProcessRequest")
+    }
+
+
+
     /**
      * Returns AAI client
      * @return AAI client
@@ -1258,7 +1462,16 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
     }
 
 
-    String getPrefix() {
+    /**
+     * Returns Catalog DB Util Factory
+     * @return ew CatalogDbUtilsFactory()
+     */
+    CatalogDbUtilsFactory getCatalogDbUtilsFactory() {
+        return new CatalogDbUtilsFactory()
+    }
+
+
+    private String getPrefix() {
         return PREFIX
     }
 
index fe881eb..c559845 100644 (file)
 
 package org.onap.so.bpmn.infrastructure.scripts
 
-
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.gson.JsonObject
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.onap.aai.domain.yang.v19.AllottedResource
+import org.onap.aai.domain.yang.v19.GenericVnf
 import org.onap.aai.domain.yang.v19.ServiceInstance
+import org.onap.aai.domain.yang.v19.SliceProfile
+import org.onap.aai.domain.yang.v19.SliceProfiles
 import org.onap.aaiclient.client.aai.AAIResourcesClient
 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
 import org.onap.aaiclient.client.aai.entities.Relationships
@@ -34,16 +38,23 @@ import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.T
 import org.onap.logging.filter.base.ONAPComponents
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.scripts.OofUtils
 import org.onap.so.bpmn.common.scripts.RequestDBUtil
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
 import org.onap.so.client.HttpClientFactory
+import org.onap.so.client.oof.adapter.beans.payload.OofRequest
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 
 import javax.ws.rs.core.Response
 
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
+import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
+
 class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
     private final String PREFIX ="DoDeallocateCoreNSSI"
     private final  String ACTION = "Deallocate"
@@ -55,54 +66,84 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
 
     private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateCoreNSSI.class)
 
+
+    @Override
+    void preProcessRequest(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start preProcessRequest")
+
+        super.preProcessRequest(execution)
+
+        execution.setVariable("operationType", "DEALLOCATE")
+
+        LOGGER.debug("${getPrefix()} Exit preProcessRequest")
+    }
+
+
+
     /**
      * Queries OOF for NSSI termination
      * @param execution
      */
     void executeTerminateNSSIQuery(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start executeTerminateNSSIQuery")
+        LOGGER.debug("${PREFIX} Start executeTerminateNSSIQuery")
 
         String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
+       // String urlString = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution)
+
+        //API Path
+        String apiPath =  "/api/oof/terminate/nxi/v1"
+        LOGGER.debug("API path for DoAllocateCoreNSSI: "+apiPath)
+
+        urlString = urlString + apiPath
 
         //Prepare auth for OOF
         def authHeader = ""
         String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution)
         String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
 
-        String basicAuthValue = encryptBasicAuth(basicAuth, msokey)
-        if (basicAuthValue != null) {
-            String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msokey)
-            String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode")
-            if(errorCode == null || errorCode.isEmpty()) { // No error
-                authHeader = responseAuthHeader
-            }
-            else {
-                exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
+        String basicAuthValue = utils.encrypt(basicAuth, msokey)
+     /*   if (basicAuthValue != null) {
+            LOGGER.debug( "Obtained BasicAuth username and password for OOF Adapter: " + basicAuthValue)
+            try {
+                authHeader = utils.getBasicAuth(basicAuthValue, msokey)
+                execution.setVariable("BasicAuthHeaderValue", authHeader)
+            } catch (Exception ex) {
+                LOGGER.error( "Unable to encode username and password string: " + ex)
+                exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
             }
         } else {
             LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
-            exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
-                    "value null")
+            exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth value null")
+        } */
+
+
+        try {
+            authHeader = utils.getBasicAuth(basicAuthValue, msokey)
+            execution.setVariable("BasicAuthHeaderValue", authHeader)
+        } catch (Exception ex) {
+            LOGGER.error( "Unable to encode username and password string: " + ex)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
         }
 
         //Prepare send request to OOF
         String oofRequest = buildOOFRequest(execution)
 
         String callOOFResponse = callOOF(urlString, authHeader, oofRequest)
+        LOGGER.debug("callOOFResponse=" + callOOFResponse)
+
         String errorCode = jsonUtil.getJsonValue(callOOFResponse, "errorCode")
         if(errorCode == null || errorCode.isEmpty()) { // No error
-            String oofResponse = callOOFResponse
-            String isTerminateNSSI = jsonUtil.getJsonValue(oofResponse, "terminateResponse")
+            String terminateNSSI = jsonUtil.getJsonValue(callOOFResponse, "terminateResponse")
+            LOGGER.debug("isTerminateNSSI=" + terminateNSSI)
 
-            execution.setVariable("isTerminateNSSI", Boolean.parseBoolean(isTerminateNSSI))
+            execution.setVariable("isTerminateNSSI", terminateNSSI)
         }
         else {
             LOGGER.error(jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
             exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
         }
 
-
-        LOGGER.trace("${PREFIX} Exit executeTerminateNSSIQuery")
+        LOGGER.debug("${PREFIX} Exit executeTerminateNSSIQuery")
     }
 
 
@@ -111,15 +152,16 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @return OOF response
      */
     String callOOF(String urlString, String authHeader, String oofRequest) {
+        LOGGER.debug("${PREFIX} Start callOOF")
+
         String errorCode = ""
         String errorMessage = ""
         String response = ""
 
         try {
-            URL url = new URL(urlString + "/api/oof/terminate/nxi/v1")
-            HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
+            URL url = new URL(urlString)
+            HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
             httpClient.addAdditionalHeader("Authorization", authHeader)
-            httpClient.addAdditionalHeader("Accept", "application/json")
             httpClient.addAdditionalHeader("Content-Type", "application/json")
 
             Response httpResponse = httpClient.post(oofRequest)
@@ -127,7 +169,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
             int responseCode = httpResponse.getStatus()
             LOGGER.debug("OOF sync response code is: " + responseCode)
 
-            if (responseCode != 202) { // Accepted
+            if(responseCode < 200 || responseCode >= 300) { // Wrong code
                 errorCode = responseCode
                 errorMessage = "Received a Bad Sync Response from OOF."
 
@@ -161,6 +203,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
                     "}"
         }
 
+        LOGGER.debug("${PREFIX} Exit callOOF")
 
         return response
     }
@@ -172,23 +215,54 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @return
      */
     private String buildOOFRequest(DelegateExecution execution) {
+        LOGGER.debug("${PREFIX} Start buildOOFRequest")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
         String nssiId = currentNSSI['nssiId']
-        String requestId = execution.getVariable("mso-request-id")
-
-        String request =    "{\n" +
-                            "  \"type\": \"NSSI\",\n" +
-                            "  \"NxIId\": \"${nssiId}\",\n" +
-                            "  \"requestInfo\": {\n" +
-                            "    \"transactionId\": \"${requestId}\",\n" +
-                            "    \"requestId\": \"${requestId}\",\n" +
-                            "    \"sourceId\": \"so\",\n" +
-                            "    }\n" +
-                            "}"
-
-        return request
+
+        ServiceInstance nssi = null
+
+        AAIResourcesClient client = getAAIClient()
+
+        // NSSI
+        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+        Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
+
+        if (nssiOpt.isPresent()) {
+            nssi = nssiOpt.get()
+        }
+        else {
+            String msg = "NSSI service instance not found in AAI for nssi id " + nssiId
+            LOGGER.error(msg)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+        }
+
+        //Setting correlator as requestId
+        String requestId = execution.getVariable("msoRequestId")
+        execution.setVariable("NSSI_correlator", requestId)
+
+        //Setting messageType for all Core slice as cn
+        String messageType = "cn"
+        execution.setVariable("NSSI_messageType", messageType)
+
+        //Prepare Callback
+        String timeout = execution.getVariable("timeout")
+        if (isBlank(timeout)) {
+            timeout = UrnPropertiesReader.getVariable("mso.oof.timeout", execution);
+            if (isBlank(timeout)) {
+                timeout = "PT30M"
+            }
+        }
+
+        String nxlId = nssi.getServiceInstanceId()
+        String nxlType = "NSSI"
+        String oofRequest = getOofUtils().buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, nssi.getServiceInstanceId())
+        LOGGER.debug("**** Terminate Nxi Request: "+oofRequest)
+
+        LOGGER.debug("${PREFIX} Exit buildOOFRequest")
+
+        return oofRequest
     }
 
 
@@ -198,24 +272,29 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void deleteServiceOrder(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start deleteServiceOrder")
+        LOGGER.debug("${PREFIX} Start deleteServiceOrder")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
         try {
             //url:/nbi/api/v4/serviceOrder/"
-            def nbiEndpointUrl = UrnPropertiesReader.getVariable("nbi.endpoint.url", execution)
+            def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution)
 
             ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
 
-            String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+            //String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+
+            GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
+
+            // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
+            String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
 
             currentNSSI['deleteServiceOrderURL'] = url
 
             String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
-            String basicAuth =  UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
+            String basicAuth =  UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
 
-            String basicAuthValue = encryptBasicAuth(basicAuth, msoKey)
+            /*String basicAuthValue = encryptBasicAuth(basicAuth, msoKey)
             def authHeader = ""
             if (basicAuthValue != null) {
                 String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey)
@@ -230,14 +309,21 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
                 LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
                 exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
                         "value null")
-            }
+            } */
+
+            def authHeader = utils.getBasicAuth(basicAuth, msoKey)
 
             String callDeleteServiceOrderResponse = callDeleteServiceOrder(execution, url, authHeader)
             String errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode")
-            String deleteServcieResponse = ""
 
             if(errorCode == null || errorCode.isEmpty()) { // No error
-                deleteServcieResponse = callDeleteServiceOrderResponse // check the response ???
+                String macroOperationId = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestId")
+                String requestSelfLink = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestSelfLink")
+
+                execution.setVariable("macroOperationId",  macroOperationId)
+                execution.setVariable("requestSelfLink", requestSelfLink)
+
+                currentNSSI['requestSelfLink'] = requestSelfLink
             }
             else {
                 LOGGER.error(jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
@@ -249,27 +335,34 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
         }
 
-        LOGGER.trace("${PREFIX} Exit deleteServiceOrder")
+        LOGGER.debug("${PREFIX} Exit deleteServiceOrder")
     }
 
 
-    String callDeleteServiceOrder(DelegateExecution execution, String urlString, String authHeader) {
+    String callDeleteServiceOrder(DelegateExecution execution, String url, String authHeader) {
+        LOGGER.debug("${PREFIX} Start callDeleteServiceOrder")
+
         String errorCode = ""
         String errorMessage = ""
         String response = ""
 
         try {
-            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(urlString), ONAPComponents.EXTERNAL)
+            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
             httpClient.addAdditionalHeader("Authorization", authHeader)
             httpClient.addAdditionalHeader("Accept", "application/json")
             Response httpResponse = httpClient.delete()
 
-            if (httpResponse.hasEntity()) {
+            int soResponseCode = httpResponse.getStatus()
+            LOGGER.debug("callDeleteServiceInstance: soResponseCode = " + soResponseCode)
+
+            if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
                 response = httpResponse.readEntity(String.class)
+
+                LOGGER.debug("callDeleteServiceInstance: response = " + response)
             }
             else {
                 errorCode = 500
-                errorMessage = "No response received."
+                errorMessage = "Response code is " + soResponseCode
 
                 response =  "{\n" +
                         " \"errorCode\": \"${errorCode}\",\n" +
@@ -278,7 +371,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
             }
         }
         catch (any) {
-            String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
+            String msg = "Exception in DoDeallocateCoreNSSI.callDeleteServiceOrder. " + any.getCause()
 
             response =  "{\n" +
                     " \"errorCode\": \"7000\",\n" +
@@ -286,6 +379,8 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
                     "}"
         }
 
+        LOGGER.debug("${PREFIX} Exit callDeleteServiceOrder")
+
         return response
     }
 
@@ -295,7 +390,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void removeNSSIAssociationWithNSI(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start removeNSSIAssociationWithNSI")
+        LOGGER.debug("${PREFIX} Start removeNSSIAssociationWithNSI")
 
         AAIResourcesClient client = getAAIClient()
 
@@ -308,38 +403,54 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
 
         // NSSI
         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
-        ServiceInstance nssi = currentNSSI['nssi']
+
 
         String allottedResourceId = null
 
-        // Removes Allotted resource
-        List<AllottedResource> allottedResources = nssi.getAllottedResources()?.getAllottedResource()
-        if(allottedResources != null && allottedResources.size() == 1) { // Shouldn contain one allotted resource
-            allottedResourceId = allottedResources.get(0).getId()
-            allottedResources.remove(0)
+
+        AAIResultWrapper nssiWrapper = client.get(nssiUri)
+        Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
+
+        if (nssiRelationships.isPresent()) {
+            // Allotted Resource
+            for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
+                AAIResultWrapper arWrapper = client.get(allottedResourceUri)
+                Optional<Relationships> arRelationships = arWrapper.getRelationships()
+
+                if(arRelationships.isPresent()) {
+                    // NSI
+                    for (AAIResourceUri nsiUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
+                        Optional<ServiceInstance> nsiOpt = client.get(ServiceInstance.class, nsiUri)
+
+                        if (nsiOpt.isPresent()) {
+                            ServiceInstance nsi = nsiOpt.get()
+                            if(nsi.getServiceRole().equals("nsi")) { // Service instance as NSI
+                                // Removes NSSI association with NSI
+                                try {
+                                    client.disconnect(nssiUri, nsiUri)
+                                }
+                                catch (Exception e) {
+                                    exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI dosconnect call: " + e.getMessage())
+                                }
+                            }
+                        }
+                        else {
+                            LOGGER.warn("No NSI found for NSSI id " + nssiId)
+                        }
+                    }
+                }
+                else {
+                    LOGGER.warn("No relationships found for Allotted Resource for NSSI id " + nssiId)
+                }
+
+            }
         }
         else {
-            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No allotted resource found for NSSI id = " + nssiId)
+            LOGGER.warn("No relationships  found for nssi id = " + nssiId)
         }
 
-        try {
-            client.update(nssiUri, nssi)
-        }catch(Exception e){
-            exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
-        }
-
-
-        // Remove association between NSI and Allotted Resource
-        AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId))
-        AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResourceId))
-
-        try {
-            client.disconnect(nsiUri, allottedResourceUri)
-        }catch(Exception e){
-            exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
-        }
 
-        LOGGER.trace("${PREFIX} Exit removeNSSIAssociationWithNSI")
+        LOGGER.debug("${PREFIX} Exit removeNSSIAssociationWithNSI")
     }
 
 
@@ -348,7 +459,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void deleteNSSIServiceInstance(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start deleteNSSIServiceInstance")
+        LOGGER.debug("${PREFIX} Start deleteNSSIServiceInstance")
 
         AAIResourcesClient client = getAAIClient()
 
@@ -358,12 +469,12 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
 
         try {
-            getAAIClient().delete(nssiUri)
+            client.delete(nssiUri)
         }catch(Exception e){
             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while NSSI Service Instance delete call: " + e.getMessage())
         }
 
-        LOGGER.trace("${PREFIX} Exit deleteNSSIServiceInstance")
+        LOGGER.debug("${PREFIX} Exit deleteNSSIServiceInstance")
     }
 
 
@@ -372,19 +483,72 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void getDeleteServiceOrderProgress(DelegateExecution execution) {
-        LOGGER.trace("${getPrefix()} Start getDeleteServiceOrderProgress")
+        LOGGER.debug("${getPrefix()} Start getDeleteServiceOrderProgress")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
-        String url = currentNSSI['deleteServiceOrderURL']
+        String url = currentNSSI['requestSelfLink']
+
+        String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
+
+        String basicAuth =  UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
 
-        getProgress(execution, url, "deleteStatus")
+        def authHeader = ""
+        String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
+
+        getProgress(execution, url, basicAuthValue, "deleteStatus")
 
+        LOGGER.debug("${getPrefix()} Exit getDeleteServiceOrderProgress")
     }
 
 
-    @Override
-    String getPrefix() {
+    /**
+     * Calculates a final list of S-NSSAI
+     * @param execution
+     */
+    void calculateSNSSAI(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start calculateSNSSAI")
+
+        def currentNSSI = execution.getVariable("currentNSSI")
+
+        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
+
+        String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+        List<String> snssais = new ArrayList<>()
+
+        String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
+
+        boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
+
+        if(!isTerminateNSSI) { // NSSI should not be terminated
+            LOGGER.debug("calculateSNSSAI: associatedProfiles.size()" + associatedProfiles.size())
+            for (SliceProfile associatedProfile : associatedProfiles) {
+                if (!associatedProfile.getProfileId().equals(givenSliceProfileId)) { // not given profile id
+                    LOGGER.debug("calculateSNSSAI: associatedProfile.getSNssai()" + associatedProfile.getSNssai())
+                    snssais.add(associatedProfile.getSNssai())
+                } else {
+                    currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
+                }
+            }
+        }
+
+        currentNSSI['S-NSSAIs'] = snssais
+
+        LOGGER.debug("${getPrefix()} Exit calculateSNSSAI")
+    }
+
+
+    /**
+     * OofUtils
+     * @return new OofUtils()
+     */
+    OofUtils getOofUtils() {
+        return new OofUtils()
+    }
+
+
+    private String getPrefix() {
         return PREFIX
     }
 
index ff16184..a52763f 100644 (file)
@@ -29,6 +29,8 @@ import org.onap.aai.domain.yang.v19.SliceProfile
 import org.onap.aai.domain.yang.v19.SliceProfiles
 import org.onap.aaiclient.client.aai.AAIResourcesClient
 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
+import org.onap.aaiclient.client.aai.entities.Relationships
 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
@@ -56,15 +58,50 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
     private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
 
 
+    @Override
+    void preProcessRequest(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start preProcessRequest")
+
+        super.preProcessRequest(execution)
+
+        String modifyAction = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "modifyAction")
+        if (isBlank(modifyAction)) {
+            String msg = "modifyAction is mandatory parameter"
+            exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+        }
+        else {
+            String createSliceProfileInstance = ""
+            if(modifyAction.equals("allocate")) { // In case Slice Profile should be created
+                createSliceProfileInstance = "true"
+            }
+            else if(modifyAction.equals("deallocate")) { // In case Slice Profile should be created
+                createSliceProfileInstance = "false"
+            }
+            else {
+                String msg = "Value of modifyAction parameter should be either allocate or deallocate"
+                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+            }
+
+            execution.setVariable("isCreateSliceProfileInstance", createSliceProfileInstance)
+        }
+
+        execution.setVariable("operationType", "MODIFY")
+
+        LOGGER.debug("${getPrefix()} Exit preProcessRequest")
+    }
+
+
     /**
      * Prepares Slice Profile
      * @param execution
      * @return SLice Profile
      */
     SliceProfile prepareSliceProfile(DelegateExecution execution) {
+        LOGGER.debug("${PREFIX} Start prepareSliceProfile")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
-        String sliceProfileID = currentNSSI['sliceProfileId']
+        String givenSliceProfileId = currentNSSI['sliceProfileId'] //UUID.randomUUID().toString()
         Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class)
 
         SliceProfile sliceProfile = new SliceProfile()
@@ -77,41 +114,43 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
         sliceProfile.setConnDensity(0)
         sliceProfile.setSNssai(currentNSSI['S-NSSAI'])
 
-        if(!isBlank(sliceProfileMap.get("expDataRateUL"))) {
+        if(sliceProfileMap.get("expDataRateUL") != null) {
             sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
         }
 
-        if(!isBlank(sliceProfileMap.get("expDataRateDL"))) {
+        if(sliceProfileMap.get("expDataRateDL") != null) {
             sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
         }
 
-        if(!isBlank(sliceProfileMap.get("activityFactor"))) {
+        if(sliceProfileMap.get("activityFactor") != null) {
             sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
         }
 
-        if(!isBlank(sliceProfileMap.get("resourceSharingLevel"))) {
+        if(sliceProfileMap.get("resourceSharingLevel") != null) {
             sliceProfile.setResourceSharingLevel(sliceProfileMap.get("resourceSharingLevel").toString())
         }
 
-        if(!isBlank(sliceProfileMap.get("uEMobilityLevel"))) {
+        if(sliceProfileMap.get("uEMobilityLevel") != null) {
             sliceProfile.setUeMobilityLevel(sliceProfileMap.get("uEMobilityLevel").toString())
         }
 
-        if(!isBlank(sliceProfileMap.get("coverageAreaTAList"))) {
+        if(sliceProfileMap.get("coverageAreaTAList") != null) {
             sliceProfile.setCoverageAreaTAList(sliceProfileMap.get("coverageAreaTAList").toString())
         }
 
-        if(!isBlank(sliceProfileMap.get("maxNumberofUEs"))) {
-            sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberofUEs").toString()))
+        if(sliceProfileMap.get("maxNumberOfUEs") != null) {
+            sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberOfUEs").toString()))
         }
 
-        if(!isBlank(sliceProfileMap.get("latency"))) {
+        if(sliceProfileMap.get("latency") != null) {
             sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
         }
 
-        sliceProfile.setProfileId(sliceProfileID)
+        sliceProfile.setProfileId(givenSliceProfileId)
         sliceProfile.setE2ELatency(0)
 
+        LOGGER.debug("${PREFIX} Exit prepareSliceProfile")
+
         return sliceProfile
     }
 
@@ -122,6 +161,7 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
      * @return Slice Profile Instance
      */
     ServiceInstance prepareSliceProfileInstance(DelegateExecution execution) {
+        LOGGER.debug("${PREFIX} Start prepareSliceProfileInstance")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -152,6 +192,8 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
 
         // TO DO: Model info
 
+        LOGGER.debug("${PREFIX} Exit prepareSliceProfileInstance")
+
         return sliceProfileInstance
     }
 
@@ -162,7 +204,7 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void createSliceProfileInstance(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
+        LOGGER.debug("${PREFIX} Start createSliceProfileInstance")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -188,7 +230,7 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Slice Profile create call:" + ex.getMessage())
         }
 
-        LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
+        LOGGER.debug("${PREFIX} Exit createSliceProfileInstance")
     }
 
 
@@ -198,6 +240,8 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
      * @return AllottedResource
      */
     AllottedResource createAllottedResource(DelegateExecution execution) {
+        LOGGER.debug("${PREFIX} Start createAllottedResource")
+
         def currentNSSI = execution.getVariable("currentNSSI")
 
         String globalSubscriberId = execution.getVariable("globalSubscriberId")
@@ -223,6 +267,8 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Allotted Resource create call:" + ex.getMessage())
         }
 
+        LOGGER.debug("${PREFIX} Exit createAllottedResource")
+
         return allottedResource
     }
 
@@ -233,7 +279,7 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
      * @param execution
      */
     void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
-        LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
+        LOGGER.debug("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
 
         def currentNSSI = execution.getVariable("currentNSSI")
 
@@ -247,12 +293,12 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
         AllottedResource allottedResource = createAllottedResource(execution)
         AAIResourceUri allottedResourceUri = (AAIResourceUri)currentNSSI['allottedResourceUri']
 
-        // Updates Slice Profile Instance with Allotted Resource
+        // Associates Allotted Resource with Slice Profile Instance
         try {
             AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId))
             Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
             if (sliceProfileInstanceOpt.isPresent()) {
-                ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+             /*   ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
 
                 AllottedResources allottedResources = sliceProfileInstance.getAllottedResources()
                 if(allottedResources == null) {
@@ -262,7 +308,9 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
                 allottedResources.getAllottedResource().add(allottedResource)
                 sliceProfileInstance.setAllottedResources(allottedResources)
 
-                client.update(sliceProfileInstanceUri, sliceProfileInstance)
+                client.update(sliceProfileInstanceUri, sliceProfileInstance) */
+
+                client.connect(sliceProfileInstanceUri, allottedResourceUri)
             }
             else {
                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found with id = " + sliceProfileInstanceId)
@@ -276,17 +324,83 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI {
         // Associates NSSI with Allotted Resource
         try {
             AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
-            client.connect(nssiUri, allottedResourceUri, AAIEdgeLabel.USES)
+            client.connect(allottedResourceUri, nssiUri)
         } catch(Exception e){
             exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI with Allotted Resource connect call: " + e.getMessage())
         }
 
-        LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
+        LOGGER.debug("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
     }
 
 
     @Override
-    String getPrefix() {
+    void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {
+        LOGGER.debug("${PREFIX} Start checkAssociatedProfiles")
+
+        LOGGER.debug("associatedProfiles == null = " + (associatedProfiles == null))
+        if(associatedProfiles == null || associatedProfiles.isEmpty()) {
+            String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" )
+            boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
+
+            if(!isCreateSliceProfileInstance) { // New Slice Profile Instance should not be created
+                String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
+                LOGGER.error(msg)
+                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+            }
+        }
+
+        LOGGER.debug("${PREFIX} Exit checkAssociatedProfiles")
+    }
+
+
+    /**
+     * Calculates a final list of S-NSSAI
+     * @param execution
+     */
+    void calculateSNSSAI(DelegateExecution execution) {
+        LOGGER.debug("${getPrefix()} Start calculateSNSSAI")
+
+        def currentNSSI = execution.getVariable("currentNSSI")
+
+        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
+
+        String currentSNSSAI = currentNSSI['S-NSSAI']
+
+        String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+        List<String> snssais = new ArrayList<>()
+
+        String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" )
+
+        boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
+
+        if(isCreateSliceProfileInstance) { // Slice Profile Instance has to be created
+            for (SliceProfile associatedProfile : associatedProfiles) {
+                snssais.add(associatedProfile.getSNssai())
+            }
+
+            snssais.add(currentSNSSAI)
+        }
+        else { // Slice profile instance has to be deleted
+            if(associatedProfiles != null) {
+                for (SliceProfile associatedProfile : associatedProfiles) {
+                    if (!associatedProfile.getProfileId().equals(givenSliceProfileId)) { // not given profile id
+                        LOGGER.debug("calculateSNSSAI: associatedProfile.getSNssai()" + associatedProfile.getSNssai())
+                        snssais.add(associatedProfile.getSNssai())
+                    } else {
+                        currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
+                    }
+                }
+            }
+        }
+
+        currentNSSI['S-NSSAIs'] = snssais
+
+        LOGGER.debug("${getPrefix()} Exit calculateSNSSAI")
+    }
+
+
+    private String getPrefix() {
         return PREFIX
     }
 
index 9707dd2..13edfee 100644 (file)
@@ -33,16 +33,23 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
+import org.onap.logging.filter.base.ONAPComponents
+import org.onap.so.bpmn.common.scripts.CatalogDbUtils
+import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.common.scripts.MsoUtils
 import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.serviceinstancebeans.RequestDetails
 
 import javax.ws.rs.core.Response
 import java.time.Instant
 
 import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertNull
 import static org.junit.Assert.assertTrue
 import static org.mockito.Mockito.*
 
@@ -53,37 +60,6 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
     }
 
 
-    @Test
-    void testPreProcessRequest() {
-
-        String nssiId = "5G-999"
-        when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
-
-        String nsiId = "5G-777"
-        when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
-
-        String snssai = "S-NSSAI"
-        String snssaiList = "[ \"${snssai}\" ]"
-        String sliceProfileId = "slice-profile-id"
-        String sliceParams =  "{\n" +
-                "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" +
-                "}"
-        when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
-
-        DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
-        dcnssi.preProcessRequest(mockExecution)
-
-        def currentNSSI = [:]
-        currentNSSI.put("nssiId", nssiId)
-        currentNSSI.put("nsiId", nsiId)
-        currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}")
-        currentNSSI.put("S-NSSAI", snssai)
-        currentNSSI.put("sliceProfileId", sliceProfileId)
-        Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
-
-    }
-
-
     @Test
     void testGetNetworkServiceInstance() {
         def currentNSSI = [:]
@@ -181,69 +157,6 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
     }
 
 
-    @Test
-    void testGetNSSIAssociatedProfiles() {
-        def currentNSSI = [:]
-        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
-        String nssiId = "5G-999"
-        ServiceInstance nssi = new ServiceInstance()
-        nssi.setServiceInstanceId(nssiId)
-        currentNSSI.put("nssiId", nssiId)
-
-        SliceProfiles sliceProfiles = new SliceProfiles()
-
-        List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
-        slProfiles.add(new SliceProfile())
-        slProfiles.add(new SliceProfile())
-
-        //nssi.setSliceProfiles(sliceProfiles)
-        currentNSSI.put("nssi", nssi)
-
-        DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
-        when(spy.getAAIClient()).thenReturn(client)
-
-        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
-
-        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
-        Relationships rsMock = mock(Relationships.class)
-        Optional<Relationships> orsMock = Optional.of(rsMock)
-        List<AAIResourceUri> allottedUris = new ArrayList<>()
-        AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
-        allottedUris.add(allottedUri)
-
-        when(client.get(nssiUri)).thenReturn(wrapperMock)
-        when(wrapperMock.getRelationships()).thenReturn(orsMock)
-        when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
-
-        String sliceProfileInstanceId = "slice-profile-instance-id"
-        ServiceInstance sliceProfileInstance = new ServiceInstance()
-        sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
-        sliceProfileInstance.setServiceRole("slice-profile-instance")
-
-        List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>()
-        AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId()))
-        sliceProfileInstanceUris.add(sliceProfileInstanceUri)
-
-        Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
-
-        when(client.get(allottedUri)).thenReturn(wrapperMock)
-        when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris)
-        when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
-
-
-        SliceProfiles sps = new SliceProfiles()
-        sps.getSliceProfile().addAll(slProfiles)
-        sliceProfileInstance.setSliceProfiles(sps)
-
-        spy.getNSSIAssociatedProfiles(mockExecution)
-
-        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
-        assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null)
-        assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
-    }
-
-
     @Test
     void testInvokePUTServiceInstance() {
         def currentNSSI = [:]
@@ -263,13 +176,18 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
         when(spy.getAAIClient()).thenReturn(client)
 
-        when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
+        GenericVnf genericVnf = new GenericVnf()
+        genericVnf.setServiceId("service-id")
+        genericVnf.setVnfName("vnf-name")
+        genericVnf.setModelInvariantId("model-invariant-id")
+        genericVnf.setModelCustomizationId("model-customization-id")
+        genericVnf.setVnfName("vnf-name")
+        genericVnf.setVnfId("vnf-id")
 
-        String authHeaderResponse =  "auth-header"
+        currentNSSI.put("constituteVnf", genericVnf)
 
-        when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
 
-        String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
+        String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
 
         String callPUTServiceInstanceResponse = "put"
 
@@ -279,13 +197,36 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
 
         when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
 
-        when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
+        MsoUtils msoUtilsMock = mock(MsoUtils.class)
+        String basicAuth = "basicAuth"
+        when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+        HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+        when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+        Response responseMock = mock(Response.class)
+
+        HttpClient httpClientMock = mock(HttpClient.class)
+
+        when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+        when(httpClientMock.put(requestDetailsStr)).thenReturn(responseMock)
+
+        when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
+
+        String macroOperationId = "request-id"
+        String requestSelfLink = "request-self-link"
+        String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
+        when(responseMock.readEntity(String.class)).thenReturn(entity)
 
         spy.invokePUTServiceInstance(mockExecution)
+
+        Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
+        Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
     }
 
 
-    @Test
+    @Test(expected = Test.None.class)
     void testRemoveSPAssociationWithNSSI() {
         def currentNSSI = [:]
 
@@ -349,7 +290,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
 
         spy.removeSPAssociationWithNSSI(mockExecution)
 
-        assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
+     //   assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
     }
 
 
@@ -471,6 +412,15 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
 
         prepareProject(cloudRegionAAIUri)
 
+        CatalogDbUtilsFactory catalogDbUtilsFactoryMock = mock(CatalogDbUtilsFactory.class)
+        when(spy.getCatalogDbUtilsFactory()).thenReturn(catalogDbUtilsFactoryMock)
+
+        CatalogDbUtils catalogDbUtilsMock = mock(CatalogDbUtils.class)
+        when(catalogDbUtilsFactoryMock.create()).thenReturn(catalogDbUtilsMock)
+
+        String json = "{\"serviceResources\":{\"serviceVnfs\": [{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"},\"vfModules\":[{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"}}]}]}}"
+        when(catalogDbUtilsMock.getServiceResourcesByServiceModelInvariantUuidString(mockExecution, networkServiceInstance.getModelInvariantId())).thenReturn(json)
+
         String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution)
 
         JsonUtils jsonUtil = new JsonUtils()
@@ -492,11 +442,16 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
         String nssiId = "5G-999"
         String nsiId = "5G-777"
 
+        ServiceInstance nssi = new ServiceInstance()
+        nssi.setServiceInstanceId(nssiId)
+        nssi.setModelVersionId(UUID.randomUUID().toString())
+
         currentNSSI.put("nssiId", nssiId)
         currentNSSI.put("nsiId", nsiId)
         currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
         currentNSSI.put("operationId", "operationId")
         currentNSSI.put("operationType", "operationType")
+        currentNSSI.put("nssi", nssi)
 
         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
 
@@ -515,11 +470,16 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
         String nssiId = "5G-999"
         String nsiId = "5G-777"
 
+        ServiceInstance nssi = new ServiceInstance()
+        nssi.setServiceInstanceId(nssiId)
+        nssi.setModelVersionId(UUID.randomUUID().toString())
+
         currentNSSI.put("nssiId", nssiId)
         currentNSSI.put("nsiId", nsiId)
         currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
         currentNSSI.put("operationId", "operationId")
         currentNSSI.put("operationType", "operationType")
+        currentNSSI.put("nssi", nssi)
 
         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
 
@@ -539,7 +499,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
     @Test
     void testGetPUTServiceInstanceProgressInProgress() {
 
-        executePUTServiceInstanceProgress("INPROGRESS")
+        executePUTServiceInstanceProgress("IN_PROGRESS")
         Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
     }
 
@@ -547,7 +507,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
     @Test
     void testGetPUTServiceInstanceProgressCompleted() {
 
-        executePUTServiceInstanceProgress("COMPLETED")
+        executePUTServiceInstanceProgress("COMPLETE")
         Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed")
     }
 
@@ -567,6 +527,21 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
     }
 
 
+    @Test
+    void testPostProcessRequest() {
+
+        def currentNSSI = [:]
+        mockExecution.setVariable("currentNSSI", currentNSSI)
+
+        DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
+        dcnssi.postProcessRequest(mockExecution)
+
+        currentNSSI = mockExecution.getVariable("currentNSSI")
+        assertNull("currentNSSI is not null", currentNSSI)
+
+    }
+
+
     void executePUTServiceInstanceProgress(String state) {
 
         def currentNSSI = [:]
@@ -575,23 +550,37 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
 
         String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777"
 
-        currentNSSI.put("putServiceInstanceURL", url)
+        currentNSSI['requestSelfLink'] =  url
 
         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
 
         ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
         when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
 
-        ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
+       // ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
 
-        when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
+       // when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
 
+        MsoUtils msoUtilsMock = mock(MsoUtils.class)
+        String basicAuth = "basicAuth"
+        when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+        HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+        when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
         Response responseMock = mock(Response.class)
-        when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
+
+        HttpClient httpClientMock = mock(HttpClient.class)
+
+
+        when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+        when(httpClientMock.get()).thenReturn(responseMock)
+//        when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
 
         when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
 
-        String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
+        String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
         when(responseMock.readEntity(String.class)).thenReturn(entity)
 
         spy.getPUTServiceInstanceProgress(mockExecution)
@@ -750,4 +739,5 @@ class DoCommonCoreNSSITest extends MsoGroovyTest {
         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
         when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
     }
+
 }
index 26b96a0..5bf4f40 100644 (file)
 
 package org.onap.so.bpmn.infrastructure.scripts
 
+import com.fasterxml.jackson.databind.ObjectMapper
 import org.junit.Before
 import org.junit.Test
 import org.mockito.Mockito
 import org.onap.aai.domain.yang.v19.*
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
+import org.onap.aaiclient.client.aai.entities.Relationships
 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
+import org.onap.logging.filter.base.ONAPComponents
 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.scripts.OofUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.serviceinstancebeans.RequestDetails
 
 import javax.ws.rs.core.Response
 
@@ -46,11 +55,45 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
     }
 
 
+    @Test
+    void testPreProcessRequest() {
+
+        String nssiId = "5G-999"
+        when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
+
+        String nsiId = "5G-777"
+        when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
+
+        String snssai = "S-NSSAI"
+        String snssaiList = "[ \"${snssai}\" ]"
+        String sliceProfileId = "slice-profile-id"
+        String modifyAction = "allocate"
+        String sliceParams =  "{\n" +
+                "\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}\n" +
+                "}"
+        when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
+
+        DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
+        obj.preProcessRequest(mockExecution)
+
+        def currentNSSI = [:]
+        currentNSSI.put("nssiId", nssiId)
+        currentNSSI.put("nsiId", nsiId)
+        currentNSSI.put("sliceProfile", sliceParams)
+        currentNSSI.put("S-NSSAI", snssai)
+        currentNSSI.put("sliceProfileId", sliceProfileId)
+        Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
+
+    }
+
+
     @Test
     void testExecuteTerminateNSSIQuery() {
 
         def currentNSSI = [:]
-        currentNSSI.put("nssiId","5G-999")
+
+        String nssiId = "5G-999"
+        currentNSSI.put("nssiId", nssiId)
 
         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
 
@@ -62,6 +105,9 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
         DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
         when(spy.getAAIClient()).thenReturn(client)
 
+        OofUtils oofUtilsMock = mock(OofUtils.class)
+        when(spy.getOofUtils()).thenReturn(oofUtilsMock)
+
         when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")
 
         String authHeaderResponse =  "auth-header"
@@ -73,6 +119,14 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
 
         when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
 
+        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+
+        ServiceInstance nssi = new ServiceInstance()
+        nssi.setServiceInstanceId("5G-999")
+        Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
+
+        when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
+
         String urlString = "http://oof.onap:8088"
 
         String httpRequest =    "{\n" +
@@ -85,7 +139,16 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
                 "    }\n" +
                 "}"
 
-        boolean terminateResponse = true
+        String requestId = "request-id"
+        String nxlId = nssi.getServiceInstanceId()
+        String nxlType = "NSSI"
+        String messageType = "cn"
+        String serviceInstanceId = nssi.getServiceInstanceId()
+
+        when(mockExecution.getVariable("msoRequestId")).thenReturn(requestId)
+        when(oofUtilsMock.buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, serviceInstanceId)).thenReturn(httpRequest)
+
+        String terminateResponse = "false"
 
         String oofResponse =   "{\n" +
                 " \"requestId\": \"mso-request-id\",\n" +
@@ -96,18 +159,28 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
                 " \"reason\": \"\"\n" +
                 " }\n"
 
-        String oofCallResponse = oofResponse
+        String apiPath =  "/api/oof/terminate/nxi/v1"
 
-      /*  String oofCallResponse =  "{\n" +
-                " \"errorCode\": \"401\",\n" +
-                " \"errorMessage\": \"Exception during the call\"\n" +
-                "}" */
+        urlString = urlString + apiPath
+
+        HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+        when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+        Response responseMock = mock(Response.class)
+
+        HttpClient httpClientMock = mock(HttpClient.class)
+
+        when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
 
-        when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)
+        when(httpClientMock.post(httpRequest)).thenReturn(responseMock)
+
+        when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
+
+        when(responseMock.readEntity(String.class)).thenReturn(oofResponse)
 
         spy.executeTerminateNSSIQuery(mockExecution)
 
-        verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)
+        Mockito.verify(mockExecution,times(1)).setVariable("isTerminateNSSI", terminateResponse)
 
     }
 
@@ -125,56 +198,101 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
 
         currentNSSI.put("networkServiceInstance", networkServiceInstance)
 
-        when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.onap:8088")
+        when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
         when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
         when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
 
         DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
         when(spy.getAAIClient()).thenReturn(client)
 
-        when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
+        GenericVnf genericVnf = new GenericVnf()
+        genericVnf.setServiceId("service-id")
+        genericVnf.setVnfName("vnf-name")
+        genericVnf.setModelInvariantId("model-invariant-id")
+        genericVnf.setModelCustomizationId("model-customization-id")
+        genericVnf.setVnfName("vnf-name")
+        genericVnf.setVnfId("vnf-id")
 
-        String authHeaderResponse =  "auth-header"
+        currentNSSI.put("constituteVnf", genericVnf)
 
-        /*  String authHeaderResponse =  "{\n" +
-                  " \"errorCode\": \"401\",\n" +
-                  " \"errorMessage\": \"Bad request\"\n" +
-                  "}" */
+        String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
 
-        when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+        RequestDetails requestDetails = new RequestDetails()
+        ObjectMapper mapper = new ObjectMapper()
+        String requestDetailsStr = mapper.writeValueAsString(requestDetails)
+
+        when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
+
+        MsoUtils msoUtilsMock = mock(MsoUtils.class)
+        String basicAuth = "basicAuth"
+        when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+        HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+        when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+        Response responseMock = mock(Response.class)
 
-        String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+        HttpClient httpClientMock = mock(HttpClient.class)
 
-        String callDeleteServiceOrderResponse = "deleted"
+        when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
 
-        when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)
+        when(httpClientMock.delete()).thenReturn(responseMock)
+
+        when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
+
+        String macroOperationId = "request-id"
+        String requestSelfLink = "request-self-link"
+        String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
+        when(responseMock.readEntity(String.class)).thenReturn(entity)
 
         spy.deleteServiceOrder(mockExecution)
+
+        Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
+        Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
+
+        assertTrue(currentNSSI['requestSelfLink'].equals(requestSelfLink))
     }
 
 
     @Test
-    void testCalculateSNSSAI() {
+    void testCalculateSNSSAITerminateNSSI() {
+        invokeCalculateSNSSAI("true")
+    }
+
+    @Test
+    void testCalculateSNSSAINotTerminateNSSI() {
+        invokeCalculateSNSSAI("false")
+    }
+
+    void invokeCalculateSNSSAI(String isTerminateNSSI) {
         def currentNSSI = [:]
         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
 
+        when(mockExecution.getVariable("isTerminateNSSI")).thenReturn(isTerminateNSSI)
+
         String theSNSSAI = "theS-NSSAI"
 
         currentNSSI.put("S-NSSAI", theSNSSAI)
 
+        String theSliceProfileId = "the-slice-profile-id"
+        currentNSSI['sliceProfileId'] = theSliceProfileId
+
         List<SliceProfile> associatedProfiles = new ArrayList<>()
         SliceProfile sliceProfile1 = new SliceProfile()
-        sliceProfile1.setSNssai("snssai1")
+        sliceProfile1.setProfileId(theSliceProfileId)
+        sliceProfile1.setSNssai(theSNSSAI)
 
         SliceProfile sliceProfile2 = new SliceProfile()
-        sliceProfile2.setSNssai(theSNSSAI)
+        sliceProfile2.setSNssai("snssai2")
 
         SliceProfile sliceProfile3 = new SliceProfile()
         sliceProfile3.setSNssai("snssai3")
 
-        associatedProfiles.add(sliceProfile1)
-        associatedProfiles.add(sliceProfile2)
-        associatedProfiles.add(sliceProfile3)
+        if(isTerminateNSSI.equals("false")) {
+            associatedProfiles.add(sliceProfile1)
+            associatedProfiles.add(sliceProfile2)
+            associatedProfiles.add(sliceProfile3)
+        }
 
         int sizeBefore = associatedProfiles.size()
 
@@ -186,9 +304,14 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
         List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
         SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
 
-        assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
-        assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
-        assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
+        if(isTerminateNSSI.equals("false")) {
+            assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
+            assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
+            assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
+        }
+        else {
+            assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == 0))
+        }
     }
 
 
@@ -212,6 +335,10 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
         ServiceInstance nssi = new ServiceInstance()
         nssi.setServiceInstanceId(nssiId)
 
+        ServiceInstance nsi = new ServiceInstance()
+        nsi.setServiceInstanceId(nsiId)
+        nsi.setServiceRole("nsi")
+
         AllottedResources allottedResources = new AllottedResources()
         AllottedResource allottedResource = new AllottedResource()
         allottedResource.setId(UUID.randomUUID().toString())
@@ -222,7 +349,26 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
 
         AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId))
 
-        doNothing().when(client).update(nssiUri, nssi)
+        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+        when(client.get(nssiUri)).thenReturn(wrapperMock)
+        Relationships rsMock = mock(Relationships.class)
+        Optional<Relationships> orsMock = Optional.of(rsMock)
+        when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+        List<AAIResourceUri> allottedUris = new ArrayList<>()
+        AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
+        allottedUris.add(allottedUri)
+
+        when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
+
+        List<AAIResourceUri> nsiUris = new ArrayList<>()
+        nsiUris.add(nsiUri)
+
+        Optional<ServiceInstance> nsiOpt = Optional.of(nsi)
+
+        when(client.get(allottedUri)).thenReturn(wrapperMock)
+        when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(nsiUris)
+        when(client.get(ServiceInstance.class, nsiUri)).thenReturn(nsiOpt)
 
         String globalSubscriberId = "globalSubscriberId"
         String subscriptionServiceType = "subscription-service-type"
@@ -231,7 +377,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
 
         AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResource.getId()))
 
-        doNothing().when(client).disconnect(nsiUri, allottedResourceUri)
+        doNothing().when(client).disconnect(nssiUri, nsiUri)
 
         spy.removeNSSIAssociationWithNSI(mockExecution)
 
@@ -270,7 +416,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
     @Test
     void testDeleteServiceOrderProgressInProgress() {
 
-        executeDeleteServiceOrderProgress("INPROGRESS")
+        executeDeleteServiceOrderProgress("IN_PROGRESS")
         Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing")
     }
 
@@ -278,7 +424,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
     @Test
     void testDeleteServiceOrderProgressCompleted() {
 
-        executeDeleteServiceOrderProgress("COMPLETED")
+        executeDeleteServiceOrderProgress("COMPLETE")
         Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed")
     }
 
@@ -290,23 +436,37 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
 
         String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777"
 
-        currentNSSI.put("deleteServiceOrderURL", url)
+        currentNSSI['requestSelfLink'] =  url
 
         DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
 
-        ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
+        /*ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
         when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
 
         ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
 
-        when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
+        when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) */
+
+        MsoUtils msoUtilsMock = mock(MsoUtils.class)
+        String basicAuth = "basicAuth"
+        when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
 
+        HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+        when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
         Response responseMock = mock(Response.class)
-        when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
+
+        HttpClient httpClientMock = mock(HttpClient.class)
+
+
+        when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+        when(httpClientMock.get()).thenReturn(responseMock)
+//        when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
 
         when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
 
-        String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
+        String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
         when(responseMock.readEntity(String.class)).thenReturn(entity)
 
         spy.getDeleteServiceOrderProgress(mockExecution)
index ac6f897..7293a23 100644 (file)
@@ -29,11 +29,14 @@ import org.onap.aai.domain.yang.v19.ServiceInstance
 import org.onap.aai.domain.yang.v19.SliceProfile
 import org.onap.aai.domain.yang.v19.SliceProfiles
 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
+import org.onap.aaiclient.client.aai.entities.Relationships
 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.springframework.data.domain.Slice
 
 import static org.junit.Assert.assertNotNull
 import static org.junit.Assert.assertTrue
@@ -47,6 +50,40 @@ class DoModifyCoreNSSITest extends MsoGroovyTest  {
     }
 
 
+    @Test
+    void testPreProcessRequest() {
+
+        String nssiId = "5G-999"
+        when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
+
+        String nsiId = "5G-777"
+        when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
+
+        String snssai = "S-NSSAI"
+        String snssaiList = "[ \"${snssai}\" ]"
+        String sliceProfileId = "slice-profile-id"
+        String modifyAction = "allocate"
+        String sliceParams =  "{\n" +
+                "\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}\n" +
+                ",\"modifyAction\":\"${modifyAction}\"\n" +
+                "}"
+        when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
+
+        DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
+        obj.preProcessRequest(mockExecution)
+
+        def currentNSSI = [:]
+        currentNSSI.put("nssiId", nssiId)
+        currentNSSI.put("nsiId", nsiId)
+        currentNSSI.put("sliceProfile", sliceParams)
+        currentNSSI.put("S-NSSAI", snssai)
+        currentNSSI.put("sliceProfileId", sliceProfileId)
+
+        Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
+
+    }
+
+
     @Test
     void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
         def currentNSSI = [:]
@@ -58,31 +95,37 @@ class DoModifyCoreNSSITest extends MsoGroovyTest  {
 
         currentNSSI.put("S-NSSAI", theSNSSAI)
 
+        String sliceProfileId = "the-slice-profile-id"
+        currentNSSI['sliceProfileId'] = sliceProfileId
+
         List<SliceProfile> associatedProfiles = new ArrayList<>()
         SliceProfile sliceProfile1 = new SliceProfile()
-        sliceProfile1.setSNssai("snssai1")
+        sliceProfile1.setProfileId(sliceProfileId)
+        sliceProfile1.setSNssai(theSNSSAI)
 
         SliceProfile sliceProfile2 = new SliceProfile()
+        sliceProfile2.setProfileId("sp-2")
         sliceProfile2.setSNssai(theSNSSAI)
 
         SliceProfile sliceProfile3 = new SliceProfile()
+        sliceProfile3.setProfileId("sp-3")
         sliceProfile3.setSNssai("snssai2")
 
         associatedProfiles.add(sliceProfile1)
         associatedProfiles.add(sliceProfile2)
         associatedProfiles.add(sliceProfile3)
 
-        int sizeBefore = associatedProfiles.size()
-
         currentNSSI.put("associatedProfiles", associatedProfiles)
 
+        when(mockExecution.getVariable("isCreateSliceProfileInstance" )).thenReturn(false)
+
         DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
         obj.calculateSNSSAI(mockExecution)
 
         List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
         SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
 
-        assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
+        assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (associatedProfiles.size() - 1)))
         assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
         assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
     }
@@ -233,4 +276,114 @@ class DoModifyCoreNSSITest extends MsoGroovyTest  {
 
     }
 
+
+    @Test
+    void testGetNSSIAssociatedProfilesCreateSLiceProfileEmptySLiceProfiles() {
+        invokeGetNSSIAssociatedProfiles("true", true)
+    }
+
+    @Test
+    void testGetNSSIAssociatedProfilesCreateSLiceProfileNonEmptySliceProfiles() {
+        invokeGetNSSIAssociatedProfiles("true", false)
+    }
+
+    @Test
+    void testGetNSSIAssociatedProfilesDeleteSLiceProfile() {
+        invokeGetNSSIAssociatedProfiles("false", false)
+    }
+
+    void invokeGetNSSIAssociatedProfiles(String isCreateSliceProfileInstance, boolean isEmptySliceProfiles) {
+        def currentNSSI = [:]
+        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+        String globalSubscriberId = "5GCustomer"
+        String subscriptionServiceType = "5G"
+        when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
+        when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
+
+        when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn(isCreateSliceProfileInstance)
+
+        String nssiId = "5G-999"
+        ServiceInstance nssi = new ServiceInstance()
+        nssi.setServiceInstanceId(nssiId)
+        currentNSSI.put("nssiId", nssiId)
+
+        String theSLiceProfileId = "slice-profile-id"
+        currentNSSI.put("sliceProfileId", theSLiceProfileId)
+
+        SliceProfiles sliceProfiles = new SliceProfiles()
+
+        List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
+
+        if(!isEmptySliceProfiles) {
+            SliceProfile sp1 = new SliceProfile()
+            sp1.setProfileId(theSLiceProfileId)
+            slProfiles.add(sp1)
+            slProfiles.add(new SliceProfile())
+        }
+
+        //nssi.setSliceProfiles(sliceProfiles)
+        currentNSSI.put("nssi", nssi)
+
+        DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
+        when(spy.getAAIClient()).thenReturn(client)
+
+        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+
+        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
+        Relationships rsMock = mock(Relationships.class)
+        Optional<Relationships> orsMock = Optional.of(rsMock)
+        List<AAIResourceUri> allottedUris = new ArrayList<>()
+        AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
+        allottedUris.add(allottedUri)
+
+        when(client.get(nssiUri)).thenReturn(wrapperMock)
+        when(wrapperMock.getRelationships()).thenReturn(orsMock)
+        when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
+
+        String sliceProfileInstanceId = "slice-profile-instance-id"
+        ServiceInstance sliceProfileInstance = new ServiceInstance()
+        sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
+        sliceProfileInstance.setServiceRole("slice-profile-instance")
+
+        List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>()
+        AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId()))
+        sliceProfileInstanceUris.add(sliceProfileInstanceUri)
+
+        Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
+
+        when(client.get(allottedUri)).thenReturn(wrapperMock)
+        when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris)
+        when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
+
+
+        SliceProfiles sps = new SliceProfiles()
+        sps.getSliceProfile().addAll(slProfiles)
+        sliceProfileInstance.setSliceProfiles(sps)
+
+        Optional<SliceProfiles> sliceProfilesOpt = Optional.of(sps)
+
+        org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
+                AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
+
+        def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
+        when(client.exists(sliceProfilesUri)).thenReturn(true)
+
+        when(client.get(sliceProfilesUri)).thenReturn(wrapperMock)
+
+        when(wrapperMock.asBean(SliceProfiles.class)).thenReturn(sliceProfilesOpt)
+
+        spy.getNSSIAssociatedProfiles(mockExecution)
+
+        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
+        int expectedSize = sps.getSliceProfile().size()
+
+        if(!isEmptySliceProfiles) {
+            assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null)
+        }
+
+        assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == expectedSize))
+    }
+
+
 }
index b55b7c4..bfc45f2 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1v4vnwb" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.1.1">
-  <bpmn:process id="Process_02hqnsq" isExecutable="true">
+  <bpmn:process id="DoDeallocateCoreNSSI" name="DoDeallocateCoreNSSI" isExecutable="true">
     <bpmn:startEvent id="StartEvent_1" name="Deallocate Core NSSI Flow">
       <bpmn:outgoing>Flow_0xxq2h8</bpmn:outgoing>
     </bpmn:startEvent>
@@ -13,7 +13,7 @@
     </bpmn:scriptTask>
     <bpmn:sequenceFlow id="Flow_0xxq2h8" sourceRef="StartEvent_1" targetRef="Activity_0u06qij" />
     <bpmn:scriptTask id="Activity_0wswwhj" name="Get Network Service Instance" scriptFormat="groovy">
-      <bpmn:incoming>Flow_189j30m</bpmn:incoming>
+      <bpmn:incoming>Flow_16bwdkl</bpmn:incoming>
       <bpmn:outgoing>Flow_16192dm</bpmn:outgoing>
       <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
 def dcnssi= new DoDeallocateCoreNSSI()
@@ -86,9 +86,6 @@ def dcnssi= new DoDeallocateCoreNSSI()
       <bpmn:outgoing>Flow_12nxpx6</bpmn:outgoing>
       <bpmn:outgoing>Flow_1r39237</bpmn:outgoing>
     </bpmn:exclusiveGateway>
-    <bpmn:endEvent id="Event_1vgebg2" name="End">
-      <bpmn:incoming>Flow_095vvrk</bpmn:incoming>
-    </bpmn:endEvent>
     <bpmn:scriptTask id="Activity_1gcmlps" name=" Delete the NSSI service instance\r" scriptFormat="groovy">
       <bpmn:incoming>Flow_1r39237</bpmn:incoming>
       <bpmn:outgoing>Flow_04hswb4</bpmn:outgoing>
@@ -137,15 +134,14 @@ def dcnssi= new DoDeallocateCoreNSSI()
     <bpmn:sequenceFlow id="Flow_009x8vn" sourceRef="Activity_0tanqh5" targetRef="Gateway_07ygtxz" />
     <bpmn:sequenceFlow id="Flow_12nxpx6" name="no" sourceRef="Gateway_07ygtxz" targetRef="Activity_0gs71qq" />
     <bpmn:sequenceFlow id="Flow_15rk73d" sourceRef="Activity_0gs71qq" targetRef="Activity_1npwfvi" />
-    <bpmn:scriptTask id="Activity_13qnpcn" name="Execute terminate NSSI query" scriptFormat="groovy">
+    <bpmn:scriptTask id="Activity_13qnpcn" name="Execute Terminate NSSI Query" scriptFormat="groovy">
       <bpmn:incoming>Flow_0g84uy5</bpmn:incoming>
-      <bpmn:outgoing>Flow_189j30m</bpmn:outgoing>
+      <bpmn:outgoing>Flow_16bwdkl</bpmn:outgoing>
       <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
 def dcnssi= new DoDeallocateCoreNSSI()
         dcnssi.executeTerminateNSSIQuery(execution)</bpmn:script>
     </bpmn:scriptTask>
     <bpmn:sequenceFlow id="Flow_0g84uy5" sourceRef="Activity_0u06qij" targetRef="Activity_13qnpcn" />
-    <bpmn:sequenceFlow id="Flow_189j30m" sourceRef="Activity_13qnpcn" targetRef="Activity_0wswwhj" />
     <bpmn:subProcess id="Activity_14l5j2f" name="Sub-process for FalloutHandler and Rollback" triggeredByEvent="true">
       <bpmn:startEvent id="Event_1blx2tk">
         <bpmn:outgoing>Flow_0z51qfz</bpmn:outgoing>
@@ -215,12 +211,11 @@ dcnssi.prepareFailedOperationStatusUpdate(execution)</bpmn:script>
         </camunda:connector>
       </bpmn:extensionElements>
       <bpmn:incoming>Flow_15rk73d</bpmn:incoming>
-      <bpmn:outgoing>Flow_095vvrk</bpmn:outgoing>
+      <bpmn:outgoing>Flow_0pj1yb5</bpmn:outgoing>
     </bpmn:serviceTask>
-    <bpmn:sequenceFlow id="Flow_095vvrk" sourceRef="Activity_1npwfvi" targetRef="Event_1vgebg2" />
     <bpmn:scriptTask id="Activity_1a5fd5v" name="Call Get Delete ServiceOrder Progress" scriptFormat="groovy">
       <bpmn:incoming>Flow_1b14can</bpmn:incoming>
-      <bpmn:incoming>Flow_1qej57v</bpmn:incoming>
+      <bpmn:incoming>Flow_0zxtlgn</bpmn:incoming>
       <bpmn:outgoing>Flow_1h8q1h1</bpmn:outgoing>
       <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
 def dcnssi= new DoDeallocateCoreNSSI()
@@ -235,7 +230,7 @@ dcnssi.getDeleteServiceOrderProgress(execution)</bpmn:script>
     <bpmn:sequenceFlow id="Flow_1mrr969" name="No" sourceRef="Gateway_13cwisg" targetRef="Event_062ulql" />
     <bpmn:scriptTask id="Activity_1ym1op6" name="Time Delay" scriptFormat="groovy">
       <bpmn:incoming>Flow_1j1en2h</bpmn:incoming>
-      <bpmn:outgoing>Flow_1qej57v</bpmn:outgoing>
+      <bpmn:outgoing>Flow_0zxtlgn</bpmn:outgoing>
       <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
 def dcnssi= new DoDeallocateCoreNSSI()
 dcnssi.timeDelay(execution)</bpmn:script>
@@ -243,7 +238,6 @@ dcnssi.timeDelay(execution)</bpmn:script>
     <bpmn:sequenceFlow id="Flow_1j1en2h" name="Yes" sourceRef="Gateway_13cwisg" targetRef="Activity_1ym1op6">
       <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("deleteStatus" ) == "processing" )}</bpmn:conditionExpression>
     </bpmn:sequenceFlow>
-    <bpmn:sequenceFlow id="Flow_1qej57v" sourceRef="Activity_1ym1op6" targetRef="Activity_1a5fd5v" />
     <bpmn:scriptTask id="Activity_07qrjro" name="Call Get PUT Service Instance Progress" scriptFormat="groovy">
       <bpmn:incoming>Flow_178myd8</bpmn:incoming>
       <bpmn:incoming>Flow_0att74c</bpmn:incoming>
@@ -274,31 +268,99 @@ dcnssi.timeDelay(execution)</bpmn:script>
       <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("putStatus" ) == "processing" )}</bpmn:conditionExpression>
     </bpmn:sequenceFlow>
     <bpmn:sequenceFlow id="Flow_0att74c" sourceRef="Activity_1lafl76" targetRef="Activity_07qrjro" />
+    <bpmn:scriptTask id="Activity_03j1rrj" name="PostProcess Incoming Request" scriptFormat="groovy">
+      <bpmn:incoming>Flow_0pj1yb5</bpmn:incoming>
+      <bpmn:outgoing>Flow_0eigzrb</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+        def dcnssi= new DoDeallocateCoreNSSI()
+        dcnssi.postProcessRequest(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="Flow_0pj1yb5" sourceRef="Activity_1npwfvi" targetRef="Activity_03j1rrj" />
+    <bpmn:endEvent id="Event_0zbwefx" name="Done">
+      <bpmn:incoming>Flow_0eigzrb</bpmn:incoming>
+    </bpmn:endEvent>
+    <bpmn:sequenceFlow id="Flow_0eigzrb" sourceRef="Activity_03j1rrj" targetRef="Event_0zbwefx" />
+    <bpmn:sequenceFlow id="Flow_16bwdkl" sourceRef="Activity_13qnpcn" targetRef="Activity_0wswwhj" />
+    <bpmn:sequenceFlow id="Flow_0zxtlgn" sourceRef="Activity_1ym1op6" targetRef="Activity_1a5fd5v" />
   </bpmn:process>
   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
-    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_02hqnsq">
-      <bpmndi:BPMNEdge id="Flow_189j30m_di" bpmnElement="Flow_189j30m">
-        <di:waypoint x="510" y="117" />
-        <di:waypoint x="580" y="117" />
+    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoDeallocateCoreNSSI">
+      <bpmndi:BPMNEdge id="Flow_0eigzrb_di" bpmnElement="Flow_0eigzrb">
+        <di:waypoint x="1470" y="670" />
+        <di:waypoint x="1532" y="670" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0g84uy5_di" bpmnElement="Flow_0g84uy5">
-        <di:waypoint x="360" y="117" />
-        <di:waypoint x="410" y="117" />
+      <bpmndi:BPMNEdge id="Flow_0pj1yb5_di" bpmnElement="Flow_0pj1yb5">
+        <di:waypoint x="1310" y="670" />
+        <di:waypoint x="1370" y="670" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_15rk73d_di" bpmnElement="Flow_15rk73d">
-        <di:waypoint x="1220" y="670" />
-        <di:waypoint x="1270" y="670" />
+      <bpmndi:BPMNEdge id="Flow_0att74c_di" bpmnElement="Flow_0att74c">
+        <di:waypoint x="990" y="560" />
+        <di:waypoint x="930" y="560" />
+        <di:waypoint x="930" y="490" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0afgah7_di" bpmnElement="Flow_0afgah7">
+        <di:waypoint x="1040" y="475" />
+        <di:waypoint x="1040" y="520" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1046" y="482" width="18" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1gxcve5_di" bpmnElement="Flow_1gxcve5">
+        <di:waypoint x="1065" y="450" />
+        <di:waypoint x="1112" y="450" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1083" y="432" width="15" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1r39237_di" bpmnElement="Flow_1r39237">
+        <di:waypoint x="770" y="695" />
+        <di:waypoint x="770" y="750" />
+        <di:waypoint x="880" y="750" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="772" y="701" width="17" height="14" />
+        </bpmndi:BPMNLabel>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_04hswb4_di" bpmnElement="Flow_04hswb4">
         <di:waypoint x="980" y="750" />
-        <di:waypoint x="1170" y="750" />
-        <di:waypoint x="1170" y="710" />
+        <di:waypoint x="1100" y="750" />
+        <di:waypoint x="1100" y="710" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0pvh1x9_di" bpmnElement="Flow_0pvh1x9">
+        <di:waypoint x="980" y="450" />
+        <di:waypoint x="1015" y="450" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1j1en2h_di" bpmnElement="Flow_1j1en2h">
+        <di:waypoint x="1105" y="350" />
+        <di:waypoint x="1000" y="350" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1019" y="352" width="18" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1mrr969_di" bpmnElement="Flow_1mrr969">
+        <di:waypoint x="1130" y="375" />
+        <di:waypoint x="1130" y="432" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1138" y="393" width="15" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1h8q1h1_di" bpmnElement="Flow_1h8q1h1">
+        <di:waypoint x="1000" y="230" />
+        <di:waypoint x="1130" y="230" />
+        <di:waypoint x="1130" y="325" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0g84uy5_di" bpmnElement="Flow_0g84uy5">
+        <di:waypoint x="360" y="117" />
+        <di:waypoint x="440" y="117" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_15rk73d_di" bpmnElement="Flow_15rk73d">
+        <di:waypoint x="1150" y="670" />
+        <di:waypoint x="1210" y="670" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_12nxpx6_di" bpmnElement="Flow_12nxpx6">
         <di:waypoint x="795" y="670" />
-        <di:waypoint x="1120" y="670" />
+        <di:waypoint x="1050" y="670" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="814" y="663" width="13" height="14" />
+          <dc:Bounds x="809" y="653" width="13" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_009x8vn_di" bpmnElement="Flow_009x8vn">
@@ -314,18 +376,18 @@ dcnssi.timeDelay(execution)</bpmn:script>
         <di:waypoint x="260" y="670" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_1b14can_di" bpmnElement="Flow_1b14can">
-        <di:waypoint x="800" y="240" />
-        <di:waypoint x="910" y="240" />
+        <di:waypoint x="820" y="230" />
+        <di:waypoint x="900" y="230" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_178myd8_di" bpmnElement="Flow_178myd8">
         <di:waypoint x="820" y="450" />
         <di:waypoint x="880" y="450" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_0e3yvck_di" bpmnElement="Flow_0e3yvck">
-        <di:waypoint x="775" y="117" />
-        <di:waypoint x="832" y="117" />
+        <di:waypoint x="795" y="117" />
+        <di:waypoint x="885" y="117" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="787" y="95" width="13" height="14" />
+          <dc:Bounds x="807" y="95" width="13" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_1qwi2ka_di" bpmnElement="Flow_1qwi2ka">
@@ -345,81 +407,31 @@ dcnssi.timeDelay(execution)</bpmn:script>
         <di:waypoint x="260" y="450" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_15ew9rs_di" bpmnElement="Flow_15ew9rs">
-        <di:waypoint x="750" y="142" />
-        <di:waypoint x="750" y="200" />
+        <di:waypoint x="770" y="142" />
+        <di:waypoint x="770" y="190" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="731" y="150" width="17" height="14" />
+          <dc:Bounds x="751" y="157" width="17" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_0nvtepd_di" bpmnElement="Flow_0nvtepd">
         <di:waypoint x="360" y="670" />
         <di:waypoint x="410" y="670" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1r39237_di" bpmnElement="Flow_1r39237">
-        <di:waypoint x="770" y="695" />
-        <di:waypoint x="770" y="750" />
-        <di:waypoint x="880" y="750" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="772" y="701" width="17" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_16192dm_di" bpmnElement="Flow_16192dm">
-        <di:waypoint x="680" y="117" />
-        <di:waypoint x="725" y="117" />
+        <di:waypoint x="691" y="117" />
+        <di:waypoint x="745" y="117" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_0xxq2h8_di" bpmnElement="Flow_0xxq2h8">
         <di:waypoint x="215" y="117" />
         <di:waypoint x="260" y="117" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_095vvrk_di" bpmnElement="Flow_095vvrk">
-        <di:waypoint x="1370" y="670" />
-        <di:waypoint x="1432" y="670" />
+      <bpmndi:BPMNEdge id="Flow_16bwdkl_di" bpmnElement="Flow_16bwdkl">
+        <di:waypoint x="540" y="117" />
+        <di:waypoint x="591" y="117" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1h8q1h1_di" bpmnElement="Flow_1h8q1h1">
-        <di:waypoint x="1010" y="240" />
-        <di:waypoint x="1130" y="240" />
-        <di:waypoint x="1130" y="325" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1mrr969_di" bpmnElement="Flow_1mrr969">
-        <di:waypoint x="1130" y="375" />
-        <di:waypoint x="1130" y="432" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1138" y="393" width="15" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1j1en2h_di" bpmnElement="Flow_1j1en2h">
-        <di:waypoint x="1105" y="350" />
-        <di:waypoint x="1010" y="350" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1026" y="352" width="18" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1qej57v_di" bpmnElement="Flow_1qej57v">
-        <di:waypoint x="960" y="310" />
-        <di:waypoint x="960" y="280" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0pvh1x9_di" bpmnElement="Flow_0pvh1x9">
-        <di:waypoint x="980" y="450" />
-        <di:waypoint x="1015" y="450" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1gxcve5_di" bpmnElement="Flow_1gxcve5">
-        <di:waypoint x="1065" y="450" />
-        <di:waypoint x="1112" y="450" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1083" y="432" width="15" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0afgah7_di" bpmnElement="Flow_0afgah7">
-        <di:waypoint x="1040" y="475" />
-        <di:waypoint x="1040" y="520" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1046" y="482" width="18" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0att74c_di" bpmnElement="Flow_0att74c">
-        <di:waypoint x="990" y="560" />
-        <di:waypoint x="930" y="560" />
-        <di:waypoint x="930" y="490" />
+      <bpmndi:BPMNEdge id="Flow_0zxtlgn_di" bpmnElement="Flow_0zxtlgn">
+        <di:waypoint x="950" y="310" />
+        <di:waypoint x="950" y="270" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
         <dc:Bounds x="179" y="99" width="36" height="36" />
@@ -430,33 +442,6 @@ dcnssi.timeDelay(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_0u06qij_di" bpmnElement="Activity_0u06qij">
         <dc:Bounds x="260" y="77" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0wswwhj_di" bpmnElement="Activity_0wswwhj">
-        <dc:Bounds x="580" y="77" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Gateway_1dqw1bg_di" bpmnElement="Gateway_1dqw1bg" isMarkerVisible="true">
-        <dc:Bounds x="725" y="92" width="50" height="50" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="708" y="53" width="85" height="40" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1kne6ot_di" bpmnElement="Activity_1kne6ot">
-        <dc:Bounds x="700" y="200" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Event_016dxue_di" bpmnElement="Event_016dxue">
-        <dc:Bounds x="832" y="99" width="36" height="36" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="821" y="140" width="74" height="40" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_13qnpcn_di" bpmnElement="Activity_13qnpcn">
-        <dc:Bounds x="410" y="77" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Event_1mk9pgp_di" bpmnElement="Event_1mk9pgp">
-        <dc:Bounds x="179" y="432" width="36" height="36" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="169" y="475" width="69" height="27" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_1anr9ry_di" bpmnElement="Activity_1anr9ry">
         <dc:Bounds x="260" y="410" width="100" height="80" />
       </bpmndi:BPMNShape>
@@ -469,21 +454,6 @@ dcnssi.timeDelay(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_0mnkgd6_di" bpmnElement="Activity_0mnkgd6">
         <dc:Bounds x="720" y="410" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1a5fd5v_di" bpmnElement="Activity_1a5fd5v">
-        <dc:Bounds x="910" y="200" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1ym1op6_di" bpmnElement="Activity_1ym1op6">
-        <dc:Bounds x="910" y="310" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_07qrjro_di" bpmnElement="Activity_07qrjro">
-        <dc:Bounds x="880" y="410" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Event_027jirg_di" bpmnElement="Event_027jirg">
-        <dc:Bounds x="179" y="652" width="36" height="36" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="160" y="695" width="88" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_19z90sm_di" bpmnElement="Activity_19z90sm">
         <dc:Bounds x="260" y="630" width="100" height="80" />
       </bpmndi:BPMNShape>
@@ -503,15 +473,12 @@ dcnssi.timeDelay(execution)</bpmn:script>
         <dc:Bounds x="880" y="710" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_0gs71qq_di" bpmnElement="Activity_0gs71qq">
-        <dc:Bounds x="1120" y="630" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1npwfvi_di" bpmnElement="Activity_1npwfvi">
-        <dc:Bounds x="1270" y="630" width="100" height="80" />
+        <dc:Bounds x="1050" y="630" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Event_1vgebg2_di" bpmnElement="Event_1vgebg2">
-        <dc:Bounds x="1432" y="652" width="36" height="36" />
+      <bpmndi:BPMNShape id="Event_1mk9pgp_di" bpmnElement="Event_1mk9pgp">
+        <dc:Bounds x="179" y="432" width="36" height="36" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1440" y="698" width="20" height="14" />
+          <dc:Bounds x="169" y="475" width="69" height="27" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Event_062ulql_di" bpmnElement="Event_062ulql">
@@ -520,39 +487,57 @@ dcnssi.timeDelay(execution)</bpmn:script>
           <dc:Bounds x="1102" y="473" width="72" height="27" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Gateway_13cwisg_di" bpmnElement="Gateway_13cwisg" isMarkerVisible="true">
-        <dc:Bounds x="1105" y="325" width="50" height="50" />
+      <bpmndi:BPMNShape id="Event_027jirg_di" bpmnElement="Event_027jirg">
+        <dc:Bounds x="179" y="652" width="36" height="36" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1165" y="336" width="54" height="27" />
+          <dc:Bounds x="160" y="695" width="88" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Gateway_1yftwt8_di" bpmnElement="Gateway_1yftwt8" isMarkerVisible="true">
-        <dc:Bounds x="1015" y="425" width="50" height="50" />
+      <bpmndi:BPMNShape id="Activity_13qnpcn_di" bpmnElement="Activity_13qnpcn">
+        <dc:Bounds x="440" y="77" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_0wswwhj_di" bpmnElement="Activity_0wswwhj">
+        <dc:Bounds x="591" y="77" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Gateway_1dqw1bg_di" bpmnElement="Gateway_1dqw1bg" isMarkerVisible="true">
+        <dc:Bounds x="745" y="92" width="50" height="50" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1028" y="396" width="54" height="27" />
+          <dc:Bounds x="728" y="53" width="86" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1lafl76_di" bpmnElement="Activity_1lafl76">
-        <dc:Bounds x="990" y="520" width="100" height="80" />
+      <bpmndi:BPMNShape id="Event_016dxue_di" bpmnElement="Event_016dxue">
+        <dc:Bounds x="885" y="99" width="36" height="36" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="874" y="140" width="74" height="40" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1ym1op6_di" bpmnElement="Activity_1ym1op6">
+        <dc:Bounds x="900" y="310" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1kne6ot_di" bpmnElement="Activity_1kne6ot">
+        <dc:Bounds x="720" y="190" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1a5fd5v_di" bpmnElement="Activity_1a5fd5v">
+        <dc:Bounds x="900" y="190" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_14l5j2f_di" bpmnElement="Activity_14l5j2f" isExpanded="true">
         <dc:Bounds x="250" y="910" width="781" height="196" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNEdge id="Flow_1vq4jz8_di" bpmnElement="Flow_1vq4jz8">
-        <di:waypoint x="640" y="1014" />
-        <di:waypoint x="710" y="1014" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1cl22g1_di" bpmnElement="Flow_1cl22g1">
-        <di:waypoint x="480" y="1014" />
-        <di:waypoint x="540" y="1014" />
+      <bpmndi:BPMNEdge id="Flow_139pcs3_di" bpmnElement="Flow_139pcs3">
+        <di:waypoint x="810" y="1014" />
+        <di:waypoint x="918" y="1014" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_0z51qfz_di" bpmnElement="Flow_0z51qfz">
         <di:waypoint x="316" y="1014" />
         <di:waypoint x="380" y="1014" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_139pcs3_di" bpmnElement="Flow_139pcs3">
-        <di:waypoint x="810" y="1014" />
-        <di:waypoint x="918" y="1014" />
+      <bpmndi:BPMNEdge id="Flow_1cl22g1_di" bpmnElement="Flow_1cl22g1">
+        <di:waypoint x="480" y="1014" />
+        <di:waypoint x="540" y="1014" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1vq4jz8_di" bpmnElement="Flow_1vq4jz8">
+        <di:waypoint x="640" y="1014" />
+        <di:waypoint x="710" y="1014" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNShape id="Event_1blx2tk_di" bpmnElement="Event_1blx2tk">
         <dc:Bounds x="280" y="996" width="36" height="36" />
@@ -569,6 +554,36 @@ dcnssi.timeDelay(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_0ckr2ke_di" bpmnElement="Activity_0ckr2ke">
         <dc:Bounds x="540" y="974" width="100" height="80" />
       </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1npwfvi_di" bpmnElement="Activity_1npwfvi">
+        <dc:Bounds x="1210" y="630" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Gateway_13cwisg_di" bpmnElement="Gateway_13cwisg" isMarkerVisible="true">
+        <dc:Bounds x="1105" y="325" width="50" height="50" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1165" y="336" width="54" height="27" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_07qrjro_di" bpmnElement="Activity_07qrjro">
+        <dc:Bounds x="880" y="410" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Gateway_1yftwt8_di" bpmnElement="Gateway_1yftwt8" isMarkerVisible="true">
+        <dc:Bounds x="1015" y="425" width="50" height="50" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1028" y="396" width="54" height="27" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1lafl76_di" bpmnElement="Activity_1lafl76">
+        <dc:Bounds x="990" y="520" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_03j1rrj_di" bpmnElement="Activity_03j1rrj">
+        <dc:Bounds x="1370" y="630" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Event_0zbwefx_di" bpmnElement="Event_0zbwefx">
+        <dc:Bounds x="1532" y="652" width="36" height="36" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1537" y="695" width="27" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
 </bpmn:definitions>
index e0c0b9a..80e154c 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1ejx57e" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.1.1">
-  <bpmn:process id="Process_1nmtzzp" isExecutable="true">
+  <bpmn:process id="DoModifyCoreNSSI" name="DoModifyCoreNSSI" isExecutable="true">
     <bpmn:startEvent id="Event_0fbqt56" name="Modify Core NSSI Flow">
       <bpmn:outgoing>Flow_0e007rx</bpmn:outgoing>
     </bpmn:startEvent>
@@ -53,9 +53,6 @@ def mcnssi= new DoModifyCoreNSSI()
 def mcnssi= new DoModifyCoreNSSI()
         mcnssi.prepareUpdateResourceOperationStatus(execution)</bpmn:script>
     </bpmn:scriptTask>
-    <bpmn:endEvent id="Event_1p0mogo" name="End">
-      <bpmn:incoming>Flow_1yphs5r</bpmn:incoming>
-    </bpmn:endEvent>
     <bpmn:sequenceFlow id="Flow_0yq24um" sourceRef="Activity_0oph5am" targetRef="Activity_0d1kk7f" />
     <bpmn:intermediateCatchEvent id="Event_0z9mer1" name="Slice Profile Instance has to be created">
       <bpmn:outgoing>Flow_1twqfsc</bpmn:outgoing>
@@ -176,9 +173,8 @@ mcnssi.prepareFailedOperationStatusUpdate(execution)</bpmn:script>
         </camunda:connector>
       </bpmn:extensionElements>
       <bpmn:incoming>Flow_0yq24um</bpmn:incoming>
-      <bpmn:outgoing>Flow_1yphs5r</bpmn:outgoing>
+      <bpmn:outgoing>Flow_0yp03pi</bpmn:outgoing>
     </bpmn:serviceTask>
-    <bpmn:sequenceFlow id="Flow_1yphs5r" sourceRef="Activity_0d1kk7f" targetRef="Event_1p0mogo" />
     <bpmn:scriptTask id="Activity_0wdaul0" name="Calculate S-NSSAI" scriptFormat="groovy">
       <bpmn:incoming>Flow_0s31teg</bpmn:incoming>
       <bpmn:outgoing>Flow_0fj4doc</bpmn:outgoing>
@@ -222,9 +218,57 @@ mcnssi.timeDelay(execution)</bpmn:script>
       <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("putStatus" ) == "processing" )}</bpmn:conditionExpression>
     </bpmn:sequenceFlow>
     <bpmn:sequenceFlow id="Flow_1twqfsc" sourceRef="Event_0z9mer1" targetRef="Activity_1q02wiz" />
+    <bpmn:scriptTask id="Activity_0rws6g3" name="PostProcess Incoming Request" scriptFormat="groovy">
+      <bpmn:incoming>Flow_0yp03pi</bpmn:incoming>
+      <bpmn:outgoing>Flow_0abxsbd</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def mcnssi= new DoModifyCoreNSSI()
+        mcnssi.postProcessRequest(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="Flow_0yp03pi" sourceRef="Activity_0d1kk7f" targetRef="Activity_0rws6g3" />
+    <bpmn:endEvent id="Event_0m863dd" name="Done">
+      <bpmn:incoming>Flow_0abxsbd</bpmn:incoming>
+    </bpmn:endEvent>
+    <bpmn:sequenceFlow id="Flow_0abxsbd" sourceRef="Activity_0rws6g3" targetRef="Event_0m863dd" />
   </bpmn:process>
   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
-    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1nmtzzp">
+    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoModifyCoreNSSI">
+      <bpmndi:BPMNEdge id="Flow_1twqfsc_di" bpmnElement="Flow_1twqfsc">
+        <di:waypoint x="248" y="430" />
+        <di:waypoint x="330" y="430" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_06or8oz_di" bpmnElement="Flow_06or8oz">
+        <di:waypoint x="1240" y="175" />
+        <di:waypoint x="1240" y="280" />
+        <di:waypoint x="1170" y="280" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1246" y="225" width="18" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1jm7045_di" bpmnElement="Flow_1jm7045">
+        <di:waypoint x="1120" y="240" />
+        <di:waypoint x="1120" y="190" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1hm2xps_di" bpmnElement="Flow_1hm2xps">
+        <di:waypoint x="1265" y="150" />
+        <di:waypoint x="1430" y="150" />
+        <di:waypoint x="1430" y="185" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1273" y="130" width="15" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0nxwq7b_di" bpmnElement="Flow_0nxwq7b">
+        <di:waypoint x="1170" y="150" />
+        <di:waypoint x="1215" y="150" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1y0m22h_di" bpmnElement="Flow_1y0m22h">
+        <di:waypoint x="1040" y="150" />
+        <di:waypoint x="1070" y="150" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0fj4doc_di" bpmnElement="Flow_0fj4doc">
+        <di:waypoint x="910" y="150" />
+        <di:waypoint x="940" y="150" />
+      </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_06j2avj_di" bpmnElement="Flow_06j2avj">
         <di:waypoint x="360" y="150" />
         <di:waypoint x="400" y="150" />
@@ -285,45 +329,13 @@ mcnssi.timeDelay(execution)</bpmn:script>
         <di:waypoint x="500" y="150" />
         <di:waypoint x="540" y="150" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1yphs5r_di" bpmnElement="Flow_1yphs5r">
+      <bpmndi:BPMNEdge id="Flow_0yp03pi_di" bpmnElement="Flow_0yp03pi">
         <di:waypoint x="920" y="510" />
-        <di:waypoint x="962" y="510" />
+        <di:waypoint x="970" y="510" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0fj4doc_di" bpmnElement="Flow_0fj4doc">
-        <di:waypoint x="910" y="150" />
-        <di:waypoint x="940" y="150" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1y0m22h_di" bpmnElement="Flow_1y0m22h">
-        <di:waypoint x="1040" y="150" />
-        <di:waypoint x="1070" y="150" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_0nxwq7b_di" bpmnElement="Flow_0nxwq7b">
-        <di:waypoint x="1170" y="150" />
-        <di:waypoint x="1215" y="150" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1hm2xps_di" bpmnElement="Flow_1hm2xps">
-        <di:waypoint x="1265" y="150" />
-        <di:waypoint x="1430" y="150" />
-        <di:waypoint x="1430" y="185" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1273" y="130" width="15" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1jm7045_di" bpmnElement="Flow_1jm7045">
-        <di:waypoint x="1120" y="240" />
-        <di:waypoint x="1120" y="190" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_06or8oz_di" bpmnElement="Flow_06or8oz">
-        <di:waypoint x="1240" y="175" />
-        <di:waypoint x="1240" y="280" />
-        <di:waypoint x="1170" y="280" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1246" y="225" width="18" height="14" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1twqfsc_di" bpmnElement="Flow_1twqfsc">
-        <di:waypoint x="248" y="430" />
-        <di:waypoint x="330" y="430" />
+      <bpmndi:BPMNEdge id="Flow_0abxsbd_di" bpmnElement="Flow_0abxsbd">
+        <di:waypoint x="1070" y="510" />
+        <di:waypoint x="1122" y="510" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNShape id="Event_0fbqt56_di" bpmnElement="Event_0fbqt56">
         <dc:Bounds x="182" y="132" width="36" height="36" />
@@ -331,9 +343,6 @@ mcnssi.timeDelay(execution)</bpmn:script>
           <dc:Bounds x="158" y="175" width="89" height="27" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0klj7y1_di" bpmnElement="Activity_0klj7y1">
-        <dc:Bounds x="260" y="110" width="100" height="80" />
-      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_0tf735w_di" bpmnElement="Activity_0tf735w">
         <dc:Bounds x="400" y="110" width="100" height="80" />
       </bpmndi:BPMNShape>
@@ -343,19 +352,10 @@ mcnssi.timeDelay(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_02skgkj_di" bpmnElement="Activity_02skgkj">
         <dc:Bounds x="680" y="110" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0wdaul0_di" bpmnElement="Activity_0wdaul0">
-        <dc:Bounds x="810" y="110" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0rvt126_di" bpmnElement="Activity_0rvt126">
-        <dc:Bounds x="940" y="110" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1gojm1c_di" bpmnElement="Activity_1gojm1c">
-        <dc:Bounds x="1070" y="110" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Gateway_13w96z9_di" bpmnElement="Gateway_13w96z9" isMarkerVisible="true">
-        <dc:Bounds x="1215" y="125" width="50" height="50" />
+      <bpmndi:BPMNShape id="Gateway_1hadnun_di" bpmnElement="Gateway_1hadnun" isMarkerVisible="true">
+        <dc:Bounds x="1405" y="185" width="50" height="50" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1213" y="87" width="54" height="27" />
+          <dc:Bounds x="1305" y="190" width="90" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Event_1243wg1_di" bpmnElement="Event_1243wg1">
@@ -364,23 +364,14 @@ mcnssi.timeDelay(execution)</bpmn:script>
           <dc:Bounds x="1603" y="233" width="90" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Gateway_1hadnun_di" bpmnElement="Gateway_1hadnun" isMarkerVisible="true">
-        <dc:Bounds x="1405" y="185" width="50" height="50" />
-        <bpmndi:BPMNLabel>
-          <dc:Bounds x="1305" y="190" width="90" height="40" />
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Event_1gjhrcq_di" bpmnElement="Event_1gjhrcq">
         <dc:Bounds x="1412" y="282" width="36" height="36" />
         <bpmndi:BPMNLabel>
           <dc:Bounds x="1393" y="323" width="90" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_15kjs2a_di" bpmnElement="Activity_15kjs2a">
-        <dc:Bounds x="1070" y="240" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1q02wiz_di" bpmnElement="Activity_1q02wiz">
-        <dc:Bounds x="330" y="390" width="100" height="80" />
+      <bpmndi:BPMNShape id="Activity_0oph5am_di" bpmnElement="Activity_0oph5am">
+        <dc:Bounds x="660" y="470" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Event_0z9mer1_di" bpmnElement="Event_0z9mer1">
         <dc:Bounds x="212" y="412" width="36" height="36" />
@@ -388,51 +379,54 @@ mcnssi.timeDelay(execution)</bpmn:script>
           <dc:Bounds x="192" y="455" width="90" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0oph5am_di" bpmnElement="Activity_0oph5am">
-        <dc:Bounds x="660" y="470" width="100" height="80" />
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_1iegufd_di" bpmnElement="Activity_1iegufd">
-        <dc:Bounds x="330" y="570" width="100" height="80" />
-      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Event_0m2jn7c_di" bpmnElement="Event_0m2jn7c">
         <dc:Bounds x="212" y="592" width="36" height="36" />
         <bpmndi:BPMNLabel>
           <dc:Bounds x="185" y="635" width="90" height="40" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_010nkjp_di" bpmnElement="Activity_010nkjp">
-        <dc:Bounds x="490" y="570" width="100" height="80" />
+      <bpmndi:BPMNShape id="Activity_1q02wiz_di" bpmnElement="Activity_1q02wiz">
+        <dc:Bounds x="330" y="390" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_1josmor_di" bpmnElement="Activity_1josmor">
         <dc:Bounds x="480" y="390" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Activity_0d1kk7f_di" bpmnElement="Activity_0d1kk7f">
-        <dc:Bounds x="820" y="470" width="100" height="80" />
+      <bpmndi:BPMNShape id="Activity_1iegufd_di" bpmnElement="Activity_1iegufd">
+        <dc:Bounds x="330" y="570" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_010nkjp_di" bpmnElement="Activity_010nkjp">
+        <dc:Bounds x="490" y="570" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_0klj7y1_di" bpmnElement="Activity_0klj7y1">
+        <dc:Bounds x="260" y="110" width="100" height="80" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="Event_1p0mogo_di" bpmnElement="Event_1p0mogo">
-        <dc:Bounds x="962" y="492" width="36" height="36" />
+      <bpmndi:BPMNShape id="Activity_0rws6g3_di" bpmnElement="Activity_0rws6g3">
+        <dc:Bounds x="970" y="470" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Event_0m863dd_di" bpmnElement="Event_0m863dd">
+        <dc:Bounds x="1122" y="492" width="36" height="36" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="970" y="538" width="20" height="14" />
+          <dc:Bounds x="1127" y="535" width="27" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Activity_1u4xfuz_di" bpmnElement="Activity_1u4xfuz" isExpanded="true">
         <dc:Bounds x="190" y="790" width="781" height="196" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNEdge id="Flow_07ftouz_di" bpmnElement="Flow_07ftouz">
-        <di:waypoint x="580" y="894" />
-        <di:waypoint x="650" y="894" />
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_14kgrjc_di" bpmnElement="Flow_14kgrjc">
-        <di:waypoint x="420" y="894" />
-        <di:waypoint x="480" y="894" />
+      <bpmndi:BPMNEdge id="Flow_00tfsrn_di" bpmnElement="Flow_00tfsrn">
+        <di:waypoint x="750" y="894" />
+        <di:waypoint x="858" y="894" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_1i9kph3_di" bpmnElement="Flow_1i9kph3">
         <di:waypoint x="256" y="894" />
         <di:waypoint x="320" y="894" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_00tfsrn_di" bpmnElement="Flow_00tfsrn">
-        <di:waypoint x="750" y="894" />
-        <di:waypoint x="858" y="894" />
+      <bpmndi:BPMNEdge id="Flow_14kgrjc_di" bpmnElement="Flow_14kgrjc">
+        <di:waypoint x="420" y="894" />
+        <di:waypoint x="480" y="894" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_07ftouz_di" bpmnElement="Flow_07ftouz">
+        <di:waypoint x="580" y="894" />
+        <di:waypoint x="650" y="894" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNShape id="Event_0xhp6c7_di" bpmnElement="Event_0xhp6c7">
         <dc:Bounds x="220" y="876" width="36" height="36" />
@@ -449,6 +443,27 @@ mcnssi.timeDelay(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_1feavwd_di" bpmnElement="Activity_1feavwd">
         <dc:Bounds x="480" y="854" width="100" height="80" />
       </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_0d1kk7f_di" bpmnElement="Activity_0d1kk7f">
+        <dc:Bounds x="820" y="470" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_0wdaul0_di" bpmnElement="Activity_0wdaul0">
+        <dc:Bounds x="810" y="110" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_0rvt126_di" bpmnElement="Activity_0rvt126">
+        <dc:Bounds x="940" y="110" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_1gojm1c_di" bpmnElement="Activity_1gojm1c">
+        <dc:Bounds x="1070" y="110" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Gateway_13w96z9_di" bpmnElement="Gateway_13w96z9" isMarkerVisible="true">
+        <dc:Bounds x="1215" y="125" width="50" height="50" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1213" y="87" width="54" height="27" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_15kjs2a_di" bpmnElement="Activity_15kjs2a">
+        <dc:Bounds x="1070" y="240" width="100" height="80" />
+      </bpmndi:BPMNShape>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
 </bpmn:definitions>