2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. 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============================================
22 import {Component, OnInit} from '@angular/core';
23 import {FilesContent, FolderNodeElement, MetaDataFile, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
24 // import {saveAs} from 'file-saver/dist/FileSaver';
25 import * as JSZip from 'jszip';
26 import {PackageCreationStore} from './package-creation.store';
29 selector: 'app-package-creation',
30 templateUrl: './package-creation.component.html',
31 styleUrls: ['./package-creation.component.css']
33 export class PackageCreationComponent implements OnInit {
36 {name: 'Designer Mode', style: 'mode-icon icon-designer-mode'},
37 {name: 'Scripting Mode', style: 'mode-icon icon-scripting-mode'}];
38 private metaDataTab: MetaDataTabModel = new MetaDataTabModel();
39 private folder: FolderNodeElement = new FolderNodeElement();
40 private zipFile: JSZip = new JSZip();
41 private filesData: any = [];
43 constructor(private packageCreationStore: PackageCreationStore) {
51 this.packageCreationStore.state$.subscribe(
53 this.metaDataTab = cbaPackage.metaData;
54 this.setModeType(this.metaDataTab);
55 this.setEntryPoint(this.metaDataTab);
57 this.addToscaMetaDataFile(this.metaDataTab);
59 // const vlbDefinition: VlbDefinition = new VlbDefinition();
60 // this.fillVLBDefinition(vlbDefinition, this.metaDataTab);
62 this.filesData.push(this.folder.TREE_DATA);
63 console.log(FilesContent.getMapOfFilesNamesAndContent());
64 this.saveBluePrintToDataBase();
70 addToscaMetaDataFile(metaDataTab: MetaDataTabModel) {
71 const filename = 'TOSCA.meta';
72 FilesContent.putData(filename, MetaDataFile.getObjectInstance(this.metaDataTab));
75 private setModeType(metaDataTab: MetaDataTabModel) {
76 if (metaDataTab.mode.startsWith('Scripting')) {
77 metaDataTab.mode = 'KOTLIN_SCRIPT';
78 } else if (metaDataTab.mode.startsWith('Designer')) {
79 metaDataTab.mode = 'DEFAULT';
81 metaDataTab.mode = 'GENERIC_SCRIPT';
85 saveBluePrintToDataBase() {
87 this.zipFile.generateAsync({type: 'blob'})
89 this.packageCreationStore.saveBluePrint(blob);
95 this.folder.TREE_DATA.forEach((path) => {
97 const name = path.name;
99 this.zipFile.folder(name);
100 path.children.forEach(children => {
101 const name2 = children.name;
102 if (FilesContent.getMapOfFilesNamesAndContent().has(name2)) {
103 this.zipFile.file(name + '/' + name2, FilesContent.getMapOfFilesNamesAndContent().get(name2));
113 private setEntryPoint(metaDataTab: MetaDataTabModel) {
114 if (metaDataTab.mode.startsWith('DEFAULT')) {
115 metaDataTab.entryFileName = 'Definitions/vLB_CDS.json';
117 metaDataTab.entryFileName = '';