Merge "Remove Swagger UI"
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / UpdateAAIVfModule.groovy
index 6691a82..3c4edd2 100644 (file)
@@ -174,23 +174,27 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                                personaModelVersionEntry = updateVfModuleNode(origRequest,  'persona-model-version')
                        }
                        String contrailServiceInstanceFqdnEntry = updateVfModuleNode(origRequest,  'contrail-service-instance-fqdn')
-                       def payload = """
-                                       {       ${orchestrationStatusEntry}
-                                               ${heatStackIdEntry}
-                                               ${personaModelVersionEntry}
-                                               ${contrailServiceInstanceFqdnEntry}
-                                               "vf-module-id": "${vfModuleId}"                                         
-                                       }
-                       """
+                       org.onap.aai.domain.yang.VfModule payload = new org.onap.aai.domain.yang.VfModule();
+                       payload.setVfModuleId(vfModuleId)
+                       payload.setOrchestrationStatus(orchestrationStatusEntry)
+                       payload.setHeatStackId(heatStackIdEntry)
+                       payload.setPersonaModelVersion(personaModelVersionEntry)
+                       payload.setContrailServiceInstanceFqdn(contrailServiceInstanceFqdnEntry)
 
             try {
                 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)
                 getAAIClient().update(resourceUri, payload)
+                               execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 200)
+                               execution.setVariable('UAAIVfMod_updateVfModuleResponse', "Success")
             }catch(NotFoundException ignored){
                 msoLogger.debug("VF-Module not found!!")
+                               execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 404)
+                execution.setVariable('UAAIVfMod_updateVfModuleResponse', ignored.getMessage())
                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "vf-module " + vfModuleId + " not found for under vnf " + vnfId + " in A&AI!")
             }
             catch(Exception ex){
+                               execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 500)
+                               execution.setVariable('UAAIVfMod_updateVfModuleResponse', 'AAI PATCH Failed:' + ex.getMessage())
                                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, 'Exception occurred while executing AAI PATCH:' + ex.getMessage())
             }
                } catch (BpmnError e) {
@@ -210,87 +214,19 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
        private String updateVfModuleNode(String origRequest, String elementName) {
 
                if (!utils.nodeExists(origRequest, elementName)) {
-                       return "" 
+                       return null
                }
                def elementValue = utils.getNodeText(origRequest, elementName)
 
                if (elementValue.equals('DELETE')) {
-                       // Set the element being deleted to null
-                       return """"${elementName}": null,"""
+                       // Set the element being deleted to empty string
+                       return ""
                }
                else {
-                       return """"${elementName}": "${elementValue}","""
+                       return elementValue
                }               
        }
 
-       
-       /**
-        * Check the Volume Group ID from the incoming update request against the Volume Group ID from the
-        * given VF Module.  If they are equal or if they are both 'null', then that is acceptable and 'null'
-        * is returned.  Otherwise a message describing how the values are unacceptable/incompatible is returned.
-        * 
-        * @param origRequest Incoming update request with VF Module elements to be updated.
-        * @param vfModuleNode VF Module (as a Node) retrieved from AAI.
-        * @param isDebugLogEnabled Is DEBUG log enabled?
-        * @return 'null' if the Volume Group IDs are acceptable. Otherwise return a message describing how the
-        * values are unacceptable/incompatible.
-        */
-       private String checkVolumeGroupId(String origRequest, Node vfModuleNode, String isDebugLogEnabled) {
-               def requestVolumeGroupId = utils.getNodeText(origRequest, 'volume-group-id')
-               def currVolumeGroupId = getCurrVolumeGroupId(vfModuleNode)
-               
-               msoLogger.debug('Check volume-group-id: volume-group-id in original request is \'' + requestVolumeGroupId + '\', volume-group-id from VF Module is \'' + currVolumeGroupId + '\'')
-               
-               def result = null
-               
-               if (requestVolumeGroupId == null) {
-                       if (currVolumeGroupId == null) {
-                               // This is OK
-                       } else {
-                               result = 'Cannot detach a volume group from an existing VF Module'
-                       }
-               } else {
-                       if (currVolumeGroupId == null) {
-                               result = 'Cannot add a volume gruop to an existing VF Module'
-                       } else {
-                               if (!requestVolumeGroupId.equals(currVolumeGroupId)) {
-                                       result = 'Cannot change the volume group on an existing VF Module'
-                               }
-                       }
-               }
-               
-               return result
-       }
-       
-       /**
-        * Find and return the value of the Volume Group ID for the specified VF Module.  If
-        * the value of the Volume Group ID cannot be found for any reason, 'null' is returned.
-        * 
-        * @param vfModuleNode VF Module (as a Node) retrieved from AAI.
-        * @return the value of the Volume Group ID for the specified VF Module.  If the
-        * value of the Volume Group ID cannot be found for any reason, 'null' is returned.
-        */
-       private String getCurrVolumeGroupId(Node vfModuleNode) {
-               def Node relationshipList = utils.getChildNode(vfModuleNode, 'relationship-list')
-               if (relationshipList == null) {
-                       return null
-               }
-               def NodeList relationships = utils.getIdenticalChildren(relationshipList, 'relationship')
-               for (Node relationshipNode in relationships) {
-                       def String relatedTo = utils.getChildNodeText(relationshipNode, 'related-to')
-                       if ((relatedTo != null) && relatedTo.equals('volume-group')) {
-                               def NodeList relationshipDataList = utils.getIdenticalChildren(relationshipNode, 'relationship-data')
-                               for (Node relationshipDataNode in relationshipDataList) {
-                                       def String relationshipKey = utils.getChildNodeText(relationshipDataNode, 'relationship-key')
-                                       if ((relationshipKey != null) && relationshipKey.equals('volume-group.volume-group-id')) {
-                                               return utils.getChildNodeText(relationshipDataNode, 'relationship-value')
-                                       }
-                               }
-                       }
-               }
-               return null
-       }
-
        /**
         * Generates a WorkflowException if the AAI query returns a response code other than 200.
         *