Skip to content

Commit

Permalink
Merge branch 'visualization/grid-pivot' of https://github.com/RevealB…
Browse files Browse the repository at this point in the history
…i/Reveal.Sdk.Dom into visualization/grid-pivot
  • Loading branch information
Tan Phat VO authored and Tan Phat VO committed Dec 24, 2024
2 parents e5dd33a + dd9f40f commit 61b53b2
Show file tree
Hide file tree
Showing 21 changed files with 905 additions and 100 deletions.
32 changes: 30 additions & 2 deletions e2e/Sandbox/DashboardCreators/GoogleBigQueryDashboard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Reveal.Sdk.Dom;
using AngleSharp.Dom;
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,7 +16,32 @@ internal class GoogleBigQueryDashboard : IDashboardCreator

public RdashDocument CreateDashboard()
{
throw new NotImplementedException();
var document = new RdashDocument();

var dataSource = new GoogleBigQueryDataSource()
{
Id = "BigQueryDSId",
Title = "Google BigQuery DS",
Subtitle = "Public Gg BigQuery",
ProjectId = "bigquery-public-data"
};
var dataSourceItem = new GoogleBigQueryDataSourceItem("Google BigQuery DS Item", dataSource)
{
Id = "BigQueryDSItemId",
Title = "Google",
Subtitle = "Ameria Health rankings",
DataSetId = "america_health_rankings",
Table = "ahr",
ProjectId = "bigquery-public-data",
Fields = new List<IField> {
new NumberField("edition"),
new TextField("state_name")
}
};

document.Visualizations.Add(new GridVisualization("List edition states", dataSourceItem).SetColumns("edition", "state_name"));

return document;
}
}
}
65 changes: 64 additions & 1 deletion e2e/Sandbox/DashboardCreators/MongoDashboard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,7 +15,68 @@ internal class MongoDashboard : IDashboardCreator

public RdashDocument CreateDashboard()
{
throw new NotImplementedException();
var mongoDbDs = new MongoDBDataSource()
{
Id = "MyMongoDatasource",
Title = "MyMongoDatasource",
Subtitle = "My MongoDB",
ProcessDataOnServerDefaultValue = true,
ProcessDataOnServerReadOnly = false,
ConnectionString = "mongodb+srv://cluster0.ta2xrrt.mongodb.net",
Database = "test"
};

var testCollection = new MongoDbDataSourceItem("DB Test", mongoDbDs)
{
Id = "MyMongoDatasourceItem",
Title = "MyMongoDatasourceItem",
Subtitle = "Test Collection",
Collection = "data",
Fields = new List<IField>
{
new TextField("_id"),
new TextField("name"),
new NumberField("price"),
new DateTimeField("available_since"),
new TextField("category"),
new NumberField("year_value"),
new NumberField("month_value"),
new NumberField("day_value"),
new NumberField("hour_value"),
new NumberField("minutes_value"),
new NumberField("seconds_value"),
new NumberField("milliseconds_value"),
new NumberField("numeric_value1"),
new NumberField("numeric_value2"),
new NumberField("numeric_value3"),
new TextField("image_url")

}
};

var document = new RdashDocument("My Dashboard");

document.Visualizations.Add(new GridVisualization("Test List", testCollection).SetColumns("name", "category", "price"));

var jsonData = document.ToJsonString();

// var filePath = "test.rdash";

// try
// {

// if (File.Exists(filePath))
// File.Delete(filePath);

// document.Save(filePath);
// }
// catch
// {
// throw;
// }


return document;
}
}
}
23 changes: 17 additions & 6 deletions e2e/Sandbox/Reveal/AuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Reveal.Sdk.Data.MySql;
using Reveal.Sdk.Data.PostgreSQL;
using Reveal.Sdk.Data.Oracle;
using Reveal.Sdk.Data.MongoDB;
using System.Threading.Tasks;
using Reveal.Sdk.Data.Amazon.Redshift;
using Reveal.Sdk.Data.Google.Analytics4;
Expand All @@ -17,10 +18,15 @@
using Reveal.Sdk.Data.MySql;
using Reveal.Sdk.Data.OData;
using Reveal.Sdk.Data.Oracle;
using Reveal.Sdk.Data.Snowflake;
using Reveal.Sdk.Data.PostgreSQL;
using Reveal.Sdk.Data.Microsoft.SynapseAnalytics;
using Google.Apis.Auth.OAuth2;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;


