Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 3488158

Browse files
feat: transform function skeleton and blob download functionality (#14)
Co-authored-by: Ian Nelson <[email protected]>
1 parent 60155ef commit 3488158

20 files changed

+426
-3
lines changed

src/ServiceLayer.Mesh/Configuration/AppConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class AppConfiguration :
55
IFileExtractFunctionConfiguration,
66
IFileExtractQueueClientConfiguration,
77
IFileTransformQueueClientConfiguration,
8+
IFileTransformFunctionConfiguration,
89
IFileRetryFunctionConfiguration,
910
IMeshHandshakeFunctionConfiguration
1011
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ServiceLayer.Mesh.Configuration;
2+
3+
public interface IFileTransformFunctionConfiguration
4+
{
5+
int StaleHours { get; }
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
4+
5+
public class FileParser : IFileParser
6+
{
7+
public ParsedFile Parse(Stream stream)
8+
{
9+
// TODO - implement this
10+
throw new NotImplementedException();
11+
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using ServiceLayer.Data.Models;
2+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Validation;
3+
4+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
5+
6+
// TODO - NBSS appointment file specific implementation of IFileTransformer. To orchestrate parsing, validation and staging of data (delegated to separate classes)
7+
public class FileTransformer : IFileTransformer
8+
{
9+
private readonly IFileParser _fileParser;
10+
private readonly IValidationRunner _validationRunner;
11+
private readonly IStagingPersister _stagingPersister;
12+
13+
public FileTransformer(IFileParser fileParser, IValidationRunner validationRunner, IStagingPersister stagingPersister)
14+
{
15+
_fileParser = fileParser;
16+
_validationRunner = validationRunner;
17+
_stagingPersister = stagingPersister;
18+
}
19+
20+
public MeshFileType HandlesFileType => MeshFileType.NbssAppointmentEvents;
21+
22+
public async Task<IList<ValidationError>> TransformFileAsync(Stream stream, MeshFile metaData)
23+
{
24+
// TODO - wrap this parsing in a try-catch and return a List<ValidationError> in case of any unforeseen parsing issues (file is totally unlike anything we expect)
25+
var parsed = _fileParser.Parse(stream);
26+
27+
var validationErrors = _validationRunner.Validate(parsed);
28+
if (!validationErrors.Any())
29+
{
30+
await _stagingPersister.WriteStagedData(parsed);
31+
}
32+
33+
return validationErrors;
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
4+
5+
public interface IFileParser
6+
{
7+
ParsedFile Parse(Stream stream);
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
4+
5+
// TODO - interface for class to take validated AppointmentEventsFile and save the records to NbssAppointmentEvents table
6+
public interface IStagingPersister
7+
{
8+
Task WriteStagedData(ParsedFile parsedFile);
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
public class FileControlRecord
4+
{
5+
public string? RecordTypeIdentifier { get; set; }
6+
7+
public string? ExtractId { get; set; }
8+
9+
public string? TransferStartDate { get; set; }
10+
11+
public string? TransferStartTime { get; set; }
12+
13+
public string? RecordCount { get; set; }
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
public class FileDataRecord
4+
{
5+
public int RowNumber { get; set; }
6+
public Dictionary<string, string> Fields { get; } = [];
7+
8+
public string? this[string fieldName] => Fields.GetValueOrDefault(fieldName);
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
public class ParsedFile
4+
{
5+
public FileControlRecord? FileHeader { get; set; }
6+
public FileControlRecord? FileTrailer { get; set; }
7+
public required List<string> ColumnHeadings { get; set; } = [];
8+
public required List<FileDataRecord> DataRecords { get; set; } = [];
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
2+
3+
namespace ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
4+
5+
// TODO - class to take validated AppointmentEventsFile and save the records to NbssAppointmentEvents table
6+
public class StagingPersister : IStagingPersister
7+
{
8+
public Task WriteStagedData(ParsedFile parsedFile)
9+
{
10+
// TODO - implement this
11+
throw new NotImplementedException();
12+
}
13+
}

0 commit comments

Comments
 (0)