diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2022-06-02 10:46:40 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-06-24 13:17:23 +0000 |
commit | 363d9a6fea48bf6f34e4f1d4ecb37d33812c7626 (patch) | |
tree | 6d5023023b0f93346ed40e62f6cf3f4bc23792b9 /catalog-ui/src/app/view-models | |
parent | 2dcfb0996a8345de5c8be73a5600ee995309664a (diff) |
Service Import - Read metadata from csar
Also exports metadata to the tosca template and
fixes service metadata not being set when the create button is clicked
Issue-ID: SDC-4044
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I6f8428d9ed385335c05e7b994e622229ea00342b
Diffstat (limited to 'catalog-ui/src/app/view-models')
-rw-r--r-- | catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index 6b0d49029a..0057ba4669 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -30,7 +30,9 @@ import { instantiationType, ModalsHandler, ResourceType, - ValidationUtils + ValidationUtils, + FileUtils, + ServiceCsarReader } from "app/utils"; import {EventListenerService, ProgressService} from "app/services"; import {CacheService, ElementService, ModelService, ImportVSPService, OnboardingService} from "app/services-ng2"; @@ -121,6 +123,7 @@ export class GeneralViewModel { 'VendorModelNumberValidationPattern', 'CommentValidationPattern', 'ValidationUtils', + 'FileUtils', 'sdcConfig', '$state', 'ModalsHandler', @@ -148,6 +151,7 @@ export class GeneralViewModel { private VendorModelNumberValidationPattern:RegExp, private CommentValidationPattern:RegExp, private ValidationUtils:ValidationUtils, + private FileUtils: FileUtils, private sdcConfig:IAppConfigurtaion, private $state:ng.ui.IStateService, private ModalsHandler:ModalsHandler, @@ -276,9 +280,25 @@ export class GeneralViewModel { } else if(this.$scope.component.isService()){ let service: Service = <Service>this.$scope.component; console.log(service.name + ": " + service.csarUUID); - if (service.importedFile) { // Component has imported file. + if (service.importedFile) { this.$scope.isShowFileBrowse = true; - (<Service>this.$scope.component).serviceType = 'Service'; + (<Service>this.$scope.component).ecompGeneratedNaming = true; + let blob = this.FileUtils.base64toBlob(service.importedFile.base64, "zip"); + new ServiceCsarReader().read(blob).then((serviceCsar) => { + serviceCsar.serviceMetadata.contactId = this.cacheService.get("user").userId; + (<Service>this.$scope.component).setComponentMetadata(serviceCsar.serviceMetadata); + (<Service>this.$scope.component).model = serviceCsar.serviceMetadata.model; + this.$scope.onModelChange(); + this.$scope.componentCategories.selectedCategory = serviceCsar.serviceMetadata.selectedCategory; + this.$scope.onCategoryChange(); + serviceCsar.extraServiceMetadata.forEach((value: string, key: string) => { + if(this.getMetadataKey(key)) { + (<Service>this.$scope.component).categorySpecificMetadata[key] = value; + } + }); + (<Service>this.$scope.component).derivedFromGenericType = serviceCsar.substitutionNodeType; + this.$scope.onBaseTypeChange(); + }); } if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) { this.$scope.isShowFileBrowse = true; @@ -878,7 +898,9 @@ export class GeneralViewModel { if (this.$scope.isBaseTypeRequired) { const baseType = baseTypeResponseList.baseTypes[0]; baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); - this.$scope.component.derivedFromGenericType = baseType.toscaResourceName; + if(!this.$scope.component.derivedFromGenericType) { + this.$scope.component.derivedFromGenericType = baseType.toscaResourceName; + } this.$scope.component.derivedFromGenericVersion = this.$scope.baseTypeVersions[0]; this.$scope.showBaseTypeVersions = true; return |