This commit is contained in:
@@ -211,7 +211,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <param name="filename"></param>
|
/// <param name="filename"></param>
|
||||||
/// <returns>Ok</returns>
|
/// <returns>Ok</returns>
|
||||||
[HttpPost("EraseDatabaseAndStartImport/{filename}")]
|
[HttpPost("EraseDatabaseAndStartImport/{filename}")]
|
||||||
public ActionResult EraseDatabaseAndStartImport([FromRoute] string filename)
|
public async Task<IActionResult> EraseDatabaseAndStartImport([FromRoute] string filename)
|
||||||
{
|
{
|
||||||
//Open or opsOnly and user is opsadminfull
|
//Open or opsOnly and user is opsadminfull
|
||||||
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
|
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
|
||||||
@@ -259,7 +259,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
j.JobType = JobType.ImportV7Data;
|
j.JobType = JobType.ImportV7Data;
|
||||||
//j.O wnerId = UserIdFromContext.Id(HttpContext.Items);
|
//j.O wnerId = UserIdFromContext.Id(HttpContext.Items);
|
||||||
j.JobInfo = jobInfo.ToString();
|
j.JobInfo = jobInfo.ToString();
|
||||||
JobsBiz.AddJobAsync(j, ct);
|
await JobsBiz.AddJobAsync(j, ct);
|
||||||
return Accepted(new { JobId = j.GId });//202 accepted
|
return Accepted(new { JobId = j.GId });//202 accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.Put(o, inObj))
|
if (!biz.PutAsync(o, inObj))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//patch and validate
|
//patch and validate
|
||||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace AyaNova.Biz
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prime the database with manager account
|
/// Prime the database with manager account
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void PrimeManagerAccount(AyContext ct)
|
public static async Task PrimeManagerAccount(AyContext ct)
|
||||||
{
|
{
|
||||||
//get a db and logger
|
//get a db and logger
|
||||||
//ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData");
|
//ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData");
|
||||||
@@ -31,8 +31,8 @@ namespace AyaNova.Biz
|
|||||||
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first
|
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first
|
||||||
u.UserType = UserType.Administrator;
|
u.UserType = UserType.Administrator;
|
||||||
u.UserOptions = new UserOptions();
|
u.UserOptions = new UserOptions();
|
||||||
ct.User.Add(u);
|
await ct.User.AddAsync(u);
|
||||||
ct.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,18 +64,16 @@ namespace AyaNova.Biz
|
|||||||
//FOR NOW NOT ASYNC so faking it at end of this method
|
//FOR NOW NOT ASYNC so faking it at end of this method
|
||||||
|
|
||||||
|
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
JobsBiz.LogJobAsync(job.GId, $"Starting...", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Starting...", ct);
|
||||||
|
|
||||||
//Get the import filename from the jsondata
|
//Get the import filename from the jsondata
|
||||||
JObject jobData = JObject.Parse(job.JobInfo);
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||||
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
||||||
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
|
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
|
||||||
JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
|
await JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
//NO, BAD! Convert the logjob etc above to async
|
|
||||||
//await Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -809,7 +809,7 @@ namespace AyaNova.Biz
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
{
|
{
|
||||||
//If there are any validation errors, log in joblog and move on
|
//If there are any validation errors, log in joblog and move on
|
||||||
JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
|
await JobsBiz.LogJobAsync(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
|
//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
|
//other things might be able to work around but this is too serious
|
||||||
@@ -907,8 +907,7 @@ namespace AyaNova.Biz
|
|||||||
break;
|
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
|
//this is the equivalent of returning void for a Task signature with nothing to return
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
|
|
||||||
//put
|
//put
|
||||||
internal bool Put(UserOptions dbObj, UserOptions inObj)
|
internal async Task<bool> PutAsync(UserOptions dbObj, UserOptions inObj)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//Replace the db object with the PUT object
|
//Replace the db object with the PUT object
|
||||||
CopyObject.Copy(inObj, dbObj, "Id, UserId");
|
CopyObject.Copy(inObj, dbObj, "Id, UserId");
|
||||||
//Set "original" value of concurrency token to input token
|
//Set "original" value of concurrency token to input token
|
||||||
@@ -57,14 +57,14 @@ namespace AyaNova.Biz
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ct.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
//Log
|
//Log
|
||||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//patch
|
//patch
|
||||||
internal bool Patch(UserOptions dbObj, JsonPatchDocument<UserOptions> objectPatch, uint concurrencyToken)
|
internal async Task<bool> PatchAsync(UserOptions dbObj, JsonPatchDocument<UserOptions> objectPatch, uint concurrencyToken)
|
||||||
{
|
{
|
||||||
//Validate Patch is allowed
|
//Validate Patch is allowed
|
||||||
if (!ValidateJsonPatch<UserOptions>.Validate(this, objectPatch, "UserId")) return false;
|
if (!ValidateJsonPatch<UserOptions>.Validate(this, objectPatch, "UserId")) return false;
|
||||||
@@ -77,9 +77,9 @@ namespace AyaNova.Biz
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ct.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
//Log
|
//Log
|
||||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ namespace AyaNova.Biz
|
|||||||
//Determine if the object can be deleted, do the deletion tentatively
|
//Determine if the object can be deleted, do the deletion tentatively
|
||||||
//Probably also in here deal with tags and associated search text etc
|
//Probably also in here deal with tags and associated search text etc
|
||||||
|
|
||||||
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.Widget.Remove(dbObj);
|
ct.Widget.Remove(dbObj);
|
||||||
@@ -290,7 +290,7 @@ namespace AyaNova.Biz
|
|||||||
//validate custom fields
|
//validate custom fields
|
||||||
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -329,13 +329,13 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
var sleepTime = 30 * 1000;
|
var sleepTime = 30 * 1000;
|
||||||
//Simulate a long running job here
|
//Simulate a long running job here
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
|
||||||
//Uncomment this to test if the job prevents other routes from running
|
//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
|
//result is NO it doesn't prevent other requests, so we are a-ok for now
|
||||||
await Task.Delay(sleepTime);
|
await Task.Delay(sleepTime);
|
||||||
JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
|
await JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user