diff --git a/src/client/src/app/components/general-map/general-map.component.ts b/src/client/src/app/components/general-map/general-map.component.ts index 7dce4f5..c6333cf 100755 --- a/src/client/src/app/components/general-map/general-map.component.ts +++ b/src/client/src/app/components/general-map/general-map.component.ts @@ -1212,21 +1212,37 @@ export class GeneralMapComponent implements OnInit, Ruler, AfterContentChecked { this.googleAnalyticsService.eventEmitter("DownloadLayer", "Layer", register_event, 1); } } + layer.download.loading = true; - switch (tipo) { - case 'csv': - this.downloadCSV(layer, tipo); - break; - case 'gpkg': - this.downloadGPKG(layer, tipo); - break; - case 'raster': - this.downloadRaster(layer, tipo); - break; - case 'shp': - this.downloadSHP(layer, tipo); - break; - } + let parameters = { + "layer": layer, + "region": this.selectRegion, + "filter": this.selectedFilterFromLayerType(layer.valueType), + "typeDownload": tipo + }; + + this.downloadService.downloadFromS3(parameters).subscribe((response) =>{ + if (response){ + window.open(response.url,'_blank') + } + layer.download.loading = false; + }, (error) => { + let name = '' + const pre_fix = 'left_sidebar.layer.' + if (error.includes(pre_fix)){ + name = this.localizationService.translate(error) + }else{ + name = this.localizationService.translate('left_sidebar.layer.down_error_msg', { name: error }) + } + + this.messageService.add({ + life: 2000, + severity: 'error', + summary: this.localizationService.translate('left_sidebar.layer.down_error_title'), + detail:name + }); + layer.download.loading = false; + }); } drop(event: CdkDragDrop) { diff --git a/src/client/src/app/components/services/download.service.ts b/src/client/src/app/components/services/download.service.ts index afc1c1b..37b33b4 100755 --- a/src/client/src/app/components/services/download.service.ts +++ b/src/client/src/app/components/services/download.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { HttpClient } from '@angular/common/http'; +import { Observable, throwError } from 'rxjs'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; import { environment } from "../../../environments/environment"; +import { catchError, map } from 'rxjs/operators'; @Injectable({ providedIn: 'root' @@ -9,15 +10,67 @@ import { environment } from "../../../environments/environment"; export class DownloadService { private apiURL = `${environment.OWS}/api/download`; + private apiS3 = `${environment.LAPIG_DOWNLOAD_API}/api/download/`; - constructor(private httpClient: HttpClient) {} + constructor( + private httpClient: HttpClient + ) {} + + + downloadFromS3(parameters): Observable{ + return this.httpClient.post(this.apiS3, parameters) + .pipe(map(response => response)) + .pipe(catchError(this.errorHandlerS3)); + } downloadRequest(parameters): Observable { - return this.httpClient.post(this.apiURL, parameters, { responseType: 'blob' }) + return this.httpClient.post(this.apiURL, parameters, { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT' + }), + responseType: 'blob' + }); } downloadRequestSLD(layer): Observable { const url = `${environment.OWS}/ows?request=GetStyles&layers=${layer}&service=wms&version=1.1.1`; - return this.httpClient.get(url, { responseType: 'blob' }) + return this.httpClient.get(url, { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT' + }), + responseType: 'blob' + }) + } + + errorHandlerS3(error) { + let errorMessage = ''; + if (error.error instanceof ErrorEvent) { + errorMessage = error.error.message; + } else if(["unable_filter_layer", 'file_empty',"file_not_found"].includes(error.error.message)){ + + errorMessage = 'left_sidebar.layer.s3_'+error.error.message + } + else{ + errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; + } + return throwError(errorMessage); + } + + errorHandler(error) { + let errorMessage = ''; + if (error.error instanceof ErrorEvent) { + errorMessage = error.error.message; + } else { + errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; + } + return throwError(errorMessage); } + + } diff --git a/src/client/src/environments/environment.prod.ts b/src/client/src/environments/environment.prod.ts index 029e246..e0ac6b0 100755 --- a/src/client/src/environments/environment.prod.ts +++ b/src/client/src/environments/environment.prod.ts @@ -7,13 +7,13 @@ export const environment = { production: false, GTAG: 'UA-215301850-1', - OWS_API: 'https://ows-homolog.lapig.iesa.ufg.br/api', - OWS: 'https://ows-homolog.lapig.iesa.ufg.br', + OWS_API: 'https://ows.lapig.iesa.ufg.br/api', + OWS: 'https://ows.lapig.iesa.ufg.br', OWS_O1: "https://o6.lapig.iesa.ufg.br/ows", OWS_O2: "https://o7.lapig.iesa.ufg.br/ows", OWS_O3: "https://o8.lapig.iesa.ufg.br/ows", OWS_O4: "https://o5.lapig.iesa.ufg.br/ows", - + LAPIG_DOWNLOAD_API: 'https://download.lapig.iesa.ufg.br', APP_URL: 'https://agrotoxicosdev.lapig.iesa.ufg.br' }; @@ -24,4 +24,4 @@ export const environment = { * This import should be commented out in production mode because it will have a negative impact * on performance if an error is thrown. */ -// import 'zone.js/plugins/zone-error'; // Included with Angular CLI. \ No newline at end of file +// import 'zone.js/plugins/zone-error'; // Included with Angular CLI. diff --git a/src/client/src/environments/environment.ts b/src/client/src/environments/environment.ts index 6f27148..371dbea 100755 --- a/src/client/src/environments/environment.ts +++ b/src/client/src/environments/environment.ts @@ -15,11 +15,12 @@ export const environment = { OWS_API: 'https://ows-homolog.lapig.iesa.ufg.br/api', OWS: 'https://ows-homolog.lapig.iesa.ufg.br', + LAPIG_DOWNLOAD_API: 'https://download.lapig.iesa.ufg.br', OWS_O1: "https://o6.lapig.iesa.ufg.br/ows", OWS_O2: "https://o7.lapig.iesa.ufg.br/ows", OWS_O3: "https://o8.lapig.iesa.ufg.br/ows", OWS_O4: "https://o5.lapig.iesa.ufg.br/ows", - + APP_URL: 'https://agrotoxicosdev.lapig.iesa.ufg.br' };