From 2fbbd1d4804c6cbf49c5b5a064bcc26a5ca9ddef Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 1 Feb 2021 13:14:38 +0200 Subject: [PATCH] updated http client lib --- README.md | 2 +- libs/red-ui-http/src/lib/api.module.ts | 4 +- libs/red-ui-http/src/lib/api/api.ts | 6 +- .../src/lib/api/downloadController.service.ts | 191 ++++++++++++++++++ .../src/lib/model/downloadDetails.ts | 34 ++++ .../src/lib/model/downloadRequest.ts | 18 ++ .../src/lib/model/downloadResponse.ts | 15 ++ .../src/lib/model/downloadStatus.ts | 33 +++ .../src/lib/model/downloadStatusResponse.ts | 16 ++ libs/red-ui-http/src/lib/model/models.ts | 6 + .../src/lib/model/prepareDownloadRequest.ts | 27 +++ 11 files changed, 349 insertions(+), 3 deletions(-) create mode 100644 libs/red-ui-http/src/lib/api/downloadController.service.ts create mode 100644 libs/red-ui-http/src/lib/model/downloadDetails.ts create mode 100644 libs/red-ui-http/src/lib/model/downloadRequest.ts create mode 100644 libs/red-ui-http/src/lib/model/downloadResponse.ts create mode 100644 libs/red-ui-http/src/lib/model/downloadStatus.ts create mode 100644 libs/red-ui-http/src/lib/model/downloadStatusResponse.ts create mode 100644 libs/red-ui-http/src/lib/model/prepareDownloadRequest.ts diff --git a/README.md b/README.md index 088a24339..8a6bf638e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ To regnerate http rune swaagger ``` -BASE=http://localhost:8080/ +BASE=https://timo-redaction-dev.iqser.cloud/ URL="$BASE"v2/api-docs?group=redaction-gateway-v1 mkdir -p /tmp/swagger swagger-codegen generate -i "$URL" -l typescript-angular -o /tmp/swagger diff --git a/libs/red-ui-http/src/lib/api.module.ts b/libs/red-ui-http/src/lib/api.module.ts index b937a6cde..34c232c74 100644 --- a/libs/red-ui-http/src/lib/api.module.ts +++ b/libs/red-ui-http/src/lib/api.module.ts @@ -18,6 +18,7 @@ import { ViewedPagesControllerService } from './api/viewedPagesController.servic import { LegalBasisMappingControllerService } from './api/legalBasisMappingController.service'; import { WatermarkControllerService } from './api/watermarkController.service'; import { RuleSetControllerService } from './api/ruleSetController.service'; +import { DownloadControllerService } from './api/downloadController.service'; @NgModule({ imports: [], @@ -39,7 +40,8 @@ import { RuleSetControllerService } from './api/ruleSetController.service'; VersionsControllerService, ViewedPagesControllerService, LegalBasisMappingControllerService, - WatermarkControllerService + WatermarkControllerService, + DownloadControllerService ] }) export class ApiModule { diff --git a/libs/red-ui-http/src/lib/api/api.ts b/libs/red-ui-http/src/lib/api/api.ts index 867707001..a4ddca993 100644 --- a/libs/red-ui-http/src/lib/api/api.ts +++ b/libs/red-ui-http/src/lib/api/api.ts @@ -17,6 +17,7 @@ import { UserPreferenceControllerService } from './userPreferenceController.serv import { VersionsControllerService } from './versionsController.service'; import { ViewedPagesControllerService } from './viewedPagesController.service'; import { WatermarkControllerService } from './watermarkController.service'; +import { DownloadControllerService } from './downloadController.service'; export * from './dictionaryController.service'; @@ -52,6 +53,8 @@ export * from './viewedPagesController.service'; export * from './watermarkController.service'; +export * from './downloadController.service'; + export const APIS = [ DebugControllerService, DictionaryControllerService, @@ -70,5 +73,6 @@ export const APIS = [ UserPreferenceControllerService, VersionsControllerService, ViewedPagesControllerService, - WatermarkControllerService + WatermarkControllerService, + DownloadControllerService ]; diff --git a/libs/red-ui-http/src/lib/api/downloadController.service.ts b/libs/red-ui-http/src/lib/api/downloadController.service.ts new file mode 100644 index 000000000..1bd90dde0 --- /dev/null +++ b/libs/red-ui-http/src/lib/api/downloadController.service.ts @@ -0,0 +1,191 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ /* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, HttpResponse, HttpEvent } from '@angular/common/http'; +import { CustomHttpUrlEncodingCodec } from '../encoder'; + +import { Observable } from 'rxjs'; + +import { DownloadRequest } from '../model/downloadRequest'; +import { DownloadResponse } from '../model/downloadResponse'; +import { DownloadStatusResponse } from '../model/downloadStatusResponse'; +import { PrepareDownloadRequest } from '../model/prepareDownloadRequest'; + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +@Injectable() +export class DownloadControllerService { + protected basePath = ''; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + + constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; + } + } + + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (const consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + + /** + * Returns a downloadable byte stream of the requested file + * Use the optional \"inline\" request parameter to select, if this report will be opened in the browser. + * @param body downloadRequest + * @param inline inline + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public downloadFile(body: DownloadRequest, inline?: boolean, observe?: 'body', reportProgress?: boolean): Observable; + public downloadFile(body: DownloadRequest, inline?: boolean, observe?: 'response', reportProgress?: boolean): Observable>; + public downloadFile(body: DownloadRequest, inline?: boolean, observe?: 'events', reportProgress?: boolean): Observable>; + public downloadFile(body: DownloadRequest, inline?: boolean, observe: any = 'body', reportProgress: boolean = false): Observable { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling downloadFile.'); + } + + let queryParameters = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() }); + if (inline !== undefined && inline !== null) { + queryParameters = queryParameters.set('inline', inline); + } + + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = ['*/*']; + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + // to determine the Content-Type header + const consumes: string[] = ['application/json']; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + headers = headers.set('Content-Type', httpContentTypeSelected); + } + + return this.httpClient.request('post', `${this.basePath}/async/download/get`, { + body: body, + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + }); + } + + /** + * Gets to download status for the current user + * None + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getDownloadStatus(observe?: 'body', reportProgress?: boolean): Observable; + public getDownloadStatus(observe?: 'response', reportProgress?: boolean): Observable>; + public getDownloadStatus(observe?: 'events', reportProgress?: boolean): Observable>; + public getDownloadStatus(observe: any = 'body', reportProgress: boolean = false): Observable { + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = ['application/json']; + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + // to determine the Content-Type header + const consumes: string[] = []; + + return this.httpClient.request('get', `${this.basePath}/async/download/status`, { + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + }); + } + + /** + * Prepares a download for given fileIds and types + * None + * @param body request + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public prepareDownload(body: PrepareDownloadRequest, observe?: 'body', reportProgress?: boolean): Observable; + public prepareDownload(body: PrepareDownloadRequest, observe?: 'response', reportProgress?: boolean): Observable>; + public prepareDownload(body: PrepareDownloadRequest, observe?: 'events', reportProgress?: boolean): Observable>; + public prepareDownload(body: PrepareDownloadRequest, observe: any = 'body', reportProgress: boolean = false): Observable { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling prepareDownload.'); + } + + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = ['application/json']; + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + // to determine the Content-Type header + const consumes: string[] = ['application/json']; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + headers = headers.set('Content-Type', httpContentTypeSelected); + } + + return this.httpClient.request('post', `${this.basePath}/async/download/prepare`, { + body: body, + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + }); + } +} diff --git a/libs/red-ui-http/src/lib/model/downloadDetails.ts b/libs/red-ui-http/src/lib/model/downloadDetails.ts new file mode 100644 index 000000000..b51a21756 --- /dev/null +++ b/libs/red-ui-http/src/lib/model/downloadDetails.ts @@ -0,0 +1,34 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +export interface DownloadDetails { + downloadFileTypes?: Array; + fileIds?: Array; + reportTypes?: Array; +} +export namespace DownloadDetails { + export type DownloadFileTypesEnum = 'ORIGINAL' | 'PREVIEW' | 'REDACTED' | 'ANNOTATED' | 'FLATTEN'; + export const DownloadFileTypesEnum = { + ORIGINAL: 'ORIGINAL' as DownloadFileTypesEnum, + PREVIEW: 'PREVIEW' as DownloadFileTypesEnum, + REDACTED: 'REDACTED' as DownloadFileTypesEnum, + ANNOTATED: 'ANNOTATED' as DownloadFileTypesEnum, + FLATTEN: 'FLATTEN' as DownloadFileTypesEnum + }; + export type ReportTypesEnum = 'SINGLE_FILE_EFSA_TEMPLATE' | 'SINGLE_FILE_SYNGENTA_TEMPLATE' | 'MULTI_FILE_EFSA_TEMPLATE' | 'MULTI_FILE_SYNGENTA_TEMPLATE'; + export const ReportTypesEnum = { + SINGLEFILEEFSATEMPLATE: 'SINGLE_FILE_EFSA_TEMPLATE' as ReportTypesEnum, + SINGLEFILESYNGENTATEMPLATE: 'SINGLE_FILE_SYNGENTA_TEMPLATE' as ReportTypesEnum, + MULTIFILEEFSATEMPLATE: 'MULTI_FILE_EFSA_TEMPLATE' as ReportTypesEnum, + MULTIFILESYNGENTATEMPLATE: 'MULTI_FILE_SYNGENTA_TEMPLATE' as ReportTypesEnum + }; +} diff --git a/libs/red-ui-http/src/lib/model/downloadRequest.ts b/libs/red-ui-http/src/lib/model/downloadRequest.ts new file mode 100644 index 000000000..5bd8b61ca --- /dev/null +++ b/libs/red-ui-http/src/lib/model/downloadRequest.ts @@ -0,0 +1,18 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/** + * Object containing information on which prepared download should be downloaded. + */ +export interface DownloadRequest { + storageId?: string; +} diff --git a/libs/red-ui-http/src/lib/model/downloadResponse.ts b/libs/red-ui-http/src/lib/model/downloadResponse.ts new file mode 100644 index 000000000..89677868c --- /dev/null +++ b/libs/red-ui-http/src/lib/model/downloadResponse.ts @@ -0,0 +1,15 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +export interface DownloadResponse { + storageId?: string; +} diff --git a/libs/red-ui-http/src/lib/model/downloadStatus.ts b/libs/red-ui-http/src/lib/model/downloadStatus.ts new file mode 100644 index 000000000..7a14af899 --- /dev/null +++ b/libs/red-ui-http/src/lib/model/downloadStatus.ts @@ -0,0 +1,33 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ +import { DownloadDetails } from './downloadDetails'; + +export interface DownloadStatus { + creationDate?: string; + downloadDetails?: DownloadDetails; + filename?: string; + lastDownload?: string; + mimeType?: string; + projectId?: string; + status?: DownloadStatus.StatusEnum; + storageId?: string; + userId?: string; +} +export namespace DownloadStatus { + export type StatusEnum = 'QUEUED' | 'GENERATING' | 'READY' | 'FAILED'; + export const StatusEnum = { + QUEUED: 'QUEUED' as StatusEnum, + GENERATING: 'GENERATING' as StatusEnum, + READY: 'READY' as StatusEnum, + FAILED: 'FAILED' as StatusEnum + }; +} diff --git a/libs/red-ui-http/src/lib/model/downloadStatusResponse.ts b/libs/red-ui-http/src/lib/model/downloadStatusResponse.ts new file mode 100644 index 000000000..7945e9202 --- /dev/null +++ b/libs/red-ui-http/src/lib/model/downloadStatusResponse.ts @@ -0,0 +1,16 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ +import { DownloadStatus } from './downloadStatus'; + +export interface DownloadStatusResponse { + downloadStatus?: Array; +} diff --git a/libs/red-ui-http/src/lib/model/models.ts b/libs/red-ui-http/src/lib/model/models.ts index 6e4cec8b9..f0043dc76 100644 --- a/libs/red-ui-http/src/lib/model/models.ts +++ b/libs/red-ui-http/src/lib/model/models.ts @@ -42,3 +42,9 @@ export * from './versionsResponse'; export * from './viewedPages'; export * from './viewedPagesRequest'; export * from './watermarkModel'; +export * from './downloadDetails'; +export * from './downloadRequest'; +export * from './downloadResponse'; +export * from './downloadStatus'; +export * from './downloadStatusResponse'; +export * from './prepareDownloadRequest'; diff --git a/libs/red-ui-http/src/lib/model/prepareDownloadRequest.ts b/libs/red-ui-http/src/lib/model/prepareDownloadRequest.ts new file mode 100644 index 000000000..2da274e9c --- /dev/null +++ b/libs/red-ui-http/src/lib/model/prepareDownloadRequest.ts @@ -0,0 +1,27 @@ +/** + * API Documentation for Redaction Gateway + * Description for redaction + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/** + * Object containing information on which file and report types should be included in the download. + */ +export interface PrepareDownloadRequest { + /** + * Which files should be included. Possible values are ORIGINAL, PREVIEW, REDACTED, ANNOTATED, FLATTEN + */ + downloadFileTypes?: Array; + projectId?: string; + /** + * Which reports should be included. Possible values are SINGLE_FILE_EFSA_TEMPLATE, SINGLE_FILE_SYNGENTA_TEMPLATE, MULTI_FILE_EFSA_TEMPLATE, MULTI_FILE_SYNGENTA_TEMPLATE + */ + reportTypes?: Array; + fileIds?: Array; +}