diff --git a/server/AyaNova/biz/BizObject.cs b/server/AyaNova/biz/BizObject.cs index 5f7c8491..e9e0055e 100644 --- a/server/AyaNova/biz/BizObject.cs +++ b/server/AyaNova/biz/BizObject.cs @@ -16,7 +16,7 @@ namespace AyaNova.Biz public BizObject() { - + } #region Roles @@ -35,11 +35,7 @@ namespace AyaNova.Biz public bool HasErrors => _errors.Any(); - // public void AddError(string errorMessage, string field="") - // { - // _errors.Add(new ValidationError() { Message = errorMessage, Target = field }); - // } - + public void AddvalidationError(ValidationError validationError) { _errors.Add(validationError); diff --git a/server/AyaNova/biz/BizObjectFactory.cs b/server/AyaNova/biz/BizObjectFactory.cs index 8614f87e..cf9a7f72 100644 --- a/server/AyaNova/biz/BizObjectFactory.cs +++ b/server/AyaNova/biz/BizObjectFactory.cs @@ -23,6 +23,8 @@ namespace AyaNova.Biz { switch (aytype) { + case AyaType.User: + return new UserBiz(dbcontext, userId, roles); case AyaType.Widget: return new WidgetBiz(dbcontext, userId, roles); case AyaType.Tag: diff --git a/server/AyaNova/biz/IBizObject.cs b/server/AyaNova/biz/IBizObject.cs index cdc123d0..a69f9646 100644 --- a/server/AyaNova/biz/IBizObject.cs +++ b/server/AyaNova/biz/IBizObject.cs @@ -38,6 +38,8 @@ namespace AyaNova.Biz /// bool PropertyHasErrors(string propertyName); + + /// /// diff --git a/server/AyaNova/biz/IImportAyaNova7Object.cs b/server/AyaNova/biz/IImportAyaNova7Object.cs index 0c2e9174..809dfa37 100644 --- a/server/AyaNova/biz/IImportAyaNova7Object.cs +++ b/server/AyaNova/biz/IImportAyaNova7Object.cs @@ -21,7 +21,11 @@ namespace AyaNova.Biz /// JobId for logging or controlling jobs from within processor /// True if imported, False if not imported due to invalid or other error (logged in job log) Task ImportV7Async(JObject v7ImportData, List importMap, Guid JobId); - + + /// + /// If true, relaxes validation rules so that incomplete data can be imported + /// + bool V7ValidationImportMode { get; set; } } diff --git a/server/AyaNova/biz/ImportAyaNova7Biz.cs b/server/AyaNova/biz/ImportAyaNova7Biz.cs index fd530800..66315dae 100644 --- a/server/AyaNova/biz/ImportAyaNova7Biz.cs +++ b/server/AyaNova/biz/ImportAyaNova7Biz.cs @@ -88,11 +88,10 @@ namespace AyaNova.Biz //NOTE: Many of these require a second pass - one to get the object imported and then another to set another imported object to that object //for example scheduleable user groups are imported as tags, but then a second pass is required to tag the users of that group - - //USERS - Import first so all other objects can be properly attributed in event log - + //USERS + await DoImport("GZTW.AyaNova.BLL.User", AyaType.User, job.GId, importMap, importFileName, zipEntries); //IMPORT UNIT MODEL CATEGORIES AS TAGS await DoImport("GZTW.AyaNova.BLL.UnitModelCategory", AyaType.Tag, job.GId, importMap, importFileName, zipEntries); @@ -161,6 +160,7 @@ namespace AyaNova.Biz var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName); IImportAyaNova7Object o = (IImportAyaNova7Object)BizObjectFactory.GetBizObject(importerType, ct); + foreach (JObject j in jList) { bool bImportSucceeded = false; diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index 0ce01e7c..beedcb39 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -21,13 +21,14 @@ namespace AyaNova.Biz private readonly AyContext ct; public readonly long userId; private readonly AuthorizationRoles userRoles; - + public bool V7ValidationImportMode { get; set; } internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) { ct = dbcontext; userId = currentUserId; userRoles = UserRoles; + V7ValidationImportMode = false;//default } @@ -449,7 +450,7 @@ namespace AyaNova.Biz ct.Locale.Add(l); ct.SaveChanges(); - + //Log now that we have the Id EventLogProcessor.AddEntry(new Event(1, l.Id, AyaType.Locale, AyaEvent.Created), ct); ct.SaveChanges(); diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs index e8f6ee1f..0990a2aa 100644 --- a/server/AyaNova/biz/TagBiz.cs +++ b/server/AyaNova/biz/TagBiz.cs @@ -21,12 +21,14 @@ namespace AyaNova.Biz public readonly long userId; private readonly AuthorizationRoles userRoles; + public bool V7ValidationImportMode { get; set; } internal TagBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) { ct = dbcontext; userId = currentUserId; userRoles = UserRoles; + V7ValidationImportMode = false;//default } diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index c64c82d7..d28e70ea 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -8,24 +8,27 @@ using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; using AyaNova.Models; - +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; namespace AyaNova.Biz { - internal class UserBiz : BizObject, IJobObject + internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object { private readonly AyContext ct; public readonly long userId; private readonly AuthorizationRoles userRoles; - + public bool V7ValidationImportMode { get; set; } internal UserBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) { ct = dbcontext; userId = currentUserId; userRoles = UserRoles; + V7ValidationImportMode = false;//default } @@ -202,7 +205,7 @@ namespace AyaNova.Biz if (isNew) { //NEW Users must be active - if (inObj.Active == null || ((bool)inObj.Active) == false) + if (((bool)inObj.Active) == false) { AddError(ValidationErrorType.InvalidValue, "Active", "New User must be active"); } @@ -233,19 +236,17 @@ namespace AyaNova.Biz } } - //Start date AND end date must both be null or both contain values - if (inObj.StartDate == null && inObj.EndDate != null) - AddError(ValidationErrorType.RequiredPropertyEmpty, "StartDate"); - if (inObj.StartDate != null && inObj.EndDate == null) - AddError(ValidationErrorType.RequiredPropertyEmpty, "EndDate"); + if (!inObj.UserType.IsValid()) + { + AddError(ValidationErrorType.InvalidValue, "UserType"); + } - //Start date before end date - if (inObj.StartDate != null && inObj.EndDate != null) - if (inObj.StartDate > inObj.EndDate) - AddError(ValidationErrorType.StartDateMustComeBeforeEndDate, "StartDate"); + //Validate client exists + if (inObj.UserType == UserType.Client) + { - //Enum is valid value + } if (!inObj.Roles.IsValid()) { @@ -271,35 +272,27 @@ namespace AyaNova.Biz // public async Task HandleJobAsync(OpsJob job) { + //just to hide compiler warning for now + await Task.CompletedTask; //Hand off the particular job to the corresponding processing code //NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so //basically any error condition during job processing should throw up an exception if it can't be handled switch (job.JobType) { - case JobType.TestUserJob: - await ProcessTestJobAsync(job); - break; + default: throw new System.ArgumentOutOfRangeException($"UserBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); } + } - /// - /// /// Handle the test job - /// - /// - private async Task ProcessTestJobAsync(OpsJob job) + + + public Task ImportV7Async(JObject v7ImportData, List importMap, Guid JobId) { - var sleepTime = 30 * 1000; - //Simulate a long running job here - JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct); - JobsBiz.LogJob(job.GId, $"UserBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct); - //Uncomment this to test if the job prevents other routes from running - //result is NO it doesn't prevent other requests, so we are a-ok for now - await Task.Delay(sleepTime); - JobsBiz.LogJob(job.GId, "UserBiz::ProcessTestJob done sleeping setting job to finished", ct); - JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); + V7ValidationImportMode=true; + }