You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/07/20 20:19:04 UTC

[incubator-streampipes] branch STREAMPIPES-319 updated: Add parameter and method for new REST API in ui client code

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-319
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-319 by this push:
     new 81dcb71  Add parameter and method for new REST API in ui client code
81dcb71 is described below

commit 81dcb71ba17e75c5fba3463bd76348f9e7815b24
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Tue Jul 20 22:18:30 2021 +0200

    Add parameter and method for new REST API in ui client code
---
 .../datalake/DatalakeQueryParameters.ts            | 31 +++++++
 .../datalake/datalake-rest.service.ts              | 95 ++++++++++++++++++----
 2 files changed, 108 insertions(+), 18 deletions(-)

diff --git a/ui/src/app/core-services/datalake/DatalakeQueryParameters.ts b/ui/src/app/core-services/datalake/DatalakeQueryParameters.ts
new file mode 100644
index 0000000..a71616f
--- /dev/null
+++ b/ui/src/app/core-services/datalake/DatalakeQueryParameters.ts
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+export class DatalakeQueryParameters {
+  public columns: string;
+  public startDate: number;
+  public endDate: number;
+  public page: number;
+  public limit: number;
+  public offset: number;
+  public groupBy: number;
+  public order: number;
+  public aggregationFunction: string;
+  public timeInterval: string;
+}
+
diff --git a/ui/src/app/core-services/datalake/datalake-rest.service.ts b/ui/src/app/core-services/datalake/datalake-rest.service.ts
index d5a6222..71b1bb2 100644
--- a/ui/src/app/core-services/datalake/datalake-rest.service.ts
+++ b/ui/src/app/core-services/datalake/datalake-rest.service.ts
@@ -25,6 +25,7 @@ import { PageResult } from '../../core-model/datalake/PageResult';
 import { AuthStatusService } from '../../services/auth-status.service';
 import {DataLakeMeasure} from "../../core-model/gen/streampipes-model";
 import {map} from "rxjs/operators";
+import { DatalakeQueryParameters } from './DatalakeQueryParameters';
 
 @Injectable()
 export class DatalakeRestService {
@@ -65,28 +66,86 @@ export class DatalakeRestService {
         return this.http.get<PageResult>(this.dataLakeUrlV3 + '/data/' + index + '/paging?itemsPerPage=' + itemsPerPage);
     }
 
-    getData(index, startDate, endDate, aggregationTimeUnit, aggregationValue): Observable<DataResult> {
-        // return this.http.get<DataResult>(
-        //   this.dataLakeUrlV3 + '/data/' + index + '/' + startDate + '/' + endDate + '?aggregationUnit=' + aggregationTimeUnit + '&aggregationValue=' + aggregationValue);
+    getData(index, _startDate, _endDate, aggregationTimeUnit, aggregationValue): Observable<DataResult> {
+      const _timeInterval = aggregationValue + aggregationTimeUnit;
 
-      const url = this.dataLakeUrlV4 + '/measurements/' + index;
+      return this.getCall(
+        index,
+        _startDate,
+        _endDate,
+        undefined,
+        undefined,
+        undefined,
+        undefined,
+        undefined,
+        undefined,
+        'mean',
+        _timeInterval);
+    }
+
+  private getCall(
+    index,
+    _startDate,
+    _endDate,
+    _columns,
+    _page,
+    _limit,
+    _offset,
+    _goupBy,
+    _order,
+    _aggregationFunction,
+    _timeInterval): Observable<DataResult> {
+
+    const url = this.dataLakeUrlV4 + '/measurements/' + index;
+
+    const queryParams: DatalakeQueryParameters = new DatalakeQueryParameters();
+
+    if (_startDate) {
+      queryParams.startDate = _startDate;
+    }
+
+    if (_endDate) {
+      queryParams.endDate = _endDate;
+    }
+
+    if (_columns) {
+      queryParams.columns = _columns;
+    }
+
+    if (_page) {
+      queryParams.page = _page;
+    }
+
+    if (_limit) {
+      queryParams.limit = _limit;
+    }
+
+    if (_offset) {
+      queryParams.offset = _offset;
+    }
+
+    if (_goupBy) {
+      queryParams.groupBy = _goupBy;
+    }
+
+    if (_order) {
+      queryParams.order = _order;
+    }
+
+    if (_aggregationFunction) {
+      queryParams.aggregationFunction = _aggregationFunction;
+    }
 
-      return this.http.get<PageResult>(url, {
-        params: {
-          // columns: 'id1234',
-          startDate: startDate,
-          endDate: endDate,
-          // page: 0,
-          // limit: 1,
-          // offset: 1,
-          // groupBy: 'asd,sadf',
-          // order: 'ASC',
-          aggregationFunction: 'mean',
-          timeInterval: '1s'
-        }
-      });
+    if (_timeInterval) {
+      queryParams.timeInterval = _timeInterval;
     }
 
+    // @ts-ignore
+    return this.http.get<PageResult>(url, {
+      // @ts-ignore
+      params: queryParams,
+    });
+  }
     getGroupedData(index, startDate, endDate, aggregationTimeUnit, aggregationValue, groupingTag) {
         return this.http.get<GroupedDataResult>(
           this.dataLakeUrlV3 + '/data/' + index + '/' + startDate + '/' + endDate + '/grouping/' + groupingTag +