diff --git a/src/Serval.Client/Client.g.cs b/src/Serval.Client/Client.g.cs index 02de8cdf..bfd1ff8e 100644 --- a/src/Serval.Client/Client.g.cs +++ b/src/Serval.Client/Client.g.cs @@ -4317,6 +4317,9 @@ public partial class TranslationBuild [Newtonsoft.Json.JsonProperty("dateFinished", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.DateTimeOffset? DateFinished { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Options { get; set; } = default!; + } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")] @@ -4358,6 +4361,9 @@ public partial class TranslationBuildConfig [Newtonsoft.Json.JsonProperty("pretranslate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Collections.Generic.IList? Pretranslate { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Options { get; set; } = default!; + } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")] diff --git a/src/Serval.Grpc/Protos/serval/translation/v1/engine.proto b/src/Serval.Grpc/Protos/serval/translation/v1/engine.proto index b5d37d37..c0cb37f0 100644 --- a/src/Serval.Grpc/Protos/serval/translation/v1/engine.proto +++ b/src/Serval.Grpc/Protos/serval/translation/v1/engine.proto @@ -60,7 +60,8 @@ message StartBuildRequest { string engine_type = 1; string engine_id = 2; string build_id = 3; - repeated Corpus corpora = 4; + string options = 4; + repeated Corpus corpora = 5; } message CancelBuildRequest { diff --git a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs index 41e81af9..9ff97076 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs @@ -1,6 +1,10 @@ -namespace Serval.Translation.Contracts; +using System.Text.Json.Nodes; + +namespace Serval.Translation.Contracts; public class TranslationBuildConfigDto { public IList? Pretranslate { get; set; } + + public string? Options { get; set; } } diff --git a/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval.Translation/Contracts/TranslationBuildDto.cs index 1bf34c54..9a34bcfc 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -16,4 +16,5 @@ public class TranslationBuildDto /// public JobState State { get; set; } public DateTime? DateFinished { get; set; } + public string? Options { get; set; } } diff --git a/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval.Translation/Controllers/TranslationEnginesController.cs index 8507a721..33d505e4 100644 --- a/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -1,4 +1,6 @@ -namespace Serval.Translation.Controllers; +using System.Text.Json; + +namespace Serval.Translation.Controllers; [ApiVersion(1.0)] [Route("api/v{version:apiVersion}/translation/engines")] @@ -784,6 +786,10 @@ CancellationToken cancellationToken { return BadRequest(ioe.Message); } + catch (ArgumentException ae) + { + return BadRequest(ae.Message); + } if (!await _engineService.StartBuildAsync(build, cancellationToken)) return NotFound(); @@ -976,6 +982,15 @@ private static Build Map(Engine engine, TranslationBuildConfigDto source) } build.Pretranslate = pretranslateCorpora; } + try + { + JsonSerializer.Deserialize(source.Options ?? "{}"); + } + catch (Exception e) + { + throw new ArgumentException($"Unable to parse field 'options' : {e.Message}"); + } + build.Options = source.Options; return build; } @@ -1013,7 +1028,8 @@ private TranslationBuildDto Map(Build source) PercentCompleted = source.PercentCompleted, Message = source.Message, State = source.State, - DateFinished = source.DateFinished + DateFinished = source.DateFinished, + Options = source.Options }; } diff --git a/src/Serval.Translation/Models/Build.cs b/src/Serval.Translation/Models/Build.cs index ac6cb7fa..3d7f8986 100644 --- a/src/Serval.Translation/Models/Build.cs +++ b/src/Serval.Translation/Models/Build.cs @@ -11,4 +11,5 @@ public class Build : IEntity public string? Message { get; set; } public JobState State { get; set; } = JobState.Pending; public DateTime? DateFinished { get; set; } + public string? Options { get; set; } } diff --git a/src/Serval.Translation/Services/EngineService.cs b/src/Serval.Translation/Services/EngineService.cs index 8c55dfab..c0acaea6 100644 --- a/src/Serval.Translation/Services/EngineService.cs +++ b/src/Serval.Translation/Services/EngineService.cs @@ -197,6 +197,7 @@ public async Task StartBuildAsync(Build build, CancellationToken cancellat EngineType = engine.Type, EngineId = engine.Id, BuildId = build.Id, + Options = build.Options, Corpora = { engine.Corpora.Select(c => diff --git a/src/Serval.Translation/Usings.cs b/src/Serval.Translation/Usings.cs index 41550d03..2129040f 100644 --- a/src/Serval.Translation/Usings.cs +++ b/src/Serval.Translation/Usings.cs @@ -1,5 +1,6 @@ global using System.Diagnostics.CodeAnalysis; global using System.Linq.Expressions; +global using System.Text.Json.Nodes; global using Asp.Versioning; global using Grpc.Core; global using Grpc.Net.ClientFactory;