From 22ac0d9189828da75e925e488f2524872cb89b52 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 23 Dec 2020 15:42:39 +0000 Subject: [PATCH] --- .../Controllers/TranslationController.cs | 1 + server/AyaNova/biz/ReviewBiz.cs | 9 +- server/AyaNova/biz/TranslationBiz.cs | 86 +++++++++++++------ 3 files changed, 69 insertions(+), 27 deletions(-) diff --git a/server/AyaNova/Controllers/TranslationController.cs b/server/AyaNova/Controllers/TranslationController.cs index 464a5ed9..385ca31e 100644 --- a/server/AyaNova/Controllers/TranslationController.cs +++ b/server/AyaNova/Controllers/TranslationController.cs @@ -187,6 +187,7 @@ namespace AyaNova.Api.Controllers [AllowAnonymous] public async Task SubSet([FromRoute] long id, [FromBody] List inObj) { + //## NOTE: This route is ONLY used at present for the reset password form at the client if (serverState.IsClosed) return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); var l = await TranslationBiz.GetSpecifiedTranslationSubsetStaticAsync(inObj, id); diff --git a/server/AyaNova/biz/ReviewBiz.cs b/server/AyaNova/biz/ReviewBiz.cs index 7d537c32..68fe2062 100644 --- a/server/AyaNova/biz/ReviewBiz.cs +++ b/server/AyaNova/biz/ReviewBiz.cs @@ -465,7 +465,7 @@ namespace AyaNova.Biz //////////////////////////////////////////////////////////////////////////////////////////////// // NOTIFICATION PROCESSING // - public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj=null) + public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null) { ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger(); if (ServerBootConfig.SEEDING) return; @@ -501,6 +501,8 @@ namespace AyaNova.Biz } { + var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId); + NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.GeneralNotification, @@ -508,7 +510,7 @@ namespace AyaNova.Biz ObjectId = proposedObj.Id, AyaType = AyaType.Review, NotifySubscriptionId = userNotifySub.Id, - Name = "LT:ReviewOverDue - " + proposedObj.Name, + Name = $"{eventNameTranslated} - {proposedObj.Name}", EventDate = r.DueDate }; await ct.NotifyEvent.AddAsync(n); @@ -517,6 +519,7 @@ namespace AyaNova.Biz if (supervisorNotifySub != null) { + var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId); NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.GeneralNotification, @@ -524,7 +527,7 @@ namespace AyaNova.Biz ObjectId = proposedObj.Id, AyaType = AyaType.Review, NotifySubscriptionId = supervisorNotifySub.Id, - Name = "LT:ReviewOverDue - " + proposedObj.Name, + Name = $"{eventNameTranslated} - {proposedObj.Name}", EventDate = r.DueDate }; await ct.NotifyEvent.AddAsync(n); diff --git a/server/AyaNova/biz/TranslationBiz.cs b/server/AyaNova/biz/TranslationBiz.cs index 0959a18e..a11b60d9 100644 --- a/server/AyaNova/biz/TranslationBiz.cs +++ b/server/AyaNova/biz/TranslationBiz.cs @@ -12,7 +12,7 @@ namespace AyaNova.Biz internal class TranslationBiz : BizObject { - + internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles) { @@ -20,7 +20,7 @@ namespace AyaNova.Biz UserId = currentUserId; UserTranslationId = userTranslationId; CurrentUserRoles = userRoles; - BizType = AyaType.Translation; + BizType = AyaType.Translation; } internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) @@ -335,7 +335,7 @@ namespace AyaNova.Biz // Get subset for specified translation ID // called from controller and Used when user is not logged in // e.g. when resetting their password - // + // ## NOTE: NO other use for this other than the reset password at this point internal static async Task>> GetSpecifiedTranslationSubsetStaticAsync(List param, long translationId) { #if (DEBUG) @@ -371,6 +371,43 @@ namespace AyaNova.Biz } } + + + + ///////////////////////////////////////////////////////////////// + // Get subset for specified user (looks up translation id) statically + // called from internal code (e.g. notification processing) + // + internal static async Task> GetSubsetForUserStaticAsync(List param, long userId) + { + long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID; + using (AyContext ct = ServiceProviderProvider.DBContext) + { + translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync(); + } + return await GetSubsetStaticAsync(param, translationId); + } + + ///////////////////////////////////////////////////////////////// + // Get single item for specified user (looks up translation id) statically + // called from internal code (e.g. notification processing) + // + internal static async Task GetTranslationForUserStaticAsync(string translationKey, long userId) + { + long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID; + using (AyContext ct = ServiceProviderProvider.DBContext) + { + translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync(); + } + var param = new List() { translationKey }; + var ret = await GetSubsetStaticAsync(param, translationId); + if (ret.Count > 0) return ret[translationKey]; + return $"??{translationKey}"; + } + + + + //used by internal notification and other processes i.e. "Server" in all languages for server based notifications internal static async Task> GetAllTranslationsForKey(string translationKey) { @@ -394,28 +431,29 @@ namespace AyaNova.Biz } - /// - /// Get the value of the key provided in the default translation chosen - /// - /// - /// - internal static async Task GetDefaultTranslationAsync(string key) - { - if (string.IsNullOrWhiteSpace(key)) - return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED"; -#if (DEBUG) - TrackRequestedKey(key); -#endif - using (AyContext ct = ServiceProviderProvider.DBContext) - return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync(); - } + //DEPRECATED + // /// + // /// Get the value of the key provided in the default translation chosen + // /// + // /// + // /// + // internal static async Task GetDefaultTranslationAsync(string key) + // { + // if (string.IsNullOrWhiteSpace(key)) + // return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED"; + // #if (DEBUG) + // TrackRequestedKey(key); + // #endif + // using (AyContext ct = ServiceProviderProvider.DBContext) + // return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync(); + // } - //Get all stock keys that are valid (used for key coverage reporting) - internal static async Task> GetKeyListAsync() - { - using (AyContext ct = ServiceProviderProvider.DBContext) - return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync(); - } + // //Get all stock keys that are valid (used for key coverage reporting) + // internal static async Task> GetKeyListAsync() + // { + // using (AyContext ct = ServiceProviderProvider.DBContext) + // return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync(); + // }