This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<bool> ImportV7Async(JObject v7ImportData, List<ImportAyaNova7MapItem> importMap, Guid JobId)
|
||||
|
||||
public async Task<bool> ImportV7Async(JObject j, List<ImportAyaNova7MapItem> 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<string>())
|
||||
{
|
||||
case "GZTW.AyaNova.BLL.User":
|
||||
{
|
||||
var V7Id = new Guid(j["ID"].Value<string>());
|
||||
|
||||
//Copy values
|
||||
User i=new User();
|
||||
i.Name= j["Name"].Value<string>();
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user