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

Implement crystal reports viewer master #2038

Merged
merged 2 commits into from Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions backend/Origam.BI.CrystalReports.NetFx/CrystalReportService.cs
Expand Up @@ -44,8 +44,6 @@ public CrystalReportService()
{
}

#region IReportService Members

public void PrintReport(Guid reportId, IXmlContainer data, string printerName, int copies, Hashtable parameters)
{
var report = ReportHelper.GetReportElement<CrystalReport>(reportId);
Expand Down Expand Up @@ -151,6 +149,12 @@ public void SetTraceTaskInfo(TraceTaskInfo traceTaskInfo)
{
// do nothing unless we need to trace
}
#endregion

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format, Hashtable parameters,
string dbTransaction)
{
throw new NotImplementedException();
}
}
}
21 changes: 21 additions & 0 deletions backend/Origam.BI.CrystalReports/CrystalReportHelper.cs
Expand Up @@ -82,6 +82,27 @@ private void TraceReportData(DataSet data, string reportName)
throw new Exception("Invalid data returned. Expected byte array.");
}

public string PrepareReport(CrystalReport report, DataSet data,
Hashtable parameters, string format)
{
// get report model element
parameters = PrepareParameters(data, parameters, report);
// get report
object result = SendReportRequest("Report/PrepareViewer",
report.ReportFileName, data, parameters, report, "");
if (result is Origam.Service.Core.XmlContainer xml)
{
var innerXml = xml.Xml.InnerXml;
var settings = ConfigurationManager.GetActiveConfiguration();
string baseUrl = ParseConnectionString(
settings.ReportConnectionString, out int? timeout);
string id = xml.Xml["ROOT"]["ViewerUrl"].InnerText;
string url = baseUrl + $"ViewReport.aspx?Id={id}";
return url;
}
throw new Exception("Invalid data returned. Expected byte array.");
}

public void PrintReport(Guid reportId, DataSet data,
Hashtable parameters, string printerName, int copies)
{
Expand Down
19 changes: 19 additions & 0 deletions backend/Origam.BI.CrystalReports/CrystalReportService.cs
Expand Up @@ -76,6 +76,25 @@ public void SetTraceTaskInfo(TraceTaskInfo traceTaskInfo)
{
// do nothing unless we need to trace
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format, Hashtable parameters,
string dbTransaction)
{
var report = ReportHelper.GetReportElement<CrystalReport>(
reportId);
var xmlDataDoc = ReportHelper
.LoadOrUseReportData(report, data, parameters, dbTransaction);
using (var langSwitcher = new LanguageSwitcher(
ReportHelper.ResolveLanguage(xmlDataDoc, report)))
{
ReportHelper.LogInfo(System.Reflection.MethodBase
.GetCurrentMethod().DeclaringType,
"Exporting report '" + report.Name + "' to " + format);
return _helper.PrepareReport(report, xmlDataDoc.DataSet,
parameters, DataReportExportFormatType.RPT.ToString());
}
}
#endregion
}
}
7 changes: 7 additions & 0 deletions backend/Origam.BI.Excel/ExcelService.cs
Expand Up @@ -282,5 +282,12 @@ public void SetTraceTaskInfo(TraceTaskInfo traceTaskInfo)
{
// do nothing unless we want something to trace
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format, Hashtable parameters,
string dbTransaction)
{
throw new NotImplementedException();
}
}
}
7 changes: 7 additions & 0 deletions backend/Origam.BI.FastReport/FastReportService.cs
Expand Up @@ -89,6 +89,13 @@ OrigamSettings settings
}
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format, Hashtable parameters,
string dbTransaction)
{
throw new NotImplementedException();
}

public void PrintReport(Guid reportId, IXmlContainer data, string printerName, int copies, Hashtable parameters)
{
throw new NotImplementedException();
Expand Down
7 changes: 7 additions & 0 deletions backend/Origam.BI.PrintIt/PrintItService.cs
Expand Up @@ -126,5 +126,12 @@ public void SetTraceTaskInfo(TraceTaskInfo traceTaskInfo)
{
// do nothing unless we need to trace something
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format,
Hashtable parameters, string dbTransaction)
{
throw new NotImplementedException();
}
}
}
7 changes: 7 additions & 0 deletions backend/Origam.BI.SSRS.NetFx/SSRSService.cs
Expand Up @@ -126,5 +126,12 @@ public void SetTraceTaskInfo(TraceTaskInfo traceTaskInfo)
{
this.traceTaskInfo = traceTaskInfo;
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format,
Hashtable parameters, string dbTransaction)
{
throw new NotImplementedException();
}
}
}
7 changes: 7 additions & 0 deletions backend/Origam.BI.SSRS/SSRSService.cs
Expand Up @@ -158,6 +158,13 @@ public void SetTraceTaskInfo(TraceTaskInfo value)
{
this.traceTaskInfo = value;
}

