diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index f75293c7..3bd632ff 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -94,9 +94,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "List of ids")); tag = TagUtil.NormalizeTag(tag); if (string.IsNullOrWhiteSpace(tag)) - return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag")); - - + return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag")); var JobName = $"BulkAdd tag {tag} to {ayaType} ({idList.Count} specified)"; JObject o = JObject.FromObject(new { @@ -107,11 +105,11 @@ namespace AyaNova.Api.Controllers }); OpsJob j = new OpsJob(); - j.Name = $"BulkTag"; + j.Name = JobName; j.JobType = JobType.BulkTag; j.Exclusive = false; j.JobInfo = o.ToString(); - // await JobsBiz.AddJobAsync(j, ct); + await JobsBiz.AddJobAsync(j, ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, ayaType, AyaEvent.Created, JobName), ct); return Accepted(new { JobId = j.GId }); } diff --git a/server/AyaNova/biz/JobsBiz.cs b/server/AyaNova/biz/JobsBiz.cs index a01fe07f..f28a1f33 100644 --- a/server/AyaNova/biz/JobsBiz.cs +++ b/server/AyaNova/biz/JobsBiz.cs @@ -408,6 +408,9 @@ namespace AyaNova.Biz case JobType.SeedTestData: o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.TrialSeeder, ct); break; + case JobType.BulkTag: + o = (IJobObject)TagBiz.GetBiz(ct); + break; default: throw new System.NotSupportedException($"ProcessJobAsync type {job.JobType.ToString()} is not supported"); } diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs new file mode 100644 index 00000000..a21ddd72 --- /dev/null +++ b/server/AyaNova/biz/TagBiz.cs @@ -0,0 +1,80 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using EnumsNET; +using AyaNova.Util; +using AyaNova.Api.ControllerHelpers; +using AyaNova.Models; + +namespace AyaNova.Biz +{ + internal class TagBiz : BizObject, IJobObject + { + internal TagBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) + { + ct = dbcontext; + UserId = currentUserId; + UserTranslationId = userTranslationId; + CurrentUserRoles = UserRoles; + BizType = AyaType.NoType; + } + + internal static TagBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) + { + if (httpContext != null) + return new TagBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items)); + else + return new TagBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull); + } + + + + //////////////////////////////////////////////////////////////////////////////////////////////// + //JOB / OPERATIONS + // + public async Task HandleJobAsync(OpsJob job) + { + //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.BulkTag: + await ProcessBulkJobAsync(job); + break; + default: + throw new System.ArgumentOutOfRangeException($"TagBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); + } + } + + + /// + /// /// Handle the test job + /// + /// + private async Task ProcessBulkJobAsync(OpsJob job) + { + + //Simulate a long running job here + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct); + await JobsBiz.LogJobAsync(job.GId, $"TagBiz::ProcessBulkJobAsync started...", ct); + + + + + await JobsBiz.LogJobAsync(job.GId, "TagBiz::ProcessBulkJobAsync done setting job to finished", ct); + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct); + + } + + + + //Other job handlers here... + + + ///////////////////////////////////////////////////////////////////// + + }//eoc + + +}//eons + diff --git a/server/AyaNova/biz/TagUtil.cs b/server/AyaNova/biz/TagUtil.cs index f8c4dcb2..f5c1f97e 100644 --- a/server/AyaNova/biz/TagUtil.cs +++ b/server/AyaNova/biz/TagUtil.cs @@ -218,7 +218,7 @@ namespace AyaNova.Biz public static async Task BulkAdd(AyaType ayaType, string tag, List idList, AyContext ct) { //SUBMIT AS JOB - + //todo iterate the object in question, open and update and save each one through it's biz object interface so rules etc are all maintained //not sure if should update locked or read only objects, probably not I guess as it should only do whatever was done in interface await Task.CompletedTask;