aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation
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/designer-client/src/app/modules/feature-modules/packages/package-creation
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/designer-client/src/app/modules/feature-modules/packages/package-creation')
-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
3 files changed, 115 insertions, 24 deletions
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);
+ }
}