From 121339d3443652660c130540f118b15367eb1961 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 7 Sep 2020 18:28:26 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/ReportController.cs | 11 ++--- server/AyaNova/biz/ReportBiz.cs | 45 +++++++++++++++++-- server/AyaNova/biz/TranslationBiz.cs | 2 - 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/server/AyaNova/Controllers/ReportController.cs b/server/AyaNova/Controllers/ReportController.cs index 6009bedc..3d8d0191 100644 --- a/server/AyaNova/Controllers/ReportController.cs +++ b/server/AyaNova/Controllers/ReportController.cs @@ -353,16 +353,11 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: FileData")); } - //fileData in JSON stringify format which contains the actual last modified dates etc - //"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]" + //fileData in JSON stringify format FileData = Newtonsoft.Json.JsonConvert.DeserializeObject>(uploadFormData.FormFieldData["FileData"].ToString()); - - - - - // long UserId = UserIdFromContext.Id(HttpContext.Items); + //Instantiate the business object handler - TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext); + ReportBiz biz = ReportBiz.GetBiz(ct, HttpContext); //We have our files now can parse and insert into db diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index 4ce39841..f81cd42a 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -9,6 +9,7 @@ using AyaNova.Api.ControllerHelpers; using AyaNova.Models; using EnumsNET; using PuppeteerSharp; +using Newtonsoft.Json.Linq; namespace AyaNova.Biz { @@ -86,6 +87,44 @@ namespace AyaNova.Biz return newObject; } + + //////////////////////////////////////////////////////////////////////////////////////////////// + //IMPORT + // + internal async Task ImportAsync(JObject o) + { + + Report newObject = new Report(); + var proposedName = (string)o["Name"]; + string newUniqueName = proposedName; + bool NotUnique = true; + long l = 1; + do + { + NotUnique = await ct.Report.AnyAsync(z => z.Name == newUniqueName); + if (NotUnique) + newUniqueName = Util.StringUtil.UniqueNameBuilder(proposedName, l++, 255); + + } while (NotUnique); + + newObject.Name = newUniqueName; + newObject.Active = (bool)o["Active"]; + newObject.JsHelpers = (string)o["JsHelpers"]; + newObject.JsPrerender = (string)o["JsPrerender"]; + newObject.Notes = (string)o["Notes"]; + newObject.ObjectType = (AyaType)(int)o["ObjectType"]; + newObject.RenderType = (ReportRenderType)(int)o["RenderType"]; + newObject.Roles = (AuthorizationRoles)(int)o["Roles"]; + newObject.Style = (string)o["Style"]; + newObject.Template = (string)o["Template"]; + await ValidateAsync(newObject, null); + if (HasErrors) return false; + await ct.Report.AddAsync(newObject); + await ct.SaveChangesAsync(); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); + return true; + } + //////////////////////////////////////////////////////////////////////////////////////////////// //GET // @@ -326,7 +365,7 @@ namespace AyaNova.Biz await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); } -//https://stackoverflow.com/questions/53367966/puppeteer-sharp-still-appear-many-chromium-instance-in-process-task-manager-when + //https://stackoverflow.com/questions/53367966/puppeteer-sharp-still-appear-many-chromium-instance-in-process-task-manager-when log.LogDebug($"Launching headless Chrome now:"); using (var browser = await Puppeteer.LaunchAsync(lo)) using (var page = await browser.NewPageAsync()) @@ -359,12 +398,12 @@ namespace AyaNova.Biz var clientMeta = "{}"; if (reportParam.ClientMeta != null) clientMeta = reportParam.ClientMeta.ToString(); - // await page.AddScriptTagAsync(new AddTagOptions() { Content = $"var ayClientMetaData = {clientMeta}" }); + // await page.AddScriptTagAsync(new AddTagOptions() { Content = $"var ayClientMetaData = {clientMeta}" }); //this is how you view the contents of the page #if (DEBUG) var pagecontent = await page.GetContentAsync(); - + #endif //compile and run handlebars template diff --git a/server/AyaNova/biz/TranslationBiz.cs b/server/AyaNova/biz/TranslationBiz.cs index ffd4e7c4..dc52f345 100644 --- a/server/AyaNova/biz/TranslationBiz.cs +++ b/server/AyaNova/biz/TranslationBiz.cs @@ -5,8 +5,6 @@ using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Models; using System.Collections.Generic; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Linq; namespace AyaNova.Biz