From e6cf7e0958b8fdbc509411223f635764dc1c8717 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 30 Aug 2018 18:58:33 +0000 Subject: [PATCH] --- devdocs/specs/core-import-v7.txt | 2 + server/AyaNova/biz/UserBiz.cs | 92 ++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/devdocs/specs/core-import-v7.txt b/devdocs/specs/core-import-v7.txt index afdf9734..cf504df2 100644 --- a/devdocs/specs/core-import-v7.txt +++ b/devdocs/specs/core-import-v7.txt @@ -6,6 +6,8 @@ CASES REQUIREMENTS +- EMPTY DESTINATION DATABASE - IMPORTER will assume there is no pre-existing data that can conflict + - DB MUST BE ERASED FIRST OR IMPORT WILL FAIL (excluding fundamental things like license key, stock locales etc) - LImited area of concern: rather than trying to do all types of import, I'm going to write this as if it's all for v7 only - only when I write the next importer will I see if there are any savings of combining objects, but for now small classes with single responsibility - Import v7 data into RAVEN via datadump plugin for v7 diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index d28e70ea..ef5698c7 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -242,10 +242,46 @@ namespace AyaNova.Biz AddError(ValidationErrorType.InvalidValue, "UserType"); } - //Validate client exists - if (inObj.UserType == UserType.Client) + //Validate client type user + if (!V7ValidationImportMode && inObj.UserType == UserType.Client) { + if (inObj.ClientId == null || inObj.ClientId == 0) + { + AddError(ValidationErrorType.RequiredPropertyEmpty, "ClientId"); + } + else + { + //verify that client exists + //TODO WHEN CLIENT OBJECT MADE if(!ct.Client.any(m)) + } + } + //Validate headoffice type user + if (!V7ValidationImportMode && inObj.UserType == UserType.HeadOffice) + { + if (inObj.HeadOfficeId == null || inObj.HeadOfficeId == 0) + { + AddError(ValidationErrorType.RequiredPropertyEmpty, "HeadOfficeId"); + } + else + { + //verify that HeadOfficeId exists + //TODO WHEN HEADOFFICE OBJECT MADE if(!ct.HeadOffice.any(m)) + } + } + + //Validate headoffice type user + if (!V7ValidationImportMode && inObj.UserType == UserType.Subcontractor) + { + if (inObj.SubVendorId == null || inObj.SubVendorId == 0) + { + AddError(ValidationErrorType.RequiredPropertyEmpty, "SubVendorId"); + } + else + { + //verify that VENDOR SubVendorId exists + //TODO WHEN VENDOR OBJECT MADE if(!ct.Vendor.any(m)) + } } if (!inObj.Roles.IsValid()) @@ -253,7 +289,6 @@ namespace AyaNova.Biz AddError(ValidationErrorType.InvalidValue, "Roles"); } - return; } @@ -279,20 +314,59 @@ namespace AyaNova.Biz //basically any error condition during job processing should throw up an exception if it can't be handled switch (job.JobType) { - + default: throw new System.ArgumentOutOfRangeException($"UserBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); } - + } - - public Task ImportV7Async(JObject v7ImportData, List importMap, Guid JobId) + + public async Task ImportV7Async(JObject j, List importMap, Guid jobId) { - V7ValidationImportMode=true; - + V7ValidationImportMode = true; + + //some types need to import from more than one source hence the seemingly redundant switch statement for futureproofing + switch (j["V7_TYPE"].Value()) + { + case "GZTW.AyaNova.BLL.User": + { + var V7Id = new Guid(j["ID"].Value()); + + //Copy values + User i=new User(); + i.Name= j["Name"].Value(); + + + User o = await CreateAsync(i); + if (HasErrors) + { + //If there are any validation errors, log in joblog and move on + JobsBiz.LogJob(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct); + + //This is a fundamental problem with the import as users are required for many things so bomb out entirely + //other things might be able to work around but this is too serious + throw new System.SystemException("UserBiz::ImportV7Async - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE WITHOUT ALL USERS BEING IMPORTED, SEE JOB ERROR LOG FOR DETAILS"); + // return false; + } + else + { + await ct.SaveChangesAsync(); + var mapItem = new ImportAyaNova7MapItem(V7Id, AyaType.User, o.Id); + //Log + EventLogProcessor.AddEntry(new Event(userId, o.Id, AyaType.User, AyaEvent.Created), ct); + await ct.SaveChangesAsync(); + } + } + break; + } + + //just to hide compiler warning for now + await Task.CompletedTask; + //this is the equivalent of returning void for a Task signature with nothing to return + return true; }