From 363d9a6fea48bf6f34e4f1d4ecb37d33812c7626 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 2 Jun 2022 10:46:40 +0100 Subject: 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 Change-Id: I6f8428d9ed385335c05e7b994e622229ea00342b --- .../workspace/tabs/general/general-view-model.ts | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'catalog-ui/src/app/view-models/workspace') 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 = this.$scope.component; console.log(service.name + ": " + service.csarUUID); - if (service.importedFile) { // Component has imported file. + if (service.importedFile) { this.$scope.isShowFileBrowse = true; - (this.$scope.component).serviceType = '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; + (this.$scope.component).setComponentMetadata(serviceCsar.serviceMetadata); + (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)) { + (this.$scope.component).categorySpecificMetadata[key] = value; + } + }); + (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 -- cgit 1.2.3-korg