namespace Sandbox.RevealSDK
{
Expand All @@ -47,10 +53,14 @@ public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSour
}
else if (dataSource is RVGoogleDriveDataSource)
{
var _token = RetrieveGoogleDriveBearerToken();
var _token = RetrieveGoogleBearerToken(new List<string>() { "https://www.googleapis.com/auth/drive" });

userCredential = new RVBearerTokenDataSourceCredential(_token, null);
}
else if (dataSource is RVMongoDBDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("user01", "*****", "admin");
}
else if (dataSource is RVSnowflakeDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("snow-flake-username", "snow-flake-password");
Expand All @@ -77,7 +87,8 @@ public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSour
}
else if (dataSource is RVBigQueryDataSource)
{
userCredential = new RVBearerTokenDataSourceCredential("token", null);
var token = RetrieveGoogleBearerToken(new List<string>() { "https://www.googleapis.com/auth/bigquery" });
userCredential = new RVBearerTokenDataSourceCredential(token, null);
}
else if (dataSource is RVGoogleDriveDataSource)
{
Expand Down Expand Up @@ -123,7 +134,7 @@ public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSour
return Task.FromResult(userCredential);
}

internal string RetrieveGoogleDriveBearerToken()
internal string RetrieveGoogleBearerToken(List<string> scopes)
{
var jsonKey = @"
{
Expand All @@ -145,9 +156,9 @@ internal string RetrieveGoogleDriveBearerToken()
byte[] jsonKeyBytes = Encoding.UTF8.GetBytes(jsonKey);
memoryStream.Write(jsonKeyBytes, 0, jsonKeyBytes.Length);
memoryStream.Seek(0, SeekOrigin.Begin);
var credential = GoogleCredential.FromStream(memoryStream).CreateScoped("https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile");
scopes.Add("https://www.googleapis.com/auth/userinfo.email");
scopes.Add("https://www.googleapis.com/auth/userinfo.profile");
var credential = GoogleCredential.FromStream(memoryStream).CreateScoped(scopes);

var accessToken = credential.UnderlyingCredential.GetAccessTokenForRequestAsync().Result;

Expand Down
11 changes: 11 additions & 0 deletions e2e/Sandbox/Reveal/DataSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Reveal.Sdk.Data.Excel;
using Reveal.Sdk.Data.Microsoft.AnalysisServices;
using Reveal.Sdk.Data.MongoDB;

namespace Sandbox.RevealSDK
{
Expand Down Expand Up @@ -60,6 +61,16 @@ public Task<RVDataSourceItem> ChangeDataSourceItemAsync(RVDataSourceItem dataSou
// ds.Database = "Northwind";
//}

//if (dataSourceItem is RVMongoDBDataSourceItem mongoDbDataSourceItem)
//{
// mongoDbDataSourceItem.Collection = "data";

// var ds = mongoDbDataSourceItem.DataSource as RVMongoDBDataSource;

// ds.ConnectionString = "mongodb+srv://user01:*******@cluster0.ta2xrrt.mongodb.net/";
// ds.Database = "test";
//}

return Task.FromResult(dataSourceItem);
}
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using Xunit;
Expand All @@ -12,22 +14,65 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
public class GoogleBigQueryDataSourceItemFixture
{
[Fact]
public void Constructor_SetsTitleAndDatasource_AsProvided()
public void Constructor_CreateGGBigQueryDSItem_WithTitle()
{
// Arrange
var dataSource = new GoogleBigQueryDataSource();
var title = "Test title";
var title = "GG BigQuery DS Title";

// Act
var dataSourceItem = new GoogleBigQueryDataSourceItem(title, dataSource);
var dataSourceItem = new GoogleBigQueryDataSourceItem(title);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(title, dataSourceItem.Title);
Assert.Equal(dataSource, dataSourceItem.DataSource);
Assert.NotNull(dataSourceItem.DataSource);
Assert.Equal(title, dataSourceItem.DataSource.Title);
Assert.IsType<GoogleBigQueryDataSource>(dataSourceItem.DataSource);
}

[Theory]
[InlineData("DS Title", "DS Title", "DS Item Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_CreateGGBigQueryDSItem_WithTitleAndDatSource(string dsTitle, string expectedDSTitle, string dsItemTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new DataSource() { Title = dsTitle };

// Act
var dataSourceItem = new GoogleBigQueryDataSourceItem(dsItemTitle, dataSource);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.NotSame(dataSource, dataSourceItem.DataSource);
Assert.IsType<GoogleBigQueryDataSource>(dataSourceItem.DataSource);
}

[Theory]
[InlineData("DS Title", "DS Title", "DS Item Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_CreateGGBigQueryDSItem_WithTitleAndGGBigQueryDatSource(string dsTitle, string expectedDSTitle, string dsItemTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new GoogleBigQueryDataSource() { Title = dsTitle };

// Act
var dataSourceItem = new GoogleBigQueryDataSourceItem(dsItemTitle, dataSource);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Same(dataSource, dataSourceItem.DataSource);
}

[Fact]
public void DataSetId_SaveValueAndProperties_WhenSet()
public void GetDataSetId_ReturnSameValue_WithSetValue()
{
// Arrange
var dataSource = new GoogleBigQueryDataSource();
Expand All @@ -39,16 +84,16 @@ public void DataSetId_SaveValueAndProperties_WhenSet()

// Assert
Assert.Equal(datasetId, dataSourceItem.DataSetId);
Assert.Equal(datasetId, dataSourceItem.Properties.GetValue<string>("DataSetId"));
Assert.Equal(datasetId, dataSourceItem.Properties.GetValue<string>("datasetId"));
}

[Fact]
public void PropertyId_SaveValueAndProperties_WhenSet()
public void GetProjectId_ReturnSameValue_WithSetValue()
{
// Arrange
var dataSource = new GoogleBigQueryDataSource();
var dataSourceItem = new GoogleBigQueryDataSourceItem("Test", dataSource);
var projectId = "TestPropertyId";
var projectId = "ProjectId";

// Act
dataSourceItem.ProjectId = projectId;
Expand All @@ -57,5 +102,63 @@ public void PropertyId_SaveValueAndProperties_WhenSet()
Assert.Equal(projectId, dataSourceItem.ProjectId);
Assert.Equal(projectId, dataSourceItem.Properties.GetValue<string>("ProjectId"));
}

[Fact]
public void GetTable_ReturnSamevalue_WithSetValue()
{
// Arrange
var dataSourceItem = new GoogleBigQueryDataSourceItem("Big Query DS Item");
var tableName = "TestTable";

// Act
dataSourceItem.Table = tableName;

// Assert
Assert.Equal(tableName, dataSourceItem.Table);
Assert.Equal(tableName, dataSourceItem.Properties.GetValue<string>("tableId"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
var expectedJson = """
{
"_type": "DataSourceItemType",
"Id": "bigqueryDSItemId",
"Title": "Big Query",
"Subtitle": "America Health rankings",
"DataSourceId": "bigquery",
"HasTabularData": true,
"HasAsset": false,
"Properties": {
"datasetId": "america_health_rankings",
"tableId": "ahr"
},
"Settings": {}
}
""";
var dataSource = new GoogleBigQueryDataSource()
{
Id = "bigquery",
};
var dataSourceItem = new GoogleBigQueryDataSourceItem("Big Query", dataSource)
{
Id = "bigqueryDSItemId",
Subtitle = "America Health rankings",
HasTabularData = true,
HasAsset = false,
DataSetId = "america_health_rankings",
Table = "ahr",
};
var expectedJObject = JObject.Parse(expectedJson);

// Act
var json = dataSourceItem.ToJsonString();
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Loading

0 comments on commit 61b53b2

Please sign in to comment.