Skip to content

Commit

Permalink
Merge pull request #3 from lapig-ufg/downloadsys
Browse files Browse the repository at this point in the history
dowload-minio
  • Loading branch information
jairomr authored Sep 10, 2023
2 parents dd40cbd + 57df760 commit b0a6791
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 24 deletions.
44 changes: 30 additions & 14 deletions src/client/src/app/components/general-map/general-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>) {
Expand Down
63 changes: 58 additions & 5 deletions src/client/src/app/components/services/download.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,76 @@
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'
})
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<any>{
return this.httpClient.post<any>(this.apiS3, parameters)
.pipe(map(response => response))
.pipe(catchError(this.errorHandlerS3));
}

downloadRequest(parameters): Observable<Blob> {
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<Blob> {
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);
}


}
8 changes: 4 additions & 4 deletions src/client/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

Expand All @@ -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.
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
3 changes: 2 additions & 1 deletion src/client/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

0 comments on commit b0a6791

Please sign in to comment.