public string PrepareExternalReportViewer(Guid reportId,
IXmlContainer data, string format, Hashtable parameters,
string dbTransaction)
{
throw new NotImplementedException();
}
}

internal class ReportingServicesEndpointBehavior : IEndpointBehavior
Expand Down
3 changes: 3 additions & 0 deletions backend/Origam.BI/IReportService.cs
Expand Up @@ -33,5 +33,8 @@ public interface IReportService : ITraceInfoContainer
{
void PrintReport(Guid reportId, IXmlContainer data, string printerName, int copies, Hashtable parameters);
object GetReport(Guid reportId, IXmlContainer data, string format, Hashtable parameters, string dbTransaction);
// Prepare report and return an external web report url with exteranl report viewer
string PrepareExternalReportViewer(Guid reportId, IXmlContainer data,
string format, Hashtable parameters, string dbTransaction);
}
}
Expand Up @@ -32,6 +32,8 @@ public enum DataReportExportFormatType
, CSV = 5
, TEXT = 6
, XML = 7
, RPT = 8
, ExternalViewer = 9
}

public static class DataReportExportFormatTypeExtensions
Expand All @@ -46,6 +48,8 @@ public static class DataReportExportFormatTypeExtensions
, "text/csv"
, "text/plain"
, "text/xml"
, "application/rpt"
, null
};

private static readonly string[] extensions =
Expand All @@ -58,6 +62,8 @@ public static class DataReportExportFormatTypeExtensions
, "csv"
, "txt"
, "xml"
, "rpt"
, null
};

public static string GetString(this DataReportExportFormatType value)
Expand All @@ -67,12 +73,18 @@ public static string GetString(this DataReportExportFormatType value)

public static string GetContentType(this DataReportExportFormatType value)
{
return contentTypes[(int)value];
return contentTypes[(int)value] == null ? throw new
OrigamException("There isn't a content type" +
" defined for the DataReportExportFormatType")
: contentTypes[(int)value];
}

public static string GetExtension(this DataReportExportFormatType value)
{
return extensions[(int)value];
return extensions[(int)value] == null ? throw new
OrigamException("There isn't a file extension" +
" defined for the DataReportExportFormatType")
: extensions[(int)value];
}
}
}
24 changes: 24 additions & 0 deletions backend/Origam.Server/Controller/ReportController.cs
Expand Up @@ -20,18 +20,22 @@
#endregion

using System;
using System.Collections;
using System.IO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Origam.BI;
using Origam.BI.CrystalReports;
using Origam.CrystalReportsService.Models;
using Origam.Schema;
using Origam.Schema.GuiModel;
using Origam.Server.Model.Report;
using Origam.Workbench.Services;
using Origam.Workbench.Services.CoreServices;
using Origam.Workflow;

namespace Origam.Server.Controller
{
Expand Down Expand Up @@ -75,6 +79,15 @@ public IActionResult Get(Guid reportRequestId)
{
if(report != null)
{
if (reportRequest.DataReportExportFormatType
== DataReportExportFormatType.ExternalViewer)
{
return HandleReportWithExternalViewer(
new Guid(reportRequest.ReportId),
report, reportRequest.Parameters);
}
// handle all other report by running
// report service agent's GetReport method
return HandleReport(reportRequest, report.Name);
}
return NotFound(localizer["ErrorReportNotAvailable"]
Expand All @@ -91,6 +104,17 @@ public IActionResult Get(Guid reportRequestId)
RemoveRequest(reportRequestId);
}
}

private IActionResult HandleReportWithExternalViewer(Guid reportId,
AbstractReport report, Hashtable parameters)
{
var reportService = ReportServiceAgent.GetService(report);
string url = reportService.PrepareExternalReportViewer(reportId,
null, DataReportExportFormatType.ExternalViewer.ToString(),
parameters, null);
return Redirect(url);
}

[HttpGet("[action]")]
public IActionResult GetReportInfo(Guid reportRequestId)
{
Expand Down
Expand Up @@ -65,7 +65,7 @@ private static AbstractReport GetReport(Guid reportId)
return report;
}

private static IReportService GetService(AbstractReport report)
public static IReportService GetService(AbstractReport report)
{
string serviceName;
if (report is CrystalReport)
Expand Down