Skip to content

Commit

Permalink
Merge pull request #51 from RevealBi/dsi-refactor
Browse files Browse the repository at this point in the history
refactored parameter order for DSI factory and the DSI classes
  • Loading branch information
brianlagunas authored May 16, 2024
2 parents 5250736 + 0bf6683 commit e4ff473
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 67 deletions.
35 changes: 0 additions & 35 deletions e2e/Sandbox/Factories/CustomDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using Sandbox.Helpers;
using DataSourceFactory = Sandbox.Helpers.DataSourceFactory;

namespace Sandbox.Factories
{
Expand All @@ -12,15 +11,6 @@ internal static RdashDocument CreateDashboard()
{
var factory = new DataSourceItemFactory();

//var excelDataSourceItem = factory.Create(DataSourceType.REST, "Marketing Sheet")
// .SetSubtitle("Excel Data Source Item")
// .SetFields(DataSourceFactory.GetMarketingDataSourceFields())
// .As<RestDataSourceItem>()
// .Uri("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx")
// .IsAnonymous(true)
// .UseExcel("Marketing")
// .Build();

var excelDataSourceItem = new RestDataSourceItem("Marketing Sheet")
{
Subtitle = "Excel Data Source Item",
Expand All @@ -30,15 +20,6 @@ internal static RdashDocument CreateDashboard()
};
excelDataSourceItem.UseExcel("Marketing");

//var csvDataSourceItem = factory.Create(DataSourceType.REST, "Illinois School Info")
// .SetSubtitle("CSV Data Source Item")
// .SetFields(DataSourceFactory.GetCsvDataSourceFields())
// .As<RestDataSourceItem>()
// .Uri("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto")
// .IsAnonymous(true)
// .UseCsv()
// .Build();

var csvDataSourceItem = new RestDataSourceItem("Illinois School Info")
{
Subtitle = "CSV Data Source Item",
Expand All @@ -48,14 +29,6 @@ internal static RdashDocument CreateDashboard()
};
csvDataSourceItem.UseCsv();

//var financialDataSourceItem = factory.Create(DataSourceType.REST, "OHLC")
// .SetSubtitle("Financial Data Source Item")
// .SetFields(DataSourceFactory.GetOHLCDataSourceFields())
// .As<RestDataSourceItem>()
// .Uri("https://excel2json.io/api/share/8bb2cd78-1b87-4142-00a2-08da188ec9ab")
// .IsAnonymous(true)
// .Build();

var financialDataSourceItem = new RestDataSourceItem("OHLC")
{
Subtitle = "Financial Data Source Item",
Expand All @@ -64,14 +37,6 @@ internal static RdashDocument CreateDashboard()
Fields = DataSourceFactory.GetOHLCDataSourceFields(),
};

//var revenueDataSourceItem = factory.Create(DataSourceType.REST, "Revenue")
// .SetSubtitle("Choropleth Data Source Item")
// .SetFields(DataSourceFactory.GetRevenueDataSourceFields())
// .As<RestDataSourceItem>()
// .Uri("https://excel2json.io/api/share/818e7b9a-f463-4565-435d-08da496bf5f2")
// .IsAnonymous(true)
// .Build();

var revenueDataSourceItem = new RestDataSourceItem("Revenue")
{
Subtitle = "Choropleth Data Source Item",
Expand Down
6 changes: 3 additions & 3 deletions e2e/Sandbox/Factories/RestDataSourceDashboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static RdashDocument CreateDashboard()
var document = new RdashDocument("My Dashboard");

//json - default
var jsonDataSourceItem = new RestDataSourceItem(new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" },"Sales by Category")
var jsonDataSourceItem = new RestDataSourceItem("Sales by Category", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" })
{
Id = "TESTING",
Subtitle = "JSON Data Source Item",
Expand All @@ -25,7 +25,7 @@ internal static RdashDocument CreateDashboard()
.SetLabel("CategoryName").SetValue("ProductSales"));

//excel
var excelDataSourceItem = new RestDataSourceItem(new DataSource { Title = "Excel DS", Subtitle = "Excel DS Subtitle" }, "Marketing")
RestDataSourceItem excelDataSourceItem = new RestDataSourceItem("Marketing", new DataSource { Title = "Excel DS", Subtitle = "Excel DS Subtitle" })
{
Subtitle = "Excel Data Source Item",
Uri = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx",
Expand All @@ -38,7 +38,7 @@ internal static RdashDocument CreateDashboard()
.SetLabel("Territory").SetValue("Conversions"));

//csv
var csvDataSourceItem = new RestDataSourceItem(new DataSource { Title = "CSV DS", Subtitle = "CSV DS Subtitle" }, "Illinois School Info")
var csvDataSourceItem = new RestDataSourceItem("Illinois School Info", new DataSource { Title = "CSV DS", Subtitle = "CSV DS Subtitle" })
{
Subtitle = "CSV Data Source Item",
Uri = "https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto",
Expand Down
8 changes: 4 additions & 4 deletions e2e/Sandbox/Helpers/DataSourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class DataSourceFactory

internal static DataSourceItem GetMarketingDataSourceItem()
{
var excelDataSourceItem = new RestDataSourceItem(_excelDataSource, "Marketing")
var excelDataSourceItem = new RestDataSourceItem("Marketing", _excelDataSource)
{
Subtitle = "Excel Data Source Item",
Uri = _restExcelUri,
Expand All @@ -32,7 +32,7 @@ internal static DataSourceItem GetMarketingDataSourceItem()

internal static DataSourceItem GetHealthcareDataSourceItem()
{
var excelDataSourceItem = new RestDataSourceItem(_excelDataSource, "Healthcare")
var excelDataSourceItem = new RestDataSourceItem("Healthcare", _excelDataSource)
{
Subtitle = "Excel Data Source Item",
Uri = _restExcelUri,
Expand All @@ -46,7 +46,7 @@ internal static DataSourceItem GetHealthcareDataSourceItem()

internal static DataSourceItem GetManufacturingDataSourceItem()
{
var excelDataSourceItem = new RestDataSourceItem(_excelDataSource, "Manufacturing")
var excelDataSourceItem = new RestDataSourceItem("Manufacturing", _excelDataSource)
{
Subtitle = "Excel Data Source Item",
Uri = _restExcelUri,
Expand All @@ -60,7 +60,7 @@ internal static DataSourceItem GetManufacturingDataSourceItem()

internal static DataSourceItem GetSalesDataSourceItem()
{
var excelDataSourceItem = new RestDataSourceItem(_excelDataSource, "Sales")
var excelDataSourceItem = new RestDataSourceItem("Sales", _excelDataSource)
{
Subtitle = "Excel Data Source Item",
Uri = _restExcelUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RdashDocumentValidatorFixture
[Fact]
public void DataSources_AddedToRdashDocument()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });

var document = new RdashDocument();
document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));
Expand All @@ -27,7 +27,7 @@ public void DataSources_AddedToRdashDocument()
[Fact]
public void DataSources_FromVisualizationsAreNotDuplicated()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });

var document = new RdashDocument();
document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));
Expand All @@ -47,7 +47,7 @@ public void DataSources_FromVisualizationsAreNotDuplicated()
[Fact]
public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });
var dataSource = dataSourceItem.DataSource;

var document = new RdashDocument();
Expand Down
73 changes: 73 additions & 0 deletions src/Reveal.Sdk.Dom.Tests/Data/DataSourceItemFactoryFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Reveal.Sdk.Dom.Data;
using System;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data
{
public class DataSourceItemFactoryFixture
{
[Fact]
public void Create_ShouldReturnDataSourceItem_WithDefaultDataSource()
{
// Arrange
var factory = new DataSourceItemFactory();
var type = DataSourceType.MicrosoftSqlServer;
var id = "1";
var title = "Test Title";

// Act
var result = factory.Create(type, id, title);

// Assert
Assert.NotNull(result);
Assert.IsType<MicrosoftSqlServerDataSourceItem>(result);
Assert.Equal(id, result.Id);
Assert.Equal(title, result.Title);
Assert.Null(result.Subtitle);
Assert.NotNull(result.DataSource);
Assert.IsType<DataSource>(result.DataSource);
}

[Fact]
public void Create_ShouldReturnDataSourceItem_WithCustomDataSource()
{
// Arrange
var factory = new DataSourceItemFactory();
var type = DataSourceType.MicrosoftSqlServer;
var id = "2";
var title = "Test Title";
var subtitle = "Test Subtitle";
var dataSource = new DataSource()
{
Id = "CustomId",
Title = "Custom Title",
Subtitle = "Custom Subtitle",
};

// Act
var result = factory.Create(type, id, title, subtitle, dataSource);

// Assert
Assert.NotNull(result);
Assert.IsType<MicrosoftSqlServerDataSourceItem>(result);
Assert.Equal(id, result.Id);
Assert.Equal(title, result.Title);
Assert.Equal(subtitle, result.Subtitle);
Assert.NotNull(result.DataSource);
Assert.Same(dataSource, result.DataSource);
}

[Fact]
public void Create_ShouldThrowNotImplementedException_WhenUnknownType()
{
// Arrange
var factory = new DataSourceItemFactory();
var type = (DataSourceType)99;
var id = "3";
var title = "Test Title";

// Act & Assert
Assert.Throws<NotImplementedException>(() => factory.Create(type, id, title));
}
}
}
4 changes: 2 additions & 2 deletions src/Reveal.Sdk.Dom.Tests/Data/RestDataSourceItemFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void DataSource_Properties_Should_Set_ResourceItemDataSource_Properties()
{
// Arrange
var dataSource = new DataSource() { Id = "DS-ID", Title = "DS-TITLE", Subtitle = "DS-SUBTITLE" };
var dataSourceItem = new RestDataSourceItem(dataSource, "Test");
var dataSourceItem = new RestDataSourceItem("Test", dataSource);

// Assert
Assert.Equal(dataSource.Id, dataSourceItem.ResourceItemDataSource.Id);
Expand All @@ -305,7 +305,7 @@ public void DataSource_No_Title_Or_Subtitle_Should_Use_ResourceItem_Title_Or_Sub
{
// Arrange
var dataSource = new DataSource();
var dataSourceItem = new RestDataSourceItem(dataSource, "Test");
var dataSourceItem = new RestDataSourceItem("Test", dataSource);

// Assert
Assert.Equal(dataSourceItem.ResourceItemDataSource.Title, dataSourceItem.ResourceItem.Title);
Expand Down
4 changes: 2 additions & 2 deletions src/Reveal.Sdk.Dom.Tests/RdashDocumentFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void RdashDocument_TitleConstructor_ShouldSetTitle()
public void RdashDocument_Import_ShouldImportVisualizations()
{
// Arrange
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });

var sourceDocument = new RdashDocument();
sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));
Expand All @@ -79,7 +79,7 @@ public void RdashDocument_Import_ShouldImportVisualizations()
public void RdashDocument_Import_ShouldImportSingleVisualization()
{
// Arrange
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });

var sourceDocument = new RdashDocument();
sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));
Expand Down
2 changes: 1 addition & 1 deletion src/Reveal.Sdk.Dom/Data/DataSourceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Reveal.Sdk.Dom.Data
{
public class DataSourceItem : SchemaType
{
public DataSourceItem(DataSource dataSource, string title) : this()
public DataSourceItem(string title, DataSource dataSource) : this()
{
InitializeDataSource(dataSource, title);
InitializeDataSourceItem(title);
Expand Down
31 changes: 19 additions & 12 deletions src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

namespace Reveal.Sdk.Dom.Data
{
public interface IDataSourceItemFactory
public class DataSourceItemFactory : IDataSourceItemFactory
{
DataSourceItem Create(DataSourceType type, string title);
public DataSourceItem Create(DataSourceType type, string id, string title)
{
return Create(type, id, title, new DataSource());
}

DataSourceItem Create(DataSourceType type, DataSource dataSource, string title);
}
public DataSourceItem Create(DataSourceType type, string id, string title, DataSource dataSource)
{
return Create(type, id, title, null, dataSource);
}

public class DataSourceItemFactory : IDataSourceItemFactory
{
public DataSourceItem Create(DataSourceType type, string title)
public DataSourceItem Create(DataSourceType type, string id, string title, string subtitle)
{
return Create(type, new DataSource(), title);
return Create(type, id, title, subtitle, new DataSource());
}

public DataSourceItem Create(DataSourceType type, DataSource dataSource, string title)
public DataSourceItem Create(DataSourceType type, string id, string title, string subtitle, DataSource dataSource)
{
return type switch
DataSourceItem item = type switch
{
DataSourceType.MicrosoftSqlServer => new MicrosoftSqlServerDataSourceItem(dataSource, title),
DataSourceType.REST => new RestDataSourceItem(dataSource, title),
DataSourceType.MicrosoftSqlServer => new MicrosoftSqlServerDataSourceItem(title, dataSource),
DataSourceType.REST => new RestDataSourceItem(title, dataSource),
_ => throw new NotImplementedException($"No builder implemented for provider: {type}")
};

item.Id = id;
item.Subtitle = subtitle;
return item;
}
}
}
13 changes: 13 additions & 0 deletions src/Reveal.Sdk.Dom/Data/Interfaces/IDataSourceItemFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Reveal.Sdk.Dom.Data
{
public interface IDataSourceItemFactory
{
DataSourceItem Create(DataSourceType type, string id, string title);

DataSourceItem Create(DataSourceType type, string id, string title, string subtitle);

DataSourceItem Create(DataSourceType type, string id, string title, DataSource dataSource);

DataSourceItem Create(DataSourceType type, string id, string title, string subtitle, DataSource dataSource);
}
}
6 changes: 3 additions & 3 deletions src/Reveal.Sdk.Dom/Data/MicrosoftSqlServerDataSourceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Reveal.Sdk.Dom.Data
public class MicrosoftSqlServerDataSourceItem : DataSourceItem
{
public MicrosoftSqlServerDataSourceItem(string title) :
this(new DataSource(), title)
base(title, new DataSource())
{ }

public MicrosoftSqlServerDataSourceItem(DataSource dataSource, string title) :
base(dataSource, title)
public MicrosoftSqlServerDataSourceItem(string title, DataSource dataSource) :
base(title, dataSource)
{ }

public string Database
Expand Down
6 changes: 4 additions & 2 deletions src/Reveal.Sdk.Dom/Data/RestDataSourceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class RestDataSourceItem : DataSourceItem
{
DataSource _dataSource;

public RestDataSourceItem(string title) : this(new DataSource(), title)
public RestDataSourceItem(string title) :
this(title, new DataSource())
{ }

public RestDataSourceItem(DataSource dataSource, string title) : base(null, title)
public RestDataSourceItem(string title, DataSource dataSource) :
base(title, null)
{
_dataSource = dataSource ?? new DataSource();
InitializeResourceItem(DataSourceProvider.REST, title);
Expand Down

0 comments on commit e4ff473

Please sign in to comment.