From e70a0e413947cc3e5e21d041f0ed3d7582b44d7a Mon Sep 17 00:00:00 2001 From: Ahmed Date: Mon, 24 Feb 2020 20:10:40 +0200 Subject: import maaping from CSV file or the current template Issue-ID: CCSDK-2065 Signed-off-by: ahmedeldeeb50 Change-Id: Idc5b1deccf2966438aed13329290df6d9b3f0da7 --- .../creationModes/DesignerCreationMode.ts | 13 ++ .../mapping-models/CBAPacakge.model.ts | 22 ++- .../mapping-models/ResourceDictionary.model.ts | 23 ++++ .../mapping-models/definitions/VlbDefinition.ts | 2 +- .../mapping-models/mappingAdapter.model.ts | 38 ++++++ .../package-creation/package-creation.service.ts | 3 +- .../package-creation/package-creation.store.ts | 23 ++-- .../templ-mapp-creation.component.html | 106 ++++++++++----- .../templ-mapp-creation.component.ts | 150 ++++++++++++++++++--- .../feature-modules/packages/packages.module.ts | 60 +++++---- 10 files changed, 349 insertions(+), 91 deletions(-) create mode 100644 cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts create mode 100644 cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages') 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 db6d0420b..162efff9e 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 @@ -7,6 +7,7 @@ import { PackageCreationUtils } from '../package-creation.utils'; export class DesignerCreationMode extends PackageCreationModes { + // Refactor methods params to be in constructor level constructor() { super(); } @@ -15,6 +16,7 @@ export class DesignerCreationMode extends PackageCreationModes { this.addToscaMetaDataFile(cbaPackage.metaData); this.createDefinitionsFolder(cbaPackage, packageCreationUtils); this.addScriptsFolder(cbaPackage.scripts); + this.addTemplateFolder(cbaPackage); } private addScriptsFolder(scripts: Scripts) { @@ -23,6 +25,17 @@ export class DesignerCreationMode extends PackageCreationModes { }); } + private addTemplateFolder(cbaPackage: CBAPackage) { + // Create Template Files Folder + cbaPackage.templates.files.forEach((value, key) => { + FilesContent.putData(key, value); + }); + // Create Mapping Files Folder + cbaPackage.mapping.files.forEach((value, key) => { + FilesContent.putData(key, value); + }); + } + private createDefinitionsFolder(cbaPackage: CBAPackage, packageCreationUtils: PackageCreationUtils) { cbaPackage.definitions.imports.forEach((valueOfFile, key) => { FilesContent.putData(key, valueOfFile); 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 3595f7872..45a00ff06 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,4 +1,4 @@ -import {MetaDataTabModel} from './metadata/MetaDataTab.model'; +import { MetaDataTabModel } from './metadata/MetaDataTab.model'; export class Definition { @@ -34,6 +34,22 @@ export class DslDefinition { content: string; } +export class Base { + public files: Map; + + constructor() { + this.files = new Map(); + } + + public setContent(key: string, value: string) { + this.files.set(key, value); + return this; + } + + public getValue(key: string): string { + return this.files.get(key); + } +} export class Scripts { public files: Map; @@ -65,12 +81,15 @@ export class Template { } } +export class Mapping extends Base { +} export class CBAPackage { public metaData: MetaDataTabModel; public definitions: Definition; public scripts: Scripts; public templates: Template; + public mapping: Mapping; constructor() { @@ -78,6 +97,7 @@ export class CBAPackage { this.scripts = new Scripts(); this.metaData = new MetaDataTabModel(); this.templates = new Template(); + this.mapping = new Mapping(); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts new file mode 100644 index 000000000..558d1c7d0 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/ResourceDictionary.model.ts @@ -0,0 +1,23 @@ +import { JsonObject, JsonProperty } from 'json2typescript'; + +@JsonObject('ResourceDictionary') +export class ResourceDictionary { + @JsonProperty() + name: string; + @JsonProperty('creation_date') + creationDate: string; + @JsonProperty('data_type') + dataType: string; + @JsonObject('definition') + definition?: any | null; + @JsonProperty('description') + description: string; + @JsonProperty('entry_schema') + entrySchema: string; + @JsonProperty('esource_dictionary_group') + resourceDictionaryGroup: string; + @JsonProperty('tags') + tags: string; + @JsonProperty('upadted_by') + updatedBy: string; +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts index b797050dd..8e2ff475e 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/definitions/VlbDefinition.ts @@ -17,7 +17,7 @@ export class VlbDefinition { export class DslContent { } - +// Refactor varaibles name and use JsonConverteri @JsonObject('metadata') export class Metadata { @JsonProperty('template_author') diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts new file mode 100644 index 000000000..638654a95 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/mapping-models/mappingAdapter.model.ts @@ -0,0 +1,38 @@ +import { ResourceDictionary } from './ResourceDictionary.model'; +import { JsonObject, JsonProperty, JsonConvert } from 'json2typescript'; + +// Convert ResourceDictionary object to store Mapping +export class MappingAdapter { + + constructor(private resourceDictionary: ResourceDictionary) { } + + ToMapping(): Mapping { + const mapping = new Mapping(); + mapping.name = this.resourceDictionary.name; + mapping.dictionaryName = this.resourceDictionary.name; + mapping.property = this.resourceDictionary.definition.property; + mapping.inputParam = false; + mapping.dictionarySource = 'sdnc'; + mapping.dependencies = []; + mapping.version = 0; + return mapping; + } +} + +@JsonObject('Mapping') +export class Mapping { + @JsonProperty('name') + name: string; + @JsonProperty() + property: any; + @JsonProperty('input-param', Boolean) + inputParam: boolean; + @JsonProperty('dictionary-name') + dictionaryName: string; + @JsonProperty('dictionary-source') + dictionarySource: string; + @JsonProperty() + dependencies: []; + @JsonProperty() + version: number; +} 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 cac27120f..494c9e555 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 @@ -26,6 +26,7 @@ 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'; @Injectable({ providedIn: 'root' @@ -62,7 +63,7 @@ export class PackageCreationService { }); } - getTemplateAndMapping(variables: string[]): Observable { + getTemplateAndMapping(variables: string[]): Observable { return this.api.post(ResourceDictionaryURLs.searchResourceDictionaryByNames, variables); } } 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 565603ad1..6a9d9c4b3 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,14 +19,16 @@ 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 {FolderNodeElement, MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model'; +import { CBAPackage, DslDefinition } from './mapping-models/CBAPacakge.model'; +import { PackageCreationService } from './package-creation.service'; +import { FolderNodeElement, MetaDataTabModel } from './mapping-models/metadata/MetaDataTab.model'; import * as JSZip from 'jszip'; +import { Observable } from 'rxjs'; +import { ResourceDictionary } from './mapping-models/ResourceDictionary.model'; @Injectable({ @@ -94,9 +96,14 @@ export class PackageCreationStore extends Store { }); } - getTemplateAndMapping(variables: string[]) { - this.packageCreationService.getTemplateAndMapping(variables).subscribe(element => { - console.log('the element is ' + element); + addMapping(filePath: string, fileContent: string) { + this.setState({ + ...this.state, + mapping: this.state.mapping.setContent(filePath, fileContent) }); } + + getTemplateAndMapping(variables: string[]): Observable { + return this.packageCreationService.getTemplateAndMapping(variables); + } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html index c3a36c9cb..d08ada98d 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html @@ -17,7 +17,7 @@
@@ -29,25 +29,24 @@
-
Use the editor to add parameters or you can also Import - File
+ data-toggle="modal" data-target="#exampleModal">Import + File
- +
@@ -70,7 +68,7 @@
@@ -79,14 +77,15 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
RequiredParameter NameDictionary NameDictionary SourceDependanciesDefaultData TypeEntry Schema
{{ dict.definition?.property?.required }}{{ dict.name }}{{ dict.name }} + + + + + {{ dict.definition?.property?.default }}{{ dict.dataType }}{{ dict.entrySchema }}
+
-
- +