From fa1e65935ec69ffea9d7c536b1119ff533416e40 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 24 Mar 2020 23:41:13 +0000 Subject: [PATCH] Addition of global business settings for static server use (equivalent of v7 Global object) --- server/AyaNova/Startup.cs | 4 ++ server/AyaNova/models/AyContext.cs | 5 +- server/AyaNova/models/GlobalBizSettings.cs | 22 +++++++++ server/AyaNova/util/AySchema.cs | 8 +++- server/AyaNova/util/ServerBootConfig.cs | 1 - .../AyaNova/util/ServerGlobalBizSettings.cs | 47 +++++++++++++++++++ 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 server/AyaNova/models/GlobalBizSettings.cs create mode 100644 server/AyaNova/util/ServerGlobalBizSettings.cs diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 2d1a37d2..172aec23 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -442,6 +442,10 @@ namespace AyaNova //Initialize license AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait(); + //Set static global biz settings + _newLog.LogDebug("BOOT: init global settings"); + ServerGlobalBizSettings.Initialize(null, dbContext); + //Ensure translations are present, not missing any keys and that there is a server default translation that exists TranslationBiz lb = new TranslationBiz(dbContext, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.OpsAdminFull); lb.ValidateTranslationsAsync().Wait(); diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index 6a06541b..aacfd59c 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -5,6 +5,7 @@ namespace AyaNova.Models { public partial class AyContext : DbContext { + public virtual DbSet GlobalBizSettings { get; set; } public virtual DbSet Event { get; set; } public virtual DbSet SearchDictionary { get; set; } public virtual DbSet SearchKey { get; set; } @@ -20,8 +21,8 @@ namespace AyaNova.Models public virtual DbSet DataListView { get; set; } public virtual DbSet Tag { get; set; } public virtual DbSet FormCustom { get; set; } - public virtual DbSet PickListTemplate { get; set; } - + public virtual DbSet PickListTemplate { get; set; } + //Note: had to add this constructor to work with the code in startup.cs that gets the connection string from the appsettings.json file //and commented out the above on configuring diff --git a/server/AyaNova/models/GlobalBizSettings.cs b/server/AyaNova/models/GlobalBizSettings.cs new file mode 100644 index 00000000..ff0a244f --- /dev/null +++ b/server/AyaNova/models/GlobalBizSettings.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; +namespace AyaNova.Models +{ + + public partial class GlobalBizSettings + { + public long Id { get; set; }//this is always 1 as there is only ever one single global biz object + public uint ConcurrencyToken { get; set; } + + //Global settings + //Picklist and other searches override the normal case insensitive value + //this is precautionarily added for non latinate languages where it could be an issue + public bool SearchCaseSensitiveOnly {get;set;} + + public GlobalBizSettings() + { + Id=1;//always 1 + SearchCaseSensitiveOnly = false; + } + } +} diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 7afd36f9..65d887e3 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -22,8 +22,8 @@ namespace AyaNova.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 10; - internal const long EXPECTED_COLUMN_COUNT = 100; - internal const long EXPECTED_INDEX_COUNT = 27; + internal const long EXPECTED_COLUMN_COUNT = 102; + internal const long EXPECTED_INDEX_COUNT = 28; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! @@ -138,6 +138,10 @@ namespace AyaNova.Util { LogUpdateMessage(log); + //create global biz settings table + await ExecQueryAsync("CREATE TABLE aglobalbizsettings (id integer NOT NULL PRIMARY KEY, " + + "searchcasesensitiveonly bool default false)"); + //create aevent biz event log table await ExecQueryAsync("CREATE TABLE aevent (id BIGSERIAL PRIMARY KEY, created timestamp not null, userid bigint not null," + "ayid bigint not null, aytype integer not null, ayevent integer not null, textra varchar(255))"); diff --git a/server/AyaNova/util/ServerBootConfig.cs b/server/AyaNova/util/ServerBootConfig.cs index 58420cef..d4259f36 100644 --- a/server/AyaNova/util/ServerBootConfig.cs +++ b/server/AyaNova/util/ServerBootConfig.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using Microsoft.Extensions.Configuration; diff --git a/server/AyaNova/util/ServerGlobalBizSettings.cs b/server/AyaNova/util/ServerGlobalBizSettings.cs new file mode 100644 index 00000000..203d55b2 --- /dev/null +++ b/server/AyaNova/util/ServerGlobalBizSettings.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.IO; +using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using System.Linq; +using AyaNova.Models; + +namespace AyaNova.Util +{ + + /// + /// Contains static mirror copy in memory of global settings values that are set from DB during boot + /// and accessible to Biz admin user (equivalent of v7's global object) + /// used by many areas of the biz logic and processing too often to fetch on every request + /// set at boot and on any update to the db global biz settings record + /// + internal static class ServerGlobalBizSettings + { + + internal static bool SearchCaseSensitiveOnly { get; set; } + + /// + /// Populate and / or create the settings + /// + internal static void Initialize(GlobalBizSettings global, AyContext ct = null) + { + + if (global == null) + { + //fetch or create as not provided (meaning this was called from Startup.cs) + global = ct.GlobalBizSettings.FirstOrDefault(m => m.Id == 1); + if (global == null) + { + global = new GlobalBizSettings(); + ct.GlobalBizSettings.Add(global); + ct.SaveChanges(); + } + } + + + SearchCaseSensitiveOnly = global.SearchCaseSensitiveOnly; + } + + + + }//eoc +}//eons \ No newline at end of file