Skip to content

Commit 2f52e76

Browse files
authored
Updates to the itr journey to display field level warnings (#2706)
### Context We need to inform users when a record has not been fully created / updated from an ITR import. At the moment these records would show as having the status `Success` in the db / UI. This change introduces the concept of a Warning status when data in a row has been partially used to create or update record.
1 parent 766b60c commit 2f52e76

File tree

26 files changed

+21575
-35
lines changed

26 files changed

+21575
-35
lines changed

TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/Mappings/IntegrationTransactionMapping.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public void Configure(EntityTypeBuilder<IntegrationTransaction> builder)
1313
builder.Property(p => p.FileName).IsRequired();
1414
builder.Property(p => p.ImportStatus).IsRequired();
1515
builder.Property(p => p.SuccessCount).IsRequired();
16+
builder.Property(p => p.WarningCount).IsRequired();
1617
builder.Property(p => p.TotalCount).IsRequired();
1718
builder.Property(p => p.DuplicateCount).IsRequired();
1819
builder.Property(p => p.FailureCount).IsRequired();

TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/Migrations/20251028165543_AddWarningCountToIntegrationTransaction.Designer.cs

Lines changed: 21320 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace TeachingRecordSystem.Core.DataStore.Postgres.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class AddWarningCountToIntegrationTransaction : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.AddColumn<int>(
14+
name: "warning_count",
15+
table: "integration_transactions",
16+
type: "integer",
17+
nullable: false,
18+
defaultValue: 0);
19+
}
20+
21+
/// <inheritdoc />
22+
protected override void Down(MigrationBuilder migrationBuilder)
23+
{
24+
migrationBuilder.DropColumn(
25+
name: "warning_count",
26+
table: "integration_transactions");
27+
}
28+
}
29+
}

TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/Migrations/TrsDbContextModelSnapshot.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
37223722
.HasColumnType("integer")
37233723
.HasColumnName("total_count");
37243724

3725+
b.Property<int>("WarningCount")
3726+
.HasColumnType("integer")
3727+
.HasColumnName("warning_count");
3728+
37253729
b.HasKey("IntegrationTransactionId")
37263730
.HasName("pk_integration_transactions");
37273731

TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/Models/IntegrationTransaction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class IntegrationTransaction
77
public required IntegrationTransactionImportStatus ImportStatus { get; set; }
88
public required int TotalCount { get; set; }
99
public required int SuccessCount { get; set; }
10+
public required int WarningCount { get; set; }
1011
public required int FailureCount { get; set; }
1112
public required int DuplicateCount { get; set; }
1213
public required string FileName { get; set; }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using TeachingRecordSystem.Core.DataStore.Postgres;
2+
3+
namespace TeachingRecordSystem.Core.Jobs;
4+
5+
public class BackfillCapitaImportWarningStatusesJob(TrsDbContext dbContext)
6+
{
7+
public async Task ExecuteAsync(bool dryRun, CancellationToken cancellationToken)
8+
{
9+
await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
10+
11+
var integrationTransactionsToBackfill = await dbContext.IntegrationTransactions
12+
.Include(it => it.IntegrationTransactionRecords)
13+
.Where(it => it.InterfaceType == IntegrationTransactionInterfaceType.CapitaImport)
14+
.ToListAsync(cancellationToken);
15+
16+
foreach (var integrationTransaction in integrationTransactionsToBackfill)
17+
{
18+
int warningCount = integrationTransaction.WarningCount;
19+
int successCount = integrationTransaction.SuccessCount;
20+
21+
foreach (var record in integrationTransaction.IntegrationTransactionRecords!.Where(r => r.Status == IntegrationTransactionRecordStatus.Success && !string.IsNullOrEmpty(r.FailureMessage)))
22+
{
23+
record.Status = IntegrationTransactionRecordStatus.Warning;
24+
warningCount++;
25+
successCount--;
26+
}
27+
28+
integrationTransaction.WarningCount = warningCount;
29+
integrationTransaction.SuccessCount = successCount;
30+
31+
await dbContext.SaveChangesAsync(cancellationToken);
32+
}
33+
34+
if (dryRun)
35+
{
36+
await transaction.RollbackAsync(cancellationToken);
37+
}
38+
else
39+
{
40+
await transaction.CommitAsync(cancellationToken);
41+
}
42+
}
43+
}

TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/CapitaExportAmendJob.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public async Task<long> ExecuteAsync(CancellationToken cancellationToken)
3232
ImportStatus = IntegrationTransactionImportStatus.InProgress,
3333
TotalCount = 0,
3434
SuccessCount = 0,
35+
WarningCount = 0,
3536
FailureCount = 0,
3637
DuplicateCount = 0,
3738
FileName = fileName,

TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/CapitaExportNewJob.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public async Task<long> ExecuteAsync(CancellationToken cancellationToken)
3030
ImportStatus = IntegrationTransactionImportStatus.InProgress,
3131
TotalCount = 0,
3232
SuccessCount = 0,
33+
WarningCount = 0,
3334
FailureCount = 0,
3435
DuplicateCount = 0,
3536
FileName = fileName,

TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/CapitaImportJob.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public async Task<long> ImportAsync(StreamReader reader, string fileName)
7878
var records = csv.GetRecords<CapitaImportRecord>().ToList();
7979
var totalRowCount = 0;
8080
var successCount = 0;
81+
var warningCount = 0;
8182
var duplicateRowCount = 0;
8283
var failureRowCount = 0;
8384
var failureMessage = new StringBuilder();
@@ -89,6 +90,7 @@ public async Task<long> ImportAsync(StreamReader reader, string fileName)
8990
ImportStatus = IntegrationTransactionImportStatus.InProgress,
9091
TotalCount = 0,
9192
SuccessCount = 0,
93+
WarningCount = 0,
9294
FailureCount = 0,
9395
DuplicateCount = 0,
9496
FileName = fileName,
@@ -108,6 +110,7 @@ public async Task<long> ImportAsync(StreamReader reader, string fileName)
108110
var personId = default(Guid?);
109111
var recordStatus = IntegrationTransactionRecordStatus.Success;
110112
var potentialDuplicate = false;
113+
var hasWarnings = warnings.Any();
111114
var rowFailureMessage = new StringBuilder();
112115
rowFailureMessage.Append(string.Concat(errors.Select(e => e + ",")));
113116
rowFailureMessage.Append(string.Concat(warnings.Select(e => e + ",")));
@@ -224,20 +227,31 @@ public async Task<long> ImportAsync(StreamReader reader, string fileName)
224227
else if (ni is not null && person.NationalInsuranceNumber is not null && !person.NationalInsuranceNumber.Equals(row.NINumber))
225228
{
226229
rowFailureMessage.Append($"Warning: Attempted to update NationalInsuranceNumber from {person.NationalInsuranceNumber} to {row.NINumber}");
230+
hasWarnings = true;
227231
}
228232

229233
// Gender is different to incomming record.
230234
if (person.Gender is not null && (int?)person.Gender != row.Gender)
231235
{
232236
rowFailureMessage.Append($"Warning: Attempted to update gender from {person.Gender} to {(Gender?)row.Gender},");
237+
hasWarnings = true;
233238
}
234239

235240
// lastname is different to incomming record
236241
if (row.LastName is not null && !person.LastName.Equals(row.LastName, StringComparison.OrdinalIgnoreCase))
237242
{
238243
rowFailureMessage.Append($"Warning: Attempted to update lastname from {person.LastName} to {row.LastName},");
244+
hasWarnings = true;
245+
}
246+
if (hasWarnings)
247+
{
248+
recordStatus = IntegrationTransactionRecordStatus.Warning;
249+
warningCount++;
250+
}
251+
else
252+
{
253+
successCount++;
239254
}
240-
successCount++;
241255
}
242256
}
243257

@@ -266,6 +280,7 @@ public async Task<long> ImportAsync(StreamReader reader, string fileName)
266280
// mark job as complete
267281
integrationJob.TotalCount = totalRowCount;
268282
integrationJob.SuccessCount = successCount;
283+
integrationJob.WarningCount = warningCount;
269284
integrationJob.FailureCount = failureRowCount;
270285
integrationJob.DuplicateCount = duplicateRowCount;
271286
integrationJob.ImportStatus = IntegrationTransactionImportStatus.Success;

TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/EwcWalesImport/InductionImporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public async Task<InductionImportResult> ImportAsync(StreamReader csvReaderStrea
3838
ImportStatus = IntegrationTransactionImportStatus.InProgress,
3939
TotalCount = 0,
4040
SuccessCount = 0,
41+
WarningCount = 0,
4142
FailureCount = 0,
4243
DuplicateCount = 0,
4344
FileName = fileName,

0 commit comments

Comments
 (0)