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>;
39 private notificationService: NotificationsService, private utilityService:UtilityService, private httpUtils: HttpUtilService
43 checkResult(result: any) {
45 if (result.output.status.code == '401') {
46 this.notificationService.info('Information', this.failureMessage);
49 else if (result.output.status.code == '400') {
50 this.notificationService.success('Success', this.successMessage);
56 // utility to add the slashes to the payload
57 appendSlashes(artifactData) {
58 return artifactData.replace(/"/g, '\\"');
61 public nullCheckForVnfcType(object: any) {
62 if (object == undefined || object == 'null' || object == false) {
68 public nullCheckForVnfcTypeList(object: any) {
69 if (object == undefined || object == null || object.length == 0) {
75 //used for forming the file exension
76 decideExtension(obj) {
77 //marking the extension based on the device-protocol selected by the user
78 let extension = '.json';
79 switch (obj['device-protocol']) {
95 createArtifactName(action, vnf, type, extension) {
97 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
99 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V' + extension;
102 createArtifactNameForIdentifiers(action, vnf, type, extension)
104 return action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V_' + type + extension;
108 createConfigTemplate(config_template_fileName) {
110 'artifact-name': 'template_' + config_template_fileName,
111 'artifact-type': 'config_template'
117 createConfigTemplateForPushReplaceData(config_template_fileName) {
119 'template_artifact': 'template_' + config_template_fileName,
125 createPdTemplate(pd_fileName) {
127 'artifact-name': 'pd_' + pd_fileName,
128 'artifact-type': 'parameter_definitions'
134 createPdTemplateForPushReplaceData(pd_fileName) {
136 'pd_artifact': 'pd_' + pd_fileName,
142 createParamValue(param_fileName) {
144 'artifact-name': 'param_' + param_fileName,
145 'artifact-type': 'param_values'
150 createParamValueForPushReplaceData(param_fileName) {
152 'param_artifact': 'param_' + param_fileName,
157 handleApiData(payloadData,artifactType)
160 this.httpUtils.post({
161 url: environment.getDesigns,
162 data: payloadData });
163 this.response.subscribe( response => {
164 this.utilityService.processApiSubscribe(response, this.utilityService.putAction, artifactType)
166 error => this.utilityService.processApiError());