Added Widget-Onboarding and dependent Services
[portal.git] / portal-FE-common / src / app / shared / services / widget-onboarding / widget-onboarding.service.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 import { Injectable } from '@angular/core';
40 import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
41 import { environment } from '../../../../environments/environment';
42 import { Observable } from 'rxjs';
43 import * as uuid from 'uuid';
44
45 @Injectable({
46   providedIn: 'root'
47 })
48 export class WidgetOnboardingService {
49
50   api = environment.api;
51   resp:string;
52
53   headerParams = {'X-Widgets-Type': 'all', 'X-ECOMP-RequestID': uuid.v4() };
54
55   constructor(private http: HttpClient) { }
56
57   getManagedWidgets(): Observable<any>{ 
58     let getManagedWidgetsURL  = this.api.widgetCommon + '/widgetCatalog';
59     return this.http.get(getManagedWidgetsURL , { withCredentials: true } );
60   }
61
62   deleteWidget(widgetId: any): Observable<any> {
63     let deleteWidgetURL = this.api.widgetCommon + '/widgetCatalog'  + '/' + widgetId;
64     return this.http.delete(deleteWidgetURL , { withCredentials: true } );
65   }
66
67   downloadWidgetFile(widgetId: any): Observable<any> {
68     let downloadWidgetURL = this.api.widgetCommon + '/download/' + widgetId;
69     let httpParam = new  HttpParams()
70     .append('requestType', 'downloadWidgetFile');
71     return this.http.get(downloadWidgetURL,{params: httpParam, responseType: "arraybuffer"});
72   }
73
74   getUploadFlag(): Observable<any> {
75     let getUploadFlagURL = this.api.widgetCommon + '/uploadFlag';
76     return this.http.get(getUploadFlagURL , { withCredentials: true } );
77   }
78
79   updateWidgetWithFile(formData: any, widgetId: any, newWidget: any): Observable<any>{
80     let updateWidgetWithFileURL = this.api.widgetCommon + '/widgetCatalog/' + widgetId;
81     let httpParam = new  HttpParams()
82     .append('newWidget', JSON.stringify(newWidget))
83     .append('requestType', 'fileUpload');
84     return this.http.post(updateWidgetWithFileURL, formData, {params: httpParam, withCredentials: true})
85   }
86
87   updateWidget(widgetId: any, widgetData: any): Observable<any> {
88     let updateWidgetURL = this.api.widgetCommon  + '/widgetCatalog' + '/' + widgetId;
89     return this.http.put(updateWidgetURL, widgetData, { withCredentials: true });
90   }
91
92   createWidget(newWidget: any, formData: any): Observable<any> {
93     let httpParam = new  HttpParams()
94     .append('newWidget', JSON.stringify(newWidget))
95     .append('requestType', 'fileUpload');
96     let  createWidgetURL = this.api.widgetCommon + '/widgetCatalog';
97     return this.http.post(createWidgetURL, formData, {params: httpParam, withCredentials: true})
98   }
99
100   populateAvailableApps(): Observable<any> {
101     let  populateAvailableAppsURL = this.api.appsForSuperAdminAndAccountAdmin;
102     return this.http.get(populateAvailableAppsURL, { withCredentials: true })
103   }
104 }