Skip to content

Commit

Permalink
compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Dec 2, 2024
1 parent 0f416f2 commit a218917
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ LinqProvider linqProvider
linqProvider
);
string fieldName = rendered.FieldName.Replace(ArrayPosition.All.ToString(CultureInfo.InvariantCulture), "$[]");
fieldName = fieldName.Replace(
ArrayPosition.NamedArrayFilter.ToString(CultureInfo.InvariantCulture),
"$[arrayFilter]"
);
fieldName = fieldName.Replace(ArrayPosition.FirstMatching.ToString(CultureInfo.InvariantCulture), "$");
if (fieldName != rendered.FieldName)
{
Expand Down
1 change: 0 additions & 1 deletion src/DataAccess/src/SIL.DataAccess/MongoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ await _collection
public async Task<int> UpdateAllAsync(
Expression<Func<T, bool>> filter,
Action<IUpdateBuilder<T>> update,
UpdateOptions? options = null,
CancellationToken cancellationToken = default
)
{
Expand Down
10 changes: 0 additions & 10 deletions src/DataAccess/src/SIL.DataAccess/MongoUpdateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ public IUpdateBuilder<T> Set<TField>(Expression<Func<T, TField>> field, TField v
return this;
}

public IUpdateBuilder<T> Set<TField>(Expression<Func<T, TField>> field, Expression filter
where TField : struct
{
if (value.HasValue)
_defs.Add(_updateBuilder.Set(ToFieldDefinition(field), value.Value));
else
_defs.Add(_updateBuilder.Unset(ToFieldDefinition(field)));
return this;
}

public IUpdateBuilder<T> SetOnInsert<TField>(Expression<Func<T, TField>> field, TField value)
{
_defs.Add(_updateBuilder.SetOnInsert(ToFieldDefinition(field), value));
Expand Down
60 changes: 30 additions & 30 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9291,9 +9291,37 @@ public partial class Corpus
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CorpusFile
{
[Newtonsoft.Json.JsonProperty("file", Required = Newtonsoft.Json.Required.Always)]
[Newtonsoft.Json.JsonProperty("fileId", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string FileId { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("textId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? TextId { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CorpusConfig
{
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? Name { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("language", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string Language { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("files", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public DataFile File { get; set; } = new DataFile();
public System.Collections.Generic.IList<CorpusFileConfig> Files { get; set; } = new System.Collections.ObjectModel.Collection<CorpusFileConfig>();

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CorpusFileConfig
{
[Newtonsoft.Json.JsonProperty("fileId", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string FileId { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("textId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? TextId { get; set; } = default!;
Expand Down Expand Up @@ -9336,34 +9364,6 @@ public enum FileFormat

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CorpusConfig
{
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? Name { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("language", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string Language { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("files", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public System.Collections.Generic.IList<CorpusFileConfig> Files { get; set; } = new System.Collections.ObjectModel.Collection<CorpusFileConfig>();

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class CorpusFileConfig
{
[Newtonsoft.Json.JsonProperty("fileId", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string FileId { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("textId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? TextId { get; set; } = default!;

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class TranslationEngine
{
Expand Down

This file was deleted.

28 changes: 17 additions & 11 deletions src/Serval/src/Serval.DataFiles/Consumers/GetCorpusConsumer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Serval.DataFiles.Consumers;

public class GetCorpusConsumer(ICorpusService corpusService) : IConsumer<GetCorpus>
public class GetCorpusConsumer(ICorpusService corpusService, IDataFileService dataFileService) : IConsumer<GetCorpus>
{
private readonly ICorpusService _corpusService = corpusService;
private readonly IDataFileService _dataFileService = dataFileService;

public async Task Consume(ConsumeContext<GetCorpus> context)
{
Expand All @@ -19,19 +20,13 @@ await context.RespondAsync(
CorpusId = corpus.Id,
Name = corpus.Name,
Language = corpus.Language,
Files = corpus
.Files.Select(f => new CorpusFileResult
Files = await Task.WhenAll(
corpus.Files.Select(async f => new CorpusFileResult
{
TextId = f.TextId!,
File = new DataFileResult
{
DataFileId = f.File.Id,
Filename = f.File.Filename,
Format = f.File.Format,
Name = f.File.Name
}
File = Map(await _dataFileService.GetAsync(f.FileId))
})
.ToList()
)
}
);
}
Expand All @@ -42,4 +37,15 @@ await context.RespondAsync(
);
}
}

private static DataFileResult Map(DataFile dataFile)
{
return new DataFileResult
{
DataFileId = dataFile.Id,
Name = dataFile.Name,
Filename = dataFile.Filename,
Format = dataFile.Format,
};
}
}
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.DataFiles/Contracts/CorpusFileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Serval.DataFiles.Contracts;

public record CorpusFileDto
{
public required DataFileDto File { get; init; }
public required string FileId { get; init; }
public string? TextId { get; init; }
}
16 changes: 2 additions & 14 deletions src/Serval/src/Serval.DataFiles/Controllers/CorporaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ CancellationToken cancellationToken
DataFile? dataFile = await _dataFileService.GetAsync(file.FileId, cancellationToken);
if (dataFile == null)
throw new InvalidOperationException($"DataFile with id {file.FileId} does not exist.");
dataFiles.Add(new CorpusFile { File = dataFile, TextId = file.TextId });
dataFiles.Add(new CorpusFile { FileId = file.FileId, TextId = file.TextId });
}
return dataFiles;
}
Expand All @@ -197,18 +197,6 @@ private CorpusDto Map(Corpus source)

private CorpusFileDto Map(CorpusFile source)
{
return new CorpusFileDto { File = Map(source.File), TextId = source.TextId };
}

private DataFileDto Map(DataFile source)
{
return new DataFileDto
{
Id = source.Id,
Url = _urlService.GetUrl(Endpoints.GetDataFile, new { id = source.Id }),
Name = source.Name,
Format = source.Format,
Revision = source.Revision
};
return new CorpusFileDto { FileId = source.FileId, TextId = source.TextId };
}
}
35 changes: 22 additions & 13 deletions src/Serval/src/Serval.DataFiles/Services/CorpusService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
namespace Serval.DataFiles.Services;

public class CorpusService(IRepository<Corpus> corpora, IDataAccessContext dataAccessContext, IScopedMediator mediator)
: OwnedEntityServiceBase<Corpus>(corpora),
ICorpusService
public class CorpusService(
IRepository<Corpus> corpora,
IDataAccessContext dataAccessContext,
IDataFileService dataFileService,
IScopedMediator mediator
) : OwnedEntityServiceBase<Corpus>(corpora), ICorpusService
{
private readonly IDataAccessContext _dataAccessContext = dataAccessContext;
private readonly IDataFileService _dataFileService = dataFileService;

private readonly IScopedMediator _mediator = mediator;

Expand Down Expand Up @@ -36,19 +40,13 @@ await _mediator.Publish(
new CorpusUpdated
{
CorpusId = corpus.Id,
Files = corpus
.Files.Select(f => new CorpusFileResult
Files = await Task.WhenAll(
corpus.Files.Select(async f => new CorpusFileResult
{
TextId = f.TextId!,
File = new DataFileResult
{
DataFileId = f.File.Id,
Filename = f.File.Filename,
Format = f.File.Format,
Name = f.File.Name
}
File = Map(await _dataFileService.GetAsync(f.FileId))
})
.ToList()
)
},
ct
);
Expand All @@ -57,4 +55,15 @@ await _mediator.Publish(
cancellationToken
);
}

private static DataFileResult Map(DataFile dataFile)
{
return new DataFileResult
{
DataFileId = dataFile.Id,
Name = dataFile.Name,
Filename = dataFile.Filename,
Format = dataFile.Format,
};
}
}
9 changes: 6 additions & 3 deletions src/Serval/src/Serval.Translation/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ public Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cance
);
}

public Task UpdateAllCorporaAsync(DataFileUpdated dataFileUpdated, CancellationToken cancellationToken = default)
public Task UpdateAllCorpusFilesAsync(
DataFileUpdated dataFileUpdated,
CancellationToken cancellationToken = default
)
{
return Entities.UpdateAllAsync(
e =>
Expand All @@ -555,11 +558,11 @@ public Task UpdateAllCorporaAsync(DataFileUpdated dataFileUpdated, CancellationT
),
u =>
u.Set(
e => e.Corpora[ArrayPosition.All].SourceFiles[ArrayPosition.NamedArrayFilter].Filename,
e => e.Corpora[ArrayPosition.All].SourceFiles[ArrayPosition.All].Filename,
dataFileUpdated.Filename
)
.Set(
e => e.Corpora[ArrayPosition.All].TargetFiles[ArrayPosition.NamedArrayFilter].Filename,
e => e.Corpora[ArrayPosition.All].TargetFiles[ArrayPosition.All].Filename,
dataFileUpdated.Filename
),
cancellationToken
Expand Down
Loading

0 comments on commit a218917

Please sign in to comment.