This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
80
server/AyaNova/biz/TagBiz.cs
Normal file
80
server/AyaNova/biz/TagBiz.cs
Normal file
@@ -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()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// /// Handle the test job
|
||||
/// </summary>
|
||||
/// <param name="job"></param>
|
||||
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
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace AyaNova.Biz
|
||||
public static async Task<long> BulkAdd(AyaType ayaType, string tag, List<long> 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;
|
||||
|
||||
Reference in New Issue
Block a user