From 07b70ec6b649020eed49bc4a81cb381a65c3d095 Mon Sep 17 00:00:00 2001 From: Ezhilarasi Date: Thu, 11 Apr 2019 18:34:10 +0530 Subject: Enrichment and Download Zip file bug fix Change-Id: If4219a99bfc7082648a28149652d75a09333bd55 Issue-ID: CCSDK-1212 Signed-off-by: Ezhilarasi --- .../modify-template/editor/editor.component.ts | 216 +++++++++++---------- 1 file changed, 118 insertions(+), 98 deletions(-) (limited to 'cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts') diff --git a/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts b/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts index 7cbf5b0a5..73cc72cfd 100644 --- a/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts +++ b/cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts @@ -36,7 +36,8 @@ import { Observable } from 'rxjs'; import { IBlueprintState } from 'src/app/common/core/store/models/blueprintState.model'; import { LoadBlueprintSuccess, SetBlueprintState } from '../../../../common/core/store/actions/blueprint.action' import { ApiService } from 'src/app/common/core/services/api.service'; - +import { IMetaData } from 'src/app/common/core/store/models/metadata.model'; +import { EditorService } from './editor.service'; interface Node { name: string; @@ -92,9 +93,9 @@ export class EditorComponent implements OnInit { currentFilePath: string = ''; selectedFileObj = { name: '', type: '' }; viewTemplateMode: boolean = false; - paramData : any = { + paramData: any = { 'capability-data': [], - 'resourceAccumulatorResolvedData' : [] + 'resourceAccumulatorResolvedData': [] }; validfile: boolean = false; @ViewChild('fileInput') fileInput; @@ -103,6 +104,7 @@ export class EditorComponent implements OnInit { private tree; private fileObject: any; private tocsaMetadaData: any; + metadata: IMetaData; private transformer = (node: Node, level: number) => { return { @@ -119,8 +121,10 @@ export class EditorComponent implements OnInit { this.transformer, node => node.level, node => node.expandable, node => node.children); dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); + artifactName: any; + artifactVersion: any; - constructor(private store: Store, private apiservice: ApiService) { + constructor(private store: Store, private apiservice: EditorService) { this.dataSource.data = TREE_DATA; this.bpState = this.store.select('blueprint'); // this.dataSource.data = TREE_DATA; @@ -161,8 +165,15 @@ export class EditorComponent implements OnInit { blueprint.push(this.blueprintdata[key]); } } - // this.text = JSON.stringify(this.blueprintdata, null, '\t'); - // this.editor.getEditor().getSession().setMode("ace/mode/json"); + this.metadata=blueprintState.blueprint.metadata; + let metadatavalues = []; + for (let key in this.metadata) { + if (this.metadata.hasOwnProperty(key)) { + metadatavalues.push(this.metadata[key]); + } + } + this.artifactName = metadatavalues[3]; + this.artifactVersion = metadatavalues[4]; this.editor.getEditor().getSession().setTabSize(2); this.editor.getEditor().getSession().setUseWrapMode(true); this.setEditorMode(); @@ -197,7 +208,7 @@ export class EditorComponent implements OnInit { } selectFileToView(file) { - if(file.name.includes('.vtl')) { this.viewTemplateMode = true;} else { this.viewTemplateMode = false;} + if (file.name.includes('.vtl')) { this.viewTemplateMode = true; } else { this.viewTemplateMode = false; } this.currentFilePath = ''; this.expandParents(file); this.selectedFileObj.name = file.name; @@ -224,70 +235,21 @@ export class EditorComponent implements OnInit { this.apiservice.enrich("/enrich-blueprint/", formData) .subscribe( (response) => { - console.log("Inside blob"); - var blob = new Blob([response.data], { type: 'application/zip' }); - const fileName = 'CBA.zip'; - saveAs(blob, fileName); this.zipFile.files = {}; - this.zipFile.loadAsync(blob) + this.zipFile.loadAsync(response) .then((zip) => { if (zip) { this.buildFileViewData(zip); + console.log("processed"); } }); - + window.alert('Blueprint enriched successfully' ); }); - }); - - } - async buildFileViewData(zip) { - this.validfile = false; - this.paths = []; - for (var file in zip.files) { - this.fileObject = { - name: zip.files[file].name, - data: '' - }; - const value = await zip.files[file].async('string'); - this.fileObject.data = value; - this.paths.push(this.fileObject); - } - - if(this.paths) { - this.paths.forEach(path =>{ - if(path.name.includes("TOSCA.meta")) { - this.validfile = true - } - }); - } else { - alert('Please update proper file'); - } - - if(this.validfile) { - this.fetchTOSACAMetadata(); - this.tree = this.arrangeTreeData(this.paths); - } else { - alert('Please update proper file with TOSCA metadata'); - } } + - fetchTOSACAMetadata() { - let toscaData = {}; - this.paths.forEach(file =>{ - if(file.name.includes('TOSCA.meta')) { - let keys = file.data.split("\n"); - keys.forEach((key)=>{ - let propertyData = key.split(':'); - toscaData[propertyData[0]] = propertyData[1]; - }); - } - }); - this.blueprintName = (((toscaData['Entry-Definitions']).split('/'))[1]).toString();; - console.log(toscaData); - } - saveToBackend() { this.create(); this.zipFile.generateAsync({ type: "blob" }) @@ -295,7 +257,11 @@ export class EditorComponent implements OnInit { const formData = new FormData(); formData.append("file", blob); this.apiservice.post("/create-blueprint/", formData) - .subscribe(data => console.log(data)); + .subscribe( + data => { + // console.log(data); + window.alert('Success:' + JSON.stringify(data)); + }); }); } @@ -307,8 +273,11 @@ export class EditorComponent implements OnInit { .then(blob => { const formData = new FormData(); formData.append("file", blob); - this.apiservice.post("/deploy-blueprint/", formData) - .subscribe(data => console.log(data)); + this.apiservice.deployPost("/deploy-blueprint/", formData) + .subscribe(data => { + // console.log(data); + window.alert('Saved Successfully:' + JSON.stringify(data)); + }); }); } @@ -320,7 +289,10 @@ export class EditorComponent implements OnInit { const formData = new FormData(); formData.append("file", blob); this.apiservice.post("/publish/", formData) - .subscribe(data => console.log(data)); + .subscribe(data => { + // console.log(data); + window.alert('Published:' + JSON.stringify(data)); + }); }); @@ -333,17 +305,19 @@ export class EditorComponent implements OnInit { } download() { - this.apiservice.downloadCBA("/download-blueprint/baseconfiguration/1.0.0") - .subscribe(response => { - console.log(response); - var blob = new Blob([response], { type: 'application/zip' }); - const fileName = 'CBA'; - saveAs(blob, fileName); - }, - error => { - console.log(error); - } - ); + console.log(this.artifactName); + status = this.apiservice.downloadCBA("/download-blueprint/" + this.artifactName + "/" + this.artifactVersion); + window.alert(status); + // .subscribe(response => { + // console.log(response); + // var blob = new Blob([response], { type: 'application/zip' }); + // const fileName = 'CBA'; + // saveAs(blob, fileName); + // }, + // error => { + // console.log(error); + // } + // ); } setEditorMode() { switch (this.fileExtension) { @@ -417,6 +391,52 @@ export class EditorComponent implements OnInit { return indexForNewNode; } + async buildFileViewData(zip) { + this.validfile = false; + this.paths = []; + for (var file in zip.files) { + this.fileObject = { + name: zip.files[file].name, + data: '' + }; + const value = await zip.files[file].async('string'); + this.fileObject.data = value; + this.paths.push(this.fileObject); + } + + if (this.paths) { + this.paths.forEach(path => { + if (path.name.includes("TOSCA.meta")) { + this.validfile = true + } + }); + } else { + alert('Please update proper file'); + } + + if (this.validfile) { + this.fetchTOSACAMetadata(); + this.tree = this.arrangeTreeData(this.paths); + } else { + alert('Please update proper file with TOSCA metadata'); + } + } + + fetchTOSACAMetadata() { + let toscaData = {}; + this.paths.forEach(file => { + if (file.name.includes('TOSCA.meta')) { + let keys = file.data.split("\n"); + keys.forEach((key) => { + let propertyData = key.split(':'); + toscaData[propertyData[0]] = propertyData[1]; + }); + } + }); + this.blueprintName = (((toscaData['Entry-Definitions']).split('/'))[1]).toString();; + console.log(toscaData); + } + arrangeTreeData(paths) { const tree = []; @@ -505,34 +525,34 @@ export class EditorComponent implements OnInit { } loadConfigParams() { console.log(this.currentFilePath); - console.log(this.selectedFile); - console.log(this.selectedFileObj); - console.log(this.selectedFolder); - console.log(this.text); - - let parsedData = JSON.parse(this.text); - this.paramData.resourceAccumulatorResolvedData = parsedData['resource-accumulator-resolved-data']; - let i=0; - - this.paramData.resourceAccumulatorResolvedData.forEach(element => { - element.id = i; - let tempElement = element['param-value']; - let indexLength = tempElement.length; - tempElement = tempElement.slice(2,indexLength); - let index = tempElement.indexOf('}'); - tempElement = this.removeItemByIndex(tempElement, index); - element['param-value'] = tempElement; - i++; - }); + console.log(this.selectedFile); + console.log(this.selectedFileObj); + console.log(this.selectedFolder); + console.log(this.text); + + let parsedData = JSON.parse(this.text); + this.paramData.resourceAccumulatorResolvedData = parsedData['resource-accumulator-resolved-data']; + let i = 0; + + this.paramData.resourceAccumulatorResolvedData.forEach(element => { + element.id = i; + let tempElement = element['param-value']; + let indexLength = tempElement.length; + tempElement = tempElement.slice(2, indexLength); + let index = tempElement.indexOf('}'); + tempElement = this.removeItemByIndex(tempElement, index); + element['param-value'] = tempElement; + i++; + }); } removeItemByIndex(paramValue, index) { - if(index == 0) { - return paramValue.slice(1) - } else if(index > 0) { + if (index == 0) { + return paramValue.slice(1) + } else if (index > 0) { let indexLength = paramValue.length; - return paramValue.slice(0,index) + paramValue.slice(index+1, indexLength); + return paramValue.slice(0, index) + paramValue.slice(index + 1, indexLength); } else { return paramValue; } -- cgit 1.2.3-korg