This commit is contained in:
@@ -158,6 +158,39 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//======================================================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Render Report
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reportId"></param>
|
||||||
|
/// <param name="apiVersion">From route path</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("render")]
|
||||||
|
public async Task<IActionResult> RenderReport([FromBody] long reportId, long[] objectIdArray, ApiVersion apiVersion)
|
||||||
|
{
|
||||||
|
if (!serverState.IsOpen)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
ReportBiz biz = ReportBiz.GetBiz(ct, HttpContext);
|
||||||
|
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
var httpConnectionFeature = HttpContext.Features.Get<IHttpConnectionFeature>();
|
||||||
|
var API_URL = $"http://127.0.0.1:{httpConnectionFeature.LocalPort}/api/v8/";
|
||||||
|
|
||||||
|
var result = await biz.RenderReport(reportId,objectIdArray,API_URL);
|
||||||
|
if (result == null)
|
||||||
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
else
|
||||||
|
return new FileContentResult(result.RenderedOutput,result.MimeType);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("render-test")]
|
[HttpGet("render-test")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> GetTestReport([FromRoute] string test)
|
public async Task<IActionResult> GetTestReport([FromRoute] string test)
|
||||||
|
|||||||
@@ -233,14 +233,37 @@ namespace AyaNova.Biz
|
|||||||
so the route just calls the biz object which handles processing, getting data, checking rights and then making the report and either attaching it to an email (maybe I do need that temp server folder after all)
|
so the route just calls the biz object which handles processing, getting data, checking rights and then making the report and either attaching it to an email (maybe I do need that temp server folder after all)
|
||||||
or return to route to return to Client end
|
or return to route to return to Client end
|
||||||
*/
|
*/
|
||||||
public async Task<byte[]> RenderReport(long reportId, long[] objectidarray, string apiUrl)
|
public async Task<RenderedReport> RenderReport(long id, long[] objectidarray, string apiUrl, long overrideUserId = 0)
|
||||||
{
|
{
|
||||||
|
var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::RenderReport");
|
||||||
|
|
||||||
//get report, vet security, see what we need before init in case of issue
|
//get report, vet security, see what we need before init in case of issue
|
||||||
|
var report = await ct.Report.FirstOrDefaultAsync(z => z.Id == id);
|
||||||
|
if (report == null)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthorizationRoles effectiveRoles = CurrentUserRoles;
|
||||||
|
if (overrideUserId != 0)
|
||||||
|
{
|
||||||
|
var effectiveUser=await ct.User.FirstOrDefaultAsync(z => z.Id == overrideUserId);
|
||||||
|
if (effectiveUser==null)
|
||||||
|
{
|
||||||
|
var msg = $"Override user id specifies user that doesn't exist({overrideUserId}) cannot generate report {report.Name}";
|
||||||
|
log.LogError(msg);
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "UserId", msg);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
effectiveRoles=effectiveUser.Roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//initialization
|
//initialization
|
||||||
var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::RenderReport");
|
|
||||||
log.LogDebug("Initializing report system");
|
log.LogDebug("Initializing report system");
|
||||||
var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "rpt");
|
var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "rpt");
|
||||||
var lo = new LaunchOptions { Headless = true };
|
var lo = new LaunchOptions { Headless = true };
|
||||||
@@ -302,6 +325,16 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RenderedReport
|
||||||
|
{
|
||||||
|
public string MimeType { get; set; }
|
||||||
|
public byte[] RenderedOutput { get; set; }
|
||||||
|
public RenderedReport()
|
||||||
|
{
|
||||||
|
MimeType = "application/pdf";
|
||||||
|
RenderedOutput = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user