Skip to content

Commit

Permalink
Update to Serval.Client 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed Dec 2, 2024
1 parent d25b782 commit 6eebdc7
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ServalBuildAdditionalInfo {
buildId: string;
corporaIds?: string[];
dateFinished?: string;
parallelCorporaIds?: string[];
step: number;
translationEngineId: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ <h1 class="mat-headline-4">
<strong>Corpora Ids:</strong>
{{ draftJob?.additionalInfo?.corporaIds?.join(", ") ?? "unknown" }}
</div>
<div>
<strong>Parallel Corpora Ids:</strong>
{{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") ?? "unknown" }}
</div>
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@if (this.canShowAdditionalInfo) {
<div><strong>Build Id:</strong> {{ draftJob?.additionalInfo?.buildId }}</div>
<div><strong>Corpora Ids:</strong> {{ draftJob?.additionalInfo?.corporaIds?.join(", ") }}</div>
<div><strong>Parallel Corpora Ids:</strong> {{ draftJob?.additionalInfo?.parallelCorporaIds?.join(", ") }}</div>
<div><strong>Date Finished:</strong> {{ draftJob?.additionalInfo?.dateFinished?.toLocaleString() }}</div>
<div><strong>Message:</strong> {{ draftJob?.message }}</div>
<div><strong>Percent Completed:</strong> {{ draftJob?.percentCompleted }}</div>
Expand Down
11 changes: 6 additions & 5 deletions src/SIL.XForge.Scripture/Models/ServalBuildAdditionalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace SIL.XForge.Scripture.Models;

public class ServalBuildAdditionalInfo
{
public string BuildId { get; set; } = string.Empty;
public IEnumerable<string>? 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<string>? CorporaIds { get; init; }
public DateTimeOffset? DateFinished { get; init; }
public IEnumerable<string>? ParallelCorporaIds { get; init; }
public int Step { get; init; }
public string TranslationEngineId { get; init; } = string.Empty;
}
2 changes: 1 addition & 1 deletion src/SIL.XForge.Scripture/SIL.XForge.Scripture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- When using a new major or minor version of ParatextData, update where dependencies.yml copies the
InternetSettings.xml file. Also update server config scriptureforge.org_v2.yml. -->
<PackageReference Include="ParatextData" Version="9.5.0.5" />
<PackageReference Include="Serval.Client" Version="1.7.3" />
<PackageReference Include="Serval.Client" Version="1.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.6.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
Expand Down
22 changes: 16 additions & 6 deletions src/SIL.XForge.Scripture/Services/MachineApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,20 +991,26 @@ private static ServalBuildDto CreateDto(TranslationBuild translationBuild) =>
CorporaIds = new HashSet<string>(
// 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<string>(
// 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,
Expand All @@ -1030,7 +1036,11 @@ private static ServalEngineDto CreateDto(TranslationEngine translationEngine) =>
/// <exception cref="NotSupportedException">
/// Method not allowed or not supported for the specified translation engine.
/// </exception>
/// <remarks>If this method returns, it is expected that the DTO will be null.</remarks>
/// <remarks>
/// 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
/// </remarks>
private static void ProcessServalApiException(ServalApiException e)
{
switch (e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 16 additions & 8 deletions test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tools/ServalBuildReport/ServalBuildReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="NPOI" Version="2.7.2" />
<PackageReference Include="Serval.Client" Version="1.7.3" />
<PackageReference Include="Serval.Client" Version="1.8.0" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions tools/ServalDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/ServalDownloader/ServalDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Serval.Client" Version="1.7.3" />
<PackageReference Include="Serval.Client" Version="1.8.0" />
</ItemGroup>

</Project>

0 comments on commit 6eebdc7

Please sign in to comment.