diff options
author | shaaban Altanany <shaaban.eltanany.ext@orange.com> | 2020-02-03 16:46:57 +0200 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2020-02-13 06:12:39 +0000 |
commit | f7a326eb312d507f0ae11e5b7edc73aba367267d (patch) | |
tree | 101293fc57b082ac8e9b733672230d58bd7e6955 | |
parent | 65bb9d0d83762e8fa8e3ab568c801908eafa0686 (diff) |
Package creation refactoring and save the package to CBA store.
Issue-ID: CCSDK-2070
Signed-off-by: shaaban Altanany <shaaban.eltanany.ext@orange.com>
Change-Id: Iac67b71dbd48fe18319b381ee8a284ef9928ec46
15 files changed, 216 insertions, 95 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts new file mode 100644 index 000000000..1df011948 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/DesignerCreationMode.ts @@ -0,0 +1,74 @@ +import {PackageCreationModes} from './PackageCreationModes'; +import {CBAPackage, Definition, Scripts} from '../mapping-models/CBAPacakge.model'; +import {FilesContent} from '../mapping-models/metadata/MetaDataTab.model'; +import {Import, Metadata, VlbDefinition} from '../mapping-models/definitions/VlbDefinition'; +import {PackageCreationUtils} from '../package-creation.utils'; + + +export class DesignerCreationMode extends PackageCreationModes { + + constructor() { + super(); + } + + execute(cbaPackage: CBAPackage, packageCreationUtils: PackageCreationUtils) { + this.addToscaMetaDataFile(cbaPackage.metaData); + this.createDefinitionsFolder(cbaPackage.definitions, packageCreationUtils); + this.addScriptsFolder(cbaPackage.scripts); + } + + + /* private createDefinitionsFolder(definition: Definition) { + definition.imports.forEach((key, value) => { + console.log(key); + FilesContent.putData(key, value); + }); + + }*/ + + private addScriptsFolder(scripts: Scripts) { + scripts.files.forEach((key, value) => { + FilesContent.putData(key, value); + }); + } + + private createDefinitionsFolder(definition: Definition, packageCreationUtils: PackageCreationUtils) { + definition.imports.forEach((key, valueOfFile) => { + FilesContent.putData(key, valueOfFile); + }); + + const filenameEntry = 'Definitions/vLB_CDS.json'; + const vlbDefinition: VlbDefinition = new VlbDefinition(); + const metadata: Metadata = new Metadata(); + + metadata.template_author = 'Shaaban Ebrahim'; + metadata.template_name = definition.metaDataTab.name; + metadata.template_tags = definition.metaDataTab.tags; + metadata.template_version = definition.metaDataTab.version; + metadata['author-email'] = 'shaaban.eltanany.ext@orange.com'; + metadata['user-groups'] = 'test'; + definition.metaDataTab.mapOfCustomKey.forEach((key, customKeyValue) => { + metadata[key] = customKeyValue; + }); + vlbDefinition.metadata = metadata; + // const files = Import[definition.imports.size]; + const files: Import[] = []; + definition.imports.forEach((key, valueOfFile) => { + files.push({file: valueOfFile}); + }); + console.log(vlbDefinition); + vlbDefinition.imports = files; + /* vlbDefinition.imports = this.definition.imports; /!*[{ + this.this.definition.imports.forEach(key,value =>{ + + }); + file: 'Definitions/data_types.json' + }]; */ + + const value = packageCreationUtils.transformToJson(vlbDefinition); + FilesContent.putData(filenameEntry, value); + console.log('hello there'); + console.log(FilesContent.getMapOfFilesNamesAndContent()); + + } +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/GenericCreationMode.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/GenericCreationMode.ts new file mode 100644 index 000000000..58409eea8 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/GenericCreationMode.ts @@ -0,0 +1,12 @@ +/*import {CBAPackage} from '../mapping-models/CBAPacakge.model'; +import {PackageCreationModes} from './PackageCreationModes'; + +export class GenericCreationMode extends PackageCreationModes { + + execute(cbaPackage: CBAPackage) { + this.addToscaMetaDataFile(cbaPackage.metaData); + } + + +} +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts deleted file mode 100644 index e1d28105f..000000000 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreation.ts +++ /dev/null @@ -1,13 +0,0 @@ -import {CBAPackage} from '../mapping-models/CBAPacakge.model'; - -export abstract class PackageCreation { - - abstract setModeType(cbaPackage: CBAPackage); - - abstract setEntryPoint(cbaPackage: CBAPackage); - - createToscaMetaData(cbaPackage: CBAPackage) { - - } - -} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationBuilder.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationBuilder.ts new file mode 100644 index 000000000..08443cca1 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationBuilder.ts @@ -0,0 +1,24 @@ +import {CBAPackage} from '../mapping-models/CBAPacakge.model'; +import {ModeType} from '../mapping-models/ModeType'; +import {DesignerCreationMode} from './DesignerCreationMode'; +import {PackageCreationModes} from './PackageCreationModes'; + + +export class PackageCreationBuilder { + + constructor() { + } + + public static getCreationMode(cbaPackage: CBAPackage): PackageCreationModes { + let creationMode: PackageCreationModes; + /*if (cbaPackage.metaData.mode.includes(ModeType.Generic)) { + creationMode = new GenericCreationMode(); + } else */ + if (cbaPackage.metaData.mode.includes(ModeType.Designer)) { + creationMode = new DesignerCreationMode(); + } /*else if (cbaPackage.metaData.mode.includes(ModeType.Scripting)) { + creationMode = new ScriptingCreationMode(); + }*/ + return creationMode; + } +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationModes.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationModes.ts new file mode 100644 index 000000000..400304aab --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/PackageCreationModes.ts @@ -0,0 +1,54 @@ +import {CBAPackage} from '../mapping-models/CBAPacakge.model'; +import {ModeType} from '../mapping-models/ModeType'; +import {FilesContent, MetaDataTabModel} from '../mapping-models/metadata/MetaDataTab.model'; +import {PackageCreationUtils} from '../package-creation.utils'; + + +export abstract class PackageCreationModes { + + protected constructor() { + } + + public static setEntryPoint(metaDataTab: MetaDataTabModel) { + if (metaDataTab.mode.startsWith(ModeType.Designer)) { + metaDataTab.entryFileName = 'Definitions/vLB_CDS.json'; + } else { + // TODO Not implemented + metaDataTab.entryFileName = ''; + } + return metaDataTab; + } + + public static mapModeType(cbaPackage: CBAPackage) { + if (cbaPackage.metaData.mode.startsWith('Scripting')) { + cbaPackage.metaData.mode = ModeType.Scripting; + } else if (cbaPackage.metaData.mode.startsWith('Designer')) { + cbaPackage.metaData.mode = ModeType.Designer; + } else { + cbaPackage.metaData.mode = ModeType.Generic; + } + return cbaPackage; + } + + getValueOfMetaData(metaDataTab: MetaDataTabModel): string { + return 'TOSCA-Meta-File-Version: 1.0.0\n' + + 'CSAR-Version: 1.0\n' + + 'Created-By: Shaaban Ebrahim <shaaban.eltanany.ext@orange.con>\n' + + 'Entry-Definitions:' + metaDataTab.entryFileName + '\n' + + 'Template-Name:' + metaDataTab.name + '\n' + + 'Template-Version:' + metaDataTab.version + '\n' + + 'Template-Type: ' + metaDataTab.mode + '\n' + + 'Template-Tags:' + metaDataTab.tags; + + } + + protected addToscaMetaDataFile(metaDataTab: MetaDataTabModel) { + const filename = 'TOSCA-Metadata/TOSCA.meta'; + FilesContent.putData(this.getValueOfMetaData(metaDataTab), filename); + } + + + abstract execute(cbaPackage: CBAPackage, packageCreationUtils: PackageCreationUtils) ; + + +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/ScriptingCreationMode.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/ScriptingCreationMode.ts new file mode 100644 index 000000000..21dce171d --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/creationModes/ScriptingCreationMode.ts @@ -0,0 +1,11 @@ +/*import {CBAPackage, Definition, Scripts} from '../mapping-models/CBAPacakge.model'; +import {PackageCreationModes} from './PackageCreationModes'; +import {FilesContent} from '../mapping-models/metadata/MetaDataTab.model'; + +export class ScriptingCreationMode extends PackageCreationModes { + execute(cbaPackage: CBAPackage) { + } + + +} +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html index 5cd888828..c40703daf 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html @@ -39,7 +39,7 @@ <button class="btn btn-link collapsed" data-toggle="collapse" [attr.data-target]="'#id-'+mapIndex" aria-expanded="false" [attr.aria-controls]="'id-'+mapIndex"> - <i class="icon-file-code"></i> Definitions/{{file.key}} + <i class="icon-file-code"></i> {{file.key}} </button> <a class="accordion-delete" (click)="removeFile(mapIndex)"><i class="icon-delete"></i></a> </h5> @@ -127,4 +127,4 @@ </div> </div> </div> -</div>
\ No newline at end of file +</div> diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts index a8ba164f3..39f3fbf60 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts @@ -92,8 +92,8 @@ export class ImportsTabComponent implements OnInit { droppedFile.file((file: File) => { const fileReader = new FileReader(); fileReader.onload = (e) => { - this.packageCreationStore.addDefinition(droppedFile.name, - this.packageCreationUtils.transformToJson(fileReader.result)); + this.packageCreationStore.addDefinition('Definitions/' + droppedFile.name, + fileReader.result.toString()); }; fileReader.readAsText(file); }); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ModeType.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ModeType.ts new file mode 100644 index 000000000..d6f9a978f --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ModeType.ts @@ -0,0 +1,5 @@ +export enum ModeType { + Scripting = 'KOTLIN_SCRIPT', + Designer = 'DEFAULT', + Generic = 'GENERIC_SCRIPT' +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts index 194e660c7..df723d58f 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/metadata/MetaDataTab.model.ts @@ -45,17 +45,6 @@ Content-Type: application/vnd.oasis.bpmn*/ export class MetaDataFile { - static getValueOfMetaData(metaDataTab: MetaDataTabModel): string { - return 'TOSCA-Meta-File-Version: 1.0.0\n' + - 'CSAR-Version: 1.0\n' + - 'Created-By: Shaaban Ebrahim <shaaban.eltanany.ext@orange.con>\n' + - 'Entry-Definitions:' + metaDataTab.entryFileName + '\n' + - 'Template-Name:' + metaDataTab.name + '\n' + - 'Template-Version:' + metaDataTab.version + '\n' + - 'Template-Type: ' + metaDataTab.mode + '\n' + - 'Template-Tags:' + metaDataTab.tags; - - } } @@ -118,4 +107,8 @@ export class FilesContent { public static putData(fileName: string, content: string) { FilesContent.mapOfFilesNamesAndContent.set(fileName, content); } + + public static clear() { + this.mapOfFilesNamesAndContent = new Map<string, string>(); + } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.css b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.css index e69de29bb..8b1378917 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.css +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.css @@ -0,0 +1 @@ + diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts index cdf8cf38b..c15a5dd4f 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts @@ -20,11 +20,15 @@ limitations under the License. */ import {Component, OnInit} from '@angular/core'; -import {FilesContent, FolderNodeElement, MetaDataFile, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; -// import {saveAs} from 'file-saver/dist/FileSaver'; +import {FilesContent, FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; + import * as JSZip from 'jszip'; import {PackageCreationStore} from './package-creation.store'; import {Definition} from './mapping-models/CBAPacakge.model'; +import {PackageCreationModes} from './creationModes/PackageCreationModes'; +import {PackageCreationBuilder} from './creationModes/PackageCreationBuilder'; +import {PackageCreationUtils} from './package-creation.utils'; + @Component({ selector: 'app-package-creation', @@ -42,7 +46,10 @@ export class PackageCreationComponent implements OnInit { private filesData: any = []; private definition: Definition = new Definition(); - constructor(private packageCreationStore: PackageCreationStore) { + // adding initial referencing to designer mode + + + constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) { } ngOnInit() { @@ -53,17 +60,12 @@ export class PackageCreationComponent implements OnInit { this.packageCreationStore.state$.subscribe( cbaPackage => { console.log(cbaPackage); - this.metaDataTab = cbaPackage.metaData; - this.setModeType(this.metaDataTab); - this.setEntryPoint(this.metaDataTab); - this.addToscaMetaDataFile(this.metaDataTab); - - this.definition = cbaPackage.definitions; - this.definition.metaDataTab = cbaPackage.metaData; - this.createDefinitionsFolder(this.definition); - // const vlbDefinition: VlbDefinition = new VlbDefinition(); - // this.fillVLBDefinition(vlbDefinition, this.metaDataTab); - + FilesContent.clear(); + let packageCreationModes: PackageCreationModes; + cbaPackage = PackageCreationModes.mapModeType(cbaPackage); + cbaPackage.metaData = PackageCreationModes.setEntryPoint(cbaPackage.metaData); + packageCreationModes = PackageCreationBuilder.getCreationMode(cbaPackage); + packageCreationModes.execute(cbaPackage, this.packageCreationUtils); this.filesData.push(this.folder.TREE_DATA); this.saveBluePrintToDataBase(); }); @@ -71,29 +73,6 @@ export class PackageCreationComponent implements OnInit { } - private addToscaMetaDataFile(metaDataTab: MetaDataTabModel) { - const filename = 'TOSCA-Metadata/TOSCA.meta'; - FilesContent.putData(filename, MetaDataFile.getValueOfMetaData(metaDataTab)); - } - -// TODO use enumerator - private setModeType(metaDataTab: MetaDataTabModel) { - if (metaDataTab.mode.startsWith('Scripting')) { - metaDataTab.mode = 'KOTLIN_SCRIPT'; - } else if (metaDataTab.mode.startsWith('Designer')) { - metaDataTab.mode = 'DEFAULT'; - } else { - metaDataTab.mode = 'GENERIC_SCRIPT'; - } - } - - private setEntryPoint(metaDataTab: MetaDataTabModel) { - if (metaDataTab.mode.startsWith('DEFAULT')) { - metaDataTab.entryFileName = 'Definitions/vLB_CDS.json'; - } else { - metaDataTab.entryFileName = ''; - } - } saveBluePrintToDataBase() { this.create(); @@ -105,7 +84,11 @@ export class PackageCreationComponent implements OnInit { create() { - this.folder.TREE_DATA.forEach((path) => { + FilesContent.getMapOfFilesNamesAndContent().forEach((key, value) => { + this.zipFile.folder(key.split('/')[0]); + this.zipFile.file(key, value); + }); + /*this.folder.TREE_DATA.forEach((path) => { const name = path.name; if (path.children) { this.zipFile.folder(name); @@ -114,37 +97,14 @@ export class PackageCreationComponent implements OnInit { if (FilesContent.getMapOfFilesNamesAndContent().has(name2)) { this.zipFile.file(name + '/' + name2, FilesContent.getMapOfFilesNamesAndContent().get(name2)); } else { + // this.zipFile.file(name2, FilesContent.getMapOfFilesNamesAndContent().get(name2)); } }); } - }); + });*/ } - private createDefinitionsFolder(definition: Definition) { - this.definition.imports.forEach((key, value) => { - FilesContent.putData(key, value); - }); - - /*const filenameEntry = 'vLB_CDS.json'; - const vlbDefinition: VlbDefinition = new VlbDefinition(); - const metadata: MetaDataTabModel = new MetaDataTabModel(); - - metadata.templateAuthor = ' lldkslds'; - metadata.templateName = ' lldkslds'; - metadata.templateTags = ' lldkslds'; - metadata.templateVersion = ' lldkslds'; - metadata['author-email'] = ' lldkslds'; - metadata['user-groups'] = ' lldkslds'; - vlbDefinition.metadata = metadata; - - vlbDefinition.imports = [{ - file: 'Definitions/data_types.json' - }]; - - const value = this.packageCreationUtils.transformToJson(vlbDefinition); - FilesContent.putData(filenameEntry, value);*/ - } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html index 1685b7eaf..893c4f741 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html @@ -23,7 +23,7 @@ <button [attr.aria-controls]="'id-'+mapIndex" [attr.data-target]="'#id-'+mapIndex" aria-expanded="false" class="btn btn-link collapsed" data-toggle="collapse"> - <i class="icon-file-code"></i> Definitions/{{file.key}} + <i class="icon-file-code"></i> {{file.key}} </button> <a (click)="removeFile(mapIndex)" class="accordion-delete"><i class="icon-delete"></i></a> </h5> diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts index 43b9b503c..634e5fc84 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts @@ -61,8 +61,8 @@ export class ScriptsTabComponent implements OnInit { droppedFile.file((file: File) => { const fileReader = new FileReader(); fileReader.onload = (e) => { - this.packageCreationStore.addScripts(droppedFile.name, - this.packageCreationUtils.transformToJson(fileReader.result)); + this.packageCreationStore.addScripts('Scripts/' + droppedFile.name, + fileReader.result.toString()); }; fileReader.readAsText(file); }); diff --git a/cds-ui/pom.xml b/cds-ui/pom.xml index 122823419..bba6bfdd2 100644 --- a/cds-ui/pom.xml +++ b/cds-ui/pom.xml @@ -38,7 +38,7 @@ limitations under the License. <modules> <module>client</module> - <module>designer-client</module> + <!--<module>designer-client</module>--> <module>server</module> <module>application</module> </modules> |