From 218e881e8d5a5d01c41a255d7107d546d10c0329 Mon Sep 17 00:00:00 2001 From: Barath Kumar R Date: Wed, 2 Sep 2020 16:43:05 +0530 Subject: [PATCH] BUG 1199 Unable to perform any CRUD operations in NG-UI v8.0.1 * NG-UI should send header request for all the request. Change-Id: I91ed6f001cd233d19f6512859e929623fdff89c0 Signed-off-by: Barath Kumar R --- .../ns-composer/NSComposerComponent.ts | 1 + src/models/NSDModel.ts | 1 + src/services/RestService.ts | 51 ++++++++++++++++--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/app/packages/ns-packages/ns-composer/NSComposerComponent.ts b/src/app/packages/ns-packages/ns-composer/NSComposerComponent.ts index 082496e..687f4fa 100644 --- a/src/app/packages/ns-packages/ns-composer/NSComposerComponent.ts +++ b/src/app/packages/ns-packages/ns-composer/NSComposerComponent.ts @@ -445,6 +445,7 @@ export class NSComposerComponent { this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL + '/' + this.identifier).subscribe((nsData: NSDDetails) => { delete nsData._admin; delete nsData._id; + delete nsData._links; this.nsData = nsData; this.vnfdPackageDetails.shortName = nsData['short-name']; this.vnfdPackageDetails.vendor = nsData.vendor; diff --git a/src/models/NSDModel.ts b/src/models/NSDModel.ts index 584f4e0..e4f94b0 100644 --- a/src/models/NSDModel.ts +++ b/src/models/NSDModel.ts @@ -49,6 +49,7 @@ export interface NSDDetails { vld: VLD[]; _admin: VNFDAdminDetails; _id: string; + _links?: string; 'constituent-vnfr-ref': string[]; } diff --git a/src/services/RestService.ts b/src/services/RestService.ts index d7ded6f..464cc0f 100644 --- a/src/services/RestService.ts +++ b/src/services/RestService.ts @@ -25,9 +25,10 @@ import { Injectable } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; import { NotifierService } from 'angular-notifier'; -import { ERRORDATA } from 'CommonModel'; +import { APIURLHEADER, ERRORDATA } from 'CommonModel'; import * as HttpStatus from 'http-status-codes'; import { Observable } from 'rxjs'; +import { isNullOrUndefined } from 'util'; /** * An Injectable is a class adorned with the @Injectable decorator function. @@ -60,7 +61,12 @@ export class RestService { */ public getResource(apiURL: string, httpHeaders?: { headers: HttpHeaders }): Observable<{}> { - return this.http.get(apiURL, httpHeaders); + const getRequest: APIURLHEADER = this.getHttpoptions(apiURL); + if (!isNullOrUndefined(httpHeaders)) { + return this.http.get(apiURL, httpHeaders); + } else { + return this.http.get(getRequest.url, getRequest.httpOptions); + } } /** @@ -70,7 +76,12 @@ export class RestService { */ public postResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable<{}> { - return this.http.post(apiURLHeader.url, payload, apiURLHeader.httpOptions); + const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url); + if (!isNullOrUndefined(apiURLHeader.httpOptions)) { + return this.http.post(apiURLHeader.url, payload, apiURLHeader.httpOptions); + } else { + return this.http.post(getRequest.url, payload, getRequest.httpOptions); + } } /** @@ -80,7 +91,12 @@ export class RestService { */ public patchResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable { - return this.http.patch(apiURLHeader.url, payload, apiURLHeader.httpOptions); + const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url); + if (!isNullOrUndefined(apiURLHeader.httpOptions)) { + return this.http.patch(apiURLHeader.url, payload, apiURLHeader.httpOptions); + } else { + return this.http.patch(getRequest.url, payload, getRequest.httpOptions); + } } /** @@ -90,7 +106,12 @@ export class RestService { */ public putResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable { - return this.http.put(apiURLHeader.url, payload, apiURLHeader.httpOptions); + const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url); + if (!isNullOrUndefined(apiURLHeader.httpOptions)) { + return this.http.put(apiURLHeader.url, payload, apiURLHeader.httpOptions); + } else { + return this.http.put(getRequest.url, payload, getRequest.httpOptions); + } } /** @@ -99,7 +120,12 @@ export class RestService { */ public deleteResource(apiURL: string, httpHeaders?: { headers: HttpHeaders }): Observable { - return this.http.delete(apiURL, httpHeaders); + const getRequest: APIURLHEADER = this.getHttpoptions(apiURL); + if (!isNullOrUndefined(httpHeaders)) { + return this.http.delete(apiURL, httpHeaders); + } else { + return this.http.delete(getRequest.url, getRequest.httpOptions); + } } /** * Handle Error response based on the status. @@ -141,4 +167,17 @@ export class RestService { err.error.detail : this.translateService.instant('ERROR')); } } + + /** Set headers for get Methods @public */ + private getHttpoptions(apiURL: string): APIURLHEADER { + const apiHeaders: HttpHeaders = new HttpHeaders({ + 'Content-Type': 'application/json; charset=UTF-8', + Accept: 'application/json', + 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' + }); + return { + url: apiURL, + httpOptions: {headers : apiHeaders} + }; + } } -- 2.25.1