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

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 90478c23d6 add datalake_dashboard_Api (#2705)
90478c23d6 is described below

commit 90478c23d6ff2dc07075aea11d1fc82e1955a2f6
Author: wyyolo <[email protected]>
AuthorDate: Wed May 8 17:28:15 2024 +0800

    add datalake_dashboard_Api (#2705)
---
 .../streampipes/data_lake_dashboard_api.go         | 118 +++++++++++++++++++++
 .../internal/serializer/deserializer.go            |  30 ++++++
 .../model/data_lake/data_lake_dashboard.go         |  39 +++++++
 .../streampipes/streampipes_client.go              |   5 +
 4 files changed, 192 insertions(+)

diff --git a/streampipes-client-go/streampipes/data_lake_dashboard_api.go 
b/streampipes-client-go/streampipes/data_lake_dashboard_api.go
new file mode 100644
index 0000000000..55718c717a
--- /dev/null
+++ b/streampipes-client-go/streampipes/data_lake_dashboard_api.go
@@ -0,0 +1,118 @@
+//
+// 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.
+//
+
+package streampipes
+
+import (
+       "github.com/apache/streampipes/streampipes-client-go/streampipes/config"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake"
+       "io"
+       "log"
+       "net/http"
+)
+
+type DataLakeDashboard struct {
+       endpoint
+}
+
+func NewDataLakeDashborad(clientConfig config.StreamPipesClientConfig) 
*DataLakeDashboard {
+
+       return &DataLakeDashboard{
+               endpoint{config: clientConfig},
+       }
+}
+
+func (d *DataLakeDashboard) GetSingleDataLakeDashboard(dashboardId string) 
(data_lake.Dashboard, error) {
+       endPointUrl := util.NewStreamPipesApiPath(d.config.Url, 
"streampipes-backend/api/v3/datalake/dashboard", []string{dashboardId})
+       log.Printf("Get data from: %s", endPointUrl)
+
+       response, err := d.executeRequest("GET", endPointUrl)
+       if err != nil {
+               return data_lake.Dashboard{}, err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = d.handleStatusCode(response)
+               if err != nil {
+                       return data_lake.Dashboard{}, err
+               }
+       }
+
+       body, err := io.ReadAll(response.Body)
+       if err != nil {
+               return data_lake.Dashboard{}, err
+       }
+
+       unmarshalData, err := 
serializer.NewDataLakeDashboardDeserializer().Unmarshal(body)
+       if err != nil {
+               return data_lake.Dashboard{}, err
+       }
+       dataLakeDashboard := unmarshalData.(data_lake.Dashboard)
+
+       return dataLakeDashboard, nil
+}
+
+func (d *DataLakeDashboard) GetAllDataLakeDashboard() ([]data_lake.Dashboard, 
error) {
+       endPointUrl := util.NewStreamPipesApiPath(d.config.Url, 
"streampipes-backend/api/v3/datalake/dashboard", nil)
+       log.Printf("Get data from: %s", endPointUrl)
+
+       response, err := d.executeRequest("GET", endPointUrl)
+       if err != nil {
+               return nil, err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = d.handleStatusCode(response)
+               if err != nil {
+                       return nil, err
+               }
+       }
+
+       body, err := io.ReadAll(response.Body)
+       if err != nil {
+               return nil, err
+       }
+
+       unmarshalData, err := 
serializer.NewDataLakeDashboardsDeserializer().Unmarshal(body)
+       if err != nil {
+               return nil, err
+       }
+       dataLakeDashboard := unmarshalData.([]data_lake.Dashboard)
+
+       return dataLakeDashboard, nil
+}
+
+func (d *DataLakeDashboard) DeleteSingleDataLakeDashboard(dashboardId string) 
error {
+       endPointUrl := util.NewStreamPipesApiPath(d.config.Url, 
"streampipes-backend/api/v3/datalake/dashboard", []string{dashboardId})
+       log.Printf("Delete data from: %s", endPointUrl)
+
+       response, err := d.executeRequest("DELETE", endPointUrl)
+       if err != nil {
+               return err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = d.handleStatusCode(response)
+               if err != nil {
+                       return err
+               }
+       }
+
+       return nil
+}
diff --git 
a/streampipes-client-go/streampipes/internal/serializer/deserializer.go 
b/streampipes-client-go/streampipes/internal/serializer/deserializer.go
index 485dc8021b..a8e8ad74ce 100644
--- a/streampipes-client-go/streampipes/internal/serializer/deserializer.go
+++ b/streampipes-client-go/streampipes/internal/serializer/deserializer.go
@@ -96,6 +96,36 @@ func (d *StreamPipesVersionDeserializer) Unmarshal(data 
[]byte) (interface{}, er
        return dataSeries, nil
 }
 
+type DataLakeDashboardDeserializer struct{}
+
+func NewDataLakeDashboardDeserializer() *DataLakeDashboardDeserializer {
+       return &DataLakeDashboardDeserializer{}
+}
+
+func (d *DataLakeDashboardDeserializer) Unmarshal(data []byte) (interface{}, 
error) {
+       var dashborad data_lake.Dashboard
+       err := json.Unmarshal(data, &dashborad)
+       if err != nil {
+               return nil, err
+       }
+       return dashborad, nil
+}
+
+type DataLakeDashboardsDeserializer struct{}
+
+func NewDataLakeDashboardsDeserializer() *DataLakeDashboardsDeserializer {
+       return &DataLakeDashboardsDeserializer{}
+}
+
+func (d *DataLakeDashboardsDeserializer) Unmarshal(data []byte) (interface{}, 
error) {
+       var dashborad []data_lake.Dashboard
+       err := json.Unmarshal(data, &dashborad)
+       if err != nil {
+               return nil, err
+       }
+  
+       return dashborad, nil
+}
 
 type DataLakeWidgetDeserializer struct{}
 
diff --git 
a/streampipes-client-go/streampipes/model/data_lake/data_lake_dashboard.go 
b/streampipes-client-go/streampipes/model/data_lake/data_lake_dashboard.go
new file mode 100644
index 0000000000..f0d81e9e09
--- /dev/null
+++ b/streampipes-client-go/streampipes/model/data_lake/data_lake_dashboard.go
@@ -0,0 +1,39 @@
+//
+// 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.
+//
+
+package data_lake
+
+type Dashboard struct {
+       ID                       string                 `json:"id"`
+       Name                     string                 `json:"name"`
+       Description              string                 `json:"description"`
+       DisplayHeader            bool                   `json:"displayHeader"`
+       DashboardTimeSettings    map[string]interface{} 
`json:"dashboardTimeSettings"`
+       DashboardGeneralSettings map[string]interface{} 
`json:"dashboardGeneralSettings"`
+       Widgets                  []DashboardItem        `json:"widgets"`
+}
+
+type DashboardItem struct {
+       ID        string   `json:"id"`
+       Name      string   `json:"name"`
+       Component string   `json:"component"`
+       Settings  []string `json:"settings"`
+       Cols      int      `json:"cols"`
+       Rows      int      `json:"rows"`
+       X         int      `json:"x"`
+       Y         int      `json:"y"`
+}
diff --git a/streampipes-client-go/streampipes/streampipes_client.go 
b/streampipes-client-go/streampipes/streampipes_client.go
index 5d0350acfd..a2e7b06990 100644
--- a/streampipes-client-go/streampipes/streampipes_client.go
+++ b/streampipes-client-go/streampipes/streampipes_client.go
@@ -73,6 +73,11 @@ func (s *StreamPipesClient) StreamPipesVersion() *Versions {
 }
 
 
+func (s *StreamPipesClient) DataLakeDashboard() *DataLakeDashboard {
+
+       return NewDataLakeDashborad(s.config)
+}
+
 func (s *StreamPipesClient) DataLakeWidget() *DataLakeWidget {
 
        return NewDataLakeWidget(s.config)

Reply via email to