Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { DownloadService } from '../../shared/service/download.service';
import { ApiKeyRequest } from '../../shared-modules/download-modal/apikey-modal/apikey-modal.component';
import { createActiveFiltersList } from '../../shared-modules/search-filters/active/observation-active.component';
import { FORMAT } from '../../shared-modules/download-modal/download.component';
import { FileFormat, GeoConvertService, isGeoConvertError } from '../../shared/service/geo-convert.service';
import { GeoConvertService, isGeoConvertError } from '../../shared/service/geo-convert.service';
import { DialogService } from '../../shared/service/dialog.service';
import { ModalRef, ModalService } from 'projects/laji-ui/src/lib/modal/modal.service';
import { PlatformService } from '../../root/platform.service';
Expand Down Expand Up @@ -382,7 +382,6 @@ export class ObservationDownloadComponent implements OnDestroy {
formData,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
data.id!,
params.fileType as FileFormat,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
params.geometry!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { tap, first, map } from 'rxjs/operators';
import { UserService } from '../../shared/service/user.service';
import { DialogService } from '../../shared/service/dialog.service';
import {
FileFormat,
FileGeometry,
FileCrs,
GeoConvertService,
Expand All @@ -21,7 +20,6 @@ export enum FileType {
@Injectable({providedIn: 'root'})
export class FileDownloadService {
fileType: FileType = FileType.standard;
format: FileFormat = FileFormat.gpkg;
geometry: FileGeometry = FileGeometry.point;
crs: FileCrs = FileCrs.euref;
loading = false;
Expand All @@ -41,7 +39,7 @@ export class FileDownloadService {
this.loading = true;
this.progressPercentage = undefined;

this.getDownloadLink(id, isPublic, this.fileType, this.format, this.geometry, this.crs).subscribe(res => {
this.getDownloadLink(id, isPublic, this.fileType, this.geometry, this.crs).subscribe(res => {
this.platformService.window.location.href = res;
this.loading = false;
this.progressPercentage = undefined;
Expand All @@ -56,12 +54,12 @@ export class FileDownloadService {
}

private getDownloadLink(
id: string, isPublic: boolean, type: FileType, format: FileFormat, geometry: FileGeometry, crs: FileCrs
id: string, isPublic: boolean, type: FileType, geometry: FileGeometry, crs: FileCrs
): Observable<string> {
const personToken = isPublic ? null : this.userService.getToken();
if (type === FileType.gis) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.geoConvertService.geoConvertFile(id, format, geometry, crs, personToken!).pipe(
return this.geoConvertService.geoConvertFile(id, geometry, crs, personToken).pipe(
tap(response => {
this.progressPercentage = response.progressPercent;
this.fileDownloadStateChangeSubject.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
</div>
</div>
<div *ngIf="downloadService.fileType === fileTypeEnum.gis" class="row">
<div class="col-sm-4">
<label for="format">{{ 'downloadRequest.fileDownload.format' | translate }}:</label>
<select id="format" name="format" class="form-control" [(ngModel)]="downloadService.format">
<option *ngFor="let option of fileFormatEnum | keyvalue: sortNull" [ngValue]="option.value">{{ '.' + option.value }}</option>
</select>
</div>
<div class="col-sm-4">
<label for="geometry">{{ 'download.geometry' | translate }}:</label>
<select id="geometry" name="geometry" class="form-control" [(ngModel)]="downloadService.geometry">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges
import { FileType, FileDownloadService } from '../file-download.service';
import { DownloadRequest } from '../models';
import { KeyValue } from '@angular/common';
import { FileFormat, FileGeometry, FileCrs } from '../../../shared/service/geo-convert.service';
import { FileGeometry, FileCrs } from '../../../shared/service/geo-convert.service';
import { Subscription } from 'rxjs';

@Component({
Expand All @@ -16,7 +16,6 @@ export class FileDownloadComponent implements OnDestroy {
@Input() downloadRequest!: DownloadRequest;

fileTypeEnum = FileType;
fileFormatEnum = FileFormat;
fileGeometryEnum = FileGeometry;
fileCrsEnum = FileCrs;

Expand Down
56 changes: 32 additions & 24 deletions projects/laji/src/app/shared/service/geo-convert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Observable, interval, throwError } from 'rxjs';
import { HttpClient, HttpParams } from '@angular/common/http';
import { switchMap, concatMap, map, catchError, takeWhile } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { environment } from '../../../environments/environment';

export type GeoConversionStatus = 'pending'|'complete';

export enum FileFormat {
gpkg = 'gpkg'
}
export enum FileGeometry {
point = 'point',
bbox = 'bbox',
Expand Down Expand Up @@ -53,28 +51,24 @@ export class GeoConvertService {
) {}

public geoConvertFile(
fileId: string, format: FileFormat, geometry: FileGeometry, crs: FileCrs, personToken?: string | null
): Observable<GeoConversionResponse> {
return this.startGeoConversion(fileId, format, geometry, crs, personToken).pipe(
switchMap(conversionId => this.getResponse(conversionId)),
fileId: string, geometry: FileGeometry, crs: FileCrs, personToken?: string | null): Observable<GeoConversionResponse> {
return this.startGeoConversion(fileId, geometry, crs, personToken).pipe(
switchMap(conversionId => this.getResponse(conversionId, personToken)),
catchError(err => this.transformError(err))
);
}

public geoConvertData(
data: FormData, fileId: string, format: FileFormat, geometry: FileGeometry, crs: FileCrs
data: FormData, fileId: string, geometry: FileGeometry, crs: FileCrs
): Observable<GeoConversionResponse> {
return this.startGeoConversionFromData(data, fileId, format, geometry, crs).pipe(
return this.startGeoConversionFromData(data, fileId, geometry, crs).pipe(
switchMap(conversionId => this.getResponse(conversionId)),
catchError(err => this.transformError(err))
);
}

private startGeoConversion(
fileId: string, format: FileFormat, geometry: FileGeometry, crs: FileCrs, personToken?: string | null
): Observable<string> {
private startGeoConversion(fileId: string, geometry: FileGeometry, crs: FileCrs, personToken?: string | null): Observable<string> {
const queryParams: any = {
outputFormat: format,
geometryType: geometry,
crs
};
Expand All @@ -87,10 +81,9 @@ export class GeoConvertService {
}

private startGeoConversionFromData(
data: FormData, fileId: string, format: FileFormat, geometry: FileGeometry, crs: FileCrs
data: FormData, fileId: string, geometry: FileGeometry, crs: FileCrs
): Observable<string> {
const queryParams = {
outputFormat: format,
geometryType: geometry,
crs
};
Expand All @@ -99,20 +92,35 @@ export class GeoConvertService {
return this.httpClient.post<string>('/api/geo-convert/' + fileId, data, {params});
}

private getResponse(conversionId: string): Observable<GeoConversionResponse> {
private getResponse(conversionId: string, personToken?: string | null): Observable<GeoConversionResponse> {
return interval(this.pollInterval).pipe(
concatMap(() => this.getGeoConversionStatus(conversionId)),
concatMap(() => this.getGeoConversionStatus(conversionId, personToken)),
takeWhile(result => result.status !== 'complete', true),
map((result) => ({
status: result.status,
progressPercent: result.progress_percent,
outputLink: result.status === 'complete' ? '/api/geo-convert/output/' + conversionId : undefined
}))
map((result) => {
let outputLink: string | undefined;
if (result.status === 'complete') {
outputLink = `${environment.apiBase}/geo-convert/output/${conversionId}`;
if (personToken) {
outputLink += '?personToken=' + personToken;
}
}

return {
status: result.status,
progressPercent: result.progress_percent,
outputLink
};
})
);
}

private getGeoConversionStatus(conversionId: string): Observable<GeoConversionStatusApiResponse> {
return this.httpClient.get<GeoConversionStatusApiResponse>('/api/geo-convert/status/' + conversionId);
private getGeoConversionStatus(conversionId: string, personToken?: string | null): Observable<GeoConversionStatusApiResponse> {
const queryParams: any = {};
if (personToken) {
queryParams['personToken'] = personToken;
}
const params = new HttpParams({fromObject: queryParams});
return this.httpClient.get<GeoConversionStatusApiResponse>('/api/geo-convert/status/' + conversionId, {params});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be converted to use laji-api-client-b at the same time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Geoconvert api swagger is not correct at the moment so the typings are wrong, I would wait for it to get fixed first. It might not make it to this release if the release is going to be soon

}

private transformError(err: any): Observable<never> {
Expand Down
3 changes: 1 addition & 2 deletions projects/laji/src/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
"downloadRequest.fileDownload": "Tiedostolataus",
"downloadRequest.fileDownload.download": "Lataa",
"downloadRequest.fileDownload.downloading": "Ladataan",
"downloadRequest.fileDownload.format": "Tiedostomuoto",
"downloadRequest.fileDownload.genericError": "Tiedoston lataaminen epäonnistui!",
"downloadRequest.fileDownload.instructionLinks": "<a href=\"https://info.laji.fi/etusivu/laji-fi/tiedostojen-vienti-exceliin/\">Tiedoston vienti Exceliin</a><br>\n<a href=\"https://info.laji.fi/etusivu/paikkatieto/muut-paikkatieto-ohjeet/\">Havaintoaineiston vienti paikkatieto-ohjelmistoihin (ArcGIs, QGIS)</a><br>\n<a href=\"https://info.laji.fi/en/frontpage/finbif-portal/file-download-field-documentation/\">Dokumentaatio tiedostojen sisällöstä (englanniksi)</a>",
"downloadRequest.fileDownload.licenseReminder": "Lataamalla tiedoston sitoudut noudattamaan alla mainittuja käyttöoikeuslisenssejä. Lisenssit löytyvät myös latauksen <code>fi_käyttöehdot.txt</code> tiedostosta.",
Expand Down Expand Up @@ -2292,4 +2291,4 @@
"whatsNew.message": "laji.fi on Suomen Lajitietokeskuksen testikäytössä oleva portaali. Tietoja täydennetään ja ominaisuuksia parannetaan jatkuvasti. Palaute on tervetullutta - sitä voi lähettää palautelomakkeella tai osoitteeseen info@laji.fi. Kiitos!<p>Voit katsoa tuoreimmat muutokset <a href=\"https://laji.fi\">etusivun</a> ajankohtaista osiosta.</p",
"wholeYear": "Koko vuosi {{year}}",
"yes": "Kyllä"
}
}