From 39d39631cd5a6526dd5682c50b8860993387ce2f Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 7 Dec 2021 16:03:51 +0700 Subject: [PATCH 01/11] Don't use a global dict in custom field handling --- .../DataConverters/ConvertFdoToMongoCustomField.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs index f687b071..348258e7 100644 --- a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs +++ b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs @@ -47,7 +47,6 @@ public class ConvertFdoToMongoCustomField }; private Dictionary GuidToListCode; - private Dictionary _fieldNameToFieldType; public ConvertFdoToMongoCustomField(FdoCache cache, FwServiceLocatorCache serviceLocator, ILogger logger) { @@ -68,7 +67,6 @@ public ConvertFdoToMongoCustomField(FdoCache cache, FwServiceLocatorCache servic {servLoc.LanguageProject.StatusOA.Guid, MagicStrings.LfOptionListCodeForStatus}, {servLoc.LanguageProject.LexDbOA.UsageTypesOA.Guid, MagicStrings.LfOptionListCodeForUsageTypes} }; - _fieldNameToFieldType = new Dictionary(); } public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes) @@ -81,7 +79,7 @@ public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary(); foreach (string lfCustomFieldName in lfCustomFieldList.Keys) { - customFieldSpecs.Add(new CustomFieldSpec(lfCustomFieldName, _fieldNameToFieldType[lfCustomFieldName])); + customFieldSpecs.Add(new CustomFieldSpec(lfCustomFieldName, lfCustomFieldTypes[lfCustomFieldName])); } var lfproxy = MainClass.Container.Resolve(); @@ -156,7 +154,6 @@ Dictionary lfCustomFieldTypes continue; string lfCustomFieldName = ConvertUtilities.NormalizedFieldName(label, fieldSourceType); CellarPropertyType fdoFieldType = (CellarPropertyType)fdoMetaData.GetFieldType(flid); - _fieldNameToFieldType[lfCustomFieldName] = fdoFieldType.ToString(); // TODO: Comment this one OUT. Bad design. lfCustomFieldTypes[lfCustomFieldName] = fdoFieldType.ToString(); string lfCustomFieldType; if (CellarPropertyTypeToLfCustomFieldType.TryGetValue(fdoFieldType, out lfCustomFieldType)) From 805575d22b065ec076e7732c1c9a17b67a67c86e Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 7 Dec 2021 16:06:19 +0700 Subject: [PATCH 02/11] MongoConnection can now update role & user views This is the first step towards being able to get rid of the RunClass code and not have our C# code call our PHP code. --- src/LfMerge.Core.Tests/TestDoubles.cs | 2 +- .../ConvertFdoToMongoLexicon.cs | 2 +- .../Config/LfRoleOrUserViewConfig.cs | 63 ++++++++++++++++++ .../MongoConnector/IMongoConnection.cs | 2 +- .../MongoConnector/MongoConnection.cs | 65 ++++++++++++++++++- 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs diff --git a/src/LfMerge.Core.Tests/TestDoubles.cs b/src/LfMerge.Core.Tests/TestDoubles.cs index 138ff563..7dfbb577 100644 --- a/src/LfMerge.Core.Tests/TestDoubles.cs +++ b/src/LfMerge.Core.Tests/TestDoubles.cs @@ -172,7 +172,7 @@ public bool SetInputSystems(ILfProject project, Dictionary lfCustomFieldList) + public bool SetCustomFieldConfig(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes) { if (lfCustomFieldList == null) _storedCustomFieldConfig = new Dictionary(); diff --git a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs index 2fcd8cf9..adb85c8a 100644 --- a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs +++ b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs @@ -109,7 +109,7 @@ public void RunConversion() Dictionary lfCustomFieldList = new Dictionary(); Dictionary lfCustomFieldTypes = new Dictionary(); _convertCustomField.WriteCustomFieldConfig(lfCustomFieldList, lfCustomFieldTypes); - Connection.SetCustomFieldConfig(LfProject, lfCustomFieldList); + Connection.SetCustomFieldConfig(LfProject, lfCustomFieldList, lfCustomFieldTypes); _convertCustomField.CreateCustomFieldsConfigViews(LfProject, lfCustomFieldList, lfCustomFieldTypes); Dictionary previousModificationDates = Connection.GetAllModifiedDatesForEntries(LfProject); diff --git a/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs b/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs new file mode 100644 index 00000000..a82cb64d --- /dev/null +++ b/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using MongoDB.Bson; + +namespace LfMerge.Core.LanguageForge.Config +{ + public class LexRoleOrUserViewConfig + { + public string[] InputSystems; + public Dictionary Fields; + public Dictionary ShowTasks; + } + + public class LexViewFieldConfig + { + public bool Show; + public string Type; + + public LexViewFieldConfig(string type, bool show = true) + { + Show = show; + Type = type; + } + public LexViewFieldConfig(bool show = true) : this("basic", show) {} + } + + public class LexViewMultiTextFieldConfig: LexViewFieldConfig + { + public bool OverrideInputSystems; + public string[] InputSystems; + + public LexViewMultiTextFieldConfig(bool show = true) : base("multitext", show) + { + this.OverrideInputSystems = false; + this.InputSystems = new string[]{}; + } + } + + public static class LexViewFieldConfigFactory + { + public static LexViewFieldConfig CreateByType(string lfCustomFieldType, bool show = true) { + if (lfCustomFieldType == "MultiUnicode" || lfCustomFieldType == "MultiString") { + return new LexViewMultiTextFieldConfig(show); + } else { + return new LexViewFieldConfig(show); + } + } + + public static BsonDocument CreateBsonDocumentByType(string lfCustomFieldType, bool show = true) { + LexViewFieldConfig config = CreateByType(lfCustomFieldType, show); + var result = new BsonDocument(); + result.Set("show", new BsonBoolean(config.Show)); + result.Set("type", new BsonString(config.Type)); + var multiTextConfig = config as LexViewMultiTextFieldConfig; + if (multiTextConfig != null) { + result.Set("overrideInputSystems", new BsonBoolean(multiTextConfig.OverrideInputSystems)); + if (multiTextConfig.InputSystems != null && multiTextConfig.InputSystems.Length > 0) { + result.Set("inputSystems", new BsonArray(multiTextConfig.InputSystems)); + } + } + return result; + } + } +} diff --git a/src/LfMerge.Core/MongoConnector/IMongoConnection.cs b/src/LfMerge.Core/MongoConnector/IMongoConnection.cs index 336244f8..44914b38 100644 --- a/src/LfMerge.Core/MongoConnector/IMongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/IMongoConnection.cs @@ -29,7 +29,7 @@ public interface IMongoConnection void UpdateCommentStatuses(ILfProject project, List>> statusChanges); bool SetInputSystems(ILfProject project, Dictionary inputSystems, List vernacularWss, List analysisWss, List pronunciationWss); - bool SetCustomFieldConfig(ILfProject project, Dictionary lfCustomFieldList); + bool SetCustomFieldConfig(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes); Dictionary GetCustomFieldConfig(ILfProject project); bool SetLastSyncedDate(ILfProject project, DateTime? newSyncedDate); // TODO: Decide if this is really where this method belongs void SetCommentReplyGuids(ILfProject project, IDictionary uniqIdToGuidMappings); diff --git a/src/LfMerge.Core/MongoConnector/MongoConnection.cs b/src/LfMerge.Core/MongoConnector/MongoConnection.cs index bf93143a..c6563662 100644 --- a/src/LfMerge.Core/MongoConnector/MongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/MongoConnection.cs @@ -645,6 +645,22 @@ public bool SetInputSystems(ILfProject project, Dictionary /// Remove previous project custom field configurations that no longer exist, /// and then update them at the appropriate entry, senses, and examples level. @@ -653,7 +669,7 @@ public bool SetInputSystems(ILfProject project, DictionaryLF project /// Dictionary of LF custom field settings /// True if mongodb was updated - public bool SetCustomFieldConfig(ILfProject project, Dictionary lfCustomFieldList) + public bool SetCustomFieldConfig(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes) { // Logger.Debug("Setting {0} custom field setting(s)", lfCustomFieldList.Count()); @@ -672,8 +688,16 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary senseCustomFieldOrder = new List(); List exampleCustomFieldOrder = new List(); + Dictionary customFieldConfig = GetCustomFieldConfig(project); + BsonDocument roleViews = GetRoleViews(project); + BsonDocument userViews = GetUserViews(project); + + List roleViewNames = roleViews.Names.ToList(); + List userViewNames = userViews.Names.ToList(); + // Note that userViewNames doesn't contain usernames like "rmunn", but ObjectId strings like "54c780ea863f1c2127635ca9" + // Clean out previous fields and fieldOrders that no longer exist (removed from FDO) - foreach (string customFieldNameToRemove in GetCustomFieldConfig(project).Keys.Except(lfCustomFieldList.Keys.ToList())) + foreach (string customFieldNameToRemove in customFieldConfig.Keys.Except(lfCustomFieldList.Keys.ToList())) { if (customFieldNameToRemove.StartsWith(MagicStrings.LfCustomFieldEntryPrefix)) { @@ -690,6 +714,13 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary 0) previousUpdates.Add(builder.PullAll("config.entry.fieldOrder", entryCustomFieldOrder)); @@ -705,6 +736,35 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary(); foreach (var customFieldKVP in lfCustomFieldList) { + string fieldName = customFieldKVP.Key; + LfConfigFieldBase fieldConfig = customFieldKVP.Value; + + string fieldType; + if (!lfCustomFieldTypes.TryGetValue(fieldName, out fieldType)) { + fieldType = "basic"; + } + BsonDocument viewFieldConfig = LexViewFieldConfigFactory.CreateBsonDocumentByType(fieldType); + + foreach (var viewName in roleViewNames) { + BsonValue value = roleViews.GetValue(viewName); + if (value != null && value.IsBsonDocument) { + BsonDocument view = value.AsBsonDocument; + if (!view.Contains(fieldName)) { + currentUpdates.Add(builder.Set(String.Format("config.roleViews.{0}.fields.{1}", viewName, fieldName), viewFieldConfig)); + } + } + } + + foreach (var viewName in userViewNames) { + BsonValue value = userViews.GetValue(viewName); + if (value != null && value.IsBsonDocument) { + BsonDocument view = value.AsBsonDocument; + if (!view.Contains(fieldName)) { + currentUpdates.Add(builder.Set(String.Format("config.userViews.{0}.fields.{1}", viewName, fieldName), viewFieldConfig)); + } + } + } + if (customFieldKVP.Key.StartsWith(MagicStrings.LfCustomFieldEntryPrefix)) { currentUpdates.Add(builder.Set(String.Format("config.entry.fields.{0}", customFieldKVP.Key), customFieldKVP.Value)); @@ -721,6 +781,7 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary 0) currentUpdates.Add(builder.AddToSetEach("config.entry.fieldOrder", entryCustomFieldOrder)); if (senseCustomFieldOrder.Count > 0) From eb742af9fed91ea3f6ff4f55ec71951f5ea9647e Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 7 Dec 2021 16:11:24 +0700 Subject: [PATCH 03/11] Remove LanguageForgeProxy class entirely Now that the MongoConnection knows how to update role views and user views, this is no longer needed at all. --- .../Infrastructure/LanguageForgeProxyTests.cs | 86 ------------------- .../LanguageForgeProxyMock.cs | 30 ------- .../ConvertFdoToMongoCustomField.cs | 8 +- .../Infrastructure/ILanguageForgeProxy.cs | 15 ---- .../Infrastructure/LanguageForgeProxy.cs | 78 ----------------- .../Infrastructure/RunClassParameters.cs | 24 ------ src/LfMerge.Core/MainClass.cs | 1 - 7 files changed, 2 insertions(+), 240 deletions(-) delete mode 100644 src/LfMerge.Core.Tests/LanguageForge/Infrastructure/LanguageForgeProxyTests.cs delete mode 100644 src/LfMerge.Core.Tests/LanguageForgeProxyMock.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Infrastructure/ILanguageForgeProxy.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Infrastructure/LanguageForgeProxy.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Infrastructure/RunClassParameters.cs diff --git a/src/LfMerge.Core.Tests/LanguageForge/Infrastructure/LanguageForgeProxyTests.cs b/src/LfMerge.Core.Tests/LanguageForge/Infrastructure/LanguageForgeProxyTests.cs deleted file mode 100644 index d2f0ea4f..00000000 --- a/src/LfMerge.Core.Tests/LanguageForge/Infrastructure/LanguageForgeProxyTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using LfMerge.Core.LanguageForge.Infrastructure; -using Newtonsoft.Json; -using NUnit.Framework; -using Palaso.TestUtilities; - -namespace LfMerge.Core.Tests.LanguageForge.Infrastructure -{ - [TestFixture] - [Category("IntegrationTests")] - public class LanguageForgeProxyTests - { - private const string testProjectCode = "testlangproj"; - private const int originalNumOfFdoEntries = 63; - private TemporaryFolder LanguageForgeFolder; - private TestEnvironment _env; - - [TestFixtureSetUp] - public void FixtureSetUp() - { - LanguageForgeFolder = new TemporaryFolder("FdoTestFixture"); - _env = new TestEnvironment( - resetLfProjectsDuringCleanup: false, - languageForgeServerFolder: LanguageForgeFolder, - registerLfProxyMock: false - ); - } - - [TestFixtureTearDown] - public void FixtureTearDown() - { - try - { - LanguageForgeProjectAccessor.Reset(); // This disposes of lfProj - LanguageForgeFolder.Dispose(); - _env.Dispose(); - } - catch (Exception) - { - // This can happen if the objects already got disposed somewhere else. - // It doesn't really matter since we're in the process of doing cleanup anyways. - // So just ignore the exception. - } - } - - [Test] - [Explicit("Requires users in the mongo database, i.e. requires setup languageforge database")] - public void ListUsers_CanCallPhpClass() - { - // Setup - var sut = new LanguageForgeProxy(); - - // Exercise - string output = sut.ListUsers(); - - // Verify - var result = JsonConvert.DeserializeObject>(output); - Assert.That(output, Is.Not.Empty); - Assert.That(result["count"], Is.GreaterThan(0)); - } - - [Test] - [Explicit("Assumes PHP unit tests have been run once")] - public void UpdateCustomFieldViews_ReturnsProjectId() - { - // Setup - var customFieldSpecs = new List(); - customFieldSpecs.Add(new CustomFieldSpec("customField_entry_testMultiPara", "OwningAtom")); - customFieldSpecs.Add(new CustomFieldSpec("customField_examples_testOptionList", "ReferenceAtom")); - var sut = new LanguageForgeProxy(); - - // Exercise - string output = sut.UpdateCustomFieldViews("TestCode1", customFieldSpecs, true); - - // Verify - var result = JsonConvert.DeserializeObject(output); - Assert.That(output, Is.Not.Empty); - Assert.That(output, Is.Not.EqualTo("false")); - Assert.That(result, Is.Not.Empty); - } - } -} - diff --git a/src/LfMerge.Core.Tests/LanguageForgeProxyMock.cs b/src/LfMerge.Core.Tests/LanguageForgeProxyMock.cs deleted file mode 100644 index 7dab500b..00000000 --- a/src/LfMerge.Core.Tests/LanguageForgeProxyMock.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using LfMerge.Core.LanguageForge.Infrastructure; -using System.Collections.Generic; - -namespace LfMerge.Core.Tests -{ - public class LanguageForgeProxyMock: ILanguageForgeProxy - { - #region ILanguageForgeProxy implementation - - public string UpdateCustomFieldViews(string projectCode, List customFieldSpecs) - { - return UpdateCustomFieldViews(projectCode, customFieldSpecs, false); - } - - public string UpdateCustomFieldViews(string projectCode, List customFieldSpecs, bool isTest) - { - return "true"; - } - - public string ListUsers() - { - return null; - } - - #endregion - } -} - diff --git a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs index 348258e7..9b635710 100644 --- a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs +++ b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs @@ -74,6 +74,7 @@ public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes, bool isTest) { var customFieldSpecs = new List(); @@ -81,12 +82,7 @@ public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary(); - string output = lfproxy.UpdateCustomFieldViews(project.ProjectCode, customFieldSpecs, isTest); - - if (string.IsNullOrEmpty(output) || output == "false") - return false; + // TODO: This no longer needs to return a bool return true; } diff --git a/src/LfMerge.Core/LanguageForge/Infrastructure/ILanguageForgeProxy.cs b/src/LfMerge.Core/LanguageForge/Infrastructure/ILanguageForgeProxy.cs deleted file mode 100644 index 4e7e6ba0..00000000 --- a/src/LfMerge.Core/LanguageForge/Infrastructure/ILanguageForgeProxy.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System.Collections.Generic; - -namespace LfMerge.Core.LanguageForge.Infrastructure -{ - public interface ILanguageForgeProxy - { - string UpdateCustomFieldViews(string projectCode, List customFieldSpecs); - string UpdateCustomFieldViews(string projectCode, List customFieldSpecs, bool isTest); - - string ListUsers(); - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Infrastructure/LanguageForgeProxy.cs b/src/LfMerge.Core/LanguageForge/Infrastructure/LanguageForgeProxy.cs deleted file mode 100644 index 7e0cdb8e..00000000 --- a/src/LfMerge.Core/LanguageForge/Infrastructure/LanguageForgeProxy.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using Autofac; -using LfMerge.Core.Settings; -using Newtonsoft.Json; - -namespace LfMerge.Core.LanguageForge.Infrastructure -{ - public class LanguageForgeProxy: ILanguageForgeProxy - { - public string UpdateCustomFieldViews(string projectCode, List customFieldSpecs) - { - return UpdateCustomFieldViews(projectCode, customFieldSpecs, false); - } - - public string UpdateCustomFieldViews(string projectCode, List customFieldSpecs, bool isTest) - { - const string className = "Api\\Model\\Languageforge\\Lexicon\\Command\\LexProjectCommands"; - const string methodName = "updateCustomFieldViews"; - var parameters = new List(); - parameters.Add(projectCode); - parameters.Add(customFieldSpecs); - return RunClass(className, methodName, parameters, isTest); - } - - public string ListUsers() - { - const string className = "Api\\Model\\Command\\UserCommands"; - const string methodName = "listUsers"; - var parameters = new List(); - - return RunClass(className, methodName, parameters); - } - - private static string RunClass(string className, string methodName, List parameters) - { - return RunClass(className, methodName, parameters, false); - } - - private static string RunClass(string className, string methodName, List parameters, bool isTest) - { - var runClassParameters = new RunClassParameters(className, methodName, parameters); - runClassParameters.isTest = isTest; - string runClassParametersJson = JsonConvert.SerializeObject(runClassParameters); - - var settings = MainClass.Container.Resolve(); - - string output; - using (var p = new Process()) - { - p.StartInfo.UseShellExecute = false; - p.StartInfo.RedirectStandardInput = true; - p.StartInfo.RedirectStandardOutput = true; - p.StartInfo.FileName = "php"; - p.StartInfo.Arguments = Path.Combine(settings.PhpSourcePath, - "Api/Library/Shared/CLI/RunClass.php"); - p.Start(); - p.StandardInput.Write(runClassParametersJson); - p.StandardInput.Close(); - - output = p.StandardOutput.ReadToEnd(); - p.WaitForExit(); - if (p.ExitCode != 0) - { - throw new Exception("RunClass non-zero exit code!\n" + output); - } - p.Close(); - } - - return output; - } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Infrastructure/RunClassParameters.cs b/src/LfMerge.Core/LanguageForge/Infrastructure/RunClassParameters.cs deleted file mode 100644 index 769e9676..00000000 --- a/src/LfMerge.Core/LanguageForge/Infrastructure/RunClassParameters.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; - -namespace LfMerge.Core.LanguageForge.Infrastructure -{ - public class RunClassParameters - { - public RunClassParameters(string _className, string _methodName, List _parameters) - { - className = _className; - methodName = _methodName; - parameters = _parameters; - isTest = false; - } - - public string className { get; set; } - public string methodName { get; set; } - public List parameters { get; set; } - public bool isTest { get; set; } - } -} - diff --git a/src/LfMerge.Core/MainClass.cs b/src/LfMerge.Core/MainClass.cs index b899cc65..aedf67c0 100644 --- a/src/LfMerge.Core/MainClass.cs +++ b/src/LfMerge.Core/MainClass.cs @@ -57,7 +57,6 @@ internal static ContainerBuilder RegisterTypes() containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().AsSelf(); containerBuilder.RegisterType().As(); - containerBuilder.RegisterType().As(); Actions.Action.Register(containerBuilder); Queue.Register(containerBuilder); return containerBuilder; From c68bf30e7435b74dab542a4946c425c22cb7bc73 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 10:33:11 +0700 Subject: [PATCH 04/11] Remove LanguageForgeProxyMock from unit tests --- src/LfMerge.Core.Tests/TestEnvironment.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/LfMerge.Core.Tests/TestEnvironment.cs b/src/LfMerge.Core.Tests/TestEnvironment.cs index 629f263b..3ff16cf4 100644 --- a/src/LfMerge.Core.Tests/TestEnvironment.cs +++ b/src/LfMerge.Core.Tests/TestEnvironment.cs @@ -35,15 +35,13 @@ static TestEnvironment() public TestEnvironment(bool registerSettingsModelDouble = true, bool registerProcessingStateDouble = true, bool resetLfProjectsDuringCleanup = true, - TemporaryFolder languageForgeServerFolder = null, - bool registerLfProxyMock = true) + TemporaryFolder languageForgeServerFolder = null) { _resetLfProjectsDuringCleanup = resetLfProjectsDuringCleanup; _languageForgeServerFolder = languageForgeServerFolder ?? new TemporaryFolder(TestName + Path.GetRandomFileName()); Environment.SetEnvironmentVariable("FW_CommonAppData", _languageForgeServerFolder.Path); MainClass.Container = RegisterTypes(registerSettingsModelDouble, - registerProcessingStateDouble, _languageForgeServerFolder.Path, - registerLfProxyMock).Build(); + registerProcessingStateDouble, _languageForgeServerFolder.Path).Build(); Settings = MainClass.Container.Resolve(); MainClass.Logger = MainClass.Container.Resolve(); Directory.CreateDirectory(Settings.FdoDirectorySettings.ProjectsDirectory); @@ -65,7 +63,7 @@ private string TestName } private ContainerBuilder RegisterTypes(bool registerSettingsModel, - bool registerProcessingStateDouble, string temporaryFolder, bool registerLfProxyMock) + bool registerProcessingStateDouble, string temporaryFolder) { ContainerBuilder containerBuilder = MainClass.RegisterTypes(); containerBuilder.RegisterType() @@ -77,9 +75,6 @@ private ContainerBuilder RegisterTypes(bool registerSettingsModel, containerBuilder.RegisterType().As().SingleInstance(); - if (registerLfProxyMock) - containerBuilder.RegisterType().As(); - if (registerSettingsModel) { containerBuilder.RegisterType().As().SingleInstance(); From 03e8d6ae4dd1fe8f81a0efeec3291a668c8a5f28 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 11:12:58 +0700 Subject: [PATCH 05/11] Handle case where there are no user views --- src/LfMerge.Core/MongoConnector/MongoConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LfMerge.Core/MongoConnector/MongoConnection.cs b/src/LfMerge.Core/MongoConnector/MongoConnection.cs index c6563662..8d144ec2 100644 --- a/src/LfMerge.Core/MongoConnector/MongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/MongoConnection.cs @@ -692,8 +692,8 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary roleViewNames = roleViews.Names.ToList(); - List userViewNames = userViews.Names.ToList(); + List roleViewNames = roleViews?.Names.ToList() ?? new List(); + List userViewNames = userViews?.Names.ToList() ?? new List(); // Note that userViewNames doesn't contain usernames like "rmunn", but ObjectId strings like "54c780ea863f1c2127635ca9" // Clean out previous fields and fieldOrders that no longer exist (removed from FDO) From d2216f81c68ae4f2de1cfdafcec2c98b6a9f37cc Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 12:31:55 +0700 Subject: [PATCH 06/11] Custom multitext fields can have FW type "String" Did a bit of debugging and found that in addition to MultiString, we can have a field type of String coming from FieldWorks for a custom field of the most common type, which should convert to "multistring" in LF. --- src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs b/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs index a82cb64d..a1749ce3 100644 --- a/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs +++ b/src/LfMerge.Core/LanguageForge/Config/LfRoleOrUserViewConfig.cs @@ -38,7 +38,7 @@ public LexViewMultiTextFieldConfig(bool show = true) : base("multitext", show) public static class LexViewFieldConfigFactory { public static LexViewFieldConfig CreateByType(string lfCustomFieldType, bool show = true) { - if (lfCustomFieldType == "MultiUnicode" || lfCustomFieldType == "MultiString") { + if (lfCustomFieldType == "MultiUnicode" || lfCustomFieldType == "MultiString" || lfCustomFieldType == "String") { return new LexViewMultiTextFieldConfig(show); } else { return new LexViewFieldConfig(show); From 5b608628482f3caf738160ff722f9041b2c2d3b1 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 13:21:46 +0700 Subject: [PATCH 07/11] No more pulling in PHP source in Dockerfile --- Dockerfile | 6 ------ docker/scripts/build-and-test.sh | 3 --- 2 files changed, 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 838f4e2b..153b338c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ # syntax=docker/dockerfile:experimental ARG DbVersion=7000072 -FROM sillsdev/web-languageforge:latest AS lf-build -# No changes needed, LF app result in /var/www/html - FROM mcr.microsoft.com/dotnet/sdk:5.0 AS lfmerge-builder-base WORKDIR /build/lfmerge @@ -61,9 +58,6 @@ ENV NUNIT_VERSION_MAJOR=3 FROM lfmerge-build-${DbVersion} AS lfmerge-build -# LanguageForge repo expected to be in /var/www/html (will be copied into ./data/php/src before running unit tests) -COPY --chown=builder:users --from=lf-build /var/www/html /var/www/html - USER builder # Git repo should be mounted under ${HOME}/packages/lfmerge when run diff --git a/docker/scripts/build-and-test.sh b/docker/scripts/build-and-test.sh index a5057cea..04058cb8 100755 --- a/docker/scripts/build-and-test.sh +++ b/docker/scripts/build-and-test.sh @@ -24,9 +24,6 @@ echo After setup-workspace.sh, pwd is $(pwd) "$SCRIPT_DIR"/compile-lfmerge-combined.sh ${DbVersion} if [ -n "$RUN_UNIT_TESTS" -a "$RUN_UNIT_TESTS" -ne 0 ]; then - rm -rf "$SCRIPT_DIR"/data/php - mkdir -p "$SCRIPT_DIR"/data/php - cp -a /var/www/html "$SCRIPT_DIR"/data/php/src "$SCRIPT_DIR"/test-lfmerge-combined.sh ${DbVersion} fi From c44712c19cf781ddd260199b81b974d0ed0cb3a0 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 15:14:00 +0700 Subject: [PATCH 08/11] Delete one more now-unused method The logic from this method has moved into MongoConnection --- .../ConvertFdoToMongoCustomField.cs | 17 ----------------- .../DataConverters/ConvertFdoToMongoLexicon.cs | 1 - 2 files changed, 18 deletions(-) diff --git a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs index 9b635710..9e90637b 100644 --- a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs +++ b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoCustomField.cs @@ -69,23 +69,6 @@ public ConvertFdoToMongoCustomField(FdoCache cache, FwServiceLocatorCache servic }; } - public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes) - { - return CreateCustomFieldsConfigViews(project, lfCustomFieldList, lfCustomFieldTypes, false); - } - - // TODO: Get rid of isTest bool - public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary lfCustomFieldList, Dictionary lfCustomFieldTypes, bool isTest) - { - var customFieldSpecs = new List(); - foreach (string lfCustomFieldName in lfCustomFieldList.Keys) - { - customFieldSpecs.Add(new CustomFieldSpec(lfCustomFieldName, lfCustomFieldTypes[lfCustomFieldName])); - } - // TODO: This no longer needs to return a bool - return true; - } - /// /// Returns a dictionary of custom fields at the LexEntry, LexSense, and LexExampleSentence levels /// From FDO to LF. If the dictionary doesn't exist, create one. diff --git a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs index adb85c8a..31346678 100644 --- a/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs +++ b/src/LfMerge.Core/DataConverters/ConvertFdoToMongoLexicon.cs @@ -110,7 +110,6 @@ public void RunConversion() Dictionary lfCustomFieldTypes = new Dictionary(); _convertCustomField.WriteCustomFieldConfig(lfCustomFieldList, lfCustomFieldTypes); Connection.SetCustomFieldConfig(LfProject, lfCustomFieldList, lfCustomFieldTypes); - _convertCustomField.CreateCustomFieldsConfigViews(LfProject, lfCustomFieldList, lfCustomFieldTypes); Dictionary previousModificationDates = Connection.GetAllModifiedDatesForEntries(LfProject); From ca8f50dfb9a18b888ff6573d3e3750f06a3cac64 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 15:23:05 +0700 Subject: [PATCH 09/11] Remove deleted files from .csproj list This wasn't needed in the master branch version of this change, where it uses the modern .NET build system that doesn't need a list of every file. But here in the fieldworks8-master branch, the .csproj file includes a list of every file in the project, so when we delete a file we also need to remove it from the .csproj list as well. --- src/LfMerge.Core.Tests/LfMerge.Core.Tests.csproj | 2 -- src/LfMerge.Core/LfMerge.Core.csproj | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/LfMerge.Core.Tests/LfMerge.Core.Tests.csproj b/src/LfMerge.Core.Tests/LfMerge.Core.Tests.csproj index bfcc59d4..d69b44bc 100644 --- a/src/LfMerge.Core.Tests/LfMerge.Core.Tests.csproj +++ b/src/LfMerge.Core.Tests/LfMerge.Core.Tests.csproj @@ -154,8 +154,6 @@ - - diff --git a/src/LfMerge.Core/LfMerge.Core.csproj b/src/LfMerge.Core/LfMerge.Core.csproj index 3c9f202c..85545ce6 100644 --- a/src/LfMerge.Core/LfMerge.Core.csproj +++ b/src/LfMerge.Core/LfMerge.Core.csproj @@ -189,9 +189,6 @@ - - - From 751b8f9b076a2aec1364bd65e287756bdf86acc7 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 15:30:55 +0700 Subject: [PATCH 10/11] Can't use ?. operator in Mono 5 --- src/LfMerge.Core/MongoConnector/MongoConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LfMerge.Core/MongoConnector/MongoConnection.cs b/src/LfMerge.Core/MongoConnector/MongoConnection.cs index 8d144ec2..d86d64fc 100644 --- a/src/LfMerge.Core/MongoConnector/MongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/MongoConnection.cs @@ -692,8 +692,8 @@ public bool SetCustomFieldConfig(ILfProject project, Dictionary roleViewNames = roleViews?.Names.ToList() ?? new List(); - List userViewNames = userViews?.Names.ToList() ?? new List(); + List roleViewNames = roleViews != null ? roleViews.Names.ToList() : new List(); + List userViewNames = userViews != null ? userViews.Names.ToList() : new List(); // Note that userViewNames doesn't contain usernames like "rmunn", but ObjectId strings like "54c780ea863f1c2127635ca9" // Clean out previous fields and fieldOrders that no longer exist (removed from FDO) From 8e88f425e3791db1d603933de8f17a1467846066 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 8 Dec 2021 15:45:40 +0700 Subject: [PATCH 11/11] Add new files to .csproj list Just like with the deleted files, this wasn't necessary in the master branch but is necessary in the fieldworks8-master branch. --- src/LfMerge.Core/LfMerge.Core.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LfMerge.Core/LfMerge.Core.csproj b/src/LfMerge.Core/LfMerge.Core.csproj index 85545ce6..4f07b4fc 100644 --- a/src/LfMerge.Core/LfMerge.Core.csproj +++ b/src/LfMerge.Core/LfMerge.Core.csproj @@ -187,6 +187,7 @@ +