From a1d7d3098d78b3f79540079bd79fe9a12666b97d Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 25 Nov 2024 17:13:20 +0700 Subject: [PATCH 1/7] Create constructors for Postgres DataSource Item --- .../DataSourceItems/PostgreSqlDataSourceItem.cs | 15 +++++++++++++++ .../Data/DataSources/PostgreSQLDataSource.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs index 47968036..161ee1a0 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs @@ -5,6 +5,16 @@ namespace Reveal.Sdk.Dom.Data { public class PostgreSqlDataSourceItem : FunctionDataSourceItem, IProcessDataOnServer { + public PostgreSqlDataSourceItem(string title, string table, PostgreSQLDataSource dataSource) : + this(title, dataSource) + { + Table = table; + } + + public PostgreSqlDataSourceItem(string title, PostgreSQLDataSource dataSource) : + base(title, dataSource) + { } + public PostgreSqlDataSourceItem(string title, DataSource dataSource) : base(title, dataSource) { } @@ -15,5 +25,10 @@ public bool ProcessDataOnServer get => Properties.GetValue("ServerAggregation"); set => Properties.SetItem("ServerAggregation", value); } + + protected override DataSource CreateDataSourceInstance(DataSource dataSource) + { + return Create(dataSource); + } } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSources/PostgreSQLDataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSources/PostgreSQLDataSource.cs index 4a98e8c0..0a07dbdb 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSources/PostgreSQLDataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSources/PostgreSQLDataSource.cs @@ -1,6 +1,6 @@ namespace Reveal.Sdk.Dom.Data { - internal class PostgreSQLDataSource : SchemaDataSource + public class PostgreSQLDataSource : SchemaDataSource { public PostgreSQLDataSource() { From da504ad21b299df3872d0c49de0fd6d0d616ab9d Mon Sep 17 00:00:00 2001 From: Viktor Date: Tue, 26 Nov 2024 14:36:07 +0700 Subject: [PATCH 2/7] Update Postgresql DataSource Item and Unit tests --- .../PostgreSqlDataSourceItemFixture.cs | 78 +++++++++++++++++-- .../Data/DataSourceItemFactory.cs | 1 + .../PostgreSqlDataSourceItem.cs | 20 +++-- .../Data/Enums/DataSourceType.cs | 3 +- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/PostgreSqlDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/PostgreSqlDataSourceItemFixture.cs index abff0791..8072ecb9 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/PostgreSqlDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/PostgreSqlDataSourceItemFixture.cs @@ -7,19 +7,83 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems public class PostgreSqlDataSourceItemFixture { [Theory] - [InlineData("Test Item")] - [InlineData(null)] - public void Constructor_SetsTitleAndDataSource_WhenCalled(string title) + [InlineData("DS Item Title", "DS Item Title", "DS Title", "DS Title")] + [InlineData("DS Item Title", "DS Item Title", null, "DS Item Title")] + public void Constructor_CreatePostgresDSItem_WithTitleAndPostgresDataSource(string dsItemTitle, string expectedDSItemTitle, string dsTitle, string expectedDSTitle) { // Arrange - var dataSource = new PostgreSQLDataSource(); + var dataSource = new PostgreSQLDataSource() { Title = dsTitle}; // Act - var item = new PostgreSqlDataSourceItem(title, dataSource); + var item = new PostgreSqlDataSourceItem(dsItemTitle, dataSource); // Assert - Assert.Equal(title, item.Title); - Assert.Equal(dataSource, item.DataSource); + Assert.Equal(expectedDSItemTitle, item.Title); + Assert.Equal(expectedDSTitle, item.DataSource.Title); + Assert.Equal(dataSource.Id, item.DataSource.Id); + Assert.Equal(dataSource.Id, item.DataSourceId); + } + + [Theory] + [InlineData("DS Item Title", "DS Item Title", "DS Title", "DS Title")] + [InlineData("DS Item Title", "DS Item Title", null, "DS Item Title")] + public void Constructor_CreatePostgresDSItem_WithTitleAndDataSource(string dsItemTitle, string expectedDSItemTitle, string dsTitle, string expectedDSTitle) + { + // Arrange + var dataSource = new DataSource() { Title = dsTitle }; + + // Act + var item = new PostgreSqlDataSourceItem(dsItemTitle, dataSource); + + // Assert + Assert.Equal(expectedDSItemTitle, item.Title); + Assert.Equal(expectedDSTitle, item.DataSource.Title); + Assert.Equal(dataSource.Id, item.DataSource.Id); + Assert.Equal(dataSource.Id, item.DataSourceId); + Assert.IsType(item.DataSource); + Assert.NotSame(dataSource, item.DataSource); + } + + [Theory] + [InlineData("DS Item Title", "DS Item Title", "DS Title", "DS Title")] + [InlineData("DS Item Title", "DS Item Title", null, "DS Item Title")] + public void Constructor_CreatePostgresDSItem_WithCustomTableAndPostgresDataSource(string dsItemTitle, string expectedDSItemTitle, string dsTitle, string expectedDSTitle) + { + // Arrange + var tableName = "Table"; + var dataSource = new PostgreSQLDataSource() { Title = dsTitle}; + + // Act + var postgresDSItem = new PostgreSqlDataSourceItem(dsItemTitle, tableName, dataSource); + + // Assert + Assert.Equal(expectedDSTitle, postgresDSItem.DataSource.Title); + Assert.Equal(expectedDSItemTitle, postgresDSItem.Title); + Assert.Equal(tableName, postgresDSItem.Table); + Assert.Equal(dataSource.Id, postgresDSItem.DataSource.Id); + Assert.Equal(dataSource.Id, postgresDSItem.DataSourceId); + } + + [Theory] + [InlineData("DS Item Title", "DS Item Title", "DS Title", "DS Title")] + [InlineData("DS Item Title", "DS Item Title", null, "DS Item Title")] + public void Constructor_CreatePostgresDSItem_WithCustomTableAndDataSource(string dsItemTitle, string expectedDSItemTitle, string dsTitle, string expectedDSTitle) + { + // Arrange + var tableName = "Table"; + var dataSource = new DataSource() { Title = dsTitle }; + + // Act + var postgresDSItem = new PostgreSqlDataSourceItem(dsItemTitle, tableName, dataSource); + + // Assert + Assert.Equal(expectedDSTitle, postgresDSItem.DataSource.Title); + Assert.Equal(expectedDSItemTitle, postgresDSItem.Title); + Assert.Equal(tableName, postgresDSItem.Table); + Assert.Equal(dataSource.Id, postgresDSItem.DataSource.Id); + Assert.Equal(dataSource.Id, postgresDSItem.DataSourceId); + Assert.IsType(postgresDSItem.DataSource); + Assert.NotSame(dataSource, postgresDSItem.DataSource); } [Fact] diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs index f57fa80e..7cecba34 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs @@ -25,6 +25,7 @@ public DataSourceItem Create(DataSourceType type, string id, string title, strin { DataSourceType.MicrosoftSqlServer => new MicrosoftSqlServerDataSourceItem(title, dataSource), DataSourceType.REST => new RestDataSourceItem(title, dataSource), + DataSourceType.PostgreSQL => new PostgreSqlDataSourceItem(title, dataSource), _ => throw new NotImplementedException($"No builder implemented for provider: {type}") }; diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs index 161ee1a0..5f9d8369 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItems/PostgreSqlDataSourceItem.cs @@ -5,19 +5,25 @@ namespace Reveal.Sdk.Dom.Data { public class PostgreSqlDataSourceItem : FunctionDataSourceItem, IProcessDataOnServer { - public PostgreSqlDataSourceItem(string title, string table, PostgreSQLDataSource dataSource) : - this(title, dataSource) - { - Table = table; - } - public PostgreSqlDataSourceItem(string title, PostgreSQLDataSource dataSource) : base(title, dataSource) { } public PostgreSqlDataSourceItem(string title, DataSource dataSource) : base(title, dataSource) - { } + { } + + public PostgreSqlDataSourceItem(string title, string table, PostgreSQLDataSource dataSource) : + this(title, dataSource) + { + Table = table; + } + + public PostgreSqlDataSourceItem(string title, string table, DataSource dataSource) : + this(title, dataSource) + { + Table = table; + } [JsonIgnore] public bool ProcessDataOnServer diff --git a/src/Reveal.Sdk.Dom/Data/Enums/DataSourceType.cs b/src/Reveal.Sdk.Dom/Data/Enums/DataSourceType.cs index 949210b7..292ef25a 100644 --- a/src/Reveal.Sdk.Dom/Data/Enums/DataSourceType.cs +++ b/src/Reveal.Sdk.Dom/Data/Enums/DataSourceType.cs @@ -3,6 +3,7 @@ public enum DataSourceType { REST, - MicrosoftSqlServer + MicrosoftSqlServer, + PostgreSQL, } } From e61b3627241af69a37093a6826ff9998fc9194f5 Mon Sep 17 00:00:00 2001 From: Viktor Date: Wed, 27 Nov 2024 15:48:47 +0700 Subject: [PATCH 3/7] Update postgresql and fields --- .../PostgreSQLDataSourceFixture.cs | 52 +++++++++++++++++++ src/Reveal.Sdk.Dom/Data/DataSource.cs | 9 +++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/PostgreSQLDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/PostgreSQLDataSourceFixture.cs index 4f887052..5527dd21 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/PostgreSQLDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/PostgreSQLDataSourceFixture.cs @@ -1,5 +1,7 @@ +using Reveal.Sdk.Dom.Core.Serialization; using Reveal.Sdk.Dom.Data; using Xunit; +using Newtonsoft.Json.Linq; namespace Reveal.Sdk.Dom.Tests.Data.DataSources { @@ -14,5 +16,55 @@ public void Constructor_SetsProviderToPostgreSQL_WhenConstructed() // Assert Assert.Equal(DataSourceProvider.PostgreSQL, dataSource.Provider); } + + [Fact] + public void ToJsonString_CreatesFormattedJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceType"", + ""Id"": ""pgSqlId"", + ""Provider"": ""POSTGRES"", + ""Description"": ""Postgres DS"", + ""Subtitle"": ""Northwind Employees"", + ""Properties"": { + ""ServerAggregationDefault"": true, + ""ServerAggregationReadOnly"": true, + ""Host"": ""revealdb01.infragistics.local"", + ""Port"": 5432, + ""Database"": ""northwind"", + ""Schema"": ""public"" + }, + ""Settings"": { + ""DefaultRefreshRate"": 180 + } + }"; + + var dataSource = new PostgreSQLDataSource() + { + Id = "pgSqlId", + Title = "Postgres DS", + Subtitle = "Northwind Employees", + ProcessDataOnServerDefaultValue = true, + ProcessDataOnServerReadOnly = true, + Host = "revealdb01.infragistics.local", + Port = 5432, + Database = "northwind", + Schema = "public", + DefaultRefreshRate = "180", + + }; + + // Act + var json = dataSource.ToJsonString(); + var aJ = RdashSerializer.SerializeObject(dataSource); + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(json); + + // Assert + //JsonConvert.SerializeObject(dataSource, Newtonsoft.Json.Formatting.Indented).JsonEquals(expectedJson); + Assert.Equal(expectedJObject, actualJObject); + + } } } \ No newline at end of file diff --git a/src/Reveal.Sdk.Dom/Data/DataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSource.cs index dbacee6b..bdca5df3 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSource.cs @@ -16,6 +16,7 @@ public DataSource() { SchemaTypeName = SchemaTypeNames.DataSourceType; Properties = new Dictionary(); + Settings = new Dictionary(); } public string Id @@ -33,15 +34,19 @@ public string Id public string Subtitle { get; set; } + [JsonIgnore] public string DefaultRefreshRate { - get => Properties.GetValue("DefaultRefreshRate"); - set => Properties.SetItem("DefaultRefreshRate", value); + get => Settings.GetValue("DefaultRefreshRate"); + set => Settings.SetItem("DefaultRefreshRate", value); } [JsonProperty] internal Dictionary Properties { get; set; } + [JsonProperty] + internal Dictionary Settings { get; set; } + public override bool Equals(object obj) { return Equals(obj as DataSource); From 2d5471f4531628b4e091837d83f5c71dc87b60d0 Mon Sep 17 00:00:00 2001 From: Viktor Date: Wed, 4 Dec 2024 17:48:14 +0700 Subject: [PATCH 4/7] Fix merge conflicts --- .../DashboardCreators/PostgresqlDashboard.cs | 43 +++++++++++ e2e/Sandbox/Helpers/DataSourceFactory.cs | 37 +++++++++ e2e/Sandbox/MainWindow.xaml | 36 ++++----- e2e/Sandbox/MainWindow.xaml.cs | 26 +++++++ e2e/Sandbox/Properties/Settings.Designer.cs | 76 +++++++++---------- e2e/Sandbox/Reveal/AuthenticationProvider.cs | 5 ++ 6 files changed, 167 insertions(+), 56 deletions(-) create mode 100644 e2e/Sandbox/DashboardCreators/PostgresqlDashboard.cs diff --git a/e2e/Sandbox/DashboardCreators/PostgresqlDashboard.cs b/e2e/Sandbox/DashboardCreators/PostgresqlDashboard.cs new file mode 100644 index 00000000..7c8047fd --- /dev/null +++ b/e2e/Sandbox/DashboardCreators/PostgresqlDashboard.cs @@ -0,0 +1,43 @@ +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Filters; +using Reveal.Sdk.Dom.Visualizations; +using Sandbox.Helpers; +using System; + +namespace Sandbox.Factories +{ + internal class PostgresqlDashboard + { + internal static RdashDocument CreateDashboard() + { + var postgresDataSourceItem = PostgresDataSourceFactory.GetEmployeeDSItem(); + + var document = new RdashDocument() + { + Title = "PostgreSQL", + Description = "Example for Postgresql", + UseAutoLayout = false, + }; + + var dateFilter = new DashboardDateFilter("My Date Filter"); + document.Filters.Add(dateFilter); + + var countryFilter = new DashboardDataFilter("Country", postgresDataSourceItem); + document.Filters.Add(countryFilter); + + document.Visualizations.Add(CreateEmployeeReportColumnVisualization(postgresDataSourceItem, countryFilter)); + + return document; + } + + private static Visualization CreateEmployeeReportColumnVisualization(DataSourceItem postgresDSItem, params DashboardFilter[] filters) + { + return new ColumnChartVisualization("Employees report", postgresDSItem) + .SetLabel("ReportsTo") + .SetValue("EmployeeID") + .ConnectDashboardFilters(filters) + .SetPosition(20, 11); + } + } +} diff --git a/e2e/Sandbox/Helpers/DataSourceFactory.cs b/e2e/Sandbox/Helpers/DataSourceFactory.cs index 67711bcf..f3025411 100644 --- a/e2e/Sandbox/Helpers/DataSourceFactory.cs +++ b/e2e/Sandbox/Helpers/DataSourceFactory.cs @@ -211,4 +211,41 @@ internal static List GetOHLCDataSourceFields() }; } } + + internal class PostgresDataSourceFactory + { + static DataSource _postgresDataSource = new PostgreSQLDataSource() + { + Id = "Postgres", + Title = "Postgres Data Source", + Subtitle = "The Data Source for Postgres", + Host = "revealdb01.infragistics.local", + Database = "northwind", + Port = 5432 + }; + + internal static DataSourceItem GetEmployeeDSItem() + { + var employeesDSItem = new PostgreSqlDataSourceItem("Employees", _postgresDataSource) + { + Title = "Postgres Employee", + Subtitle = "Postgres DS Item for Employee", + Database = "northwind", + Table = "employees", + Fields = GetEmployeeColumnFields() + }; + + return employeesDSItem; + } + + internal static List GetEmployeeColumnFields() + { + return new List + { + new NumberField("ReportsTo"), + new NumberField("EmployeeID"), + new TextField("Country"), + }; + } + } } diff --git a/e2e/Sandbox/MainWindow.xaml b/e2e/Sandbox/MainWindow.xaml index a81abd25..c5e615d2 100644 --- a/e2e/Sandbox/MainWindow.xaml +++ b/e2e/Sandbox/MainWindow.xaml @@ -1,18 +1,18 @@ - - - + + + - - - + + @@ -21,10 +21,10 @@ @@ -21,10 +21,10 @@