From f1e61ce405cf11ea77fe98abd5e10f7ed2d72611 Mon Sep 17 00:00:00 2001 From: sj108s Date: Tue, 13 Mar 2018 20:29:58 +0530 Subject: Fixed defects in test screen & updated test cases Fixed few defects raised by ST in test screen and also updated test cases to improve coverage. Also,changed code to match onap standards, and rectfied grep code violations. Issue-ID: APPC-730 Change-Id: I0286c38eb4f76dc8c0253a4ccab721b3ccfeff9d Signed-off-by: sj108s --- .../param-name-value.component.html | 24 +- .../param-name-value.component.spec.ts | 242 +++++++++++++++++ .../param-name-value/param-name-value.component.ts | 291 ++------------------- 3 files changed, 266 insertions(+), 291 deletions(-) create mode 100644 src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts (limited to 'src/app/vnfs/build-artifacts/template-holder/param-name-value') diff --git a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.html b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.html index 150d5ad..3b1199b 100644 --- a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.html +++ b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.html @@ -22,8 +22,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. --> - + @@ -69,6 +68,9 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
+ +
@@ -83,8 +85,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. - +

- - - +
- - +
diff --git a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts new file mode 100644 index 0000000..991ff45 --- /dev/null +++ b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts @@ -0,0 +1,242 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + +import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; +import { By, BrowserModule } from '@angular/platform-browser'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; +import { Component, OnInit, ViewChild, Input } from '@angular/core'; +import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service'; +import { MappingEditorService } from '../../../../shared/services/mapping-editor.service'; +import { ArtifactRequest } from '../../../../shared/models/index'; +import { ActivatedRoute, Router } from "@angular/router"; +import { saveAs } from "file-saver"; +import { NotificationService } from '../../../../shared/services/notification.service'; +import { NotificationsService } from "angular2-notifications" +import { ParamShareService } from '../../../../shared/services/paramShare.service'; +import { DialogService } from "ng2-bootstrap-modal"; +import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component'; +import { BuildDesignComponent } from '../../build-artifacts.component'; +import { environment } from '../../../../../environments/environment'; +import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal' +import { FormsModule } from '@angular/forms'; +import { RouterTestingModule } from '@angular/router/testing'; +import { HomeComponent } from '../../../../home/home/home.component'; +import { LogoutComponent } from '../../../../shared/components/logout/logout.component'; +import { HelpComponent } from '../../../../shared/components/help/help/help.component'; +import { AboutUsComponent } from '../../../../about-us/aboutus.component'; +import { TestComponent } from '../../../../test/test.component'; +import { HttpModule } from '@angular/http'; +import { AceEditorComponent } from 'ng2-ace-editor'; +import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal'; +import { SimpleNotificationsModule } from 'angular2-notifications'; +import { GoldenConfigurationMappingComponent } from './param-name-value.component'; +import { Observable } from 'rxjs/Observable'; +import { NgProgress } from 'ngx-progressbar'; +import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http'; +import { MockBackend, MockConnection } from '@angular/http/testing'; + + +describe('GoldenConfigurationMappingComponent', () => { + let component: GoldenConfigurationMappingComponent; + let fixture: ComponentFixture; + let buildDesignComponent: BuildDesignComponent; + let paramShareService: ParamShareService; + let dialogService: DialogService; + let notificationService: NotificationService; + let httpUtil: HttpUtilService; + let mappingEditorService: MappingEditorService; + let activeRoutes: ActivatedRoute; + let router: Router; + let nService: NotificationsService + const routes = [ + { + path: 'home', + component: HomeComponent + }, { + path: 'vnfs', + loadChildren: '../../../../vnfs/vnfs.module#VnfsModule' + }, { + path: 'test', + component: TestComponent + }, + { + path: 'help', + component: HelpComponent + }, { + path: 'aboutUs', + component: AboutUsComponent + }, { + path: 'logout', + component: LogoutComponent + }, { + path: '', + redirectTo: '/home', + pathMatch: 'full' + } + ]; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()], + declarations: [GoldenConfigurationMappingComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent], + providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService,MockBackend, + HttpUtilService, MappingEditorService, NotificationsService, + BaseRequestOptions, + { + provide: Http, + useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + } + + ], + schemas: [NO_ERRORS_SCHEMA], + }) + + }); + + beforeEach(async(() => { + TestBed.compileComponents() + + })); + + it('validate if uploaded file should be only json', () => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + expect(component.validateUploadedFile('xls')).toBe(false); + expect(component.validateUploadedFile('json')).toBe(true); + expect(component.validateUploadedFile('xml')).toBe(false); + }); + + + + it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" } + mappingEditorService.fromScreen = 'MappingScreen'; + component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "; + expect(component.ngOnInit()); + expect(component.ngAfterViewInit()); + + component.paramsContent = JSON.stringify({ + "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_address1": "", + "node0_tacplus_server_name2": "testIp2" + }); + expect(component.ngOnInit()); + + expect(component.ngAfterViewInit()); + + expect(component.action).toEqual('Configure'); + expect(component.vnfType).toEqual('testVnf'); + expect(component.vnfcType).toEqual(''); + expect(component.protocol).toEqual('CHEF'); + + expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json'); + + mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "testVnfc" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" } + expect(component.ngOnInit()); + expect(component.vnfcType).toEqual('testVnfc'); + + + })); + + it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + mappingEditorService.latestAction = undefined; + component.ngOnInit(); + expect(component.ngAfterViewInit()); + expect(component.action).toEqual(''); + expect(component.vnfType).toEqual(''); + expect(component.vnfcType).toEqual(''); + expect(component.artifactName).toEqual(''); + + })); + + it('test whether onparamchanges function is able to set the cache correctly for param name values', () => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + var data = JSON.stringify({ + "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_address1": "", + "node0_tacplus_server_name2": "testIp2" + }); + component.onParamChanges(data); + expect(localStorage["paramsContent"]).toBe(data); + }) + + + it('retrieveNameValue function should return response on success and set the localstorage data for param', inject([HttpUtilService, NgProgress, MappingEditorService, MockBackend], (httpUtilService: HttpUtilService, mappingEditorService: MappingEditorService, ngProgress: NgProgress, mockBackend: MockBackend) => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + var mockData = { + "output": { + "data": { + "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\"[{\\\"node0_tacplus_server_name1\\\":\\\"testIp1\\\",\\\"node0_tacplus_server_source_address1\\\":\\\"testIp2\\\",\\\"node0_tacplus_server_name2\\\":\\\"testIp3\\\"}]\"}]}", + "requestId": "497085412083" + }, + "status": { + "code": "400", + "message": "success" + } + } + }; + + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockRespond(baseResponse) + ); + + mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" } + + mappingEditorService.fromScreen = 'MappingScreen'; + component.action = 'Configure'; + component.refObj = mappingEditorService.latestAction; + component.scopeName = "testVnf"; + component.vnfType = "testVnf"; + component.userId = "abc"; + component.item.action = "Configure"; + component.retrieveNameValueFromAppc(); + expect(localStorage["localStorage['paramsContent']"]).not.toBe(null); + + })); + + it('test sync from param value function', inject([ParamShareService], (paramShareService: ParamShareService) => { + fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); + component = fixture.componentInstance; + localStorage['paramsContent'] = JSON.stringify({ + "node0_tacplus_server_name1": "testIp1", "node0_tacplus_server_source_address1": "testIp2", "node0_tacplus_server_name2": "testIp3" + }); + var pdData = [{ "name": "sync_auto-pop_name1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vnfc-oam-ipv4-address-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vnfc" }, { "key-name": "field-key-name", "key-value": "ipaddress-v4-oam-vip" }, { "key-name": null, "key-value": "vm-number" }, { "key-name": null, "key-value": "test" }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "sync_auto-pop_address1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vm-name-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vserver" }, { "key-name": "field-key-name", "key-value": "vserver-name" }, { "key-name": null, "key-value": "vnfc-function-code" }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "node0_tacplus_server_name2", "type": null, "description": null, "required": null, "default": null, "source": "Manual", "rule-type": null, "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null] }]; + paramShareService.setSessionParamData([pdData]); + component.syncParam(); + })); + + +}); \ No newline at end of file diff --git a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.ts b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.ts index 9ea95ec..a3c5a8e 100644 --- a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.ts +++ b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.ts @@ -40,17 +40,6 @@ import { environment } from '../../../../../environments/environment'; import { NgProgress } from 'ngx-progressbar'; import * as XLSX from 'xlsx'; -type AOA = Array>; - -function s2ab(s: string): ArrayBuffer { - const buf = new ArrayBuffer(s.length); - const view = new Uint8Array(buf); - for (let i = 0; i !== s.length; ++i) { - view[i] = s.charCodeAt(i) & 0xFF; - } - return buf; -} - declare var $: any; @Component({ @@ -62,7 +51,7 @@ export class GoldenConfigurationMappingComponent implements OnInit { enableMappingSave: boolean = false; aceText: string = ''; fileName: string = ''; - actionType: any; + actionType: any=''; modal: any; configMappingEditorContent: any; fileType: any = ''; @@ -80,11 +69,13 @@ export class GoldenConfigurationMappingComponent implements OnInit { enableDownload: boolean = false; showMappingDownloadDiv: boolean = false; mapppingDownloadType: any; - action: any; - artifactName: any; + action: any=''; + artifactName: any=''; enableMerge: boolean = false; apiToken = localStorage['apiToken']; userId = localStorage['userId']; + identifier: any; + public uploadTypes = [ { value: 'Mapping Data', @@ -107,20 +98,9 @@ export class GoldenConfigurationMappingComponent implements OnInit { @ContentChildren(Tab) tabs: QueryList; public subscription: any; public item: any = {}; - - public Actions = [ - { action: 'ConfigBackup', value: 'ConfigBackup' }, - { action: 'ConfigModify', value: 'ConfigModify' }, - { action: 'ConfigRestore', value: 'ConfigRestore' }, - { action: 'Configure', value: 'Configure' }, - { action: 'GetRunningConfig', value: 'GetRunningConfig' }, - { action: 'HealthCheck', value: 'HealthCheck' }, - { action: 'StartApplication', value: 'StartApplication' }, - { action: 'StopApplication', value: 'StopApplication' } - ]; - vnfType: any; - vnfcType: any; - protocol: any; + vnfType: any=''; + vnfcType: any=''; + protocol: any=''; refObj: any; public paramsContent = localStorage['paramsContent']; @@ -175,13 +155,12 @@ export class GoldenConfigurationMappingComponent implements OnInit { this.activeRoutes.url.subscribe(UrlSegment => { this.actionType = UrlSegment[0].path; }); - if (this.actionType === 'configureTemplate') { - this.mappingEditorService.fromScreen = 'TemplateScreen'; - } + if (this.actionType === 'myTemplates') { this.mappingEditorService.fromScreen = 'MappingScreen'; } this.mappingEditorService.paramData = []; + this.identifier = this.mappingEditorService.identifier; } @@ -192,11 +171,7 @@ export class GoldenConfigurationMappingComponent implements OnInit { } //========================== End of browseOption() Method============================================ - selectedNavItem(item: any) { - this.item = item; - } - - //========================== End of selectedNavItem() Method============================================ + ngOnDestroy() { this.prepareFileName(); } @@ -221,73 +196,13 @@ export class GoldenConfigurationMappingComponent implements OnInit { } } else { - this.Actions = []; this.enableMappingBrowse = false; } } //========================== End of ngAfterViewInit() Method============================================ - upload(evt: any) { - /* wire up file reader */ - if (evt.target.files[0]) { - const target: DataTransfer = (evt.target); - this.myfileName = evt.target.files[0].name; - var fileExtension = this.myfileName.substr(this.myfileName.lastIndexOf('.') + 1); - if (fileExtension.toUpperCase() === 'xls'.toUpperCase()) { - if (target.files.length != 1) { - throw new Error('Cannot upload multiple files on the entry'); - } - const reader = new FileReader(); - reader.onload = (e: any) => { - /* read workbook */ - const bstr = e.target.result; - const wb = XLSX.read(bstr, { type: 'binary' }); - /* grab first sheet */ - const wsname = wb.SheetNames[0]; - const ws = wb.Sheets[wsname]; - /* save data */ - let arrData = ((XLSX.utils.sheet_to_json(ws, { header: 1 }))); - var jsonStr = arrData.toString(); - var JsonArr = jsonStr.split(','); - var finalStr = '{\r\n'; - for (var i = 0; i < JsonArr.length; i = i + 2) { - var key = JsonArr[i]; - var value = JsonArr[i + 1]; - finalStr = finalStr + key + ':' + value + ',\r\n'; - } - finalStr = finalStr.substring(0, finalStr.length - 3) + '\r\n}'; - this.artifactRequest.paramsContent = finalStr; - this.initialData = finalStr; - this.enableMappingSave = true; - }; - reader.readAsBinaryString(target.files[0]); - if ('Mapping Data' === this.selectedUploadType) { - this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..'); - this.mappingEditorService.setParamContent(this.artifactRequest.paramsContent); - } - } - else { - let reader = new FileReader(); - this.readFile(evt.target.files[0], reader, (result) => { - if ('Mapping Data' === this.selectedUploadType) { - var jsonObject = JSON.parse(result); - this.artifactRequest.paramsContent = JSON.stringify(jsonObject, null, 1); - this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..'); - this.mappingEditorService.setParamContent(this.artifactRequest.paramsContent); - } - this.initialData = result; - this.enableMappingSave = true; - }); - } - } - else { - this.notificationService.notifyErrorMessage('Failed to reading file..'); - } - this.myInputParam.nativeElement.value = ''; - } - - //========================== End of upload() Method============================================ - //uncommenting for 1710 + + public fileParamChange(input) { if (input.files && input.files[0]) { this.enableMappingSave = true; @@ -349,75 +264,7 @@ export class GoldenConfigurationMappingComponent implements OnInit { } //========================== End of onParamChanges() Method============================================ - onDownloadParameter() { - let refObj = this.refObj; - if (refObj) { - // refObj = refObj[refObj.length - 1]; - let paramsKeyValueFromEditor: JSON; - this.initialData = this.artifactRequest.paramsContent; - paramsKeyValueFromEditor = JSON.parse(this.artifactRequest.paramsContent); - let theJSON = JSON.stringify(paramsKeyValueFromEditor, null, '\t'); - var blob = new Blob([theJSON], { - type: 'text/json' - }); - this.showVersionDiv = true; - let fileName: any; - fileName = this.updateFileName(refObj.action, this.scopeName, this.versionNo); - saveAs(blob, fileName); - } - else { - this.nService.error('Error', 'Please enter Action and VNF type in Reference Data screen'); - - } - } - - //========================== End of onDownloadParameter() Method============================================ - JSONToCSVConvertor(JSONData, fileName, ShowLabel) { - //If JSONData is not an object then JSON.parse will parse the JSON string in an Object - var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; - var CSV = ''; - //This condition will generate the Label/Header - if (ShowLabel) { - var testRow = ''; - for (var index in arrData[0]) { - CSV += index + '\t' + arrData[0][index] + '\r\n'; - } - } - if (CSV == '') { - return; - } - //Initialize file format you want csv or xls - var uri = 'data:application/vnd.ms-excel,' + encodeURI(CSV); - var link = document.createElement('a'); - link.href = uri; - link.download = fileName + '.xls'; - //this part will append the anchor tag and remove it after automatic click - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } - - //========================== End of JSONToCSVConvertor() Method============================================ - updateFileNameForXls(action: any, scopeName: any, versionNo: any) { - let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V'; - return fileName; - } - - //========================== End of updateFileNameForXls() Method============================================ - appendSlashes(artifactData) { - let x = artifactData.replace(new RegExp(',"', 'g'), ',\"'); - let y = x.replace(new RegExp('":', 'g'), '\":'); - let z = y.replace(new RegExp('{"', 'g'), '{\"'); - let t = z.replace(new RegExp(':"', 'g'), ':\"'); - let m = t.replace(new RegExp('",', 'g'), '\",'); - let n = y.replace(new RegExp('"}', 'g'), '\"}'); - let nw = n.replace(new RegExp('{"', 'g'), '{\"'); - let nw1 = nw.replace(new RegExp(':"', 'g'), ':\"'); - let nw2 = nw1.replace(new RegExp('",', 'g'), '\",'); - return nw2; - } - - //========================== End of appendSlashes() Method============================================ + updateFileName(action: any, scopeName: any, versionNo: any) { let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V.json'; this.downloadedFileName = fileName; @@ -431,55 +278,14 @@ export class GoldenConfigurationMappingComponent implements OnInit { } //========================== End of prepareFileName() Method============================================ - openModel(toShow: any, message: any, title: any) { - this.message = message; - this.title = title; - $('#modalButton').trigger('click'); - } - - //========================== End of openModel() Method============================================ - checkSave(selectedAction): void { - if (this.actionType === 'updateTemplate') { - if (!this.buildDesignComponent.isReferenceFound(selectedAction, this.mappingEditorService.getReferenceList())) { - this.nService.error('Error', 'Reference Data not found. Please add Reference Data for Action:' + selectedAction); - } - } - if (this.initialData != this.artifactRequest.paramsContent) { - this.showConfirm(this.initialData); - } - else { - this.initialAction = this.item.action; - } - } - - //========================== End of checkSave() Method============================================ - showConfirm(initialData) { - let disposable = this.dialogService.addDialog(ConfirmComponent, { - title: 'Confirm title', - message: 'Confirm message' - }) - .subscribe((isConfirmed) => { - //We get dialog result - if (isConfirmed) { - this.artifactRequest.paramsContent = initialData; - this.initialAction = this.item.action; - } - else { - this.item.action = this.initialAction; - } - }); - } - - //========================== End of showConfirm() Method============================================ + retrieveNameValueFromAppc() { let refObj = this.refObj; if (refObj && refObj != undefined) { - // console.log("REF OBJECT IN RETRIVE"+JSON.stringify(refObj)); this.enableMerge = true; var scopeName = this.scopeName.replace(/ /g, '').replace(new RegExp('/', "g"), '_').replace(/ /g, ''); let fileName = this.updateFileName(this.item.action, scopeName, this.versionNo); let payload = '{"userID": "' + this.userId + '", "action": "' + this.item.action + '", "vnf-type" : "' + this.vnfType + '", "artifact-type":"APPC-CONFIG", "artifact-name":"' + fileName + '"}'; - // console.log("payload OBJECT IN RETRIVE"+JSON.stringify(payload)); let input = { 'input': { 'design-request': { @@ -531,70 +337,8 @@ export class GoldenConfigurationMappingComponent implements OnInit { } //========================== End of retrieveNameValueFromAppc() Method============================================ - saveNameValueToAppc() { - let refObj = this.refObj; - if (refObj && refObj != undefined) { - // refObj = refObj[refObj.length - 1]; - let paramsKeyValueFromEditor = JSON.parse(this.artifactRequest.paramsContent); - let action = this.item.action; - let fileName = this.updateFileName(refObj.action, this.scopeName, this.versionNo); - 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.versionNo, - 'artifact-contents': slashedPayload - }; - let data = - { - 'input': { - 'design-request': { - 'request-id': this.apiToken, - 'action': 'uploadArtifact', - 'payload': JSON.stringify(newPayload) - } - } - }; - this - .httpUtil - .post( - { url: environment.getDesigns, data: data }) - .subscribe(resp => { - if (resp.output.status.code === '400' && resp.output.status.message === 'success') { - this.nService.success('Success', 'Name/value pairs saved successfully to APPC'); - } - if (resp.output.status.code === '401') { - this.nService.error('Error', resp.output.status.message); - } - }, - error => this.nService.error('Error', 'Could not save name value pairs. Error in connecting APPC Server')); - } - setTimeout(() => { - this.ngProgress.done(); - }, 3500); - } - - //========================== End of saveNameValueToAppc() Method============================================ + formatNameValuePairs(namevaluePairs: string) { - //var string = namevaluePairs.substring(2, namevaluePairs.length - 2); - /* var stringArr = string.split(","); - var newStringArr = []; - var resultStr = "{\r\n\""; - for (var index in stringArr) { - newStringArr[index] = stringArr[index] + ",\r\n"; - } - for (var index in newStringArr) { - resultStr = resultStr + newStringArr[index]; - } - resultStr = resultStr.substring(0, resultStr.length - 3) + "\"\r\n}" - return resultStr;*/ - var string = namevaluePairs.substring(1, namevaluePairs.length - 1); var stringArr = string.split(','); var newStringArr = []; @@ -619,7 +363,6 @@ export class GoldenConfigurationMappingComponent implements OnInit { var pdDataArrayForSession = []; try { paramNameValues = JSON.parse(paramNameValuesStr); - console.log('Param Name values array==' + JSON.stringify(paramNameValues)); if (paramNameValues && paramNameValues != undefined) { for (var index in paramNameValues) { var json = { @@ -688,7 +431,7 @@ export class GoldenConfigurationMappingComponent implements OnInit { 'ruleTypeValues': arr2item.ruleTypeValues }; pdDataArrayForSession.splice(i, 1, json); - // console.log("Result array index ==" + JSON.stringify(resultArr[i])) + } }); -- cgit 1.2.3-korg