diff options
Diffstat (limited to 'src/app/vnfs/build-artifacts/template-holder/template-configuration')
3 files changed, 234 insertions, 282 deletions
diff --git a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.html b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.html index c1fb030..335b595 100644 --- a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.html +++ b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.html @@ -21,8 +21,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ --> <simple-notifications [options]="options"></simple-notifications> -<ng-progress [positionUsing]="'marginLeft'" [minimum]="0.15" [maximum]="1" [speed]="200" [showSpinner]="false" [direction]="'leftToRightIncreased'" [color]="'#6ab344'" - [trickleSpeed]="250" [thick]="true" [ease]="'linear'"></ng-progress> +<ng-progress [positionUsing]="'marginLeft'" [minimum]="0.15" [maximum]="1" [speed]="200" [showSpinner]="false" [direction]="'leftToRightIncreased'" [color]="'#6ab344'" [trickleSpeed]="250" [thick]="true" [ease]="'linear'"></ng-progress> <div> <div> <div class="card" style="margin-bottom: 23px;"> @@ -43,7 +42,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <label>Protocol</label><input class="form-control" type="text" disabled value="{{protocol}}" /> </div> <div *ngIf="(action === 'ConfigScaleOut')" class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> - <label>templateIdentifier</label><input class="form-control" type="text" disabled value="{{identifier}}" /> + <label>Template Identifier</label><input class="form-control" type="text" disabled value="{{identifier}}" /> </div> </div> </div> @@ -53,8 +52,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <div class="input-group"> <input id="inputFile" class="file" #myInput type='file' (change)='fileChange(myInput)'> <input [(ngModel)]="fileName" type="text" class="input-lg" disabled placeholder="Upload template from PC" style="width:80%"> - <button (click)="browseOption($event)" [disabled]="!enableBrowse" class="browse mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary input-lg" - type="button">Upload Template File + <button (click)="browseOption($event)" [disabled]="!enableBrowse" class="browse mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary input-lg" type="button">Upload Template File </button> </div> </div> @@ -73,10 +71,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <div><label for="textAreaGeneratedTemplate"> <div class="mdl-card__title-text">File Editor</div> </label> - <!-- <ace-editor [(text)]="configMappingEditorContent" #templateeditor [theme]="'chrome'" [mode]="'velocity'" [options]="{maxLines: 'Infinity', fontSize: '13pt'}" - style="min-height: 500px; width: fit-content;scroll-snap-coordinate: 3%"></ace-editor> --> - <ace-editor [(text)]="configMappingEditorContent" #templateeditor [theme]="'chrome'" [mode]="'velocity'" [options]="{maxLines: 'Infinity', fontSize: '13pt' }" - style="min-height: 500px; width: 100%"></ace-editor> + <ace-editor [(text)]="configMappingEditorContent" #templateeditor [theme]="'chrome'" [mode]="'velocity'" [options]="{maxLines: 'Infinity', fontSize: '13pt' }" style="min-height: 500px; width: 100%"></ace-editor> </div> <app-modal [title]="'Confirmation'" [isShow]="false" [message]="'Template is saved and ready for creating parameter definition'" #modalComponent> </app-modal> diff --git a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts index f26e5fd..d2412a0 100644 --- a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts +++ b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts @@ -21,12 +21,11 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ -/* tslint:disable:no-unused-variable */ + 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 { ModalComponent } from '../../modal/modal.component'; import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service'; import { MappingEditorService } from '../../../../shared/services/mapping-editor.service'; import { ArtifactRequest } from '../../../../shared/models/index'; @@ -36,8 +35,8 @@ import { NotificationService } from '../../../../shared/services/notification.se 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 { 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'; @@ -53,6 +52,8 @@ import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal'; import { SimpleNotificationsModule } from 'angular2-notifications'; import { GoldenConfigurationComponent } from './template-configuration.component'; import { NgProgress } from 'ngx-progressbar'; +import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http'; +import { MockBackend, MockConnection } from '@angular/http/testing'; describe('GoldenConfigurationComponent', () => { let component: GoldenConfigurationComponent; @@ -97,7 +98,17 @@ describe('GoldenConfigurationComponent', () => { TestBed.configureTestingModule({ imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()], declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent], - providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, HttpUtilService, MappingEditorService, NotificationsService], + providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, MockBackend, + BaseRequestOptions, + { + provide: Http, + useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + }, + + HttpUtilService, MappingEditorService, NotificationsService], schemas: [NO_ERRORS_SCHEMA], }) @@ -132,28 +143,28 @@ describe('GoldenConfigurationComponent', () => { 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'); - + 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(GoldenConfigurationComponent); component = fixture.componentInstance; - mappingEditorService.latestAction = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" }; - + // mappingEditorService.latestAction = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" }; + mappingEditorService.latestAction = undefined; expect(component.ngAfterViewInit()); expect(component.action).toEqual(''); expect(component.vnfType).toEqual(''); expect(component.vnfcType).toEqual(''); expect(component.protocol).toEqual(''); expect(component.artifactName).toEqual(''); - + })); - it('check if correct notification is fired while initialising if reference data object is undefined',()=>{ + it('check if correct notification is fired while initialising if reference data object is undefined', () => { fixture = TestBed.createComponent(GoldenConfigurationComponent); component = fixture.componentInstance; expect(component.ngAfterViewInit()); @@ -161,39 +172,205 @@ describe('GoldenConfigurationComponent', () => { expect(component.enableBrowse).toBe(false) }); - it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => { + it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => { fixture = TestBed.createComponent(GoldenConfigurationComponent); component = fixture.componentInstance; mappingEditorService.fromScreen === 'MappingScreen' - component.configMappingEditorContent="<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); - - 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]}]; + + 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]); - localStorage["paramsContent"]={ - "sync_auto-pop_name1":"10.0.1.34", - "sync_auto-pop_address1":"", - "node0_tacplus_server_name2":"192.34.45.5" - }; + localStorage["paramsContent"] = { + "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_address1": "", + "node0_tacplus_server_name2": "testIp2" + }; expect(component.syncTemplate()); - - + + })); - it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => { + it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => { fixture = TestBed.createComponent(GoldenConfigurationComponent); component = fixture.componentInstance; mappingEditorService.fromScreen === 'MappingScreen' - component.configMappingEditorContent="<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); - - var pdData=[]; + + var pdData = []; paramShareService.setSessionParamData([pdData]); - localStorage["paramsContent"]={}; + localStorage["paramsContent"] = {}; expect(component.syncTemplate()); - - + + + })); + + it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} }; + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" + mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "testIp1", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "testIp2" }); + + component.userId = "testuser"; + component.apiToken = "87264736473"; + component.prepareAppData(); + var paramData = { "input": ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"testuser","vnf-type":"testVnf","action":"Configure","artifact-name":"param_Configure_testVnf_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"[{\"sync_auto-pop_name1\":\"10.0.1.34\",\"sync_auto-pop_address1\":\"\",\"node0_tacplus_server_name2\":\"192.34.45.5\"}]"}' }) }) }; + var templateData = { input: ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"testuser","vnf-type":"testVnf","action":"Configure","artifact-name":"template_Configure_test_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n<version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"}' }) }) }; + expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"])); + expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"])); + })); + + + it('test whether proper param data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + component.downloadDataObject = { + reference: {}, + template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, + pd: { pdData: '', pdFileName: '' } + }; + localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "testIp1", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "testIp2" }); + + component.onDownloadParameter(); + var nameValueData = { + "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_address1": "", + "node0_tacplus_server_name2": "testIp2" + }; + expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t")); + expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json"); + })); + + it('test whether proper template data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + component.downloadDataObject = { + reference: {}, + template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, + pd: { pdData: '', pdFileName: '' } + }; + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" + component.fileType = "text/xml" + component.onDownloadTemplate('Template'); + + component.fileType = "text/plain" + component.onDownloadTemplate('Template'); + component.fileType = "text/json" + component.onDownloadTemplate('Template'); + component.tempretrieveFlag = true; + component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json" + component.onDownloadTemplate('Template'); + expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}')); + })); + + + it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + component.downloadDataObject = { + reference: {}, + template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, + pd: { pdData: '', pdFileName: '' } + }; + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>testIp1</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>testIp2</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>"; + mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + localStorage["paramsContent"] = JSON.stringify({ + "node0_tacplus_server_name1": "testIp1", + "node0_tacplus_server_source_address1": "675453432", + "node0_tacplus_server_name2": "testIp2" + }); + component.mergeParams(); + expect(component.mergeStatus).toBe(true); + + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>" + mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + component.mergeParams(); + expect(component.mergeStatus).toBe(false); + + })); + + it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>199.37.184.211</name>\r\n <source-address>675453432</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>675453432</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>"; + mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + component.selectedWord = "node0"; + expect(component.handleAnnotation(component.modal)); })); + it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + 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" }; + component.ngOnInit(); + component.ngAfterViewInit(); + + component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>{(node1)=(name1)}</name>\r\n <source-address>675453432</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>675453432</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>"; + mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); + component.selectedWord = "node0"; + component.tempName = "name0"; + component.submitNameValues() + expect(component.replaceWord).toContain("{(node0)=(name0)}"); + component.selectedWord = "{(node1)=(name1)}"; + component.submitNameValues(); + component.tempName = false; + component.submitNameValues(); + })); + + it('retrieveTemplateFromAppc function should return response on success and set the configMappingEditorContent object', inject([HttpUtilService, NgProgress, MappingEditorService, MockBackend], (httpUtilService: HttpUtilService, mappingEditorService: MappingEditorService, ngProgress: NgProgress, mockBackend: MockBackend) => { + fixture = TestBed.createComponent(GoldenConfigurationComponent); + component = fixture.componentInstance; + var mockData = { + "output": { + "data": { + "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\" <configuration xmlns=\\\"http://xml.juniper.net/xnm/1.1/xnm\\\" \\n xmlns:a=\\\"http://xml.juniper.net/junos/15.1X49/junos\\\" >\\n <version>15.1X49-D50.3</version>\\n <groups>\\n <name>node0</name>\\n <system>\\n <tacplus-server>\\n <name>${sync_auto-pop_name1}</name>\\n <source-address>${sync_auto-pop_address1}</source-address>\\n </tacplus-server>\\n <tacplus-server>\\n <name>${node0_tacplus_server_name2}</name>\\n <source-address>${sync_auto-pop_address1}</source-address>\\n </tacplus-server>\\n </system> \\n </groups>\\n </configuration>\"}]}", + "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.retrieveTemplateFromAppc(); + expect(component.configMappingEditorContent).not.toBe(null); + + })); }); diff --git a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.ts b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.ts index 8514e24..1d1bc4f 100644 --- a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.ts +++ b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.ts @@ -22,7 +22,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. */ import { Component, Input, OnInit, ViewChild } from '@angular/core'; -//import { ModalComponent } from '../../modal/modal.component'; import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service'; import { MappingEditorService } from '../../../../shared/services/mapping-editor.service'; import { ArtifactRequest } from '../../../../shared/models/index'; @@ -45,7 +44,6 @@ export class GoldenConfigurationComponent implements OnInit { @Input() configMappingEditorContent: string; @Input() isMappingComp: boolean; @ViewChild('myInput') myInputVariable: any; - // @ViewChild(ModalComponent) modalComponent: ModalComponent; @ViewChild('myModal') modal: ModalComponent; aceText: string = "" fileName: string = "" @@ -96,6 +94,7 @@ export class GoldenConfigurationComponent implements OnInit { clickToClose: true, maxLength: 200 } + public replaceWord; public enableDownloadButtons: boolean = false; constructor(private buildDesignComponent: BuildDesignComponent, private paramShareService: ParamShareService, private dialogService: DialogService, private notificationService: NotificationService, private httpUtil: HttpUtilService, private mappingEditorService: MappingEditorService, private activeRoutes: ActivatedRoute, private router: Router, private nService: NotificationsService, private ngProgress: NgProgress) { this.artifactRequest.action = ''; @@ -131,13 +130,13 @@ export class GoldenConfigurationComponent implements OnInit { enableValidateTemplate: boolean = false;; public selectedUploadType: string = this.uploadTypes[0].value; identifier: any; - //this.mappingeditorservice.referenceNameObjects = object;PLEASE USE THIS OBJECT TO GET TEMPALLDATA - //==================================================== + public tempRetrievalResponse:any; + public mergeStatus:boolean=false; + + //======================================Start of ngOnInit() Method============================================ ngOnInit() { var refObj = this.refObj = this.prepareFileName(); - // console.log("Ref object: " + JSON.stringify(refObj)) if (refObj && refObj != undefined) { - // refObj = refObj[refObj.length - 1]; this.item = refObj; this.vnfType = this.item.scope["vnf-type"]; @@ -160,17 +159,11 @@ export class GoldenConfigurationComponent implements OnInit { this.activeRoutes.url.subscribe(UrlSegment => { this.actionType = UrlSegment[0].path }) - /*if (this.actionType === 'createTemplate') { - this.mappingEditorService.fromScreen = 'TemplateScreen'; - } - if (this.actionType === 'updateTemplate') {*/ this.mappingEditorService.fromScreen = 'MappingScreen'; - // } this.identifier = this.mappingEditorService.identifier; } //========================== End of ngOnInit() Method============================================ ngOnDestroy() { - //console.log("Reference object =="+ JSON.stringify(this.refObj)); if (this.refObj && this.refObj != undefined) { if (this.configMappingEditorContent && this.configMappingEditorContent != undefined) { this.saveTemplate(); @@ -200,13 +193,6 @@ export class GoldenConfigurationComponent implements OnInit { } let self = this; this.templateEditor = self.templateeditor.getEditor(); - /* this.templateeditor.getEditor().commands.addCommand({ - name: 'annotateCommand', - bindKey: { win: 'Ctrl-4', mac: 'Command-4' }, - exec: function (editor) { - self.mappingEditorService.checkMethodCall(this.modal); - } - });*/ this.templateeditor.getEditor().commands.addCommand({ name: 'annotateCommand', bindKey: { win: 'ENTER', mac: 'ENTER' }, @@ -218,10 +204,6 @@ export class GoldenConfigurationComponent implements OnInit { this.configMappingEditorContent = this.mappingEditorService.getTemplateMappingDataFromStore(); this.fileType = sessionStorage.getItem('fileType'); } - /* else if (this.mappingEditorService.fromScreen === 'TemplateScreen') { - this.configMappingEditorContent = this.mappingEditorService.getTemplateDataFromStore(); - this.fileType = sessionStorage.getItem('fileType'); - }*/ if (this.configMappingEditorContent) { this.artifactRequest.templateContent = this.configMappingEditorContent; this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal); @@ -246,18 +228,6 @@ export class GoldenConfigurationComponent implements OnInit { $("#inputFile").trigger('click'); } //========================== End of browseOption() Method============================================ - /* openFile(event) { - let input = event.target; - this.fileName = event.currentTarget.value.replace(/C:\\fakepath\\/i, ''); - for (let index = 0; index < input.files.length; index++) { - let reader = new FileReader(); - reader.onload = () => { - this.configMappingEditorContent = reader.result; - } - reader.readAsText(input.files[index]); - }; - } - //========================== End of openFile() Method============================================*/ //save to GUI public saveTemplate() { this.saveToGuiCacheFlag = 'true'; @@ -286,46 +256,9 @@ export class GoldenConfigurationComponent implements OnInit { if (this.fileType === '') { sessionStorage.setItem('fileType', ''); } - // paramArr = this.mappingEditorService.paramData; - // this.paramShareService.setTemplateData(paramArr) - } + } } //========================== End of saveTemplate() Method============================================ - /* clearHighlight() { - this.mappingEditorService.removeTheSelectedMarkers(); - } - //========================== End of clearHighlight() Method============================================*/ - /*validateTemplate() { - var fileExtensionArr = this.fileType.split("/"); - let data = { - "input": { - "design-request": { - "request-id": this.apiToken, - "action": "validateTemplate", - "data-type": fileExtensionArr[1].toUpperCase(), - "payload": this.configMappingEditorContent - } - } - }; - let url = environment.validateTemplate; - this - .httpUtil - .post( - { url: url, data: data }) - .subscribe(resp => { - if (resp.output.status.code === '400' && resp.output.status.message === "success") { - this.uploadValidationSuccess = true; - this.nService.success("Success", "Template Validated succesfully"); - return true; - } - else if (resp.output.status.code === '401') { - this.nService.error("Error", resp.output.status.message); - return false; - } - }, - error => this.nService.error("Error", "Unable to validate the uploaded template. Error in connecting APPC Server")); - } - //========================== End of validateTemplate() Method============================================*/ retrieveTemplateFromAppc() { let refObj = this.refObj; if (refObj && refObj != undefined) { @@ -341,7 +274,6 @@ export class GoldenConfigurationComponent implements OnInit { } } }; - // console.log("Retrieve artifact payload=="+ payload); let artifactContent: any; this.ngProgress.start(); this.httpUtil.post({ @@ -350,6 +282,7 @@ export class GoldenConfigurationComponent implements OnInit { }).subscribe(resp => { if (resp.output.status.code === '400' && resp.output.status.message === "success") { this.nService.success("Success", "Template retrieved successfully from APPC"); + this.tempRetrievalResponse=resp; let result = JSON.parse(resp.output.data.block).artifactInfo[0]; result = result['artifact-content']; if ('Generated Template' === this.selectedUploadType) { @@ -371,16 +304,7 @@ export class GoldenConfigurationComponent implements OnInit { } this.ngProgress.done(); }, - /* (error) => { - // this.showUploadErrorStatus = true; - // this.nService.error('Status','Error Connecting to the APPC Network') - //this.notificationService.notifyErrorMessage('Configuration Template file successfully uploaded..') - //this.uploadStatusError = true; - //window.scrollTo(0, 0) - // this. nService.error('Status','Error Connecting to the APPC Network') - this.openModel(true, "Could not retrieve latest template for given action""Error in connecting to APPC database") - });*/ - error => this.nService.error("Error", "Error in connecting to APPC Server")); + error => this.nService.error("Error", "Error in connecting to APPC Server")); setTimeout(() => { this.ngProgress.done(); }, 3500); @@ -389,14 +313,8 @@ export class GoldenConfigurationComponent implements OnInit { //========================== End of retrieveTemplateFromAppc() Method============================================ prepareAppData() { let refObj = this.refObj; - //console.log("Reference object =="+ JSON.stringify(refObj)); if (refObj && refObj != undefined) { - // refObj = refObj[refObj.length - 1]; let paramsKeyValueFromEditor: JSON; - /* if (this.fileExtension.toUpperCase() === "XML") - paramsKeyValueFromEditor = this.mappingEditorService.generateParams(this.templateeditor.getEditor(), this.artifactRequest.templateContent); - else*/ - // paramsKeyValueFromEditor = this.mappingEditorService.generateParams(this.templateeditor.getEditor(), this.artifactRequest.templateContent); try { paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]); } @@ -432,7 +350,7 @@ export class GoldenConfigurationComponent implements OnInit { } } } - this.appDataObject.template.nameValueData = data; + this.appDataObject.template.nameValueData = data; } if (this.configMappingEditorContent) { let actualContent = this.configMappingEditorContent; @@ -452,7 +370,6 @@ export class GoldenConfigurationComponent implements OnInit { fileName = this.fileNameForTempSave; } else { - // fileName = this.updateDownloadTemplateFileName(refObj.action, this.scopeName, versionandFileType); fileName = this.artifactName; } let vnfType = this.vnfType; @@ -464,7 +381,6 @@ export class GoldenConfigurationComponent implements OnInit { "artifact-name": fileName, "artifact-type": "APPC-CONFIG", "artifact-version": this.templateVersionNo, - //"artifact-contents": this.configMappingEditorContent "artifact-contents": this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}') } @@ -485,51 +401,6 @@ export class GoldenConfigurationComponent implements OnInit { } } //========================== End of prepareAppData() Method============================================ - /*retrieveNameValueFromAppc() { - let refObj: any = this.prepareFileName(); - if (refObj && refObj != undefined) { - let fileName = this.updateParamFileName(this.item.action, this.scopeName, this.templateVersionNo); - let payload = '{"userID": "' + this.userId + '","action": "' + this.item.action + '", "vnf-type" : "' + this.vnfType + '", "artifact-type":"APPC-CONFIG", "artifact-name":"' + fileName + '"}'; - let input = { - "input": { - "design-request": { - "request-id": this.apiToken, - "action": "getArtifact", - "payload": payload - } - } - }; - - let artifactContent: any; - this.httpUtil.post({ - // url:"https://mtanjv9apdb51.aic.cip.att.com:8443/restconf/operations/design-services:dbservice", - url: environment.getDesigns, - data: input - }).subscribe(resp => { - if (resp.output.status.code === '400' && resp.output.status.message === "success") { - this.openModel(true, 'Name/value pairs retrieved successfully from APPC', 'Success'); - let result = JSON.parse(resp.output.data.block).artifactInfo[0]; - result = JSON.parse(result['artifact-content']); - var jsonString = JSON.stringify(result[0]); - var string = jsonString.substring(1, jsonString.length - 1); - 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}" - this.configMappingEditorContent = resultStr; - - } - }, - error => this.openModel(true, "Could not retrieve the name value pairs. Error in connecting to APPC Server", "ERROR")); - } - }*/ - //========================== End of retrieveNameValueFromAppc() Method============================================ prepareFileName(): any { let fileNameObject: any = this.mappingEditorService.latestAction; this.appDataObject = this.mappingEditorService.appDataObject; @@ -541,14 +412,8 @@ export class GoldenConfigurationComponent implements OnInit { onDownloadParameter() { let refObj = this.refObj; if (refObj) { - // refObj = refObj[refObj.length - 1]; let paramsKeyValueFromEditor: JSON; - if (this.fileExtension.toUpperCase() === "XML") - paramsKeyValueFromEditor = this.mappingEditorService.generateParams(this.templateeditor.getEditor(), this.artifactRequest.templateContent); - else - paramsKeyValueFromEditor = this.mappingEditorService.generateParams(this.templateeditor.getEditor(), this.artifactRequest.templateContent); - - try { + try { paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]); } catch (error) { @@ -571,37 +436,6 @@ export class GoldenConfigurationComponent implements OnInit { } //========================== 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============================================ - updateParamFileNameForXls(action: any, scopeName: any, versionNo: any) { - let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V'; - this.downloadedParamFileName = fileName; - return fileName; - } - //========================== End of updateParamFileNameForXls() Method============================================*/ updateParamFileName(action: any, scopeName: any, versionNo: any) { let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V.json'; this.downloadedParamFileName = fileName; @@ -614,9 +448,7 @@ export class GoldenConfigurationComponent implements OnInit { var config_template_fileName: any let refObj = this.refObj; let versionandFileType: string; - this.mappingEditorService.generateTemplate(this.templateEditor); - if (artifact == 'Template' && this.artifactRequest && this.configMappingEditorContent && refObj) { - // refObj = refObj[refObj.length - 1]; + if (artifact == 'Template' && this.artifactRequest && this.configMappingEditorContent && refObj) { this.showTemplateVersionDiv = true; if (this.fileType === "text/xml") { textToSaveAsBlob = new Blob([this.configMappingEditorContent], { @@ -645,30 +477,15 @@ export class GoldenConfigurationComponent implements OnInit { }); } else { - // config_template_fileName = this.updateDownloadTemplateFileName(refObj.action, this.scopeName, versionandFileType); config_template_fileName = this.artifactName; } - // saveAs(textToSaveAsBlob, config_template_fileName); this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal); - //this.downloadDataObject.template.templateData = this.configMappingEditorContent; this.downloadDataObject.template.templateData = this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'); this.downloadDataObject.template.templateFileName = config_template_fileName; } } //========================== End of onDownloadTemplate() Method============================================ - updateDownloadTemplateFileName(action: any, scopeName: any, versionandFileType: any) { - let fileName = 'template_' + action + '_' + scopeName + '_' + versionandFileType; - this.downloadedTemplateFileName = fileName; - return fileName; - } - //========================== End of updateDownloadTemplateFileName() Method============================================ - /* openModel(toShow: any, message: any, title: any) { - //this.modalComponent.isShow = toShow; - //this.modalComponent.message = message; - //this.modalComponent.title = title; - } - //========================== End of openModel() Method============================================*/ fileChange(input) { let self = this; @@ -676,17 +493,11 @@ export class GoldenConfigurationComponent implements OnInit { this.enableValidateTemplate = true; if (refObj && refObj != undefined) { - // refObj = refObj[refObj.length - 1]; if (input.files && input.files[0]) { - console.log("input files0" + JSON.stringify(input.files[0])) this.myfileName = input.files[0].name; this.fileName = input.files[0].name; this.fileType = input.files[0].type; - // var fileExtension = this.myfileName.substr(this.myfileName.lastIndexOf('.') + 1); - let reader = new FileReader(); - // if(this.validateUploadedFile(fileExtension)) - //{ this.readFile(input.files[0], reader, (result) => { if (this.fileType === 'text/xml') { sessionStorage.setItem('fileType', 'text/xml'); @@ -703,7 +514,6 @@ export class GoldenConfigurationComponent implements OnInit { if ('Generated Template' === this.selectedUploadType) { this.configMappingEditorContent = result this.artifactRequest.templateContent = this.configMappingEditorContent; - console.log("editor content==" + JSON.stringify(this.configMappingEditorContent)) this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..'); if (this.artifactRequest.templateContent) { this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal); @@ -714,12 +524,7 @@ export class GoldenConfigurationComponent implements OnInit { this.saveTemplate(); }); - // } - // else{ - // this.nService.error("Error", "Incorrect File Format") - //this.configMappingEditorContent='' - //} - } + } else { this.nService.error("Error", "Failed to read file"); } @@ -776,22 +581,13 @@ export class GoldenConfigurationComponent implements OnInit { this.saveTemplate(); var templateData = this.mappingEditorService.paramData; //template data array - // this.paramShareService.setTemplateData(templateData); - - //console.log("Template Name value pairs ===" + JSON.stringify(templateData)) var pdData = this.paramShareService.getSessionParamData(); //PD data array - console.log("PD name value pairs===" + JSON.stringify(pdData)) - - var paramsContent = localStorage["paramsContent"]; - console.log("Param content before==" + paramsContent); - + if (paramsContent && paramsContent != undefined) { try { var paramTabData = JSON.parse(paramsContent); - //console.log("Param content after==" + paramsContent); - //console.log("Param tab data after==" + JSON.stringify(paramTabData)) - } + } catch (error) { console.log("error is : " + error) } @@ -812,7 +608,6 @@ export class GoldenConfigurationComponent implements OnInit { templateData.forEach(function (item) { resultParamObj[item.paramName] = item.paramValue; }); - // console.log("pARAM Result array before is " + JSON.stringify(resultParamObj)) if (paramTabData && paramTabData != undefined) { templateData.forEach(function (item) { for (var index in paramTabData) { @@ -836,9 +631,6 @@ export class GoldenConfigurationComponent implements OnInit { } localStorage["paramsContent"] = JSON.stringify(resultParamObj); - //console.log("param content after==" +JSON.stringify(resultParamObj)); - - //removing duplicate elements from the array templateData = Array.from(new Set(templateData.map((itemInArray) => itemInArray.paramName))) //reformatting arr1 to match with PD @@ -883,9 +675,6 @@ export class GoldenConfigurationComponent implements OnInit { }) }); } - //console.log("Result array before is " + JSON.stringify(resultArr)) - // console.log("Length before is: " + resultArr.length) - if (pdData && pdData != undefined) { for (var i = 0; i < resultArr.length; i++) { @@ -905,8 +694,7 @@ export class GoldenConfigurationComponent implements OnInit { "ruleTypeValues": arr2item.ruleTypeValues }; resultArr.splice(i, 1, json) - // console.log("Result array index ==" + JSON.stringify(resultArr[i])) - } + } }); @@ -914,8 +702,6 @@ export class GoldenConfigurationComponent implements OnInit { } this.paramShareService.setSessionParamData(resultArr); - //console.log("Result array after is " + JSON.stringify(resultArr)) - //console.log("Length after is: " + resultArr.length) this.mappingEditorService.paramData = []; //navigate to PD page after sync this @@ -925,8 +711,8 @@ export class GoldenConfigurationComponent implements OnInit { //========================== End of syncTemplate() Method============================================ mergeParams() { - var mergeStatus: boolean = this.mappingEditorService.autoAnnotateDataForParams(this.fileType); - if (mergeStatus) { + this.mergeStatus = this.mappingEditorService.autoAnnotateDataForParams(); + if (this.mergeStatus) { this.nService.success("Success", "Merge Successful"); } else { @@ -937,30 +723,24 @@ export class GoldenConfigurationComponent implements OnInit { //========================== End of mergeParams() Method============================================ public handleAnnotation(modal) { - let selectedWord: string = this.templateeditor.getEditor().session.getTextRange(this.templateeditor.getEditor().selectionRange); - this.selectedWord = selectedWord; + this.selectedWord = this.templateeditor.getEditor().session.getTextRange(this.templateeditor.getEditor().selectionRange); modal.open(); } //========================== End of handleAnnotations() Method============================================ public submitNameValues() { - /*var editor = this.templateeditor.getEditor() - this.editor = editor; - this.editor.session = editor.session; - this.editor.selection.session.$backMarkers = {}; - this.editorContent = this.artifactRequest.templateContent; - this.editor.$blockScrolling = Infinity; - this.editor.$blockSelectEnabled = false;*/ if (this.tempName) { this.checkNameEntered = true; if (this.selectedWord) { if (this.selectedWord.startsWith('${(')) { - var replaceWord: any = this.selectedWord.substring(3, this.selectedWord.indexOf(')=(')) + this.tempName; + var replaceWord: any =this.replaceWord = this.selectedWord.substring(3, this.selectedWord.indexOf(')=(')) + this.tempName; this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord); + } else { let mappingKey = this.mappingEditorService.getKeysForValues(this.selectedWord); - var replaceWord: any = '${(' + this.selectedWord + ')=(' + this.tempName + ')}'; + var replaceWord: any = this.replaceWord='${(' + this.selectedWord + ')=(' + this.tempName + ')}'; this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord); + } } this.mappingEditorService.refreshEditor(); |