From 6f0182042ec58c362e67a14821851f1fe19df6b2 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 16 May 2020 15:32:53 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/TagController.cs | 27 ++++++++++++++++++++- server/AyaNova/biz/JobType.cs | 4 +-- server/AyaNova/biz/TagUtil.cs | 4 ++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index ac3a265d..f75293c7 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; +using Newtonsoft.Json.Linq; + namespace AyaNova.Api.Controllers @@ -88,7 +90,30 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); if (!Authorized.HasModifyRole(HttpContext.Items, ayaType)) return StatusCode(403, new ApiNotAuthorizedResponse()); - return Ok(ApiOkResponse.Response(await TagUtil.BulkAdd(ayaType, tag, idList, ct), true)); + if (idList.Count == 0) + 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")); + + + var JobName = $"BulkAdd tag {tag} to {ayaType} ({idList.Count} specified)"; + JObject o = JObject.FromObject(new + { + ayaType = ayaType, + idList = idList, + op = "bulk-add", + tag = tag + }); + + OpsJob j = new OpsJob(); + j.Name = $"BulkTag"; + j.JobType = JobType.BulkTag; + j.Exclusive = false; + j.JobInfo = o.ToString(); + // 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/JobType.cs b/server/AyaNova/biz/JobType.cs index e93abbae..b0767c03 100644 --- a/server/AyaNova/biz/JobType.cs +++ b/server/AyaNova/biz/JobType.cs @@ -3,7 +3,7 @@ namespace AyaNova.Biz /// - /// All AyaNova Job types, used by OpsJob and biz objects for long running applications + /// All AyaNova Job types, used by OpsJob and biz objects for long running processes /// public enum JobType : int { @@ -11,7 +11,7 @@ namespace AyaNova.Biz TestWidgetJob = 1,//test job for unit testing CoreJobSweeper = 2, SeedTestData = 4, - + BulkTag = 5 } diff --git a/server/AyaNova/biz/TagUtil.cs b/server/AyaNova/biz/TagUtil.cs index 634d1e04..f8c4dcb2 100644 --- a/server/AyaNova/biz/TagUtil.cs +++ b/server/AyaNova/biz/TagUtil.cs @@ -212,11 +212,13 @@ namespace AyaNova.Biz ///////////////////////////////// - //BULK OPS + //BULK OPS JOBS // 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;