From b83cbed31a48743b71b52c3e79e239e6f31310ca Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 22 Jan 2020 00:47:17 +0000 Subject: [PATCH] --- devdocs/todo.txt | 13 ++----- .../Controllers/DataListFilterController.cs | 6 ++-- server/AyaNova/DataList/DataListFetcher.cs | 4 +-- .../DataListSqlFilterCriteriaBuilder.cs | 2 +- .../DataListSqlFilterOrderByBuilder.cs | 2 +- server/AyaNova/Startup.cs | 2 +- .../AyaNova/biz/BizObjectExistsInDatabase.cs | 6 ++-- server/AyaNova/biz/DataListFilterBiz.cs | 36 +++++++++---------- server/AyaNova/models/AyContext.cs | 6 ++-- .../{DataFilter.cs => DataListFilter.cs} | 2 +- server/AyaNova/models/DataListTemplate.cs | 16 +++++++++ server/AyaNova/util/AySchema.cs | 10 +++--- 12 files changed, 57 insertions(+), 48 deletions(-) rename server/AyaNova/models/{DataFilter.cs => DataListFilter.cs} (91%) create mode 100644 server/AyaNova/models/DataListTemplate.cs diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 09b64eb1..52e27ee3 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -5,22 +5,15 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTcxODU5OTU0IiwiZXhwIjoiMTU3MjQ ## IMMEDIATE ITEMS - - -Rename objectfieldscontroller / routes - -MAKE DATALIST ROUTE FOR FETCHING LISTS BY KEY - - REMOVE LISTS FROM INDIVIDUAL OBJECT ROUTES AS MUCH AS POSSIBLE - - Accepts datalist key - - finds applicable AyaDataList object for the key specified (maybe keeps a static list of them rather than finding upon reflection) - UnMock MOCK_WIDGET_DISPLAY_TEMPLATE_JSON into db with objects and with seeded data for test and or all lists - One single object with all templates in JSON maybe? since there are not going to be multiple templates for same list object anyway - Server can load it up and cache it like LT? - Can it just make a default template if none is found? (no they are all required) - Once both lists are working: -User Object datalists? +Rename DataFilter model / table etc to DataListFilter + +Make up the user Object datalists DataList object naming scheme, should it be prepended to they all align well? diff --git a/server/AyaNova/Controllers/DataListFilterController.cs b/server/AyaNova/Controllers/DataListFilterController.cs index 4f2ceb85..901c04f9 100644 --- a/server/AyaNova/Controllers/DataListFilterController.cs +++ b/server/AyaNova/Controllers/DataListFilterController.cs @@ -113,7 +113,7 @@ namespace AyaNova.Api.Controllers /// /// [HttpPut("{id}")] - public async Task PutDataFilter([FromRoute] long id, [FromBody] DataFilter inObj) + public async Task PutDataFilter([FromRoute] long id, [FromBody] DataListFilter inObj) { if (!serverState.IsOpen) return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); @@ -157,7 +157,7 @@ namespace AyaNova.Api.Controllers /// Automatically filled from route path, no need to specify in body /// [HttpPost] - public async Task PostDataFilter([FromBody] DataFilter inObj, ApiVersion apiVersion) + public async Task PostDataFilter([FromBody] DataListFilter inObj, ApiVersion apiVersion) { if (!serverState.IsOpen) return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); @@ -173,7 +173,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); //Create and validate - DataFilter o = await biz.CreateAsync(inObj); + DataListFilter o = await biz.CreateAsync(inObj); if (o == null) return BadRequest(new ApiErrorResponse(biz.Errors)); else diff --git a/server/AyaNova/DataList/DataListFetcher.cs b/server/AyaNova/DataList/DataListFetcher.cs index 76e3846d..4d8d187c 100644 --- a/server/AyaNova/DataList/DataListFetcher.cs +++ b/server/AyaNova/DataList/DataListFetcher.cs @@ -57,12 +57,12 @@ namespace AyaNova.DataList var qFrom = DataList.SQLFrom; //FILTERED? - DataFilter TheFilter = null; + DataListFilter TheFilter = null; var qWhere = string.Empty; var qOrderBy = string.Empty; if (listOptions.DataFilterId > 0) { - TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId); + TheFilter = await ct.DataListFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId); //WHERE CLAUSE - FILTER qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, DataList.FieldDefinitions, UserId); //ORDER BY CLAUSE - SORT diff --git a/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs b/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs index 4d0b83a1..0c630f54 100644 --- a/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlFilterCriteriaBuilder.cs @@ -11,7 +11,7 @@ namespace AyaNova.DataList { public static class DataListSqlFilterCriteriaBuilder { - public static string DataFilterToSQLCriteria(AyaNova.Models.DataFilter dataFilter, List objectFields, long userId) + public static string DataFilterToSQLCriteria(AyaNova.Models.DataListFilter dataFilter, List objectFields, long userId) { if (string.IsNullOrWhiteSpace(dataFilter.Filter)) diff --git a/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs b/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs index 7b5b2820..7f021ba9 100644 --- a/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlFilterOrderByBuilder.cs @@ -10,7 +10,7 @@ namespace AyaNova.DataList // public static string DefaultPickListOrderBy => "ORDER BY NAME ASC"; - public static string DataFilterToSQLOrderBy(AyaNova.Models.DataFilter dataFilter) + public static string DataFilterToSQLOrderBy(AyaNova.Models.DataListFilter dataFilter) { if (string.IsNullOrWhiteSpace(dataFilter.Sort)) diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 58c11f3f..3671331e 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -408,7 +408,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) diff --git a/server/AyaNova/biz/BizObjectExistsInDatabase.cs b/server/AyaNova/biz/BizObjectExistsInDatabase.cs index 95fdfff5..78851b87 100644 --- a/server/AyaNova/biz/BizObjectExistsInDatabase.cs +++ b/server/AyaNova/biz/BizObjectExistsInDatabase.cs @@ -38,12 +38,12 @@ namespace AyaNova.Biz case AyaType.User: return ct.User.Any(m => m.Id == id); case AyaType.Widget: - return ct.Widget.Any(m => m.Id == id); + return ct.Widget.Any(m => m.Id == id); case AyaType.FileAttachment: return ct.FileAttachment.Any(m => m.Id == id); case AyaType.DataFilter: - return ct.DataFilter.Any(m => m.Id == id); - case AyaType.FormCustom: + return ct.DataListFilter.Any(m => m.Id == id); + case AyaType.FormCustom: return ct.FormCustom.Any(m => m.Id == id); diff --git a/server/AyaNova/biz/DataListFilterBiz.cs b/server/AyaNova/biz/DataListFilterBiz.cs index e1a75f47..e64986fe 100644 --- a/server/AyaNova/biz/DataListFilterBiz.cs +++ b/server/AyaNova/biz/DataListFilterBiz.cs @@ -40,20 +40,20 @@ namespace AyaNova.Biz //EXISTS internal async Task ExistsAsync(long id) { - return await ct.DataFilter.AnyAsync(e => e.Id == id); + return await ct.DataListFilter.AnyAsync(e => e.Id == id); } //////////////////////////////////////////////////////////////////////////////////////////////// /// GET - internal async Task GetNoLogAsync(long fetchId) + internal async Task GetNoLogAsync(long fetchId) { //This is simple so nothing more here, but often will be copying to a different output object or some other ops - return await ct.DataFilter.SingleOrDefaultAsync(m => m.Id == fetchId); + return await ct.DataListFilter.SingleOrDefaultAsync(m => m.Id == fetchId); } //////////////////////////////////////////////////////////////////////////////////////////////// //CREATE - internal async Task CreateAsync(DataFilter inObj) + internal async Task CreateAsync(DataListFilter inObj) { Validate(inObj, true); if (HasErrors) @@ -61,11 +61,11 @@ namespace AyaNova.Biz else { //do stuff with datafilter - DataFilter outObj = inObj; + DataListFilter outObj = inObj; outObj.UserId = UserId; - await ct.DataFilter.AddAsync(outObj); + await ct.DataListFilter.AddAsync(outObj); await ct.SaveChangesAsync(); //Handle child and associated items: @@ -83,7 +83,7 @@ namespace AyaNova.Biz //////////////////////////////////////////////////////////////////////////////////////////////// //CREATE - internal DataFilter Create(AyContext TempContext, DataFilter inObj) + internal DataListFilter Create(AyContext TempContext, DataListFilter inObj) { Validate(inObj, true); if (HasErrors) @@ -91,11 +91,11 @@ namespace AyaNova.Biz else { //do stuff with datafilter - DataFilter outObj = inObj; + DataListFilter outObj = inObj; outObj.UserId = UserId; - TempContext.DataFilter.Add(outObj); + TempContext.DataListFilter.Add(outObj); TempContext.SaveChanges(); //Handle child and associated items: @@ -115,10 +115,10 @@ namespace AyaNova.Biz /// GET //Get one - internal async Task GetAsync(long fetchId) + internal async Task GetAsync(long fetchId) { //This is simple so nothing more here, but often will be copying to a different output object or some other ops - var ret = await ct.DataFilter.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId)); + var ret = await ct.DataListFilter.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId)); if (ret != null) { //Log @@ -134,7 +134,7 @@ namespace AyaNova.Biz List items = new List(); if (!string.IsNullOrWhiteSpace(listKey)) { - items = await ct.DataFilter + items = await ct.DataListFilter .AsNoTracking() .Where(m => m.ListKey == listKey && (m.Public == true || m.UserId == UserId)) .OrderBy(m => m.Name) @@ -156,7 +156,7 @@ namespace AyaNova.Biz // //put - internal bool Put(DataFilter dbObj, DataFilter inObj) + internal bool Put(DataListFilter dbObj, DataListFilter inObj) { //preserve the owner ID if none was specified if (inObj.UserId == 0) @@ -185,7 +185,7 @@ namespace AyaNova.Biz //////////////////////////////////////////////////////////////////////////////////////////////// //DELETE // - internal bool Delete(DataFilter dbObj) + internal bool Delete(DataListFilter dbObj) { //Determine if the object can be deleted, do the deletion tentatively //Probably also in here deal with tags and associated search text etc @@ -193,7 +193,7 @@ namespace AyaNova.Biz ValidateCanDelete(dbObj); if (HasErrors) return false; - ct.DataFilter.Remove(dbObj); + ct.DataListFilter.Remove(dbObj); ct.SaveChanges(); //Delete sibling objects @@ -214,7 +214,7 @@ namespace AyaNova.Biz // //Can save or update? - private void Validate(DataFilter inObj, bool isNew) + private void Validate(DataListFilter inObj, bool isNew) { //UserId required @@ -238,7 +238,7 @@ namespace AyaNova.Biz if (!PropertyHasErrors("Name")) { //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false - if (ct.DataFilter.Any(m => m.Name == inObj.Name && m.Id != inObj.Id)) + if (ct.DataListFilter.Any(m => m.Name == inObj.Name && m.Id != inObj.Id)) { AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name"); } @@ -386,7 +386,7 @@ namespace AyaNova.Biz //Can delete? - private void ValidateCanDelete(DataFilter inObj) + private void ValidateCanDelete(DataListFilter inObj) { //Leaving this off for now } diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index f4cc1ff2..49adbb5f 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -1,8 +1,5 @@ -using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; -using AyaNova.Util; -using Microsoft.Extensions.Logging; namespace AyaNova.Models { @@ -20,9 +17,10 @@ namespace AyaNova.Models public virtual DbSet OpsJobLog { get; set; } public virtual DbSet Locale { get; set; } public virtual DbSet LocaleItem { get; set; } - public virtual DbSet DataFilter { get; set; } + public virtual DbSet DataListFilter { get; set; } public virtual DbSet Tag { get; set; } public virtual DbSet FormCustom { get; set; } + public virtual DbSet DataListTemplate { 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/DataFilter.cs b/server/AyaNova/models/DataListFilter.cs similarity index 91% rename from server/AyaNova/models/DataFilter.cs rename to server/AyaNova/models/DataListFilter.cs index abb580bb..9c4f035f 100644 --- a/server/AyaNova/models/DataFilter.cs +++ b/server/AyaNova/models/DataListFilter.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations; namespace AyaNova.Models { - public partial class DataFilter + public partial class DataListFilter { public long Id { get; set; } public uint ConcurrencyToken { get; set; } diff --git a/server/AyaNova/models/DataListTemplate.cs b/server/AyaNova/models/DataListTemplate.cs new file mode 100644 index 00000000..29607c9d --- /dev/null +++ b/server/AyaNova/models/DataListTemplate.cs @@ -0,0 +1,16 @@ + +using System.ComponentModel.DataAnnotations; + +namespace AyaNova.Models +{ + + public partial class DataListTemplate + { + public long Id { get; set; } + public uint ConcurrencyToken { get; set; } + [Required] + public string DataListKey { get; set; } + public string Template { get; set; }//JSON fragment template + + } +} diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index bf501ca6..bce127e4 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 = 9; - internal const long EXPECTED_COLUMN_COUNT = 96; - internal const long EXPECTED_INDEX_COUNT = 24; + internal const long EXPECTED_COLUMN_COUNT = 99; + internal const long EXPECTED_INDEX_COUNT = 26; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! @@ -261,13 +261,15 @@ namespace AyaNova.Util ////////////////////////////////////////////////// - //DATAFILTER table + //DATAFILTER / DATALISTTEMPLATE tables if (currentSchema < 7) { LogUpdateMessage(log); - exec("CREATE TABLE adatafilter (id BIGSERIAL PRIMARY KEY, userId bigint not null, name varchar(255) not null, public bool not null," + + exec("CREATE TABLE adatalistfilter (id BIGSERIAL PRIMARY KEY, userId bigint not null, name varchar(255) not null, public bool not null," + "listkey varchar(255) not null, filter text, sort text, UNIQUE(name))"); + + exec("CREATE TABLE adatalisttemplate (id BIGSERIAL PRIMARY KEY, datalistkey text not null, template text, UNIQUE(datalistkey))"); setSchemaLevel(++currentSchema); }