This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace AyaNova.Biz
|
||||
/// </summary>
|
||||
bool PropertyHasErrors(string propertyName);
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace AyaNova.Biz
|
||||
/// <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>
|
||||
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
|
||||
//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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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()}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// /// Handle the test job
|
||||
/// </summary>
|
||||
/// <param name="job"></param>
|
||||
private async Task ProcessTestJobAsync(OpsJob job)
|
||||
|
||||
|
||||
public Task<bool> ImportV7Async(JObject v7ImportData, List<ImportAyaNova7MapItem> 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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user