Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Oracle Datasource #146

Merged
merged 10 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
6 changes: 5 additions & 1 deletion e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Reveal.Sdk.Data.Rest;
using Reveal.Sdk.Data.Snowflake;
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Sandbox.DashboardCreators;
using Sandbox.DashboardFactories;
using Sandbox.RevealSDK;
using System;
Expand Down Expand Up @@ -54,6 +56,7 @@ public partial class MainWindow : Window
new SalesDashboard(),
new SnowflakeDashboard(),
new SqlServerDataSourceDashboards(),
new OracleDataSourceDashboard(),
};

public MainWindow()
Expand All @@ -63,6 +66,7 @@ public MainWindow()
RevealSdkSettings.DataSourceProvider = new DataSourceProvider();
RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider();
RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices().RegisterPostgreSQL();
RevealSdkSettings.DataSources.RegisterOracle();
RevealSdkSettings.DataSources.RegisterSnowflake();

LoadDashboards();
Expand Down Expand Up @@ -180,7 +184,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);

e.Callback(new RevealDataSources(ds, dsi, true));
}
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 @@ -3,6 +3,7 @@
using Reveal.Sdk.Data.Microsoft.SqlServer;
using Reveal.Sdk.Data.Snowflake;
using Reveal.Sdk.Data.PostgreSQL;
using Reveal.Sdk.Data.Oracle;
using System.Threading.Tasks;

namespace Sandbox.RevealSDK
Expand Down Expand Up @@ -32,6 +33,10 @@ public Task<IRVDataSourceCredential> ResolveCredentialsAsync(RVDashboardDataSour
{
userCredential = new RVUsernamePasswordDataSourceCredential("postgres", "postgres");
}
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_ForMySQLDataSource()
brianlagunas marked this conversation as resolved.
Show resolved Hide resolved
{
// 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);
}
}
}
7 changes: 3 additions & 4 deletions src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
<None Update="Dashboards\Sales.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Dashboards\" />
<None Update="Dashboards\TestOracle.rdash">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
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 @@ -26,6 +26,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),
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,5 +5,6 @@ public enum DataSourceType
REST,
MicrosoftSqlServer,
PostgreSQL,
Oracle
brianlagunas marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading