2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6 Copyright (C) 2018 IBM.
7 ===================================================================
8 Unless otherwise specified, all software contained herein is licensed
9 under the Apache License, Version 2.0 (the License);
10 you may not use this software except in compliance with the License.
11 You may obtain a copy of the License at
13 http://www.apache.org/licenses/LICENSE-2.0
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20 ============LICENSE_END============================================
23 import { Injectable } from '@angular/core';
24 import { NotificationsService } from 'angular2-notifications';
25 import {Observable} from 'rxjs';
26 import {UtilityService} from '../../../shared/services/utilityService/utility.service';
27 import { environment } from '../../../../environments/environment';
28 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
29 import {APIService} from "../../../shared/services/cdt.apicall";
32 export class ReferenceDataFormUtil {
34 private successMessage = 'Retrieved artifact successfully';
35 private failureMessage = 'There is no artifact saved in APPC for the selected action!';
36 private response: Observable<Object>;
38 constructor(private notificationService: NotificationsService, private utilityService:UtilityService, private apiService: APIService) {
41 checkResult(result: any) {
43 if (result.output.status.code == '401') {
44 this.notificationService.info('Information', this.failureMessage);
47 else if (result.output.status.code == '400') {
48 this.notificationService.success('Success', this.successMessage);
54 // utility to add the slashes to the payload
55 appendSlashes(artifactData) {
56 return artifactData.replace(/"/g, '\\"');
59 public nullCheckForVnfcType(object: any) {
60 if (object == undefined || object == 'null' || object == false) {
66 public nullCheckForVnfcTypeList(object: any) {
67 if (object == undefined || object == null || object.length == 0) {
73 //used for forming the file exension
74 decideExtension(obj) {
75 //marking the extension based on the device-protocol selected by the user
76 let extension = '.json';
77 switch (obj['device-protocol']) {
93 createArtifactName(action, vnf, type, extension) {
95 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
97 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V' + extension;
100 createArtifactNameForIdentifiers(action, vnf, type, extension)
102 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V_' + type + extension;
106 createConfigTemplate(config_template_fileName) {
108 'artifact-name': 'template_' + config_template_fileName,
109 'artifact-type': 'config_template'
115 createConfigTemplateForPushReplaceData(config_template_fileName) {
117 'template_artifact': 'template_' + config_template_fileName,
123 createPdTemplate(pd_fileName) {
125 'artifact-name': 'pd_' + pd_fileName,
126 'artifact-type': 'parameter_definitions'
132 createPdTemplateForPushReplaceData(pd_fileName) {
134 'pd_artifact': 'pd_' + pd_fileName,
140 createParamValue(param_fileName) {
142 'artifact-name': 'param_' + param_fileName,
143 'artifact-type': 'param_values'
148 createParamValueForPushReplaceData(param_fileName) {
150 'param_artifact': 'param_' + param_fileName,
155 handleApiData(data,artifactType)
157 this.response = this.apiService.callGetArtifactsApi(data);
158 this.response.subscribe(response => {
159 this.utilityService.processApiSubscribe(response, this.utilityService.putAction, artifactType)
161 error => this.utilityService.processApiError());