diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/machine-api/build-dto.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/machine-api/build-dto.ts index 6884f7fc4d..c506b2c9ed 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/machine-api/build-dto.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/machine-api/build-dto.ts @@ -14,6 +14,7 @@ export interface ServalBuildAdditionalInfo { buildId: string; corporaIds?: string[]; dateFinished?: string; + parallelCorporaIds?: string[]; step: number; translationEngineId: string; } diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.html b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.html index 5da4444d67..857a27d3f8 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.html +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.html @@ -256,6 +256,10 @@

Corpora Ids: {{ draftJob?.additionalInfo?.corporaIds?.join(", ") ?? "unknown" }} +
+ Parallel Corpora Ids: + {{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") ?? "unknown" }} +
diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-information/draft-information.component.html b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-information/draft-information.component.html index 1d0285db62..8870f9f6bd 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-information/draft-information.component.html +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-information/draft-information.component.html @@ -1,6 +1,7 @@ @if (this.canShowAdditionalInfo) {
Build Id: {{ draftJob?.additionalInfo?.buildId }}
Corpora Ids: {{ draftJob?.additionalInfo?.corporaIds?.join(", ") }}
+
Parallel Corpora Ids: {{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") }}
Date Finished: {{ draftJob?.additionalInfo?.dateFinished?.toLocaleString() }}
Message: {{ draftJob?.message }}
Percent Completed: {{ draftJob?.percentCompleted }}
diff --git a/src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs b/src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs index b01c7d95ef..2a1d7a248a 100644 --- a/src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs +++ b/src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs @@ -5,9 +5,10 @@ namespace SIL.XForge.Scripture.Models; public class ServalBuildAdditionalInfo { - public string BuildId { get; set; } = string.Empty; - public IEnumerable? CorporaIds { get; set; } - public DateTimeOffset? DateFinished { get; set; } - public int Step { get; set; } - public string TranslationEngineId { get; set; } = string.Empty; + public string BuildId { get; init; } = string.Empty; + public IEnumerable? CorporaIds { get; init; } + public DateTimeOffset? DateFinished { get; init; } + public IEnumerable? ParallelCorporaIds { get; init; } + public int Step { get; init; } + public string TranslationEngineId { get; init; } = string.Empty; } diff --git a/src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj b/src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj index c3f4bf2972..f2814d2db7 100644 --- a/src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj +++ b/src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj @@ -38,7 +38,7 @@ - + diff --git a/src/SIL.XForge.Scripture/Services/MachineApiService.cs b/src/SIL.XForge.Scripture/Services/MachineApiService.cs index 4cedbde472..5d2ad3c56d 100644 --- a/src/SIL.XForge.Scripture/Services/MachineApiService.cs +++ b/src/SIL.XForge.Scripture/Services/MachineApiService.cs @@ -991,20 +991,26 @@ private static ServalBuildDto CreateDto(TranslationBuild translationBuild) => CorporaIds = new HashSet( // Use a HashSet to ensure there are no duplicate corpus ids [ - .. translationBuild - .Pretranslate?.Select(t => t.Corpus?.Id) - .Where(id => !string.IsNullOrEmpty(id)) ?? [], .. translationBuild .Pretranslate?.SelectMany(t => t.SourceFilters ?? []) .Select(f => f.Corpus.Id) ?? [], - .. translationBuild.TrainOn?.Select(t => t.Corpus?.Id).Where(id => !string.IsNullOrEmpty(id)) - ?? [], .. translationBuild.TrainOn?.SelectMany(t => t.SourceFilters ?? []).Select(f => f.Corpus.Id) ?? [], .. translationBuild.TrainOn?.SelectMany(t => t.TargetFilters ?? []).Select(f => f.Corpus.Id) ?? [], ] ), + ParallelCorporaIds = new HashSet( + // Use a HashSet to ensure there are no duplicate parallel corpus ids + [ + .. translationBuild + .Pretranslate?.Select(t => t.ParallelCorpus?.Id) + .Where(id => !string.IsNullOrEmpty(id)) ?? [], + .. translationBuild + .TrainOn?.Select(t => t.ParallelCorpus?.Id) + .Where(id => !string.IsNullOrEmpty(id)) ?? [], + ] + ), DateFinished = translationBuild.DateFinished, Step = translationBuild.Step, TranslationEngineId = translationBuild.Engine.Id, @@ -1030,7 +1036,11 @@ private static ServalEngineDto CreateDto(TranslationEngine translationEngine) => /// /// Method not allowed or not supported for the specified translation engine. /// - /// If this method returns, it is expected that the DTO will be null. + /// + /// If this method returns, it is expected that the DTO will be null. + /// The following status codes may be thrown by Serval, and are not handled by this method: + /// - 499: Operation Cancelled + /// private static void ProcessServalApiException(ServalApiException e) { switch (e) diff --git a/src/SIL.XForge.Scripture/Services/MachineServiceCollectionExtensions.cs b/src/SIL.XForge.Scripture/Services/MachineServiceCollectionExtensions.cs index 2bda05a77f..08242daada 100644 --- a/src/SIL.XForge.Scripture/Services/MachineServiceCollectionExtensions.cs +++ b/src/SIL.XForge.Scripture/Services/MachineServiceCollectionExtensions.cs @@ -38,22 +38,23 @@ IWebHostEnvironment env client.Parameters = new Parameters { { "audience", servalOptions.Audience } }; } ); - services.AddClientCredentialsHttpClient( - MachineApi.HttpClientName, - MachineApi.TokenClientName, - configureClient: client => client.BaseAddress = new Uri(servalOptions.ApiServer) - ) - .ConfigurePrimaryHttpMessageHandler(() => - { - var handler = new HttpClientHandler(); - if (env.IsDevelopment() || env.IsEnvironment("Testing")) + services + .AddClientCredentialsHttpClient( + MachineApi.HttpClientName, + MachineApi.TokenClientName, + configureClient: client => client.BaseAddress = new Uri(servalOptions.ApiServer) + ) + .ConfigurePrimaryHttpMessageHandler(() => { - handler.ServerCertificateCustomValidationCallback = - HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; - } + var handler = new HttpClientHandler(); + if (env.IsDevelopment() || env.IsEnvironment("Testing")) + { + handler.ServerCertificateCustomValidationCallback = + HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + } - return handler; - }); + return handler; + }); services .AddHttpClient(MachineApi.HttpClientName) .SetHandlerLifetime(TimeSpan.FromMinutes(5)) diff --git a/test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs b/test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs index eb21e763cf..c69a96f3fb 100644 --- a/test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs +++ b/test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs @@ -411,6 +411,8 @@ public async Task GetBuildAsync_IncludesAdditionalInfo() const string corpusId2 = "corpusId2"; const string corpusId3 = "corpusId3"; const string corpusId4 = "corpusId4"; + const string parallelCorpusId1 = "parallelCorpusId1"; + const string parallelCorpusId2 = "parallelCorpusId2"; const int step = 123; env.TranslationEnginesClient.GetBuildAsync( TranslationEngine01, @@ -436,17 +438,22 @@ public async Task GetBuildAsync_IncludesAdditionalInfo() [ new PretranslateCorpus { - // Previous corpus format - Corpus = new ResourceLink { Id = corpusId1, Url = "https://example.com" }, + ParallelCorpus = new ResourceLink + { + Id = parallelCorpusId1, + Url = "https://example.com", + }, }, new PretranslateCorpus { - // Previous corpus format - Corpus = new ResourceLink { Id = corpusId2, Url = "https://example.com" }, + ParallelCorpus = new ResourceLink + { + Id = parallelCorpusId2, + Url = "https://example.com", + }, }, new PretranslateCorpus { - // New parallel corpus format SourceFilters = [ new ParallelCorpusFilter @@ -466,12 +473,10 @@ public async Task GetBuildAsync_IncludesAdditionalInfo() [ new TrainingCorpus { - // Previous corpus format - Corpus = new ResourceLink { Id = corpusId3, Url = "https://example.com" }, + ParallelCorpus = new ResourceLink { Id = corpusId3, Url = "https://example.com" }, }, new TrainingCorpus { - // New parallel corpus format SourceFilters = [ new ParallelCorpusFilter @@ -526,6 +531,9 @@ public async Task GetBuildAsync_IncludesAdditionalInfo() Assert.AreEqual(corpusId2, actual.AdditionalInfo.CorporaIds.ElementAt(1)); Assert.AreEqual(corpusId3, actual.AdditionalInfo.CorporaIds.ElementAt(2)); Assert.AreEqual(corpusId4, actual.AdditionalInfo.CorporaIds.ElementAt(3)); + Assert.IsNotNull(actual.AdditionalInfo.ParallelCorporaIds); + Assert.AreEqual(parallelCorpusId1, actual.AdditionalInfo.ParallelCorporaIds.ElementAt(0)); + Assert.AreEqual(parallelCorpusId2, actual.AdditionalInfo.ParallelCorporaIds.ElementAt(1)); } [Test] diff --git a/tools/ServalBuildReport/ServalBuildReport.csproj b/tools/ServalBuildReport/ServalBuildReport.csproj index 29d233ee8d..6b2fb796c6 100644 --- a/tools/ServalBuildReport/ServalBuildReport.csproj +++ b/tools/ServalBuildReport/ServalBuildReport.csproj @@ -20,7 +20,7 @@ - + diff --git a/tools/ServalDownloader/Program.cs b/tools/ServalDownloader/Program.cs index 7ae03c447a..6ac289fca3 100644 --- a/tools/ServalDownloader/Program.cs +++ b/tools/ServalDownloader/Program.cs @@ -30,7 +30,9 @@ } // Download every file for every legacy corpus +#pragma warning disable CS0612 // Type or member is obsolete foreach (TranslationCorpus corpus in await translationEnginesClient.GetAllCorporaAsync(translationEngineId)) +#pragma warning restore CS0612 // Type or member is obsolete { string corpusPath = Path.Combine(translationEnginePath, corpus.Id); Directory.CreateDirectory(corpusPath); diff --git a/tools/ServalDownloader/ServalDownloader.csproj b/tools/ServalDownloader/ServalDownloader.csproj index c8b12a42fa..0048705e51 100644 --- a/tools/ServalDownloader/ServalDownloader.csproj +++ b/tools/ServalDownloader/ServalDownloader.csproj @@ -19,7 +19,7 @@ - +