You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by GitBox <gi...@apache.org> on 2023/01/02 16:18:47 UTC

[GitHub] [streampipes] tenthe commented on a diff in pull request #1012: [#877] Apply UI linting to projects module

tenthe commented on code in PR #1012:
URL: https://github.com/apache/streampipes/pull/1012#discussion_r1060116497


##########
ui/projects/streampipes/platform-services/src/lib/apis/datalake-rest.service.ts:
##########
@@ -19,190 +19,243 @@
 import { Injectable } from '@angular/core';
 import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http';
 import { Observable, of } from 'rxjs';
-import { DataLakeMeasure, PageResult, SpQueryResult } from '../model/gen/streampipes-model';
+import {
+    DataLakeMeasure,
+    PageResult,
+    SpQueryResult,
+} from '../model/gen/streampipes-model';
 import { map } from 'rxjs/operators';
 import { DatalakeQueryParameters } from '../model/datalake/DatalakeQueryParameters';
 
 @Injectable({
-  providedIn: 'root'
+    providedIn: 'root',
 })
 export class DatalakeRestService {
-  constructor(private http: HttpClient) {
-  }
-
-  private get baseUrl() {
-    return '/streampipes-backend';
-  }
-
-  public get dataLakeUrl() {
-    return this.baseUrl + '/api/v4' + '/datalake';
-  }
-
-  public get dataLakeMeasureUrl() {
-    return this.baseUrl + '/api/v4/datalake/measure';
-  }
-
-  getAllMeasurementSeries(): Observable<DataLakeMeasure[]> {
-    const url = this.dataLakeUrl + '/measurements/';
-    return this.http.get(url).pipe(map(response => {
-      return (response as any[]).map(p => DataLakeMeasure.fromData(p));
-    }));
-  }
-
-  getMeasurement(id: string): Observable<DataLakeMeasure> {
-    return this.http.get(`${this.dataLakeMeasureUrl}/${id}`).pipe(map(res => res as DataLakeMeasure));
-  }
-
-  performMultiQuery(queryParams: DatalakeQueryParameters[]): Observable<SpQueryResult[]> {
-    return this.http.post(`${this.dataLakeUrl}/query`, queryParams, {headers: {ignoreLoadingBar: ''}})
-      .pipe(map(response => response as SpQueryResult[]));
-  }
-
-  getData(index: string,
-          queryParams: DatalakeQueryParameters,
-          ignoreLoadingBar?: boolean): Observable<SpQueryResult> {
-
-    const columns = queryParams.columns;
-    if (columns === '') {
-      const emptyQueryResult = new SpQueryResult();
-      emptyQueryResult.total = 0;
-      return of(emptyQueryResult);
-    } else {
-      const url = this.dataLakeUrl + '/measurements/' + index;
-      const headers = ignoreLoadingBar ? {ignoreLoadingBar: ''} : {};
-      // @ts-ignore
-      return this.http.get<SpQueryResult>(url, {params: queryParams, headers});
-    }
-  }
-
-
-  getPagedData(index: string, itemsPerPage: number, page: number, columns?: string, order?: string): Observable<PageResult> {
-    const url = this.dataLakeUrl + '/measurements/' + index;
-
-    const queryParams: DatalakeQueryParameters = this.getQueryParameters(columns, undefined, undefined, page,
-      itemsPerPage, undefined, undefined, order, undefined, undefined);
-
-    // @ts-ignore
-    return this.http.get<PageResult>(url, {params: queryParams});
-  }
-
-  getTagValues(index: string,
-               fieldNames: string[]): Observable<Map<string, string[]>> {
-
-    if (fieldNames.length === 0) {
-      return of(new Map<string, string[]>());
-    } else {
-      return this.http.get(this.dataLakeUrl + '/measurements/' + index + '/tags?fields=' + fieldNames.toString())
-        .pipe(map(r => r as Map<string, string[]>));
+    constructor(private http: HttpClient) {}
 
+    private get baseUrl() {
+        return '/streampipes-backend';
     }
-  }
-
-  downloadRawData(index: string,
-                  format: string,
-                  delimiter: string,
-                  missingValueBehaviour: string,
-                  startTime?: number,
-                  endTime?: number) {
-    const queryParams = (startTime && endTime) ? {format, delimiter, startDate: startTime, endDate: endTime} : {
-      format,
-      delimiter,
-      missingValueBehaviour
-    };
-    return this.buildDownloadRequest(index, queryParams);
-  }
-
-  downloadQueriedData(
-    index: string,
-    format: string,
-    delimiter: string,
-    missingValueBehaviour: string,
-    queryParams: DatalakeQueryParameters) {
-
-    (queryParams as any).format = format;
-    (queryParams as any).delimiter = delimiter;
-    (queryParams as any).missingValueBehaviour = missingValueBehaviour;
-
-    return this.buildDownloadRequest(index, queryParams);
-
-  }
-
-  buildDownloadRequest(index: string,
-                       queryParams: any) {
-    const url = this.dataLakeUrl + '/measurements/' + index + '/download';
-    const request = new HttpRequest('GET', url, {
-      reportProgress: true,
-      responseType: 'text',
-      params: this.toHttpParams(queryParams)
-    });
-
-    return this.http.request(request);
-  }
 
-  toHttpParams(queryParamObject: any): HttpParams {
-    return new HttpParams({fromObject: queryParamObject});
-  }
-
-  removeData(index: string) {
-    const url = this.dataLakeUrl + '/measurements/' + index;
+    public get dataLakeUrl() {
+        return this.baseUrl + '/api/v4' + '/datalake';
+    }
 
-    return this.http.delete(url);
-  }
+    public get dataLakeMeasureUrl() {
+        return this.baseUrl + '/api/v4/datalake/measure';
+    }
 
-  dropSingleMeasurementSeries(index: string) {
-    const url = this.dataLakeUrl + '/measurements/' + index + '/drop';
-    return this.http.delete(url);
-  }
+    getAllMeasurementSeries(): Observable<DataLakeMeasure[]> {
+        const url = this.dataLakeUrl + '/measurements/';
+        return this.http.get(url).pipe(
+            map(response => {
+                return (response as any[]).map(p =>
+                    DataLakeMeasure.fromData(p),
+                );
+            }),
+        );
+    }
 
-  dropAllMeasurementSeries() {
-    const url = this.dataLakeUrl + '/measurements/';
-    return this.http.delete(url);
-  }
+    getMeasurement(id: string): Observable<DataLakeMeasure> {
+        return this.http
+            .get(`${this.dataLakeMeasureUrl}/${id}`)
+            .pipe(map(res => res as DataLakeMeasure));
+    }
 
-  private getQueryParameters(columns?: string, startDate?: number, endDate?: number, page?: number, limit?: number,
-                             offset?: number, groupBy?: string, order?: string, aggregationFunction?: string, timeInterval?: string):
-    DatalakeQueryParameters {
-    const queryParams: DatalakeQueryParameters = new DatalakeQueryParameters();
+    performMultiQuery(
+        queryParams: DatalakeQueryParameters[],
+    ): Observable<SpQueryResult[]> {
+        return this.http
+            .post(`${this.dataLakeUrl}/query`, queryParams, {
+                headers: { ignoreLoadingBar: '' },
+            })
+            .pipe(map(response => response as SpQueryResult[]));
+    }
 
-    if (columns) {
-      queryParams.columns = columns;
+    getData(
+        index: string,
+        queryParams: DatalakeQueryParameters,
+        ignoreLoadingBar?: boolean,
+    ): Observable<SpQueryResult> {
+        const columns = queryParams.columns;
+        if (columns === '') {
+            const emptyQueryResult = new SpQueryResult();
+            emptyQueryResult.total = 0;
+            return of(emptyQueryResult);
+        } else {
+            const url = this.dataLakeUrl + '/measurements/' + index;
+            const headers = ignoreLoadingBar ? { ignoreLoadingBar: '' } : {};
+            // @ts-ignore

Review Comment:
   I think this is the reason why the PR validation failed.
   Can you try to replace it with:
   ```
    return this.http.get<SpQueryResult>(url, {
      params: queryParams as unknown as HttpParams,
      headers,
   });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org