refactord payload creatn for template & param save 43/57143/3
authorSandeep J <sandeejh@in.ibm.com>
Mon, 23 Jul 2018 10:42:26 +0000 (16:12 +0530)
committerTakamune Cho <tc012c@att.com>
Wed, 25 Jul 2018 14:01:23 +0000 (14:01 +0000)
refactored payload creation for saving template and param artifacts to
APPC using createPayloadForSave method in utility.service.ts

Issue-ID: APPC-1105
Change-Id: I2dd446aebdbcbc1ffc070993ee53d09e25eeae6b
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.ts

index dc40704..a3d55ba 100644 (file)
@@ -40,7 +40,8 @@ import { NgProgress } from 'ngx-progressbar';
 import { NgxSpinnerService } from 'ngx-spinner';
 import { UtilityService } from '../../../../shared/services/utilityService/utility.service';
 declare var $: any
-
+const PARAM_DATA:string="param_data";
+const TEMPLATE_DATA:string="template_data";
 @Component({ selector: 'app-golden-configuration', templateUrl: './template-configuration.component.html', styleUrls: ['./template-configuration.component.css'] })
 export class GoldenConfigurationComponent implements OnInit {
   @ViewChild('templateeditor') templateeditor;
@@ -99,6 +100,7 @@ export class GoldenConfigurationComponent implements OnInit {
   }
   public replaceWord;
   public enableDownloadButtons: boolean = false;
+   
   constructor(
     private buildDesignComponent: BuildDesignComponent, 
     private paramShareService: ParamShareService, 
@@ -354,27 +356,7 @@ export class GoldenConfigurationComponent implements OnInit {
         let vnfType = this.vnfType;
         let Json = [paramsKeyValueFromEditor];
         let slashedPayload = this.appendSlashes(JSON.stringify(Json));
-        let newPayload =
-          {
-            "userID": this.userId,
-            "vnf-type": this.vnfType,
-            "action": action,
-            "artifact-name": fileName,
-            "artifact-type": "APPC-CONFIG",
-            "artifact-version": this.templateVersionNo,
-            "artifact-contents": slashedPayload
-          }
-        let data =
-          {
-            "input": {
-              "design-request": {
-                "request-id": this.apiToken,
-                "action": "uploadArtifact",
-                "payload": JSON.stringify(newPayload)
-
-              }
-            }
-          }
+        let data = this.utilityService.createPayLoadForSave(PARAM_DATA, this.vnfType, action, fileName, this.templateVersionNo, slashedPayload);
         this.appDataObject.template.nameValueData = data;
       }
       if (this.configMappingEditorContent) {
@@ -398,28 +380,7 @@ export class GoldenConfigurationComponent implements OnInit {
           fileName = this.artifactName;
         }
         let vnfType = this.vnfType;
-        let newPayload =
-          {
-            "userID": this.userId,
-            "vnf-type": this.vnfType,
-            "action": action,
-            "artifact-name": fileName,
-            "artifact-type": "APPC-CONFIG",
-            "artifact-version": this.templateVersionNo,
-            "artifact-contents": this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}')
-
-          }
-        let data =
-          {
-            "input": {
-              "design-request": {
-                "request-id": this.apiToken,
-                "action": "uploadArtifact",
-                "payload": JSON.stringify(newPayload)
-
-              }
-            }
-          }
+        let data = this.utilityService.createPayLoadForSave(TEMPLATE_DATA, this.vnfType, action, fileName, this.templateVersionNo, this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
         this.appDataObject.template.templateData = data;
         this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal);
       }