Skip to content

Commit

Permalink
Merge pull request #146 from RevealBi/data-soruce/oracle
Browse files Browse the repository at this point in the history
Update Oracle Datasource
  • Loading branch information
brianlagunas authored Dec 12, 2024
2 parents d3f58c7 + 503bf69 commit af3ab6f
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 3 deletions.
70 changes: 70 additions & 0 deletions e2e/Sandbox/DashboardCreators/OracleDataSourceDashboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Reveal.Sdk.Data.MySql;
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Filters;
using Reveal.Sdk.Dom.Visualizations;
using Sandbox.DashboardFactories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Antlr4.Runtime.Atn.SemanticContext;

namespace Sandbox.DashboardCreators
{
public class OracleDataSourceDashboard : IDashboardCreator
{
public string Name => "Oracle Data Source";

public RdashDocument CreateDashboard()
{
var oracleDataSource = new OracleDataSource
{
Id = "oracleSIDId",
Title = "Oracle SID DS",
Subtitle = "Oracle SID Datasource",
Host = "revealdb01.infragistics.local",
Database = "HR",
SID = "orcl",
Port = 1521
};

var oracleDataSourceItem = new OracleDataSourceItem("employees report to ID", oracleDataSource)
{
Id = "oracleSIDDSItemId",
Title = "Oracle SID DSItem",
Database = "HR",
Table = "EMPLOYEES",
Fields = new List<IField>
{
new NumberField("MANAGER_ID"),
new NumberField("EMPLOYEE_ID"),
}
};

var document = new RdashDocument()
{
Title = "Oracle",
Description = "Example for Oracle",
UseAutoLayout = false,
};

var dateFilter = new DashboardDateFilter("My Date Filter");
document.Filters.Add(dateFilter);

document.Visualizations.Add(CreateEmployeeReportColumnVisualization(oracleDataSourceItem));

return document;
}

private static Visualization CreateEmployeeReportColumnVisualization(DataSourceItem dsi, params DashboardFilter[] filters)
{
return new ColumnChartVisualization("Employees report", dsi)
.SetLabel("MANAGER_ID")
.SetValue("EMPLOYEE_ID")
.ConnectDashboardFilters(filters)
.SetPosition(20, 11);
}
}
}
3 changes: 2 additions & 1 deletion e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public partial class MainWindow : Window
new SalesDashboard(),
new SnowflakeDashboard(),
new SqlServerDataSourceDashboards(),
new OracleDataSourceDashboard(),
new WebServiceDataSourceDashboard(),
};

Expand Down Expand Up @@ -213,7 +214,7 @@ private void RevealView_DataSourcesRequested(object sender, DataSourcesRequested
//httpItem.Title = "HTTP Analysis Services Item";
//httpItem.Subtitle = "HTTP Analysis Services Item Subtitle";
//httpItem.Cube = "Adventure Works";
//dsi.Add(httpItem);
//dsi.Add(httpItem);

//var mysqlDS = new RVMySqlDataSource
//{
Expand Down
5 changes: 5 additions & 0 deletions e2e/Sandbox/Reveal/AuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Reveal.Sdk.Data.Snowflake;
using Reveal.Sdk.Data.MySql;
using Reveal.Sdk.Data.PostgreSQL;
using Reveal.Sdk.Data.Oracle;
using System.Threading.Tasks;
using Reveal.Sdk.Data.Amazon.Redshift;
using Reveal.Sdk.Data.Google.Analytics4;
Expand Down Expand Up @@ -115,6 +116,10 @@ public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSour

}

else if (dataSource is RVOracleDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("username", "password");
}
return Task.FromResult(userCredential);
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
using Reveal.Sdk.Dom.Data;
using System.IO;
using System.Linq;
using System;
using Xunit;
using Reveal.Sdk.Dom.Core.Extensions;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Reveal.Sdk.Dom.Visualizations;
using Reveal.Sdk.Dom.Core.Serialization;

namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
{
Expand All @@ -20,5 +28,91 @@ public void Constructor_SetsTitleAndDataSource_WhenCalled(string title)
Assert.Equal(title, item.Title);
Assert.Equal(dataSource, item.DataSource);
}

