Handle CSAR reading errors in Service Import 17/130717/10
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>
Mon, 5 Sep 2022 05:51:13 +0000 (06:51 +0100)
committerMichael Morris <michael.morris@est.tech>
Thu, 15 Sep 2022 08:56:26 +0000 (08:56 +0000)
Issue-ID: SDC-4162
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I13c2d053991f4a2b12e4c845dcd0da6e1c00adae

catalog-ui/src/app/utils/service-csar-reader.ts
catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
catalog-ui/src/assets/languages/en_US.json

index 73b7755..90de53b 100644 (file)
@@ -26,17 +26,21 @@ export class ServiceCsarReader {
 
     private serviceCsar = new ServiceCsar();
 
-    public read(serviceCsarBlob:Blob): Promise<ServiceCsar> {
+    public read(serviceCsarBlob: Blob): Promise<ServiceCsar> {
         const jsZip = require("jszip");
-        return new Promise<ServiceCsar>((resolve) => {
+        return new Promise<ServiceCsar>((resolve, reject) => {
             jsZip.loadAsync(serviceCsarBlob).then(async zip => {
-                const toscaMetaFileContent = await zip.file("TOSCA-Metadata/TOSCA.meta").async("string");
-                this.readToscaMeta(toscaMetaFileContent);
-                const entryDefinitionFileContent = await zip.file(this.serviceCsar.entryDefinitionFileName).async("string");
-                this.readServiceMetadata(entryDefinitionFileContent);
-                const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string");
-                this.readServiceSubstitutionNode(interfaceDefinitionFileContent);
-                resolve(this.serviceCsar);
+                try {
+                    const toscaMetaFileContent = await zip.file("TOSCA-Metadata/TOSCA.meta").async("string");
+                    this.readToscaMeta(toscaMetaFileContent);
+                    const entryDefinitionFileContent = await zip.file(this.serviceCsar.entryDefinitionFileName).async("string");
+                    this.readServiceMetadata(entryDefinitionFileContent);
+                    const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string");
+                    this.readServiceSubstitutionNode(interfaceDefinitionFileContent);
+                    resolve(this.serviceCsar);
+                } catch (error) {
+                    reject(error);
+                }
             });
         });
     }
index 9d67b8e..77c9330 100644 (file)
@@ -41,6 +41,7 @@ import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view
 import {CATEGORY_SERVICE_METADATA_KEYS, PREVIOUS_CSAR_COMPONENT, DEFAULT_MODEL_NAME} from "../../../../utils/constants";
 import {Observable} from "rxjs";
 import {Model} from "../../../../models/model";
+import {SdcUiServices} from "onap-ui-angular/dist";
 
 export class Validation {
     componentNameValidationPattern:RegExp;
@@ -127,6 +128,7 @@ export class GeneralViewModel {
         'sdcConfig',
         '$state',
         'ModalsHandler',
+        'ModalServiceSdcUI',
         'EventListenerService',
         'Notification',
         'Sdc.Services.ProgressService',
@@ -155,6 +157,7 @@ export class GeneralViewModel {
                 private sdcConfig:IAppConfigurtaion,
                 private $state:ng.ui.IStateService,
                 private ModalsHandler:ModalsHandler,
+                private modalServiceSdcUI: SdcUiServices.ModalService,
                 private EventListenerService:EventListenerService,
                 private Notification:any,
                 private progressService:ProgressService,
@@ -277,28 +280,40 @@ export class GeneralViewModel {
             if (resource.resourceType === ResourceType.VF && !resource.csarUUID) {
                 this.$scope.isShowFileBrowse = true;
             }
-        } else if(this.$scope.component.isService()){
+        } else if (this.$scope.component.isService()) {
             let service: Service = <Service>this.$scope.component;
             console.log(service.name + ": " + service.csarUUID);
             if (service.importedFile) {
                 this.$scope.isShowFileBrowse = true;
                 (<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;
-                        }
+                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();
+                    },
+                    (error) => {
+                        const errorMsg = this.$filter('translate')('IMPORT_FAILURE_MESSAGE_TEXT');
+                        console.error(errorMsg, error);
+                        const errorDetails = {
+                            'Error': error.reason,
+                            'Details': error.message
+                        };
+                        this.modalServiceSdcUI.openErrorDetailModal('Error', this.$filter('translate')('IMPORT_FAILURE_MESSAGE_TEXT'),
+                            'error-modal', errorDetails);
+                        this.$state.go('dashboard');
                     });
-                    (<Service>this.$scope.component).derivedFromGenericType = serviceCsar.substitutionNodeType;
-                    this.$scope.onBaseTypeChange();
-                });
             }
             if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) {
                 this.$scope.isShowFileBrowse = true;
index 586717a..13c8669 100644 (file)
   "CAP_VALID_SOURCE": "Valid Sources",
   "VALUE_LABEL": "Value",
   "VALUE_EXPRESSION_LABEL": "Value Expression",
-  "OPERATOR_LABEL": "Operator"
+  "OPERATOR_LABEL": "Operator",
+  "=========== SERVICE IMPORT ===========": "",
+  "IMPORT_FAILURE_MESSAGE_TEXT": "Import Failure - error reading CSAR"
 }