adding manual enrichment 22/112222/1
authorShaabanEltanany <shaaban.eltanany.ext@orange.com>
Mon, 7 Sep 2020 10:00:44 +0000 (12:00 +0200)
committerShaabanEltanany <shaaban.eltanany.ext@orange.com>
Mon, 7 Sep 2020 10:00:44 +0000 (12:00 +0200)
Issue-ID: CCSDK-2542
Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com>
Change-Id: I14eac56b1541a54b7b3e6d3e2c4e34dc667f0c8c

cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html
cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.service.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts

index f79657a..9e8ef5d 100644 (file)
                 </nav>
                 <div class="row mt-4">
                     <div class="col">
-                        <div class="tab-content" id="nav-tabContent">
+                        <div class="tab-content" id="nav-tabContent" (change)="clickEvent()">
                             <div class="tab-pane fade show active" id="nav-metadata" role="tabpanel"
-                                 aria-labelledby="nav-metadata-tab" (change)="clickEvent()">
+                                 aria-labelledby="nav-metadata-tab" >
                                 <app-metadata-tab></app-metadata-tab>
                             </div>
                             <div class="tab-pane fade" id="nav-template" role="tabpanel"
index 47e89b3..029601d 100644 (file)
@@ -70,6 +70,7 @@ export class ConfigurationDashboardComponent implements OnInit {
                     }
                 } else {
                     this.metadataClasses = this.metadataClasses.replace('complete', '');
+                    this.isSaveEnabled = false;
                 }
 
             });
@@ -92,27 +93,32 @@ export class ConfigurationDashboardComponent implements OnInit {
             bluePrintDetailModels[0].artifactName + '/' + bluePrintDetailModels[0].artifactVersion).subscribe(response => {
             const blob = new Blob([response], {type: 'application/octet-stream'});
             this.currentBlob = blob;
-            this.zipFile.loadAsync(blob).then((zip) => {
-                Object.keys(zip.files).forEach((filename) => {
-                    zip.files[filename].async('string').then((fileData) => {
-                        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, bluePrintDetailModels);
-                            } else if (filename.includes('TOSCA-Metadata/')) {
-                                const metaDataTabInfo: MetaDataTabModel = this.getMetaDataTabInfo(fileData);
-                                this.setMetaData(metaDataTabInfo, bluePrintDetailModels[0]);
+            this.extractBlobToStore(blob, bluePrintDetailModels);
+        });
+    }
+
+    private extractBlobToStore(blob: Blob, bluePrintDetailModels: 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, bluePrintDetailModels);
+                        } else if (filename.includes('TOSCA-Metadata/')) {
+                            const metaDataTabInfo: MetaDataTabModel = this.getMetaDataTabInfo(fileData);
+                            this.setMetaData(metaDataTabInfo, bluePrintDetailModels[0]);
                         }
-                    });
+                    }
                 });
             });
         });
@@ -239,8 +245,9 @@ export class ConfigurationDashboardComponent implements OnInit {
     }
 
     deployCurrentPackage() {
-        console.log('happened');
-        this.router.navigate(['/packages']);
+        this.collectZipFileFromStore();
+        this.deployPackage();
+
     }
 
     goToDesignerMode(id) {
@@ -266,19 +273,21 @@ export class ConfigurationDashboardComponent implements OnInit {
 
     enrichBluePrint() {
 
+        this.collectZipFileFromStore();
+        this.enrichPackage();
+    }
+
+    private collectZipFileFromStore() {
         this.packageCreationStore.state$.subscribe(
             cbaPackage => {
                 FilesContent.clear();
                 console.log(cbaPackage);
-
                 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.enrichPackage();
-
             });
     }
 
@@ -289,8 +298,18 @@ export class ConfigurationDashboardComponent implements OnInit {
                 this.packageCreationStore.enrichBluePrint(blob).subscribe(response => {
                     console.log('success');
                     const blobInfo = new Blob([response], {type: 'application/octet-stream'});
-                    saveAs(blobInfo, 'test' + '-' + '1.0.0' + '-CBA.zip');
-                    this.toastService.info('enriched successfully ');
+                    this.configurationDashboardService.getPagedPackages(this.id).subscribe(
+                        (bluePrintDetailModels) => {
+                            if (bluePrintDetailModels) {
+                                this.packageCreationStore.clear();
+                                this.extractBlobToStore(blob, bluePrintDetailModels);
+                                this.isSaveEnabled = true;
+                                this.toastService.info('enriched successfully ');
+                            }
+                        });
+
+                    // saveAs(blobInfo, 'test' + '-' + '1.0.0' + '-CBA.zip');
+
                 });
             }, error => {
                 this.toastService.error('error happened when editing ' + error.message);
@@ -298,6 +317,23 @@ export class ConfigurationDashboardComponent implements OnInit {
             });
     }
 
+    private deployPackage() {
+        this.create();
+        this.zipFile.generateAsync({type: 'blob'})
+            .then(blob => {
+                this.packageCreationStore.deployBluePrint(blob).subscribe(response => {
+                    console.log('success');
+                    console.log(response);
+
+                    // saveAs(blobInfo, 'test' + '-' + '1.0.0' + '-CBA.zip');
+
+                });
+            }, error => {
+                this.toastService.error('error happened when deploying ' + error.message);
+                console.log('Error -' + error.message);
+            });
+    }
+
     clickEvent() {
         this.isSaveEnabled = true;
     }
index 952fea3..e7ccbb3 100644 (file)
@@ -45,6 +45,10 @@ export class PackageCreationService {
         return this.api.post(BlueprintURLs.enrich, body, {responseType: 'text'});
     }
 
+    private deployBluePrint(body: any | null, options?: any): Observable<any> {
+        return this.api.post(BlueprintURLs.deploy, body, {responseType: 'text'});
+    }
+
     async checkBluePrintNameAndVersion(name: string, version: string): Promise<boolean> {
         return await this.packagesListService.checkBluePrintIfItExists(name, version)
             .then(bluePrintModelsResult => bluePrintModelsResult != null && bluePrintModelsResult.length > 0);
@@ -64,6 +68,11 @@ export class PackageCreationService {
         return this.enrichBlueprint(formData);
     }
 
+    deploy(blob) {
+        const formData = this.getFormData(blob);
+        return this.deployBluePrint(formData);
+    }
+
     private getFormData(blob) {
         const formData = new FormData();
         formData.append('file', blob);
@@ -73,4 +82,6 @@ export class PackageCreationService {
     getTemplateAndMapping(variables: string[]): Observable<ResourceDictionary[]> {
         return this.api.post(ResourceDictionaryURLs.searchResourceDictionaryByNames, variables);
     }
+
+
 }
index f64e361..b608312 100644 (file)
@@ -106,6 +106,10 @@ export class PackageCreationStore extends Store<CBAPackage> {
         return this.packageCreationService.enrichPackage(blob);
     }
 
+    deployBluePrint(blob): Observable<BluePrintDetailModel> {
+        return this.packageCreationService.deploy(blob);
+    }
+
     addTemplate(filePath: string, fileContent: string) {
         this.setState({
             ...this.state,