From 2f5d2a8d2623d6ca3ce08805e2e347eb0fe9218c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 9 Oct 2018 15:05:26 +0000 Subject: [PATCH] --- devdocs/todo.txt | 3 +-- server/AyaNova/Startup.cs | 25 +++++----------------- server/AyaNova/biz/ValidateJsonPatch.cs | 6 ++++++ server/AyaNova/biz/WidgetBiz.cs | 9 ++++---- server/AyaNova/util/AySchema.cs | 4 ++-- server/AyaNova/util/ServerBootConfig.cs | 28 ++++++++++++++++++++++++- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index e3964461..84178fc0 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -28,8 +28,7 @@ Once that is done then can steam ahead on the biz objects but until I have the c IMMEDIATE ITEMS: ================ - - Auto visible id number assigning code - - Give widgets a visible ID number scheme and add to tests + - Auto visible id number assigning code - Ensure search code process keywords includes the Visible ID value andadd test for that in Search indexing tests - Remove validation index from awidget table that was only for testing uniqueness of serial field diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 678c9d0a..7e88e047 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -363,7 +363,7 @@ namespace AyaNova // ******************** TESTING WIPE DB ***************************** // //Set this to true to wipe the db and reinstall a trial license and re-seed the data - var TESTING_REFRESH_DB = false; + var TESTING_REFRESH_DB = true; #if (DEBUG) //TESTING @@ -372,8 +372,6 @@ namespace AyaNova #endif - - if (ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE) { _log.LogWarning("BOOT: AYANOVA_PERMANENTLY_ERASE_DATABASE is true, dropping and recreating database"); @@ -389,8 +387,6 @@ namespace AyaNova _log.LogDebug("BOOT: db integrity check"); DbUtil.CheckFingerPrint(AySchema.EXPECTED_COLUMN_COUNT, AySchema.EXPECTED_INDEX_COUNT, _log); - - //Initialize license AyaNova.Core.License.Initialize(apiServerState, dbContext, _log); @@ -405,25 +401,14 @@ namespace AyaNova if (TESTING_REFRESH_DB) { AyaNova.Core.License.Fetch(apiServerState, dbContext, _log); - Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.HugeForLoadTest); + Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet); } //TESTING #endif - - //TEST AUTOID - //Note that seeder may init this already in which case this code doesn't even need to run - if (ServerBootConfig.WIDGET_SERIAL == null) - { - //query for most recently used serial number - //(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time - // so the algorithm is to keep the most recent sequence going on startup of the server) - var MostRecentWidget = dbContext.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault(); - uint MaxWidgetId = 0; - if (MostRecentWidget != null) - MaxWidgetId = MostRecentWidget.Serial; - ServerBootConfig.WIDGET_SERIAL = new AutoId(MaxWidgetId); - } + + //Set autoId values + ServerBootConfig.SetMostRecentAutoIdValuesFromDatabase(dbContext); //Open up the server for visitors apiServerState.SetOpen(); diff --git a/server/AyaNova/biz/ValidateJsonPatch.cs b/server/AyaNova/biz/ValidateJsonPatch.cs index 74b8ed56..42f81746 100644 --- a/server/AyaNova/biz/ValidateJsonPatch.cs +++ b/server/AyaNova/biz/ValidateJsonPatch.cs @@ -43,6 +43,12 @@ namespace AyaNova.Biz IsValid = false; } + if (objectPatch.Operations.Any(m => m.path == "/serial")) + { + biz.AddError(ValidationErrorType.NotChangeable, "Serial"); + IsValid = false; + } + if (objectPatch.Operations.Any(m => m.op == "add")) { biz.AddError(ValidationErrorType.InvalidOperation, "add"); diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index f89a1736..8767955e 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -78,7 +78,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); //SEARCH INDEXING - Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name); + Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString()); return outObj; @@ -109,7 +109,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext); //SEARCH INDEXING - Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name); + Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString()); return outObj; @@ -225,7 +225,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct); //Update keywords - Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name); + Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString()); return true; } @@ -234,6 +234,7 @@ namespace AyaNova.Biz internal bool Patch(Widget dbObj, JsonPatchDocument objectPatch, uint concurrencyToken) { //Validate Patch is allowed + //Note: Id, OwnerId and Serial are all checked for and disallowed in the validate code by default if (!ValidateJsonPatch.Validate(this, objectPatch)) return false; //Do the patching @@ -247,7 +248,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct); //Update keywords - Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name); + Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString()); return true; } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 062d8735..a03ec8b7 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -23,7 +23,7 @@ namespace AyaNova.Util private const int DESIRED_SCHEMA_LEVEL = 9; internal const long EXPECTED_COLUMN_COUNT = 100; - internal const long EXPECTED_INDEX_COUNT = 23; + internal const long EXPECTED_INDEX_COUNT = 22; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!! @@ -205,7 +205,7 @@ namespace AyaNova.Util "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, notes text)"); //TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS - exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);"); + //exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);"); //Compound index for name fetching diff --git a/server/AyaNova/util/ServerBootConfig.cs b/server/AyaNova/util/ServerBootConfig.cs index 6470891c..ab731f3f 100644 --- a/server/AyaNova/util/ServerBootConfig.cs +++ b/server/AyaNova/util/ServerBootConfig.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using System.Linq; namespace AyaNova.Util { @@ -12,7 +14,8 @@ namespace AyaNova.Util internal static class ServerBootConfig { - //TEST AUTOID + //AUTOID's + //Get the highest id number issued previously and start the auto-id at that level internal static AutoId WIDGET_SERIAL { get; set; } @@ -202,6 +205,29 @@ namespace AyaNova.Util } } + + //Get the auto-id most recent values at boot time + internal static void SetMostRecentAutoIdValuesFromDatabase(AyaNova.Models.AyContext ct) + { + //WIDGET SERIALS + if (WIDGET_SERIAL == null) + { + //query for most recently used serial number + //(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time + // so the algorithm is to keep the most recent sequence going on startup of the server) + var MostRecentWidget = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault(); + uint MaxWidgetId = 0; + if (MostRecentWidget != null) + MaxWidgetId = MostRecentWidget.Serial; + WIDGET_SERIAL = new AutoId(MaxWidgetId); + + } + + //OTHER SERIALS HERE IN FUTURE... + } + + + }//eoc