aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui
diff options
context:
space:
mode:
authorShaabanEltanany <shaaban.eltanany.ext@orange.com>2020-09-28 17:24:34 +0200
committerShaabanEltanany <shaaban.eltanany.ext@orange.com>2020-09-28 17:26:41 +0200
commit4ea4a4c90d1ecee5430bd99ded79856392fd9ecb (patch)
treeeee4ec5fcfd05e54300d6dfa96d660ccc65db603 /cds-ui
parent809ebd8d7974b1a658fb7f7a8a2466ca5d13bf52 (diff)
refactor package creation service and blob extractor
Issue-ID: CCSDK-2298 Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com> Change-Id: I2a83f8db4d67c8e8114ce7c85f0c227c86046b53
Diffstat (limited to 'cds-ui')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts95
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts39
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.component.ts10
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts90
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts6
5 files changed, 121 insertions, 119 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts
index eb121e98e..e86a2c500 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts
@@ -7,7 +7,7 @@ import {MetadataTabComponent} from '../package-creation/metadata-tab/metadata-ta
import * as JSZip from 'jszip';
import {ConfigurationDashboardService} from './configuration-dashboard.service';
import {TemplateTopology, VlbDefinition} from '../package-creation/mapping-models/definitions/VlbDefinition';
-import {CBAPackage, DslDefinition} from '../package-creation/mapping-models/CBAPacakge.model';
+import {CBAPackage} from '../package-creation/mapping-models/CBAPacakge.model';
import {PackageCreationUtils} from '../package-creation/package-creation.utils';
import {PackageCreationModes} from '../package-creation/creationModes/PackageCreationModes';
import {PackageCreationBuilder} from '../package-creation/creationModes/PackageCreationBuilder';
@@ -89,7 +89,6 @@ export class ConfigurationDashboardComponent extends ComponentCanDeactivate impl
}
-
private refreshCurrentPackage(id?) {
this.id = this.route.snapshot.paramMap.get('id');
console.log(this.id);
@@ -109,80 +108,10 @@ export class ConfigurationDashboardComponent extends ComponentCanDeactivate impl
this.viewedPackage.artifactName + '/' + this.viewedPackage.artifactVersion).subscribe(response => {
const blob = new Blob([response], {type: 'application/octet-stream'});
this.currentBlob = blob;
- this.extractBlobToStore(blob, this.viewedPackage);
- });
- }
-
- private extractBlobToStore(blob: Blob, bluePrintDetailModel: BluePrintDetailModel) {
- this.zipFile.loadAsync(blob).then((zip) => {
- Object.keys(zip.files).forEach((filename) => {
- zip.files[filename].async('string').then((fileData) => {
- console.log(filename);
- if (fileData) {
- if (filename.includes('Scripts/')) {
- this.setScripts(filename, fileData);
- } else if (filename.includes('Templates/')) {
- if (filename.includes('-mapping.')) {
- this.setMapping(filename, fileData);
- } else if (filename.includes('-template.')) {
- this.setTemplates(filename, fileData);
- }
-
- } else if (filename.includes('Definitions/')) {
- this.setImports(filename, fileData, bluePrintDetailModel);
- } else if (filename.includes('TOSCA-Metadata/')) {
- const metaDataTabInfo: MetaDataTabModel = this.getMetaDataTabInfo(fileData);
- this.setMetaData(metaDataTabInfo, bluePrintDetailModel);
- }
- }
- });
- });
+ this.packageCreationExtractionService.extractBlobToStore(blob);
});
}
- setScripts(filename: string, fileData: any) {
- this.packageCreationStore.addScripts(filename, fileData);
- }
-
- setImports(filename: string, fileData: any, bluePrintDetailModels: BluePrintDetailModel) {
- console.log(filename);
- if (filename.includes(bluePrintDetailModels.artifactName)) {
- let definition = new VlbDefinition();
- definition = fileData as VlbDefinition;
- definition = JSON.parse(fileData);
- const dslDefinition = new DslDefinition();
- dslDefinition.content = this.packageCreationUtils.transformToJson(definition.dsl_definitions);
- const mapOfCustomKeys = new Map<string, string>();
- for (const metadataKey in definition.metadata) {
- if (!this.entryDefinitionKeys.includes(metadataKey + '')) {
- mapOfCustomKeys.set(metadataKey + '', definition.metadata[metadataKey + '']);
- }
- }
- this.packageCreationStore.changeDslDefinition(dslDefinition);
- this.packageCreationStore.setCustomKeys(mapOfCustomKeys);
- if (definition.topology_template) {
- const content = {};
- const workflow = 'workflows';
- content[workflow] = definition.topology_template.workflows;
- const nodeTemplates = 'node_templates';
- content[nodeTemplates] = definition.topology_template.node_templates;
- this.designerStore.saveSourceContent(JSON.stringify(content));
- this.packageCreationStore.addTopologyTemplate(definition.topology_template);
- }
-
- }
- this.packageCreationStore.addDefinition(filename, fileData);
-
- }
-
- setTemplates(filename: string, fileData: any) {
- this.packageCreationStore.addTemplate(filename, fileData);
- }
-
- setMapping(fileName: string, fileData: string) {
- this.packageCreationStore.addMapping(fileName, fileData);
- }
-
editBluePrint() {
this.configurationDashboardService.deletePackage(this.viewedPackage.id).subscribe(res => {
this.formTreeData();
@@ -201,26 +130,8 @@ export class ConfigurationDashboardComponent extends ComponentCanDeactivate impl
this.filesData.push(this.folder.TREE_DATA);
}
- setMetaData(metaDataObject: MetaDataTabModel, bluePrintDetailModel: BluePrintDetailModel) {
- metaDataObject.description = bluePrintDetailModel.artifactDescription;
- this.packageCreationStore.changeMetaData(metaDataObject);
-
- }
-
saveMetaData() {
this.metadataTabComponent.saveMetaDataToStore();
-
- }
-
- getMetaDataTabInfo(fileData: string) {
- const metaDataTabModel = new MetaDataTabModel();
- const arrayOfLines = fileData.split('\n');
- metaDataTabModel.entryFileName = arrayOfLines[3].split(':')[1];
- metaDataTabModel.name = arrayOfLines[4].split(':')[1];
- metaDataTabModel.version = arrayOfLines[5].split(':')[1];
- metaDataTabModel.mode = arrayOfLines[6].split(':')[1];
- metaDataTabModel.templateTags = new Set<string>(arrayOfLines[7].split(':')[1].split(','));
- return metaDataTabModel;
}
saveBluePrintToDataBase() {
@@ -316,7 +227,7 @@ export class ConfigurationDashboardComponent extends ComponentCanDeactivate impl
const blobInfo = new Blob([response], {type: 'application/octet-stream'});
this.currentBlob = blobInfo;
this.packageCreationStore.clear();
- this.extractBlobToStore(this.currentBlob, this.viewedPackage);
+ this.packageCreationExtractionService.extractBlobToStore(this.currentBlob);
this.isSaveEnabled = true;
this.toastService.info('enriched successfully ');
});
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts
index fe98fa22b..2cc58e6a4 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation-extraction.service.ts
@@ -1,25 +1,26 @@
-import { Injectable, ViewChild } from '@angular/core';
-import { MetaDataTabModel } from './mapping-models/metadata/MetaDataTab.model';
-import { VlbDefinition } from './mapping-models/definitions/VlbDefinition';
-import { DslDefinition } from './mapping-models/CBAPacakge.model';
-import { PackageCreationStore } from './package-creation.store';
+import {Injectable, ViewChild} from '@angular/core';
+import {MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
+import {VlbDefinition} from './mapping-models/definitions/VlbDefinition';
+import {DslDefinition} from './mapping-models/CBAPacakge.model';
+import {PackageCreationStore} from './package-creation.store';
import * as JSZip from 'jszip';
-import { PackageCreationUtils } from './package-creation.utils';
-import { MetadataTabComponent } from './metadata-tab/metadata-tab.component';
-import { DesignerStore } from '../designer/designer.store';
+import {PackageCreationUtils} from './package-creation.utils';
+import {MetadataTabComponent} from './metadata-tab/metadata-tab.component';
+import {DesignerStore} from '../designer/designer.store';
+import {BluePrintDetailModel} from '../model/BluePrint.detail.model';
@Injectable({
providedIn: 'root'
})
export class PackageCreationExtractionService {
- private zipFile: JSZip = new JSZip();
+ private zipFile: JSZip;
private entryDefinitionKeys: string[] = ['template_tags', 'user-groups',
'author-email', 'template_version', 'template_name', 'template_author', 'template_description'];
private toscaMetaDataKeys: string[] = ['TOSCA-Meta-File-Version', 'CSAR-Version',
'Created-By', 'Entry-Definitions', 'Template-Name', 'Template-Version', 'Template-Type', 'Template-Tags'];
- @ViewChild(MetadataTabComponent, { static: false })
+ @ViewChild(MetadataTabComponent, {static: false})
private metadataTabComponent: MetadataTabComponent;
constructor(
@@ -31,7 +32,7 @@ export class PackageCreationExtractionService {
}
public extractBlobToStore(blob) {
-
+ this.zipFile = new JSZip();
let packageName = null;
this.zipFile.loadAsync(blob).then((zip) => {
Object.keys(zip.files).filter(fileName => fileName.includes('TOSCA-Metadata/'))
@@ -73,11 +74,11 @@ export class PackageCreationExtractionService {
});
}
- private setScripts(filename: string, fileData: any) {
+ public setScripts(filename: string, fileData: any) {
this.packageCreationStore.addScripts(filename, fileData);
}
- private setImports(filename: string, fileData: any, packageName: string) {
+ public setImports(filename: string, fileData: any, packageName: string) {
console.log(filename);
if (filename.includes(packageName)) {
let definition = new VlbDefinition();
@@ -108,11 +109,11 @@ export class PackageCreationExtractionService {
}
- private setTemplates(filename: string, fileData: any) {
+ public setTemplates(filename: string, fileData: any) {
this.packageCreationStore.addTemplate(filename, fileData);
}
- private setMapping(fileName: string, fileData: string) {
+ public setMapping(fileName: string, fileData: string) {
this.packageCreationStore.addMapping(fileName, fileData);
}
@@ -120,7 +121,13 @@ export class PackageCreationExtractionService {
this.packageCreationStore.changeMetaData(metaDataObject);
}
- private getMetaDataTabInfo(fileData: string) {
+ public setMetaDataWithObject(metaDataObject: MetaDataTabModel, bluePrintDetailModel: BluePrintDetailModel) {
+ metaDataObject.description = bluePrintDetailModel.artifactDescription;
+ this.packageCreationStore.changeMetaData(metaDataObject);
+
+ }
+
+ public getMetaDataTabInfo(fileData: string) {
const metaDataTabModel = new MetaDataTabModel();
const arrayOfLines = fileData.split('\n');
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 25f5c5996..c7285774e 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
@@ -19,7 +19,7 @@ limitations under the License.
============LICENSE_END============================================
*/
-import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
+import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {FilesContent, FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
import * as JSZip from 'jszip';
@@ -42,7 +42,7 @@ import {DesignerStore} from '../designer/designer.store';
templateUrl: './package-creation.component.html',
styleUrls: ['./package-creation.component.css']
})
-export class PackageCreationComponent extends ComponentCanDeactivate implements OnInit {
+export class PackageCreationComponent extends ComponentCanDeactivate implements OnInit, OnDestroy {
// adding initial referencing to designer mode
@@ -84,6 +84,8 @@ export class PackageCreationComponent extends ComponentCanDeactivate implements
this.elementRef.nativeElement.focus();
const regexp = RegExp(this.versionPattern);
this.packageCreationStore.state$.subscribe(cbaPackage => {
+ console.log(cbaPackage);
+ console.log('abbaaaas' + cbaPackage.metaData.name);
this.cbaPackage = cbaPackage;
if (cbaPackage && cbaPackage.metaData && cbaPackage.metaData.description
&& cbaPackage.metaData.name && cbaPackage.metaData.version &&
@@ -164,4 +166,8 @@ export class PackageCreationComponent extends ComponentCanDeactivate implements
canDeactivate(): boolean {
return this.isSaveEnabled;
}
+
+ ngOnDestroy(): void {
+
+ }
}
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts
index 94ab9ed02..ed3db4286 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts
@@ -21,23 +21,41 @@ limitations under the License.
import {Injectable} from '@angular/core';
-import {Observable} from 'rxjs';
+import {Observable, Subject} from 'rxjs';
import {ApiService} from '../../../../common/core/services/api.service';
import {BlueprintURLs, ResourceDictionaryURLs} from '../../../../common/constants/app-constants';
import {PackagesApiService} from '../packages-api.service';
import {PackagesStore} from '../packages.store';
import {ResourceDictionary} from './mapping-models/ResourceDictionary.model';
+import {FilesContent, FolderNodeElement} from './mapping-models/metadata/MetaDataTab.model';
+import {PackageCreationModes} from './creationModes/PackageCreationModes';
+import {PackageCreationBuilder} from './creationModes/PackageCreationBuilder';
+import {PackageCreationStore} from './package-creation.store';
+import {CBAPackage} from './mapping-models/CBAPacakge.model';
+import {PackageCreationUtils} from './package-creation.utils';
+import * as JSZip from 'jszip';
+import {DesignerStore} from '../designer/designer.store';
@Injectable({
providedIn: 'root'
})
export class PackageCreationService {
-
-
- constructor(private api: ApiService, private packagesListService: PackagesApiService, private packagesStore: PackagesStore) {
+ private cbaPackage: CBAPackage;
+ folder: FolderNodeElement = new FolderNodeElement();
+ filesData: any = [];
+ zipFile: JSZip = new JSZip();
+
+ constructor(private api: ApiService, private packagesListService: PackagesApiService,
+ private packagesStore: PackagesStore, private designerStore: DesignerStore,
+ private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils
+ ) {
+ this.packageCreationStore.state$.subscribe(
+ cbaPackage => {
+ this.cbaPackage = cbaPackage;
+ });
}
- private saveBlueprint(body: any | null, options?: any): Observable<any> {
+ private saveBlueprint(body: any | null, options?: any): Observable<string> {
return this.api.post(BlueprintURLs.save, body, {responseType: 'text'});
}
@@ -58,7 +76,7 @@ export class PackageCreationService {
this.packagesStore.getAll();
}
- savePackage(blob) {
+ public savePackage(blob): Observable<string> {
const formData = this.getFormData(blob);
return this.saveBlueprint(formData);
}
@@ -87,5 +105,65 @@ export class PackageCreationService {
return this.api.getCustomized(BlueprintURLs.download + id, {responseType: 'blob'});
}
+ public saveBluePrintToDataBase(): Observable<string> {
+ this.formTreeData();
+ this.create();
+ const subject = new Subject<any>();
+ this.zipFile.generateAsync({type: 'blob'})
+ .then(blob => {
+ this.savePackage(blob).subscribe(bluePrintModel => {
+ subject.next(bluePrintModel);
+ });
+ });
+ return subject.asObservable();
+ }
+
+ public deployCurrentPackage() {
+ this.formTreeData();
+ this.create();
+ const subject = new Subject<any>();
+ this.zipFile.generateAsync({type: 'blob'})
+ .then(blob => {
+ this.deploy(blob).subscribe(bluePrintModel => {
+ subject.next(bluePrintModel);
+ });
+ });
+ return subject.asObservable();
+ }
+
+ public enrichCurrentPackage() {
+ this.formTreeData();
+ this.create();
+ const subject = new Subject<any>();
+ return this.zipFile.generateAsync({type: 'blob'})
+ .then(blob => {
+ return this.enrichPackage(blob).pipe();
+ });
+ // return subject.asObservable();
+
+ }
+
+ private create() {
+ this.zipFile = new JSZip();
+ FilesContent.getMapOfFilesNamesAndContent().forEach((value, key) => {
+ this.zipFile.folder(key.split('/')[0]);
+ this.zipFile.file(key, value);
+ });
+
+ }
+
+ private formTreeData() {
+
+ FilesContent.clear();
+ let packageCreationModes: PackageCreationModes;
+ this.cbaPackage = PackageCreationModes.mapModeType(this.cbaPackage);
+ this.cbaPackage.metaData = PackageCreationModes.setEntryPoint(this.cbaPackage.metaData);
+ packageCreationModes = PackageCreationBuilder.getCreationMode(this.cbaPackage);
+ this.designerStore.state$.subscribe(state => {
+ this.cbaPackage.templateTopology.content = this.packageCreationUtils.transformToJson(state.template);
+ });
+ packageCreationModes.execute(this.cbaPackage, this.packageCreationUtils);
+ this.filesData.push(this.folder.TREE_DATA);
+ }
}
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts
index 50799a531..dae58a493 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/packages-dashboard/import-package/import-package.component.ts
@@ -19,11 +19,11 @@ export class ImportPackageComponent implements OnInit {
constructor(private packageCreationExtractionService: PackageCreationExtractionService,
private packageCreationStore: PackageCreationStore,
private router: Router) {
- this.packageCreationStore.clear();
+
}
ngOnInit() {
- this.packageCreationStore.clear();
+
}
removeInitFile(index) {
@@ -72,7 +72,7 @@ export class ImportPackageComponent implements OnInit {
public fileLeave(event) {
console.log(event);
}
-
+// TODO mix two function in ond bigger one
saveFileToStore() {
console.log(this.uploadedFiles.length);
const file = this.getFile(this.uploadedFiles[this.uploadedFiles.length - 1]);