2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 IBM 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.
19 ============LICENSE_END============================================
21 import { Component, OnInit } from '@angular/core';
22 import * as JSZip from 'jszip';
23 import { SortPipe } from '../../../../common/shared/pipes/sort.pipe';
24 import { LoaderService } from '../../../../common/core/services/loader.service';
27 selector: 'app-zipfile-extraction',
28 templateUrl: './zipfile-extraction.component.html',
29 styleUrls: ['./zipfile-extraction.component.scss']
31 export class ZipfileExtractionComponent implements OnInit {
34 private zipFile: JSZip = new JSZip();
35 private fileObject: any;
36 private activationBlueprint: any;
37 private tocsaMetadaData: any;
38 private blueprintName: string;
39 private entryDefinition: string;
40 validfile: boolean = false;
41 uploadedFileName: string;
43 constructor(private loader: LoaderService) { }
47 async buildFileViewData(zip) {
48 this.validfile = false;
50 console.log(zip.files);
51 for (var file in zip.files) {
52 console.log("name: " + zip.files[file].name);
54 // nameForUIDisplay: this.uploadedFileName + '/' + zip.files[file].name,
55 // name: zip.files[file].name,
56 name: this.uploadedFileName + '/' + zip.files[file].name,
59 const value = <any>await zip.files[file].async('string');
60 this.fileObject.data = value;
61 this.paths.push(this.fileObject);
65 this.paths.forEach(path => {
66 if (path.name.includes("TOSCA.meta")) {
71 alert('Please update proper file');
75 this.fetchTOSACAMetadata();
76 this.paths = new SortPipe().transform(this.paths, 'asc', 'name');
77 this.tree = this.arrangeTreeData(this.paths);
79 alert('Please update proper file with TOSCA metadata');
83 arrangeTreeData(paths) {
86 paths.forEach((path) => {
88 const pathParts = path.name.split('/');
90 let currentLevel = tree;
92 pathParts.forEach((part) => {
93 const existingPath = currentLevel.filter(level => level.name === part);
95 if (existingPath.length > 0) {
96 currentLevel = existingPath[0].children;
104 if (part.trim() == this.blueprintName.trim()) {
105 this.activationBlueprint = path.data;
106 newPart.data = JSON.parse(this.activationBlueprint.toString());
107 console.log('newpart', newPart);
108 this.entryDefinition = path.name.trim();
110 if (newPart.name !== '') {
111 currentLevel.push(newPart);
112 currentLevel = newPart.children;
117 this.loader.hideLoader();
121 fetchTOSACAMetadata() {
123 this.paths.forEach(file => {
124 if (file.name.includes('TOSCA.meta')) {
125 let keys = file.data.split("\n");
126 keys.forEach((key) => {
127 let propertyData = key.split(':');
128 toscaData[propertyData[0]] = propertyData[1];
132 this.blueprintName = (((toscaData['Entry-Definitions']).split('/'))[1]).toString();;
133 console.log(toscaData);