diff --git a/backend/Origam.BI.CrystalReports.NetFx/CrystalReportService.cs b/backend/Origam.BI.CrystalReports.NetFx/CrystalReportService.cs index 5beaf790d6..04b045008b 100644 --- a/backend/Origam.BI.CrystalReports.NetFx/CrystalReportService.cs +++ b/backend/Origam.BI.CrystalReports.NetFx/CrystalReportService.cs @@ -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(reportId); @@ -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(); + } } } diff --git a/backend/Origam.BI.CrystalReports/CrystalReportHelper.cs b/backend/Origam.BI.CrystalReports/CrystalReportHelper.cs index b327c61e01..c65a8ebea1 100644 --- a/backend/Origam.BI.CrystalReports/CrystalReportHelper.cs +++ b/backend/Origam.BI.CrystalReports/CrystalReportHelper.cs @@ -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) { diff --git a/backend/Origam.BI.CrystalReports/CrystalReportService.cs b/backend/Origam.BI.CrystalReports/CrystalReportService.cs index 3d93e3587c..d6a60f8d6f 100644 --- a/backend/Origam.BI.CrystalReports/CrystalReportService.cs +++ b/backend/Origam.BI.CrystalReports/CrystalReportService.cs @@ -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( + 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 } } diff --git a/backend/Origam.BI.Excel/ExcelService.cs b/backend/Origam.BI.Excel/ExcelService.cs index 8983aa84c0..644f968cc9 100644 --- a/backend/Origam.BI.Excel/ExcelService.cs +++ b/backend/Origam.BI.Excel/ExcelService.cs @@ -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(); + } } } diff --git a/backend/Origam.BI.FastReport/FastReportService.cs b/backend/Origam.BI.FastReport/FastReportService.cs index 5ea6960ed7..df5d25a120 100644 --- a/backend/Origam.BI.FastReport/FastReportService.cs +++ b/backend/Origam.BI.FastReport/FastReportService.cs @@ -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(); diff --git a/backend/Origam.BI.PrintIt/PrintItService.cs b/backend/Origam.BI.PrintIt/PrintItService.cs index 3e95afa94a..32a1e9e6cc 100644 --- a/backend/Origam.BI.PrintIt/PrintItService.cs +++ b/backend/Origam.BI.PrintIt/PrintItService.cs @@ -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(); + } } } diff --git a/backend/Origam.BI.SSRS.NetFx/SSRSService.cs b/backend/Origam.BI.SSRS.NetFx/SSRSService.cs index d9b282b0f2..49610e67d2 100644 --- a/backend/Origam.BI.SSRS.NetFx/SSRSService.cs +++ b/backend/Origam.BI.SSRS.NetFx/SSRSService.cs @@ -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(); + } } } diff --git a/backend/Origam.BI.SSRS/SSRSService.cs b/backend/Origam.BI.SSRS/SSRSService.cs index e69e2e5077..54de08ae35 100644 --- a/backend/Origam.BI.SSRS/SSRSService.cs +++ b/backend/Origam.BI.SSRS/SSRSService.cs @@ -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 diff --git a/backend/Origam.BI/IReportService.cs b/backend/Origam.BI/IReportService.cs index 468a817cf3..062661af83 100644 --- a/backend/Origam.BI/IReportService.cs +++ b/backend/Origam.BI/IReportService.cs @@ -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); } } diff --git a/backend/Origam.Schema.GuiModel/Reports/DataReportExportFormatType.cs b/backend/Origam.Schema.GuiModel/Reports/DataReportExportFormatType.cs index 23e3b82dee..5365a558f1 100644 --- a/backend/Origam.Schema.GuiModel/Reports/DataReportExportFormatType.cs +++ b/backend/Origam.Schema.GuiModel/Reports/DataReportExportFormatType.cs @@ -32,6 +32,8 @@ public enum DataReportExportFormatType , CSV = 5 , TEXT = 6 , XML = 7 + , RPT = 8 + , ExternalViewer = 9 } public static class DataReportExportFormatTypeExtensions @@ -46,6 +48,8 @@ public static class DataReportExportFormatTypeExtensions , "text/csv" , "text/plain" , "text/xml" + , "application/rpt" + , null }; private static readonly string[] extensions = @@ -58,6 +62,8 @@ public static class DataReportExportFormatTypeExtensions , "csv" , "txt" , "xml" + , "rpt" + , null }; public static string GetString(this DataReportExportFormatType value) @@ -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]; } } } \ No newline at end of file diff --git a/backend/Origam.Server/Controller/ReportController.cs b/backend/Origam.Server/Controller/ReportController.cs index c499e598c7..787a2d5105 100644 --- a/backend/Origam.Server/Controller/ReportController.cs +++ b/backend/Origam.Server/Controller/ReportController.cs @@ -20,6 +20,7 @@ #endregion using System; +using System.Collections; using System.IO; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -27,11 +28,14 @@ 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 { @@ -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"] @@ -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) { diff --git a/backend/Origam.Workflow/Service Agents/ReportServiceAgent.cs b/backend/Origam.Workflow/Service Agents/ReportServiceAgent.cs index e310f80633..0410df2dc1 100644 --- a/backend/Origam.Workflow/Service Agents/ReportServiceAgent.cs +++ b/backend/Origam.Workflow/Service Agents/ReportServiceAgent.cs @@ -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)