From f1a1ca69d98c9c178ddcf80a90f5c4e6b8f5dd03 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 27 Feb 2020 16:25:21 +0000 Subject: [PATCH] --- server/AyaNova/biz/DataListViewBiz.cs | 11 ++++++- server/AyaNova/util/AySchema.cs | 10 +++--- server/AyaNova/util/StringUtil.cs | 46 +++++++++++++-------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/server/AyaNova/biz/DataListViewBiz.cs b/server/AyaNova/biz/DataListViewBiz.cs index ad89a7dc..7699c3c1 100644 --- a/server/AyaNova/biz/DataListViewBiz.cs +++ b/server/AyaNova/biz/DataListViewBiz.cs @@ -86,7 +86,16 @@ namespace AyaNova.Biz DataListView outObj = new DataListView(); CopyObject.Copy(dbObj, outObj); - outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255); + //generate unique name + string newUniqueName = string.Empty; + bool NotUnique = true; + long l = 1; + do + { + newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255); + NotUnique = await ct.DataListView.AnyAsync(m => m.Name == newUniqueName); + } while (NotUnique); + outObj.Name = newUniqueName; outObj.Id = 0; outObj.ConcurrencyToken = 0; diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 103b5a05..f7068483 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 = 98; - internal const long EXPECTED_INDEX_COUNT = 25; + internal const long EXPECTED_INDEX_COUNT = 26; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! @@ -167,7 +167,7 @@ namespace AyaNova.Util //Add user table - await ExecQueryAsync("CREATE TABLE auser (id BIGSERIAL PRIMARY KEY, active bool not null, name varchar(255) not null, " + + await ExecQueryAsync("CREATE TABLE auser (id BIGSERIAL PRIMARY KEY, active bool not null, name varchar(255) not null unique, " + "login text not null, password text not null, salt text not null, roles integer not null, localeid bigint not null REFERENCES alocale (id), " + "dlkey text, dlkeyexpire timestamp, usertype integer not null, employeenumber varchar(255), notes text, customerid bigint, " + "headofficeid bigint, subvendorid bigint, customfields text, tags varchar(255) ARRAY)"); @@ -266,8 +266,8 @@ namespace AyaNova.Util { LogUpdateMessage(log); - await ExecQueryAsync("CREATE TABLE adatalistview (id BIGSERIAL PRIMARY KEY, userId bigint not null, name varchar(255) not null, public bool not null," + - "listkey varchar(255) not null, listview text, UNIQUE(name))"); + await ExecQueryAsync("CREATE TABLE adatalistview (id BIGSERIAL PRIMARY KEY, userId bigint not null, name varchar(255) not null unique, public bool not null," + + "listkey varchar(255) not null, listview text)"); await SetSchemaLevelAsync(++currentSchema); } @@ -278,7 +278,7 @@ namespace AyaNova.Util if (currentSchema < 8) { LogUpdateMessage(log); - await ExecQueryAsync("CREATE TABLE atag (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, refcount bigint not null, UNIQUE(name))"); + await ExecQueryAsync("CREATE TABLE atag (id BIGSERIAL PRIMARY KEY, name varchar(255) not null unique, refcount bigint not null)"); await SetSchemaLevelAsync(++currentSchema); } diff --git a/server/AyaNova/util/StringUtil.cs b/server/AyaNova/util/StringUtil.cs index 06ad3614..b4b9faf4 100644 --- a/server/AyaNova/util/StringUtil.cs +++ b/server/AyaNova/util/StringUtil.cs @@ -90,30 +90,30 @@ namespace AyaNova.Util } - /// - /// Make a unique but duplicate object name of desired length - /// (Used by Duplicate object function) - /// - /// - /// - /// - public static string NameUniquify(string s, int maxLength) - { - //Unique string - string unique = " - " + DateUtil.SortableShortCurrentDateTimeValue; - string ret = s + unique; - var diff = maxLength - ret.Length; - if (diff < 0) - { - if (unique.Length >= maxLength) - { - throw new System.ArgumentOutOfRangeException("StringUtil::nameUniquify - maxlength> unique value, source field too short for this function?"); - } - ret = s.Substring(0, Math.Abs(diff)) + unique; - } + // /// + // /// Make a unique but duplicate object name of desired length + // /// (Used by Duplicate object function) + // /// + // /// + // /// + // /// + // public static string NameUniquify(string s, int maxLength) + // { + // //Unique string + // string unique = " - " + DateUtil.SortableShortCurrentDateTimeValue; + // string ret = s + unique; + // var diff = maxLength - ret.Length; + // if (diff < 0) + // { + // if (unique.Length >= maxLength) + // { + // throw new System.ArgumentOutOfRangeException("StringUtil::nameUniquify - maxlength> unique value, source field too short for this function?"); + // } + // ret = s.Substring(0, Math.Abs(diff)) + unique; + // } - return ret; - } + // return ret; + // } //Used to ensure a unique name generated by appending -nnn is within length requirements by splitting and chopping part of text to keep name