Provide UI support to upload csar to update service 48/135848/6
authorimamSidero <imam.hussain@est.tech>
Tue, 29 Aug 2023 10:39:37 +0000 (11:39 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Thu, 7 Sep 2023 13:40:17 +0000 (13:40 +0000)
Upload capability is porvided in tosca artifact to update the service

Issue-ID: SDC-4605
Signed-off-by: Imam hussain <imam.hussain@est.tech>
Change-Id: I075250f91e6e68f007298d1b982db86244a696db

catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts
catalog-ui/src/app/ng2/pages/workspace/tosca-artifacts/tosca-artifact-page.component.ts
catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts

index 00e2fd8..d548d42 100644 (file)
@@ -14,11 +14,19 @@ export class HeadersInterceptor implements HttpInterceptor {
     constructor(private injector: Injector, private cookieService: Cookie2Service, private httpHelperService: HttpHelperService) {}
 
     intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
-        let authReq = req.clone({ headers: req.headers.set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
-            .set('Content-Type', 'application/json; charset=UTF-8')
-            .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
-            .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
-        });
+        let authReq: HttpRequest<any>;
+        if (req.body instanceof FormData) {
+            authReq = req.clone({ headers: req.headers.set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+                .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+                .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+            });
+        } else {
+            authReq = req.clone({ headers: req.headers.set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+                .set('Content-Type', 'application/json; charset=UTF-8')
+                .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+                .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())
+            });
+        }
 
         const uuidValue = this.httpHelperService.getUuidValue(authReq.url);
         if (uuidValue !== '') {
index e6d820e..c18d22b 100644 (file)
@@ -70,11 +70,15 @@ export class ToscaArtifactPageComponent implements OnInit {
             this.isLoading = true;
             switch (artifactType) {
                 case (ArtifactType.TOSCA.TOSCA_CSAR):
-                    this.Notification.error({
-                        message: "Feature not implemented yet",
-                        title: "Error"
+                    this.componentService.putServiceToscaModel(this.componentId, this.componentType, file).subscribe((response)=> {
+                        this.Notification.success({
+                            message: "Service " + response.name + " has been updated",
+                            title: "Success"
+                        });
+                        this.isLoading = false;
+                    }, () => {
+                        this.isLoading = false;
                     });
-                    this.isLoading = false;
                     break;
                 case (ArtifactType.TOSCA.TOSCA_TEMPLATE):
                     this.componentService.putServiceToscaTemplate(this.componentId, this.componentType, file).subscribe((response)=> {
index 0386a15..0af8c73 100644 (file)
@@ -80,6 +80,12 @@ export class TopologyTemplateService {
         return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/toscaTemplate', file)
     }
 
+    putServiceToscaModel(componentId: string, componentType: string, file) {
+        let uploadData:FormData = new FormData();
+        uploadData.append('upload', file);
+        return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/toscaModel', uploadData);
+    }
+
     getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
         return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
     }