From 9e311c77a64f723f9776b13937e7e1b5acf9be06 Mon Sep 17 00:00:00 2001 From: ssylver93 <107515688+ssylver93@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:41:17 -0700 Subject: [PATCH 1/2] WFNEWS-2146 Revert CorsFilter change and add appropriate headers (#1859) * WFNEWS-2146 Set CORS headers explicitly * WFNEWS-2146 Allow wildcard in case of null headers * WFNEWS-2146 Revert CorsFilter change and add appropriate headers * Return headers from function --- .../services/published-incident-service.ts | 168 ++++++++---------- .../wfnews/api/rest/v1/spring/CorsFilter.java | 19 +- 2 files changed, 74 insertions(+), 113 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/services/published-incident-service.ts b/client/wfnews-war/src/main/angular/src/app/services/published-incident-service.ts index 1cc4540e2a..e9df7775c8 100644 --- a/client/wfnews-war/src/main/angular/src/app/services/published-incident-service.ts +++ b/client/wfnews-war/src/main/angular/src/app/services/published-incident-service.ts @@ -32,12 +32,34 @@ export class PublishedIncidentService { private appConfigService: AppConfigService, private tokenService: TokenService, private httpClient: HttpClient, - ) {} + ) { } + + getSituationReportHeaders() { + const headers = { + headers: { + Authorization: `bearer ${this.tokenService.getOauthToken()}`, + apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], + 'Access-Control-Allow-Origin': "*", + 'Accept': '*/*' + } + } + return headers; + } + + getPublicSituationReportHeaders() { + const headers = { + headers: { + apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], + 'Access-Control-Allow-Origin': "*", + 'Accept': '*/*' + } + } + return headers; + } public async getActiveFireCount(): Promise { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncident?pageNumber=1&pageRowCount=1&out=false&stageOfControlList=OUT_CNTRL&stageOfControlList=HOLDING&stageOfControlList=UNDR_CNTRL`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncident?pageNumber=1&pageRowCount=1&out=false&stageOfControlList=OUT_CNTRL&stageOfControlList=HOLDING&stageOfControlList=UNDR_CNTRL`; const result = await this.httpClient .get(url, { headers: { @@ -53,9 +75,8 @@ export class PublishedIncidentService { pageNum: number = 0, rowCount: number = 9999, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&stageOfControlList=OUT&newFires=false`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&stageOfControlList=OUT&newFires=false`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -71,12 +92,10 @@ export class PublishedIncidentService { orderBy: string = 'lastUpdatedTimestamp%20DESC', ): Observable { const url = out - ? `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&fireOfNote=${fireOfNote}&out=true` - : `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&fireOfNote=${fireOfNote}&out=false&orderBy=${orderBy}&stageOfControlList=OUT_CNTRL&stageOfControlList=HOLDING&stageOfControlList=UNDR_CNTRL`; + ? `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&fireOfNote=${fireOfNote}&out=true` + : `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncident?pageNumber=${pageNum}&pageRowCount=${rowCount}&fireOfNote=${fireOfNote}&out=false&orderBy=${orderBy}&stageOfControlList=OUT_CNTRL&stageOfControlList=HOLDING&stageOfControlList=UNDR_CNTRL`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -138,11 +157,9 @@ export class PublishedIncidentService { guid: string, fireYear: string = null, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncident/${guid}${ - fireYear ? '?fireYear=' + fireYear : '' - }`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncident/${guid}${fireYear ? '?fireYear=' + fireYear : '' + }`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -154,9 +171,8 @@ export class PublishedIncidentService { fireYear: string, incidentNumber: string, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['incidents'] - }/incidents/${fireYear}/${incidentNumber}`; + const url = `${this.appConfigService.getConfig().rest['incidents'] + }/incidents/${fireYear}/${incidentNumber}`; return this.httpClient .get(url, { @@ -166,15 +182,14 @@ export class PublishedIncidentService { }) .pipe( map((response: any) => ({ - response, - wildfireIncidentGuid: response.wildfireIncidentGuid, - })), + response, + wildfireIncidentGuid: response.wildfireIncidentGuid, + })), ) .pipe( concatMap((data) => { - const publishedUrl = `${ - this.appConfigService.getConfig().rest['incidents'] - }/publishedIncidents/byIncident/${data.wildfireIncidentGuid}`; + const publishedUrl = `${this.appConfigService.getConfig().rest['incidents'] + }/publishedIncidents/byIncident/${data.wildfireIncidentGuid}`; return of({ response: data.response, getPublishedIncident: this.httpClient.get(publishedUrl, { @@ -189,9 +204,8 @@ export class PublishedIncidentService { } public saveIMPublishedIncident(publishedIncident: any): Observable { - const publishedUrl = `${ - this.appConfigService.getConfig().rest['incidents'] - }/publishedIncidents`; + const publishedUrl = `${this.appConfigService.getConfig().rest['incidents'] + }/publishedIncidents`; const headers = { headers: { Authorization: `bearer ${this.tokenService.getOauthToken()}`, @@ -210,9 +224,8 @@ export class PublishedIncidentService { } public fetchPublishedIncidentAttachments(incidentName): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncidentAttachment/${incidentName}/attachments`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncidentAttachment/${incidentName}/attachments`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -224,9 +237,8 @@ export class PublishedIncidentService { page: number = 1, rows: number = 10, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicExternalUri?pageNumber=${page}&pageRowCount=${rows}`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicExternalUri?pageNumber=${page}&pageRowCount=${rows}`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -235,9 +247,8 @@ export class PublishedIncidentService { } public fetchExternalUri(incidentNumber): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicExternalUri?sourceObjectUniqueId=${incidentNumber}&pageNumber=1&pageRowCount=100`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicExternalUri?sourceObjectUniqueId=${incidentNumber}&pageNumber=1&pageRowCount=100`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -246,9 +257,8 @@ export class PublishedIncidentService { } public fetchAttachments(incidentNumber): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncidentAttachment/${incidentNumber}/attachments`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncidentAttachment/${incidentNumber}/attachments`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -257,9 +267,8 @@ export class PublishedIncidentService { } public fetchAttachmentBytes(incidentNumber, attachmentGuid): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicPublishedIncidentAttachment/${incidentNumber}/attachments/${attachmentGuid}/bytes`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicPublishedIncidentAttachment/${incidentNumber}/attachments/${attachmentGuid}/bytes`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -273,11 +282,9 @@ export class PublishedIncidentService { fireYear: number, fireCentre: string = 'BC', ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/statistics?fireYear=${fireYear}${ - fireCentre ? '&fireCentre=' + fireCentre : '' - }`; + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/statistics?fireYear=${fireYear}${fireCentre ? '&fireCentre=' + fireCentre : '' + }`; return this.httpClient.get(url, { headers: { apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], @@ -293,69 +300,40 @@ export class PublishedIncidentService { published = true, cacheBust = false, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicSituationReport?pageNumber=${pageNum}&pageRowCount=${rowCount}&published=${ - published ? 'TRUE' : 'FALSE' - }${cacheBust ? '&cacheBust=' + new Date().getTime() : ''}`; - return this.httpClient.get(url, { - headers: { - apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], - }, - }); + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicSituationReport?pageNumber=${pageNum}&pageRowCount=${rowCount}&published=${published ? 'TRUE' : 'FALSE' + }${cacheBust ? '&cacheBust=' + new Date().getTime() : ''}`; + return this.httpClient.get(url, this.getPublicSituationReportHeaders()); } public fetchSituationReport(reportGuid: string): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/publicSituationReport/${reportGuid}`; - return this.httpClient.get(url, { - headers: { - apikey: this.appConfigService.getConfig().application['wfnewsApiKey'], - }, - }); + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/publicSituationReport/${reportGuid}`; + return this.httpClient.get(url, this.getPublicSituationReportHeaders()); } public updateSituationReport( report: SituationReport, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/situationReport/${report.reportGuid}`; - const headers = { - headers: { - Authorization: `bearer ${this.tokenService.getOauthToken()}`, - }, - }; - return this.httpClient.put(url, report, headers); + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/situationReport/${report.reportGuid}`; + return this.httpClient.put(url, report, this.getSituationReportHeaders()); } public createSituationReport( report: SituationReport, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/situationReport`; - const headers = { - headers: { - Authorization: `bearer ${this.tokenService.getOauthToken()}`, - }, - }; - return this.httpClient.post(url, report, headers); + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/situationReport`; + return this.httpClient.post(url, report, this.getSituationReportHeaders()); } public deleteSituationReport( report: SituationReport, ): Observable { - const url = `${ - this.appConfigService.getConfig().rest['wfnews'] - }/situationReport/${report.reportGuid}`; - const headers = { - headers: { - Authorization: `bearer ${this.tokenService.getOauthToken()}`, - }, - }; - return this.httpClient.delete(url, headers); + const url = `${this.appConfigService.getConfig().rest['wfnews'] + }/situationReport/${report.reportGuid}`; + return this.httpClient.delete(url, this.getSituationReportHeaders()); } async populateIncidentByPoint(restrictionPolygon: [][]) { diff --git a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/CorsFilter.java b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/CorsFilter.java index 11a664200a..7bc5ac58f2 100644 --- a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/CorsFilter.java +++ b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/CorsFilter.java @@ -32,24 +32,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "*"); response.setHeader("Access-Control-Max-Age", "3600"); - - // Set Access-Control-Allow-Headers explicitly - Enumeration headerNames = request.getHeaderNames(); - ArrayList headersList = new ArrayList(); - - if (headerNames != null) { - while (headerNames.hasMoreElements()) { - headersList.add(headerNames.nextElement()); - } - } - - if (!headersList.isEmpty()) { - String headers = String.join(", ", headersList); - if (headers != null) { - response.setHeader("Access-Control-Allow-Headers", headers); - }else response.setHeader("Access-Control-Allow-Headers", "*"); - } else - response.setHeader("Access-Control-Allow-Headers", "*"); + response.setHeader("Access-Control-Allow-Headers", "*"); if ("OPTIONS".equalsIgnoreCase(request.getMethod())) { response.setStatus(HttpServletResponse.SC_OK); From 341db00b795794af1d5f18a40a318da4200e030f Mon Sep 17 00:00:00 2001 From: Lucas Li <35748253+yzlucas@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:30:53 -0700 Subject: [PATCH 2/2] use FIRE_YEAR for perimiter (#1858) --- .../incident-identify-panel.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/incident-identify-panel/incident-identify-panel.component.ts b/client/wfnews-war/src/main/angular/src/app/components/incident-identify-panel/incident-identify-panel.component.ts index 1c8eb90a71..a1982306d8 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/incident-identify-panel/incident-identify-panel.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/incident-identify-panel/incident-identify-panel.component.ts @@ -81,8 +81,8 @@ export class IncidentIdentifyPanelComponent { const id = incidentRef.FIRE_NUMBER ? incidentRef.FIRE_NUMBER : incidentRef.incident_number_label; - const year = incidentRef.fire_year; - + const year = incidentRef.fire_year ? incidentRef.fire_year : incidentRef.FIRE_YEAR; + // activeFire uses fire_year and fire perimeter uses FIRE_YEAR this.publishedIncidentService .fetchPublishedIncident(id, year) .toPromise()