From da134f7f3dc23c7ca08f1971d68d959e4625c997 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Tue, 21 Jan 2025 11:30:25 -0500 Subject: [PATCH] Fix 2 for #595 - make sure Name field is always there. * The "OK" is not needed but will be auto-added. * If "Name" is not there, it will crash when trying to get the fields. --- .../IMongoDataAccessConfiguratorExtensions.cs | 13 ++++++++++--- .../Controllers/CorporaController.cs | 4 ++-- src/Serval/test/Serval.E2ETests/ServalApiTests.cs | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Serval/src/Serval.DataFiles/Configuration/IMongoDataAccessConfiguratorExtensions.cs b/src/Serval/src/Serval.DataFiles/Configuration/IMongoDataAccessConfiguratorExtensions.cs index d9370a0f..c1e25e70 100644 --- a/src/Serval/src/Serval.DataFiles/Configuration/IMongoDataAccessConfiguratorExtensions.cs +++ b/src/Serval/src/Serval.DataFiles/Configuration/IMongoDataAccessConfiguratorExtensions.cs @@ -23,10 +23,17 @@ public static IMongoDataAccessConfigurator AddDataFilesRepositories(this IMongoD ); configurator.AddRepository( "corpora.corpus", - init: c => - c.Indexes.CreateOrUpdateAsync( + init: async c => + { + await c.Indexes.CreateOrUpdateAsync( new CreateIndexModel(Builders.IndexKeys.Ascending(p => p.Owner)) - ) + ); + // migrate by adding Name field + await c.UpdateManyAsync( + Builders.Filter.Exists(b => b.Name, false), + Builders.Update.Set(b => b.Name, "") + ); + } ); return configurator; } diff --git a/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs b/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs index 29a72170..21529a1d 100644 --- a/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs +++ b/src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs @@ -28,9 +28,9 @@ IDataFileService dataFileService [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)] - public async Task>> GetAllAsync(CancellationToken cancellationToken) + public async Task> GetAllAsync(CancellationToken cancellationToken) { - return Ok((await _corpusService.GetAllAsync(Owner, cancellationToken)).Select(Map)); + return (await _corpusService.GetAllAsync(Owner, cancellationToken)).Select(Map); } /// diff --git a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs index 45fae1ba..06a191c1 100644 --- a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs +++ b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs @@ -173,6 +173,10 @@ public async Task NmtQueueMultiple() "en", true ); + // Verify the corpora are readable + var allCorpora = await _helperClient.CorporaClient.GetAllAsync(); + Assert.That(allCorpora, Has.Count.GreaterThan(0)); + for (int i = 0; i < NUM_ENGINES; i++) { _helperClient.InitTranslationBuildConfig();