From d51813d6a8bd24d28a0c1e337be63d213f4d564c Mon Sep 17 00:00:00 2001 From: Timo Date: Thu, 28 Jan 2021 09:33:06 +0200 Subject: [PATCH] updated API to match gateway --- .../file-download-btn.component.ts | 2 +- .../service/single-file-download.service.ts | 57 ++++++++++++------- .../red-ui/src/app/state/app-state.service.ts | 2 +- .../api/fileManagementController.service.ts | 28 ++++----- 4 files changed, 51 insertions(+), 38 deletions(-) diff --git a/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts b/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts index c0a325a9d..3615924b8 100644 --- a/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts +++ b/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts @@ -65,7 +65,7 @@ export class FileDownloadBtnComponent { this._changeDetectorRef.detectChanges(); } else { this._fileManagementControllerService - .downloadPreviewFile(this.file.fileId, true, this.file.lastProcessed, 'body') + .downloadPreviewFile(this.file.fileId, this.file.projectId, true, this.file.lastProcessed, 'body') .subscribe((data) => saveAs(data, (this.file).filename)); } } diff --git a/apps/red-ui/src/app/screens/file/service/single-file-download.service.ts b/apps/red-ui/src/app/screens/file/service/single-file-download.service.ts index d7936bd98..ff0216ee8 100644 --- a/apps/red-ui/src/app/screens/file/service/single-file-download.service.ts +++ b/apps/red-ui/src/app/screens/file/service/single-file-download.service.ts @@ -3,7 +3,6 @@ import { forkJoin, Observable, of } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { FileManagementControllerService, - FileStatus, ManualRedactionControllerService, RedactionLogControllerService, ViewedPagesControllerService @@ -12,6 +11,7 @@ import { FileType } from '../model/file-type'; import { FileDataModel } from '../model/file-data.model'; import { AppStateService } from '../../../state/app-state.service'; import { PermissionsService } from '../../../common/service/permissions.service'; +import { FileStatusWrapper } from '../model/file-status.wrapper'; @Injectable({ providedIn: 'root' @@ -57,45 +57,58 @@ export class SingleFileDownloadService { return of({ pages: [] }); } - loadFile(fileType: FileType | string, fileStatus: FileStatus, saveTo: (fileData) => void = () => null, fetch: () => any = () => null): Observable { + loadFile( + fileType: FileType | string, + fileStatus: FileStatusWrapper, + saveTo: (fileData) => void = () => null, + fetch: () => any = () => null + ): Observable { let fileObs$: Observable; switch (fileType) { case FileType.ANNOTATED: fileObs$ = fetch() ? of(fetch()) - : this._fileManagementControllerService.downloadAnnotatedFile(fileStatus.fileId, true, fileStatus.lastProcessed, 'body').pipe( - tap((data) => { - saveTo(data); - }) - ); + : this._fileManagementControllerService + .downloadAnnotatedFile(fileStatus.projectId, fileStatus.fileId, true, fileStatus.lastProcessed, 'body') + .pipe( + tap((data) => { + saveTo(data); + }) + ); break; case FileType.REDACTED: fileObs$ = fetch() ? of(fetch()) - : this._fileManagementControllerService.downloadRedactedFile(fileStatus.fileId, true, fileStatus.lastProcessed, 'body').pipe( - tap((data) => { - saveTo(data); - }) - ); + : this._fileManagementControllerService + .downloadRedactedFile(fileStatus.projectId, fileStatus.fileId, true, fileStatus.lastProcessed, 'body') + .pipe( + tap((data) => { + saveTo(data); + }) + ); break; case FileType.FLAT_REDACTED: fileObs$ = fetch() ? of(fetch()) - : this._fileManagementControllerService.downloadFlatRedacted(fileStatus.fileId, true, fileStatus.lastProcessed, 'body').pipe( - tap((data) => { - saveTo(data); - }) - ); + : this._fileManagementControllerService + .downloadFlatRedacted(fileStatus.projectId, fileStatus.fileId, true, fileStatus.lastProcessed, 'body') + .pipe( + tap((data) => { + saveTo(data); + }) + ); break; case FileType.ORIGINAL: default: fileObs$ = fetch() ? of(fetch()) - : this._fileManagementControllerService.downloadOriginalFile(fileStatus.fileId, true, fileStatus.lastUploaded, 'body').pipe( - tap((data) => { - saveTo(data); - }) - ); + : this._fileManagementControllerService + .downloadOriginalFile(fileStatus.projectId, fileStatus.fileId, true, fileStatus.lastUploaded, 'body') + .pipe( + tap((data) => { + saveTo(data); + }) + ); break; } return fileObs$; diff --git a/apps/red-ui/src/app/state/app-state.service.ts b/apps/red-ui/src/app/state/app-state.service.ts index 45033ec08..5bca60a27 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -450,7 +450,7 @@ export class AppStateService { if (!file) { file = this.activeFile; } - this._fileManagementControllerService.downloadRedactionReport({ fileIds: [file.fileId] }, true, template, 'body').subscribe((data) => { + this._fileManagementControllerService.downloadRedactionReport({ fileIds: [file.fileId] }, file.projectId, true, template, 'body').subscribe((data) => { saveAs(data, 'redaction-report-' + file.filename + '.docx'); }); } diff --git a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts index c7fe298d3..691bd5e19 100644 --- a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts +++ b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts @@ -71,7 +71,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = []; + const httpHeaderAccepts: string[] = []; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -124,7 +124,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = []; + const httpHeaderAccepts: string[] = []; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -215,7 +215,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -306,7 +306,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -397,7 +397,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -488,7 +488,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -554,7 +554,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -646,7 +646,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -712,7 +712,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -805,7 +805,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -889,7 +889,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -969,7 +969,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAccepts: string[] = ['*/*']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -1024,7 +1024,7 @@ export class FileManagementControllerService { } // to determine the Accept header - let httpHeaderAccepts: string[] = ['application/json']; + const httpHeaderAccepts: string[] = ['application/json']; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); @@ -1037,7 +1037,7 @@ export class FileManagementControllerService { let formParams: { append(param: string, value: any): void }; let useForm = false; - let convertFormParamsToString = false; + const convertFormParamsToString = false; // use FormData to transmit files using content-type "multipart/form-data" // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm;