This commit is contained in:
@@ -16,7 +16,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
public BizObject()
|
public BizObject()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Roles
|
#region Roles
|
||||||
@@ -35,11 +35,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
public bool HasErrors => _errors.Any();
|
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)
|
public void AddvalidationError(ValidationError validationError)
|
||||||
{
|
{
|
||||||
_errors.Add(validationError);
|
_errors.Add(validationError);
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
switch (aytype)
|
switch (aytype)
|
||||||
{
|
{
|
||||||
|
case AyaType.User:
|
||||||
|
return new UserBiz(dbcontext, userId, roles);
|
||||||
case AyaType.Widget:
|
case AyaType.Widget:
|
||||||
return new WidgetBiz(dbcontext, userId, roles);
|
return new WidgetBiz(dbcontext, userId, roles);
|
||||||
case AyaType.Tag:
|
case AyaType.Tag:
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ namespace AyaNova.Biz
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool PropertyHasErrors(string propertyName);
|
bool PropertyHasErrors(string propertyName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ namespace AyaNova.Biz
|
|||||||
/// <param name="JobId">JobId for logging or controlling jobs from within processor</param>
|
/// <param name="JobId">JobId for logging or controlling jobs from within processor</param>
|
||||||
/// <returns>True if imported, False if not imported due to invalid or other error (logged in job log)</returns>
|
/// <returns>True if imported, False if not imported due to invalid or other error (logged in job log)</returns>
|
||||||
Task<bool> ImportV7Async(JObject v7ImportData, List<ImportAyaNova7MapItem> importMap, Guid JobId);
|
Task<bool> ImportV7Async(JObject v7ImportData, List<ImportAyaNova7MapItem> importMap, Guid JobId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, relaxes validation rules so that incomplete data can be imported
|
||||||
|
/// </summary>
|
||||||
|
bool V7ValidationImportMode { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
//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
|
//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
|
//IMPORT UNIT MODEL CATEGORIES AS TAGS
|
||||||
await DoImport("GZTW.AyaNova.BLL.UnitModelCategory", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
|
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);
|
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
|
||||||
|
|
||||||
IImportAyaNova7Object o = (IImportAyaNova7Object)BizObjectFactory.GetBizObject(importerType, ct);
|
IImportAyaNova7Object o = (IImportAyaNova7Object)BizObjectFactory.GetBizObject(importerType, ct);
|
||||||
|
|
||||||
foreach (JObject j in jList)
|
foreach (JObject j in jList)
|
||||||
{
|
{
|
||||||
bool bImportSucceeded = false;
|
bool bImportSucceeded = false;
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ namespace AyaNova.Biz
|
|||||||
private readonly AyContext ct;
|
private readonly AyContext ct;
|
||||||
public readonly long userId;
|
public readonly long userId;
|
||||||
private readonly AuthorizationRoles userRoles;
|
private readonly AuthorizationRoles userRoles;
|
||||||
|
public bool V7ValidationImportMode { get; set; }
|
||||||
|
|
||||||
internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
ct = dbcontext;
|
ct = dbcontext;
|
||||||
userId = currentUserId;
|
userId = currentUserId;
|
||||||
userRoles = UserRoles;
|
userRoles = UserRoles;
|
||||||
|
V7ValidationImportMode = false;//default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -449,7 +450,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
ct.Locale.Add(l);
|
ct.Locale.Add(l);
|
||||||
ct.SaveChanges();
|
ct.SaveChanges();
|
||||||
|
|
||||||
//Log now that we have the Id
|
//Log now that we have the Id
|
||||||
EventLogProcessor.AddEntry(new Event(1, l.Id, AyaType.Locale, AyaEvent.Created), ct);
|
EventLogProcessor.AddEntry(new Event(1, l.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||||
ct.SaveChanges();
|
ct.SaveChanges();
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ namespace AyaNova.Biz
|
|||||||
public readonly long userId;
|
public readonly long userId;
|
||||||
private readonly AuthorizationRoles userRoles;
|
private readonly AuthorizationRoles userRoles;
|
||||||
|
|
||||||
|
public bool V7ValidationImportMode { get; set; }
|
||||||
|
|
||||||
internal TagBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
internal TagBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
ct = dbcontext;
|
ct = dbcontext;
|
||||||
userId = currentUserId;
|
userId = currentUserId;
|
||||||
userRoles = UserRoles;
|
userRoles = UserRoles;
|
||||||
|
V7ValidationImportMode = false;//default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,24 +8,27 @@ using AyaNova.Util;
|
|||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
internal class UserBiz : BizObject, IJobObject
|
internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object
|
||||||
{
|
{
|
||||||
private readonly AyContext ct;
|
private readonly AyContext ct;
|
||||||
public readonly long userId;
|
public readonly long userId;
|
||||||
private readonly AuthorizationRoles userRoles;
|
private readonly AuthorizationRoles userRoles;
|
||||||
|
public bool V7ValidationImportMode { get; set; }
|
||||||
|
|
||||||
internal UserBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
internal UserBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
ct = dbcontext;
|
ct = dbcontext;
|
||||||
userId = currentUserId;
|
userId = currentUserId;
|
||||||
userRoles = UserRoles;
|
userRoles = UserRoles;
|
||||||
|
V7ValidationImportMode = false;//default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,7 +205,7 @@ namespace AyaNova.Biz
|
|||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
//NEW Users must be active
|
//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");
|
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)
|
if (!inObj.UserType.IsValid())
|
||||||
AddError(ValidationErrorType.RequiredPropertyEmpty, "EndDate");
|
{
|
||||||
|
AddError(ValidationErrorType.InvalidValue, "UserType");
|
||||||
|
}
|
||||||
|
|
||||||
//Start date before end date
|
//Validate client exists
|
||||||
if (inObj.StartDate != null && inObj.EndDate != null)
|
if (inObj.UserType == UserType.Client)
|
||||||
if (inObj.StartDate > inObj.EndDate)
|
{
|
||||||
AddError(ValidationErrorType.StartDateMustComeBeforeEndDate, "StartDate");
|
|
||||||
|
|
||||||
//Enum is valid value
|
}
|
||||||
|
|
||||||
if (!inObj.Roles.IsValid())
|
if (!inObj.Roles.IsValid())
|
||||||
{
|
{
|
||||||
@@ -271,35 +272,27 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
public async Task HandleJobAsync(OpsJob job)
|
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
|
//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
|
//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
|
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||||
switch (job.JobType)
|
switch (job.JobType)
|
||||||
{
|
{
|
||||||
case JobType.TestUserJob:
|
|
||||||
await ProcessTestJobAsync(job);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentOutOfRangeException($"UserBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
throw new System.ArgumentOutOfRangeException($"UserBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// /// Handle the test job
|
|
||||||
/// </summary>
|
public Task<bool> ImportV7Async(JObject v7ImportData, List<ImportAyaNova7MapItem> importMap, Guid JobId)
|
||||||
/// <param name="job"></param>
|
|
||||||
private async Task ProcessTestJobAsync(OpsJob job)
|
|
||||||
{
|
{
|
||||||
var sleepTime = 30 * 1000;
|
V7ValidationImportMode=true;
|
||||||
//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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user