2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
20 ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 ============LICENSE_END============================================
24 import { Component, OnInit, ViewChild } from '@angular/core';
25 import { saveAs } from 'file-saver';
26 import { ParamShareService } from '../../../shared/services/paramShare.service';
27 import { MappingEditorService } from '../../../shared/services/mapping-editor.service';
28 import { ModalComponent } from '../../../shared/modal/modal.component';
29 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
30 import { UtilityService } from '../../../shared/services/utilityService/utility.service';
31 import { environment } from '../../../../environments/environment';
32 import { NotificationsService } from 'angular2-notifications';
33 import { ParameterDefinitionService } from './parameter-definition.service';
34 import 'rxjs/add/operator/map';
35 import { NgProgress } from 'ngx-progressbar';
38 let YAML = require('yamljs');
43 selector: 'parameter-form',
44 templateUrl: './parameter.component.html',
45 styleUrls: ['../reference-dataform/reference-dataform.component.css'],
46 providers: [ParameterDefinitionService]
48 export class ParameterComponent implements OnInit {
49 public paramForm: any;
50 public actionType: any;
51 public showFilterFields: boolean;
52 public filterByFieldvalues = [null, 'vm-number', 'vnfc-function-code'];
53 public ruleTypeConfiguaration = {
56 'key-name': 'unique-key-name',
57 'key-value': 'parent-name'
60 'key-name': 'unique-key-value',
64 'key-name': 'field-key-name',
65 'key-value': 'vnf-name'
70 'key-name': 'unique-key-name',
71 'key-value': 'parent-name'
74 'key-name': 'unique-key-value',
75 'key-value': 'vserver'
78 'key-name': 'field-key-name',
79 'key-value': 'vserver-name'
84 'key-name': 'unique-key-name',
85 'key-value': 'parent-name'
88 'key-name': 'unique-key-value',
92 'key-name': 'field-key-name',
93 'key-value': 'vnfc-name'
96 'vnf-oam-ipv4-address': [
98 'key-name': 'unique-key-name',
99 'key-value': 'parent-name'
102 'key-name': 'unique-key-value',
106 'key-name': 'field-key-name',
107 'key-value': 'ipv4-oam-ipaddress'
110 'vnfc-oam-ipv4-address-list': [
112 'key-name': 'unique-key-name',
113 'key-value': 'parent-name'
116 'key-name': 'unique-key-value',
120 'key-name': 'field-key-name',
121 'key-value': 'ipaddress-v4-oam-vip'
125 public requiredValues: boolean[] = [null, true, false];
126 public sourceValues = ['Manual', 'A&AI'];
127 public ruleTypeValues = [null, 'vnf-name', 'vm-name-list', 'vnfc-name-list', 'vnf-oam-ipv4-address', 'vnfc-oam-ipv4-address-list'];
128 public typeValues = [null, 'ipv4-address', 'ipv6-address', 'ipv4-prefix', 'ipv6-prefix'];
129 public responseKeyNameValues = ['', 'unique-key-name', 'unique-key-value', 'field-key-name'];
130 public responseKeyValues = ['(none)', 'addressfqdn', 'ipaddress-v4', 'ipaddress-v6'];
131 public requestKeyNameValues = [''];
132 public requestKeyValues = ['', '(none)'];
133 public myKeyFileName = null;
134 public myPdFileName = null;
135 public disposable: any;
136 public confirmation: boolean;
137 public showConfirmation: boolean;
138 public test: boolean;
139 apiToken = localStorage['apiToken'];
140 userId = localStorage['userId'];
141 public initialData: any;
142 public intialData: any;
143 public initialAction: any;
144 public item: any = {};
145 public subscription: any;
147 { action: 'ConfigBackup', value: 'ConfigBackup' },
148 { action: 'ConfigModify', value: 'ConfigModify' },
149 { action: 'ConfigRestore', value: 'ConfigRestore' },
150 { action: 'Configure', value: 'Configure' },
151 { action: 'GetRunningConfig', value: 'GetRunningConfig' },
152 { action: 'HealthCheck', value: 'HealthCheck' },
153 { action: 'StartApplication', value: 'StartApplication' },
154 { action: 'StopApplication', value: 'StopApplication' }
156 public uploadTypes = [{
157 value: 'External Key File',
168 showProgressBar: true,
173 public vnfcTypeData: string = '';
174 public selectedUploadType: string;
175 @ViewChild(ModalComponent) modalComponent: ModalComponent;
176 public title: string;
177 public parameterDefinitionMap: { [index: string]: string; } = {};
178 public parameterNameValues = {};
179 public displayParamObjects;
180 public modelParamDefinitionObjects;
184 public refNameObj = {};
187 public appDataObject: any;
188 public downloadDataObject: any;
189 public artifact_fileName;
191 private selectedActionReference: any;
193 constructor (private httpService: HttpUtilService,
194 private parameterDefinitionService: ParameterDefinitionService,
195 private paramShareService: ParamShareService,
196 private mappingEditorService: MappingEditorService,
197 private httpUtil: HttpUtilService,
198 private utilService: UtilityService,
199 private nService: NotificationsService,
200 private ngProgress: NgProgress) {
204 this.selectedActionReference = this.parameterDefinitionService.prepareFileName();
205 if (this.selectedActionReference && this.selectedActionReference != undefined) {
207 this.vnfType = this.selectedActionReference.scope['vnf-type'];
208 this.vnfcType = this.selectedActionReference.scope['vnfc-type'];
209 this.protocol = this.selectedActionReference['device-protocol'];
210 this.action = this.selectedActionReference.action;
212 for (let i = 0; i < this.selectedActionReference['artifact-list'].length; i++) {
213 let artifactList = this.selectedActionReference['artifact-list'];
214 if (artifactList[i]['artifact-type'] === 'parameter_definitions') {
215 this.artifact_fileName = artifactList[i]['artifact-name'];
218 this.parameterDefinitionService.setValues(this.vnfType, this.vnfcType, this.protocol, this.action, this.artifact_fileName);
221 this.selectedActionReference = {
223 'scope': { 'vnf-type': '', 'vnfc-type': '' },
226 'download-dg-reference': '',
230 'deviceTemplate': '',
235 this.identifier = this.mappingEditorService.identifier;
239 if (this.mappingEditorService.latestAction) {
240 this.displayParamObjects = [];
241 this.modelParamDefinitionObjects = [];
242 if (this.paramShareService.getSessionParamData() != undefined && this.paramShareService.getSessionParamData().length > 0) {
243 this.displayParamObjects = this.paramShareService.getSessionParamData();
248 this.nService.error('Error', 'Please enter Action and VNF type in Reference Data screen');
250 return this.displayParamObjects;
259 'request-id': this.apiToken,
260 'action': 'getArtifact',
261 'payload': '{"userID": "' + this.userId + '", "vnf-type" : "' + this.vnfType + '", "artifact-type":"APPC-CONFIG", "artifact-name":"' + this.artifact_fileName + '"}'
265 let artifactContent: any;
266 this.ngProgress.start();
267 return this.httpService.post({
268 url: environment.getDesigns,
270 }).subscribe(data => {
271 if (this.utilService.checkResult(data)) {
272 let result: any = JSON.parse(data.output.data.block).artifactInfo[0];
273 var pdObject = YAML.parse(result['artifact-content']);
274 let fileModel = pdObject['vnf-parameter-list'];
275 this.displayParamObjects = this.parameterDefinitionService.populatePD(fileModel);
280 this.ngProgress.done();
283 error => this.nService.error('Error', 'Error in connecting APPC Server'));
287 //========================== End of NGInit() Method============================================
288 selectedNavItem(item: any) {
292 //========================== End of selectedNavItem() Method============================================
294 $('#inputFile1').trigger('click');
297 //========================== End of browsePdFile() Method============================================
299 $('#inputFile2').trigger('click');
303 //========================== End of browseKeyFile() Method============================================
306 //========================== End of appendSlashes() Method============================================
309 //========================== End of prepareFileName() Method============================================
311 this.parameterDefinitionService.destroy(this.displayParamObjects);
314 //========================== End of ngOnDestroy() Method============================================
316 //========================== End of createOrUpdateParameterDefinitionData() Method============================================
317 public showUpload() {
318 this.selectedUploadType = this.uploadTypes[0].value;
321 //========================== End of showUpload() Method============================================
322 //This is called when the user selects new files from the upload button
323 public fileChange(input, uploadType) {
324 if (input.files && input.files[0]) {
325 // Create the file reader
326 let reader = new FileReader();
327 this.readFile(input.files[0], reader, (result) => {
328 if ('pdfile' === uploadType) {
329 this.myPdFileName = input.files[0].name;
330 this.displayParamObjects = this.parameterDefinitionService.processPDfile(this.myPdFileName, result);
334 //this.notificationService.notifyErrorMessage('Failed to read file!Please try again.');
338 //========================== End of fileChange() Method============================================
339 public readFile(file, reader, callback) {
340 // Set a callback funtion to fire after the file is fully loaded
341 reader.onload = () => {
342 // callback with the results
343 callback(reader.result);
346 reader.readAsText(file, 'UTF-8');
349 //========================== End of readFile() Method============================================
350 fileChangeEvent(fileInput: any) {
351 let obj: any = fileInput.target.files;
355 sourceChanged(data, obj) {
356 if (data == 'A&AI') {
357 obj.ruleTypeValues = [null, 'vnf-name', 'vm-name-list', 'vnfc-name-list', 'vnf-oam-ipv4-address', 'vnfc-oam-ipv4-address-list'];
358 for (let x = 0; x < 5; x++) {
359 obj['response-keys'][x]['key-name'] = null;
360 obj['response-keys'][x]['key-value'] = null;
362 } else if (data == 'Manual') {
363 obj.ruleTypeValues = [null];
364 obj['rule-type'] = null;
365 obj.showFilterFields = false;
366 for (let x = 0; x < 5; x++) {
367 obj['response-keys'][x]['key-name'] = null;
368 obj['response-keys'][x]['key-value'] = null;
372 obj.ruleTypeValues = [null];
376 //========================== End of sourceChanged() Method============================================
377 ruleTypeChanged(data, obj) {
378 if (data == null || data == undefined || data == 'null') {
379 obj.showFilterFields = false;
380 obj['rule-type'] = null;
381 for (let x = 0; x < 5; x++) {
382 obj['response-keys'][x]['key-name'] = null;
383 obj['response-keys'][x]['key-value'] = null;
386 let sourceObject = this.ruleTypeConfiguaration[data];
387 if (data == 'vm-name-list' || data == 'vnfc-name-list' || data == 'vnfc-oam-ipv4-address-list') {
388 this.showFilterFields = false;
389 obj.showFilterFields = true;
390 this.filetrByFieldChanged(obj['response-keys'][3]['key-value'], obj);
392 obj.showFilterFields = false;
393 obj['response-keys'][3]['key-name'] = null;
394 obj['response-keys'][3]['key-value'] = null;
395 obj['response-keys'][4]['key-name'] = null;
396 obj['response-keys'][4]['key-value'] = null;
398 for (let x = 0; x < sourceObject.length; x++) {
399 obj['response-keys'][x]['key-name'] = sourceObject[x]['key-name'];
400 obj['response-keys'][x]['key-value'] = sourceObject[x]['key-value'];
406 //========================== End of ruleTypeChanged() Method============================================
407 filetrByFieldChanged(data, obj) {
408 if (data == null || data == undefined || data == 'null') {
409 obj.enableFilterByValue = false;
410 obj['response-keys'][4]['key-value'] = null;
412 obj.enableFilterByValue = true;