From 7ea5c911aa692b4c0c7b392a0f29e25478f78c36 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 4 Oct 2018 20:56:40 +0000 Subject: [PATCH] --- devdocs/todo.txt | 4 ---- .../Controllers/AttachmentController.cs | 21 +++++++++---------- server/AyaNova/biz/AyaType.cs | 5 +++-- .../AyaNova/biz/BizObjectExistsInDatabase.cs | 3 +++ server/AyaNova/biz/BizObjectNameFetcher.cs | 2 ++ .../AyaNova/biz/BizObjectNameFetcherDirect.cs | 7 ++++++- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index a2754d55..fb7231a1 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -28,10 +28,6 @@ Once that is done then can steam ahead on the biz objects but until I have the c IMMEDIATE ITEMS: ================ - - - Search and search text indexing - - Update all the other routes to include search indexing (attachments, tags, taggroup) - - see if any other callers to name fetcher are in tight loops and could benefit from using the new Direct version - Schema: clean up all the LOOKAT items and verify the indexes are being used diff --git a/server/AyaNova/Controllers/AttachmentController.cs b/server/AyaNova/Controllers/AttachmentController.cs index 1a54f37c..e9082ae1 100644 --- a/server/AyaNova/Controllers/AttachmentController.cs +++ b/server/AyaNova/Controllers/AttachmentController.cs @@ -73,9 +73,7 @@ namespace AyaNova.Api.Controllers public async Task GetDownloadToken() { if (!serverState.IsOpen) - { return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - } long lUserId = UserIdFromContext.Id(HttpContext.Items); var u = await ct.User.FirstOrDefaultAsync(a => a.Id == lUserId); @@ -127,22 +125,15 @@ namespace AyaNova.Api.Controllers { //Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming - - if (!serverState.IsOpen) - { return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - } var returnList = new List(); - try { if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) - { return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "FileUploadAttempt", $"Expected a multipart request, but got {Request.ContentType}")); - } var uploadFormData = await ApiUploadProcessor.ProcessAttachmentUpload(HttpContext); @@ -238,9 +229,13 @@ namespace AyaNova.Api.Controllers Id = v.Id }); - //Log + //EVENT LOG EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct); ct.SaveChanges(); + + //SEARCH INDEXING + Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName, v.DisplayFileName, v.Notes, v.StoredFileName); + } } } @@ -305,9 +300,13 @@ namespace AyaNova.Api.Controllers //this handles removing the file if there are no refs left and also the db record for the attachment FileUtil.deleteFileAttachment(dbObj, ct); - //Log + //Event log process delete EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct); ct.SaveChanges(); + + //Delete search index + Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.FileAttachment); + return NoContent(); } diff --git a/server/AyaNova/biz/AyaType.cs b/server/AyaNova/biz/AyaType.cs index 6fb0bf62..3b85811b 100644 --- a/server/AyaNova/biz/AyaType.cs +++ b/server/AyaNova/biz/AyaType.cs @@ -30,14 +30,15 @@ namespace AyaNova.Biz Locale = 13, UserOptions = 14, TagGroup = 15, - TagGroupMap = 16 + TagGroupMap = 16, + FileAttachment = 17 //NOTE: New objects added here need to also be added to the following classes: //AyaNova.Biz.BizObjectExistsInDatabase //AyaNova.Biz.BizObjectFactory //AyaNova.Biz.BizRoles - //AyaNova.Biz.BizObjectNameFetcher + //AyaNova.Biz.BizObjectNameFetcher && BizObjectNameFetcherDIRECT } diff --git a/server/AyaNova/biz/BizObjectExistsInDatabase.cs b/server/AyaNova/biz/BizObjectExistsInDatabase.cs index 42482d6a..04fe6316 100644 --- a/server/AyaNova/biz/BizObjectExistsInDatabase.cs +++ b/server/AyaNova/biz/BizObjectExistsInDatabase.cs @@ -43,6 +43,9 @@ namespace AyaNova.Biz return ct.Tag.Any(m => m.Id == id); case AyaType.TagGroup: return ct.TagGroup.Any(m => m.Id == id); + case AyaType.FileAttachment: + return ct.FileAttachment.Any(m => m.Id == id); + diff --git a/server/AyaNova/biz/BizObjectNameFetcher.cs b/server/AyaNova/biz/BizObjectNameFetcher.cs index bed72fa3..c99b3b00 100644 --- a/server/AyaNova/biz/BizObjectNameFetcher.cs +++ b/server/AyaNova/biz/BizObjectNameFetcher.cs @@ -63,6 +63,8 @@ namespace AyaNova.Biz return ct.Tag.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); case AyaType.TagGroup: return ct.TagGroup.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); + case AyaType.FileAttachment: + return ct.FileAttachment.AsNoTracking().Where(m => m.Id == id).Select(m => m.DisplayFileName).FirstOrDefault(); default: throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported"); diff --git a/server/AyaNova/biz/BizObjectNameFetcherDirect.cs b/server/AyaNova/biz/BizObjectNameFetcherDirect.cs index dd37e335..4c893d3b 100644 --- a/server/AyaNova/biz/BizObjectNameFetcherDirect.cs +++ b/server/AyaNova/biz/BizObjectNameFetcherDirect.cs @@ -28,6 +28,7 @@ namespace AyaNova.Biz internal static string Name(AyaType aytype, long id, System.Data.Common.DbCommand cmd) { string TABLE = string.Empty; + string COLUMN = "name"; switch (aytype) { case AyaType.User: @@ -42,10 +43,14 @@ namespace AyaNova.Biz case AyaType.TagGroup: TABLE = "ataggroup"; break; + case AyaType.FileAttachment: + TABLE = "afileattachment"; + COLUMN = "displayfilename"; + break; default: throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported"); } - cmd.CommandText = $"SELECT m.name FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1"; + cmd.CommandText = $"SELECT m.{COLUMN} FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1"; using (var dr = cmd.ExecuteReader()) return dr.Read() ? dr.GetString(0) : "UNKNOWN"; }