[Fact]
public void RDashDocument_HasCorrectDataSourceItem_WhenLoadFromFile()
{
// Arrange
var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestOracle.rdash");

// Act
var document = RdashDocument.Load(filePath);
var dataSource = document.DataSources.FirstOrDefault();
var dataSourceItem = document.Visualizations.FirstOrDefault().DataDefinition.DataSourceItem;

// Assert
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Equal(DataSourceProvider.Oracle, dataSource.Provider);
Assert.NotNull(dataSourceItem.Properties.GetValue<string>("Table"));
Assert.NotNull(dataSourceItem.Properties.GetValue<string>("Database"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_ForOracleDataSource()
{
// Arrange
var expectedJson =
"""
{
"_type": "DataSourceItemType",
"Id": "oracleSIDDSItemId",
"Title": "Oracle SID DSItem",
"DataSourceId": "oracleSIDId",
"HasTabularData": true,
"HasAsset": false,
"Properties": {
"Database": "HR",
"Table": "EMPLOYEES"
},
"Parameters": {}
}
""";

var oracleDataSource = new OracleDataSource
{
Id = "oracleSIDId",
Title = "Oracle SID DS",
Subtitle = "Oracle SID Datasource",
Host = "revealdb01.infragistics.local",
Database = "HR",
SID = "orcl",
Port = 1521
};

var oracleDataSourceItem = new OracleDataSourceItem("employees report to ID", oracleDataSource)
{
Id = "oracleSIDDSItemId",
Title = "Oracle SID DSItem",
Database = "HR",
Table = "EMPLOYEES",
Fields = new List<IField>
{
new NumberField("MANAGER_ID"),
new NumberField("EMPLOYEE_ID"),
}
};

var document = new RdashDocument()
{
Title = "Oracle",
Description = "Example for Oracle",
UseAutoLayout = false,
};

document.Visualizations.Add(new ColumnChartVisualization("Employees report", oracleDataSourceItem)
.SetLabel("MANAGER_ID")
.SetValue("EMPLOYEE_ID")
.SetPosition(20, 11));
var expectedJObject = JObject.Parse(expectedJson);

// Act
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["Widgets"][0]["DataSpec"]["DataSourceItem"];

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using System.IO;
using System.Linq;
using System;
using Xunit;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Reveal.Sdk.Dom.Visualizations;
using Reveal.Sdk.Dom.Core.Serialization;

namespace Reveal.Sdk.Dom.Tests.Data.DataSources
{
Expand Down Expand Up @@ -47,5 +54,92 @@ public void SID_SetsAndGetsValue_WithDifferentInputs(string sid)
Assert.Equal(sid, dataSource.SID);
Assert.Equal(sid, dataSource.Properties.GetValue<string>("SID"));
}

[Fact]
public void RDashDocument_HasCorrectDataSource_WhenLoadFromFile()
{
// Arrange
var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestOracle.rdash");

// Act
var document = RdashDocument.Load(filePath);
var dataSource = document.DataSources.FirstOrDefault();

// Assert
Assert.Equal(DataSourceProvider.Oracle, dataSource.Provider);
Assert.NotNull(dataSource.Properties.GetValue<string>("Host"));
Assert.NotNull(dataSource.Properties.GetValue<string>("Database"));
Assert.NotNull(dataSource.Properties.GetValue<string>("SID"));
Assert.NotNull(dataSource.Properties.GetValue<string>("Port"));
}

[Fact]
public void ToJsonString_CreatesFormattedJson_ForOracleDataSource()
{
// Arrange
var expectedJson =
"""
{
"_type": "DataSourceType",
"Id": "oracleSIDId",
"Provider": "ORACLE",
"Description": "Oracle SID DS",
"Subtitle": "Oracle SID Datasource",
"Properties": {
"Host": "revealdb01.infragistics.local",
"Database": "HR",
"SID": "orcl",
"Port": 1521
},
"Settings": {}
}
""";

var oracleDataSource = new OracleDataSource
{
Id = "oracleSIDId",
Title = "Oracle SID DS",
Subtitle = "Oracle SID Datasource",
Host = "revealdb01.infragistics.local",
Database = "HR",
SID = "orcl",
Port = 1521
};

var oracleDataSourceItem = new OracleDataSourceItem("employees report to ID", oracleDataSource)
{
Id = "oracleSIDDSItemId",
Title = "Oracle SID DSItem",
Database = "HR",
Table = "EMPLOYEES",
Fields = new List<IField>
{
new NumberField("MANAGER_ID"),
new NumberField("EMPLOYEE_ID"),
}
};

var document = new RdashDocument()
{
Title = "Oracle",
Description = "Example for Oracle",
UseAutoLayout = false,
};

document.Visualizations.Add(new ColumnChartVisualization("Employees report", oracleDataSourceItem)
.SetLabel("MANAGER_ID")
.SetValue("EMPLOYEE_ID")
.SetPosition(20, 11));
var expectedJObject = JObject.Parse(expectedJson);

// Act
RdashSerializer.SerializeObject(document);
var json = document.ToJsonString();
var jObject = JObject.Parse(json);
var actualJObject = jObject["DataSources"].FirstOrDefault();

// Assert
Assert.Equal(expectedJObject, actualJObject);
}
}
}
3 changes: 3 additions & 0 deletions src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<None Update="Dashboards\Sales.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Dashboards\TestOracle.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Dashboards\TestGoogleSheet.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public DataSourceItem Create(DataSourceType type, string id, string title, strin
DataSourceType.REST => new RestDataSourceItem(title, dataSource),
DataSourceType.MySql => new MySqlDataSourceItem(title, dataSource),
DataSourceType.PostgreSQL => new PostgreSqlDataSourceItem(title, dataSource),
DataSourceType.Oracle => new OracleDataSourceItem(title, dataSource),
_ => throw new NotImplementedException($"No builder implemented for provider: {type}")
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
namespace Reveal.Sdk.Dom.Data
{
internal class OracleDataSourceItem : ProcedureDataSourceItem
public class OracleDataSourceItem : ProcedureDataSourceItem
{
public OracleDataSourceItem(string title, DataSource dataSource) :
base(title, dataSource)
{ }

protected override DataSource CreateDataSourceInstance(DataSource dataSource)
{
return Create<OracleDataSource>(dataSource);
}
}
}
2 changes: 1 addition & 1 deletion src/Reveal.Sdk.Dom/Data/DataSources/OracleDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Reveal.Sdk.Dom.Data
{
internal class OracleDataSource : HostDataSource
public class OracleDataSource : HostDataSource
{
public OracleDataSource()
{
Expand Down
1 change: 1 addition & 0 deletions src/Reveal.Sdk.Dom/Data/Enums/DataSourceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum DataSourceType
REST,
MicrosoftSqlServer,
MySql,
Oracle,
PostgreSQL,
}
}

0 comments on commit af3ab6f

Please sign in to comment.