diff options
author | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-07-15 23:50:43 +0200 |
---|---|---|
committer | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-07-16 10:37:27 +0200 |
commit | f6c51a61086e2bf892f41c912ae1e08e55d878f8 (patch) | |
tree | b3634c01414584f00de1e996686a46310f7c383d /cds-ui/designer-client/src/app/modules/feature-modules/packages | |
parent | 0882e287bbb6aee4543f7659b1f9d001a1b01a1a (diff) |
starting manual enrichment functionality
Issue-ID: CCSDK-2542
Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com>
Change-Id: I3ce3e7aa5deb131b958cef0ca424e4d92fd7913c
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages')
6 files changed, 132 insertions, 72 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html index ba5eca973..fb2dce6c9 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/configuration-dashboard/configuration-dashboard.component.html @@ -660,7 +660,7 @@ </div> </div> <button type="button" class="btn btn-sm mb-2 btn-enrich" data-toggle="modal" - data-target="#enrichModal"> + data-target="#enrichModal" > <i class="icon-enrich" aria-hidden="true"></i> Manual Enrich </button> @@ -746,14 +746,14 @@ <li>1. Copy and paste "workflows" and "node_templates"</li> <li>2. Press <b>Enrich</b> button</li> </ul> - <ace-editor [(text)]="dslDefinition.content" [mode]="'javascript'" [autoUpdateContent]="true" + <ace-editor [(text)]="vlbDefinition.topology_template.content" [mode]="'javascript'" [autoUpdateContent]="true" [durationBeforeCallback]="1000" (textChanged)="textChanged($event)" [theme]="'eclipse'" #editor style="height:300px;"> </ace-editor> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> - <button type="button" data-dismiss="modal" class="btn btn-primary btn-enrich">Enrich</button> + <button type="button" data-dismiss="modal" class="btn btn-primary btn-enrich" (click)="enrichBluePrint()">Enrich</button> </div> </div> </div> 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 fa127290c..e668b6417 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 @@ -1,21 +1,21 @@ -import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { BluePrintDetailModel } from '../model/BluePrint.detail.model'; -import { PackageCreationStore } from '../package-creation/package-creation.store'; -import { FilesContent, FolderNodeElement, MetaDataTabModel } from '../package-creation/mapping-models/metadata/MetaDataTab.model'; -import { MetadataTabComponent } from '../package-creation/metadata-tab/metadata-tab.component'; +import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {BluePrintDetailModel} from '../model/BluePrint.detail.model'; +import {PackageCreationStore} from '../package-creation/package-creation.store'; +import {FilesContent, FolderNodeElement, MetaDataTabModel} from '../package-creation/mapping-models/metadata/MetaDataTab.model'; +import {MetadataTabComponent} from '../package-creation/metadata-tab/metadata-tab.component'; import * as JSZip from 'jszip'; -import { ConfigurationDashboardService } from './configuration-dashboard.service'; -import { VlbDefinition } from '../package-creation/mapping-models/definitions/VlbDefinition'; -import { DslDefinition } 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'; -import { saveAs } from 'file-saver'; -import { DesignerStore } from '../designer/designer.store'; -import { DesignerService } from '../designer/designer.service'; -import { ToastrService } from 'ngx-toastr'; -import { NgxFileDropEntry } from 'ngx-file-drop'; +import {ConfigurationDashboardService} from './configuration-dashboard.service'; +import {TemplateTopology, VlbDefinition} from '../package-creation/mapping-models/definitions/VlbDefinition'; +import {DslDefinition} 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'; +import {saveAs} from 'file-saver'; +import {DesignerStore} from '../designer/designer.store'; +import {ToastrService} from 'ngx-toastr'; +import {NgxFileDropEntry} from 'ngx-file-drop'; +import {TopologyTemplate} from '../designer/model/designer.topologyTemplate.model'; @Component({ selector: 'app-configuration-dashboard', @@ -24,13 +24,13 @@ import { NgxFileDropEntry } from 'ngx-file-drop'; }) export class ConfigurationDashboardComponent implements OnInit { viewedPackage: BluePrintDetailModel = new BluePrintDetailModel(); - @ViewChild(MetadataTabComponent, { static: false }) + @ViewChild(MetadataTabComponent, {static: false}) metadataTabComponent: MetadataTabComponent; public customActionName = ''; entryDefinitionKeys: string[] = ['template_tags', 'user-groups', 'author-email', 'template_version', 'template_name', 'template_author', 'template_description']; - @ViewChild('nameit', { static: true }) + @ViewChild('nameit', {static: true}) elementRef: ElementRef; uploadedFiles = []; zipFile: JSZip = new JSZip(); @@ -39,7 +39,7 @@ export class ConfigurationDashboardComponent implements OnInit { id: any; currentBlob = new Blob(); - dslDefinition: DslDefinition = new DslDefinition(); + vlbDefinition: VlbDefinition = new VlbDefinition(); constructor( private route: ActivatedRoute, @@ -53,6 +53,8 @@ export class ConfigurationDashboardComponent implements OnInit { } ngOnInit() { + this.vlbDefinition.topology_template = new TemplateTopology(); + this.elementRef.nativeElement.focus(); this.id = this.route.snapshot.paramMap.get('id'); this.configurationDashboardService.getPagedPackages(this.id).subscribe( @@ -72,32 +74,32 @@ export class ConfigurationDashboardComponent implements OnInit { private downloadCBAPackage(bluePrintDetailModels: BluePrintDetailModel) { this.configurationDashboardService.downloadResource( 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]); + 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]); } - }); + } }); }); }); + }); } setScripts(filename: string, fileData: any) { @@ -122,10 +124,10 @@ export class ConfigurationDashboardComponent implements OnInit { if (definition.topology_template && definition.topology_template.content) { this.designerStore.saveSourceContent(definition.topology_template.content); } - } else { - this.packageCreationStore.addDefinition(filename, fileData); } + this.packageCreationStore.addDefinition(filename, fileData); + } setTemplates(filename: string, fileData: any) { @@ -173,7 +175,7 @@ export class ConfigurationDashboardComponent implements OnInit { saveBluePrintToDataBase() { this.create(); - this.zipFile.generateAsync({ type: 'blob' }) + this.zipFile.generateAsync({type: 'blob'}) .then(blob => { this.packageCreationStore.saveBluePrint(blob).subscribe( bluePrintDetailModels => { @@ -198,6 +200,7 @@ export class ConfigurationDashboardComponent implements OnInit { console.log(err); }); } + create() { this.zipFile = new JSZip(); FilesContent.getMapOfFilesNamesAndContent().forEach((value, key) => { @@ -213,35 +216,25 @@ export class ConfigurationDashboardComponent implements OnInit { downloadPackage(artifactName: string, artifactVersion: string) { this.configurationDashboardService.downloadResource(artifactName + '/' + artifactVersion).subscribe(response => { - const blob = new Blob([response], { type: 'application/octet-stream' }); + const blob = new Blob([response], {type: 'application/octet-stream'}); saveAs(blob, artifactName + '-' + artifactVersion + '-CBA.zip'); }); } deployCurrentPackage() { console.log('happened'); - /* this.zipFile.generateAsync({type: 'blob'}) - .then(blob => { - const formData = new FormData(); - formData.append('file', this.currentBlob); - this.configurationDashboardService.deployPost(formData) - .subscribe(data => { - }, error => { - }); - this.router.navigate(['/packages']); - }); - */ this.router.navigate(['/packages']); } goToDesignerMode(id) { // this.designerService.setActionName(this.customActionName); - this.router.navigate(['/packages/designer', id, { actionName: this.customActionName }]); + this.router.navigate(['/packages/designer', id, {actionName: this.customActionName}]); } public dropped(files: NgxFileDropEntry[]) { } + public fileOver(event) { console.log(event); } @@ -251,6 +244,40 @@ export class ConfigurationDashboardComponent implements OnInit { } textChanged($event: {}) { + this.packageCreationStore.addTopologyTemplate(this.vlbDefinition.topology_template); + } + + enrichBluePrint() { + 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(); + + }); + } + + private enrichPackage() { + this.create(); + this.zipFile.generateAsync({type: 'blob'}) + .then(blob => { + 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 '); + }); + }, error => { + this.toastService.error('error happened when editing ' + error.message); + console.log('Error -' + error.message); + }); } } 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 index 184ccf9ef..58307005c 100644 --- 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 @@ -77,6 +77,9 @@ export class DesignerCreationMode extends PackageCreationModes { if (cbaPackage.definitions.dslDefinition.content) { vlbDefinition.dsl_definitions = JSON.parse(cbaPackage.definitions.dslDefinition.content); } + if (cbaPackage.templateTopology.content) { + vlbDefinition.topology_template = JSON.parse(cbaPackage.templateTopology.content); + } console.log(vlbDefinition); const value = packageCreationUtils.transformToJson(vlbDefinition); FilesContent.putData(filenameEntry, value); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts index a37339d90..e34b5491b 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/CBAPacakge.model.ts @@ -1,6 +1,5 @@ import {MetaDataTabModel} from './metadata/MetaDataTab.model'; - - +import {TemplateTopology} from './definitions/VlbDefinition'; export class Definition { @@ -94,6 +93,7 @@ export class CBAPackage { public scripts: Scripts; public templates: Template; public mapping: Mapping; + public templateTopology: TemplateTopology; constructor() { @@ -102,6 +102,7 @@ export class CBAPackage { this.metaData = new MetaDataTabModel(); this.templates = new Template(); this.mapping = new Mapping(); + this.templateTopology = new TemplateTopology(); } 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 818577a59..952fea3ca 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 @@ -41,6 +41,10 @@ export class PackageCreationService { return this.api.post(BlueprintURLs.save, body, {responseType: 'text'}); } + private enrichBlueprint(body: any | null, options?: any): Observable<any> { + return this.api.post(BlueprintURLs.enrich, 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); @@ -51,11 +55,19 @@ export class PackageCreationService { } savePackage(blob) { + const formData = this.getFormData(blob); + return this.saveBlueprint(formData); + } + enrichPackage(blob) { + const formData = this.getFormData(blob); + return this.enrichBlueprint(formData); + } + + private getFormData(blob) { const formData = new FormData(); formData.append('file', blob); - return this.saveBlueprint(formData); - + return formData; } getTemplateAndMapping(variables: string[]): Observable<ResourceDictionary[]> { diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts index 55e715654..f64e361d4 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/package-creation.store.ts @@ -19,16 +19,17 @@ limitations under the License. ============LICENSE_END============================================ */ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; -import { Store } from '../../../../common/core/stores/Store'; +import {Store} from '../../../../common/core/stores/Store'; -import { CBAPackage, DslDefinition } from './mapping-models/CBAPacakge.model'; -import { PackageCreationService } from './package-creation.service'; -import { MetaDataTabModel } from './mapping-models/metadata/MetaDataTab.model'; -import { Observable } from 'rxjs'; -import { ResourceDictionary } from './mapping-models/ResourceDictionary.model'; -import { BluePrintDetailModel } from '../model/BluePrint.detail.model'; +import {CBAPackage, DslDefinition} from './mapping-models/CBAPacakge.model'; +import {PackageCreationService} from './package-creation.service'; +import {MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; +import {Observable} from 'rxjs'; +import {ResourceDictionary} from './mapping-models/ResourceDictionary.model'; +import {BluePrintDetailModel} from '../model/BluePrint.detail.model'; +import {TemplateTopology} from './mapping-models/definitions/VlbDefinition'; @Injectable({ @@ -59,6 +60,7 @@ export class PackageCreationStore extends Store<CBAPackage> { istemplateExist(): boolean { return this.state.templates.files.size > 0 && this.state.mapping.files.size > 0; } + changeDslDefinition(dslDefinition: DslDefinition) { this.setState({ @@ -100,6 +102,10 @@ export class PackageCreationStore extends Store<CBAPackage> { return this.packageCreationService.savePackage(blob); } + enrichBluePrint(blob): Observable<any> { + return this.packageCreationService.enrichPackage(blob); + } + addTemplate(filePath: string, fileContent: string) { this.setState({ ...this.state, @@ -121,4 +127,15 @@ export class PackageCreationStore extends Store<CBAPackage> { clear() { this.setState(new CBAPackage()); } + + setEntryDefinition(data: string) { + console.log('setting manual enrichment '); + } + + addTopologyTemplate(templateTopology: TemplateTopology) { + this.setState({ + ...this.state, + templateTopology + }); + } } |