| | | 1 | | using System.Globalization; |
| | | 2 | | using System.Net; |
| | | 3 | | using RoleRadar.Application.Abstractions; |
| | | 4 | | using RoleRadar.Domain.Audit; |
| | | 5 | | using RoleRadar.Domain.Common; |
| | | 6 | | using RoleRadar.Domain.Notes; |
| | | 7 | | using RoleRadar.Domain.Tracking; |
| | | 8 | | |
| | | 9 | | namespace RoleRadar.Application.Tracking.Import.Pipeline; |
| | | 10 | | |
| | | 11 | | public sealed class ApplicationsStep : ITrackerImportStep |
| | | 12 | | { |
| | | 13 | | private const string ImportActor = "cli-import-tracker"; |
| | | 14 | | private readonly ICsvParser _csvParser; |
| | | 15 | | private readonly ITrackingTransactionContext _context; |
| | | 16 | | private readonly Func<int, Task>? _faultInjectionHook; |
| | | 17 | | |
| | 66 | 18 | | public ApplicationsStep( |
| | 66 | 19 | | ICsvParser csvParser, |
| | 66 | 20 | | ITrackingTransactionContext context, |
| | 66 | 21 | | Func<int, Task>? faultInjectionHook = null) |
| | | 22 | | { |
| | 66 | 23 | | _csvParser = csvParser ?? throw new ArgumentNullException(nameof(csvParser)); |
| | 66 | 24 | | _context = context ?? throw new ArgumentNullException(nameof(context)); |
| | 66 | 25 | | _faultInjectionHook = faultInjectionHook; |
| | 66 | 26 | | } |
| | | 27 | | |
| | | 28 | | public async Task<Result<bool>> ExecuteAsync(TrackerImportContext context, CancellationToken cancellationToken = def |
| | | 29 | | { |
| | 66 | 30 | | ArgumentNullException.ThrowIfNull(context); |
| | | 31 | | |
| | 66 | 32 | | var filePath = Path.Combine(context.BundleDirectory, "applications.csv"); |
| | 66 | 33 | | var recon = context.Summary.GetOrCreateFileReconciliation("applications.csv"); |
| | | 34 | | |
| | 66 | 35 | | if (!File.Exists(filePath)) |
| | | 36 | | { |
| | 2 | 37 | | recon.IsAbsent = true; |
| | 2 | 38 | | return Result<bool>.Success(true); |
| | | 39 | | } |
| | | 40 | | |
| | 64 | 41 | | recon.IsAbsent = false; |
| | | 42 | | |
| | 64 | 43 | | var content = await File.ReadAllTextAsync(filePath, cancellationToken); |
| | 64 | 44 | | if (string.IsNullOrWhiteSpace(content)) |
| | | 45 | | { |
| | 2 | 46 | | recon.RecordErrored(); |
| | 2 | 47 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 2 | 48 | | "applications.csv", |
| | 2 | 49 | | 1, |
| | 2 | 50 | | ErrorCode.ValidationError.ToString(), |
| | 2 | 51 | | "File is present but empty.")); |
| | 2 | 52 | | return Result<bool>.Failure(ErrorCode.ValidationError, "applications.csv is present but empty."); |
| | | 53 | | } |
| | | 54 | | |
| | 62 | 55 | | using var headerReader = new StringReader(content); |
| | 62 | 56 | | var headers = _csvParser.ReadHeader(headerReader); |
| | 62 | 57 | | var headerValidation = CsvHeaderValidator.Validate("applications.csv", headers, CsvHeaderValidator.ApplicationsH |
| | 62 | 58 | | if (!headerValidation.IsSuccess) |
| | | 59 | | { |
| | 2 | 60 | | recon.RecordErrored(); |
| | 2 | 61 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 2 | 62 | | "applications.csv", |
| | 2 | 63 | | 1, |
| | 2 | 64 | | ErrorCode.ValidationError.ToString(), |
| | 2 | 65 | | headerValidation.Error!.Value.Message)); |
| | 2 | 66 | | return Result<bool>.Failure(headerValidation.Error!.Value); |
| | | 67 | | } |
| | | 68 | | |
| | 60 | 69 | | _standaloneNoteOrdinal = 0; |
| | | 70 | | |
| | 60 | 71 | | using var reader = new StringReader(content); |
| | 60 | 72 | | var defaultDate = context.DefaultDate ?? DateOnly.FromDateTime(DateTime.UtcNow); |
| | | 73 | | |
| | 288 | 74 | | foreach (var row in _csvParser.Read(reader, hasHeader: true)) |
| | | 75 | | { |
| | 84 | 76 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 84 | 77 | | recon.RecordRead(); |
| | | 78 | | |
| | 2856 | 79 | | foreach (var def in SourceFieldCatalog.ByFile["applications.csv"]) |
| | | 80 | | { |
| | 1344 | 81 | | var val = TrackerImportTextSanitizer.SanitizePlainText(row[def.Field])?.Trim(); |
| | 1344 | 82 | | context.Summary.RecordFieldRead("applications.csv", def.Field, !string.IsNullOrWhiteSpace(val)); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | try |
| | | 86 | | { |
| | 168 | 87 | | if (!row.Fields.Any(f => !string.IsNullOrWhiteSpace(f))) |
| | | 88 | | { |
| | 0 | 89 | | recon.RecordSkipped("empty_row"); |
| | 0 | 90 | | continue; |
| | | 91 | | } |
| | | 92 | | |
| | 84 | 93 | | var decision = row["decision"]?.Trim(); |
| | 84 | 94 | | if (string.Equals(decision, "skip", StringComparison.OrdinalIgnoreCase)) |
| | | 95 | | { |
| | 0 | 96 | | context.Summary.ApplicationsUnchanged++; |
| | 0 | 97 | | recon.RecordSkipped("decision_skip"); |
| | 0 | 98 | | continue; |
| | | 99 | | } |
| | | 100 | | |
| | 84 | 101 | | if (!string.IsNullOrWhiteSpace(decision)) |
| | | 102 | | { |
| | 0 | 103 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 0 | 104 | | "applications.csv", |
| | 0 | 105 | | row.LineNumber, |
| | 0 | 106 | | ErrorCode.ValidationError.ToString(), |
| | 0 | 107 | | $"Invalid decision value '{decision}'. Expected blank or 'skip'.")); |
| | 0 | 108 | | recon.RecordErrored(); |
| | 0 | 109 | | continue; |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | // Flag detection for people |
| | 84 | 113 | | var peopleDetected = row["people_detected"]?.Trim(); |
| | 84 | 114 | | var reviewFlags = row["review_flags"]?.Trim(); |
| | 84 | 115 | | var containsPeopleCol = row["contains_people"]?.Trim(); |
| | 84 | 116 | | var containsPeople = (!string.IsNullOrWhiteSpace(reviewFlags) && |
| | 84 | 117 | | reviewFlags.Contains("contains_people", StringComparison.OrdinalIgnoreCase)) || |
| | 84 | 118 | | (!string.IsNullOrWhiteSpace(containsPeopleCol) && |
| | 84 | 119 | | (containsPeopleCol.Equals("true", StringComparison.OrdinalIgnoreCase) || |
| | 84 | 120 | | containsPeopleCol.Contains("contains_people", StringComparison.OrdinalIgnoreCase) |
| | | 121 | | |
| | 84 | 122 | | if (!string.IsNullOrWhiteSpace(peopleDetected) || containsPeople) |
| | | 123 | | { |
| | 14 | 124 | | var details = !string.IsNullOrWhiteSpace(peopleDetected) ? peopleDetected : "Contains people flagged |
| | 14 | 125 | | context.Summary.PeopleDetected.Add($"[applications.csv:{row.LineNumber}] {details}"); |
| | | 126 | | } |
| | | 127 | | |
| | 84 | 128 | | var kind = row["kind"]?.Trim(); |
| | | 129 | | |
| | | 130 | | // 1. Standalone Note branch |
| | 84 | 131 | | if (string.Equals(kind, "standalone_note", StringComparison.OrdinalIgnoreCase)) |
| | | 132 | | { |
| | 28 | 133 | | var noteCreated = false; |
| | 28 | 134 | | var noteResult = await _context.ExecuteInTransactionAsync(async (txCtx, ct) => |
| | 28 | 135 | | { |
| | 28 | 136 | | noteCreated = await ProcessStandaloneNoteAsync(context, row, defaultDate, ct); |
| | 28 | 137 | | return Result<bool>.Success(true); |
| | 56 | 138 | | }, cancellationToken); |
| | | 139 | | |
| | 28 | 140 | | if (!noteResult.IsSuccess) |
| | | 141 | | { |
| | 0 | 142 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 0 | 143 | | "applications.csv", |
| | 0 | 144 | | row.LineNumber, |
| | 0 | 145 | | noteResult.Error?.Code.ToString() ?? ErrorCode.ValidationError.ToString(), |
| | 0 | 146 | | noteResult.Error?.Message ?? "Failed to save note")); |
| | 0 | 147 | | recon.RecordErrored(); |
| | | 148 | | } |
| | 28 | 149 | | else if (noteCreated) |
| | | 150 | | { |
| | 20 | 151 | | recon.RecordCreated(); |
| | | 152 | | } |
| | | 153 | | else |
| | | 154 | | { |
| | 8 | 155 | | recon.RecordUnchanged(); |
| | | 156 | | } |
| | 28 | 157 | | continue; |
| | | 158 | | } |
| | | 159 | | |
| | | 160 | | // 2. Application branch validation |
| | 56 | 161 | | var rawCompany = TrackerImportTextSanitizer.SanitizePlainText(row["company"])?.Trim(); |
| | 56 | 162 | | var rawTitle = (TrackerImportTextSanitizer.SanitizePlainText(row["title"]) ?? TrackerImportTextSanitizer |
| | 56 | 163 | | if (string.IsNullOrWhiteSpace(rawCompany) || string.IsNullOrWhiteSpace(rawTitle)) |
| | | 164 | | { |
| | 0 | 165 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 0 | 166 | | "applications.csv", |
| | 0 | 167 | | row.LineNumber, |
| | 0 | 168 | | ErrorCode.ValidationError.ToString(), |
| | 0 | 169 | | "Missing required company or title.")); |
| | 0 | 170 | | recon.RecordErrored(); |
| | 0 | 171 | | continue; |
| | | 172 | | } |
| | | 173 | | |
| | 56 | 174 | | var appCreated = false; |
| | 56 | 175 | | var appResult = await _context.ExecuteInTransactionAsync(async (txCtx, ct) => |
| | 56 | 176 | | { |
| | 56 | 177 | | var res = await ProcessApplicationAsync(context, row, defaultDate, reviewFlags, ct); |
| | 52 | 178 | | if (!res.IsSuccess) |
| | 56 | 179 | | { |
| | 2 | 180 | | return res; |
| | 56 | 181 | | } |
| | 50 | 182 | | appCreated = res.Value; |
| | 50 | 183 | | return Result<bool>.Success(true); |
| | 108 | 184 | | }, cancellationToken); |
| | | 185 | | |
| | 56 | 186 | | if (!appResult.IsSuccess) |
| | | 187 | | { |
| | 6 | 188 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 6 | 189 | | "applications.csv", |
| | 6 | 190 | | row.LineNumber, |
| | 6 | 191 | | appResult.Error?.Code.ToString() ?? ErrorCode.ValidationError.ToString(), |
| | 6 | 192 | | appResult.Error?.Message ?? "Failed to save application")); |
| | 6 | 193 | | recon.RecordErrored(); |
| | | 194 | | } |
| | 50 | 195 | | else if (appCreated) |
| | | 196 | | { |
| | 46 | 197 | | recon.RecordCreated(); |
| | | 198 | | } |
| | | 199 | | else |
| | | 200 | | { |
| | 4 | 201 | | recon.RecordUnchanged(); |
| | | 202 | | } |
| | 56 | 203 | | } |
| | 0 | 204 | | catch (Exception ex) when (ex is not OperationCanceledException) |
| | | 205 | | { |
| | 0 | 206 | | context.Summary.Errors.Add(new TrackerImportRowError( |
| | 0 | 207 | | "applications.csv", |
| | 0 | 208 | | row.LineNumber, |
| | 0 | 209 | | ErrorCode.ValidationError.ToString(), |
| | 0 | 210 | | ex.Message)); |
| | 0 | 211 | | recon.RecordErrored(); |
| | 0 | 212 | | } |
| | 56 | 213 | | } |
| | | 214 | | |
| | 60 | 215 | | return Result<bool>.Success(true); |
| | 66 | 216 | | } |
| | | 217 | | |
| | | 218 | | private int _standaloneNoteOrdinal; |
| | | 219 | | |
| | | 220 | | private async Task<bool> ProcessStandaloneNoteAsync( |
| | | 221 | | TrackerImportContext context, |
| | | 222 | | ICsvRecord row, |
| | | 223 | | DateOnly defaultDate, |
| | | 224 | | CancellationToken cancellationToken) |
| | | 225 | | { |
| | 28 | 226 | | _standaloneNoteOrdinal++; |
| | 28 | 227 | | var company = TrackerImportTextSanitizer.SanitizePlainText(row["company"])?.Trim(); |
| | 28 | 228 | | var title = (TrackerImportTextSanitizer.SanitizePlainText(row["title"]) ?? TrackerImportTextSanitizer.SanitizePl |
| | 28 | 229 | | var appliedOn = (TrackerImportTextSanitizer.SanitizePlainText(row["applied_on"]) ?? TrackerImportTextSanitizer.S |
| | 28 | 230 | | var raw = TrackerImportTextSanitizer.SanitizeFreeText(row["raw"])?.Trim(); |
| | 28 | 231 | | var correctedNotes = TrackerImportTextSanitizer.SanitizeFreeText(row["corrected_notes"])?.Trim(); |
| | 28 | 232 | | var notes = TrackerImportTextSanitizer.SanitizeFreeText(row["notes"])?.Trim(); |
| | 28 | 233 | | var rawBody = !string.IsNullOrWhiteSpace(correctedNotes) |
| | 28 | 234 | | ? correctedNotes |
| | 28 | 235 | | : (!string.IsNullOrWhiteSpace(notes) ? notes : (!string.IsNullOrWhiteSpace(raw) ? raw : "Standalone note")); |
| | | 236 | | |
| | 28 | 237 | | var body = TrackerImportFieldLimiter.LimitNoteBody(rawBody, context.Summary) ?? "Standalone note"; |
| | | 238 | | |
| | 28 | 239 | | var dateOutcome = DateInferenceRule.Resolve(appliedOn, defaultDate); |
| | 28 | 240 | | TrackDateInference(context, dateOutcome); |
| | | 241 | | |
| | | 242 | | string fullTitle; |
| | 28 | 243 | | if (!string.IsNullOrWhiteSpace(company) && !string.IsNullOrWhiteSpace(title)) |
| | | 244 | | { |
| | 16 | 245 | | fullTitle = $"{company} - {title}"; |
| | | 246 | | } |
| | 12 | 247 | | else if (!string.IsNullOrWhiteSpace(company)) |
| | | 248 | | { |
| | 0 | 249 | | var rawSnippet = !string.IsNullOrWhiteSpace(raw) ? raw : (!string.IsNullOrWhiteSpace(notes) ? notes : "Note" |
| | 0 | 250 | | var snippet = rawSnippet.Length > 40 ? rawSnippet[..40].Trim() : rawSnippet.Trim(); |
| | 0 | 251 | | fullTitle = $"{company} - Imported note {_standaloneNoteOrdinal}: {snippet}"; |
| | | 252 | | } |
| | 12 | 253 | | else if (!string.IsNullOrWhiteSpace(title)) |
| | | 254 | | { |
| | 0 | 255 | | fullTitle = title; |
| | | 256 | | } |
| | | 257 | | else |
| | | 258 | | { |
| | 12 | 259 | | var rawSnippet = !string.IsNullOrWhiteSpace(raw) ? raw : (!string.IsNullOrWhiteSpace(notes) ? notes : (!stri |
| | 12 | 260 | | var snippet = rawSnippet.Length > 40 ? rawSnippet[..40].Trim() : rawSnippet.Trim(); |
| | 12 | 261 | | fullTitle = $"Imported note {_standaloneNoteOrdinal}: {snippet}"; |
| | | 262 | | } |
| | | 263 | | |
| | 28 | 264 | | fullTitle = TrackerImportFieldLimiter.LimitNoteTitle(fullTitle, context.Summary) ?? $"Imported note {_standalone |
| | | 265 | | |
| | 28 | 266 | | var existingNoteRes = await _context.NoteExistsAsync(context.OwnerId, fullTitle, "job-search", cancellationToken |
| | 28 | 267 | | if (existingNoteRes.IsSuccess && existingNoteRes.Value) |
| | | 268 | | { |
| | 8 | 269 | | return false; |
| | | 270 | | } |
| | | 271 | | |
| | 20 | 272 | | var noteDateStr = dateOutcome.ResolvedDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); |
| | 20 | 273 | | var note = Note.Create( |
| | 20 | 274 | | ownerId: context.OwnerId, |
| | 20 | 275 | | title: fullTitle, |
| | 20 | 276 | | body: body, |
| | 20 | 277 | | tags: ["tracker-import"], |
| | 20 | 278 | | area: "job-search", |
| | 20 | 279 | | provenance: new ProvenanceMarker(RoleRadar.Domain.Notes.ProvenanceKind.Stated, noteDateStr, null), |
| | 20 | 280 | | createdAtUtc: dateOutcome.ResolvedDate.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)); |
| | | 281 | | |
| | 20 | 282 | | await _context.UpsertNoteAsync(note, cancellationToken); |
| | | 283 | | |
| | 20 | 284 | | var audit = AuditLogEntry.CreateForImportCreate( |
| | 20 | 285 | | ownerId: context.OwnerId, |
| | 20 | 286 | | actor: ImportActor, |
| | 20 | 287 | | targetNoteId: note.Id, |
| | 20 | 288 | | resultingVersionToken: note.VersionToken, |
| | 20 | 289 | | resolvedDefaultDate: defaultDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), |
| | 20 | 290 | | occurredAtUtc: DateTime.UtcNow, |
| | 20 | 291 | | afterSummary: AuditContentSummary.FromNote(note)); |
| | | 292 | | |
| | 20 | 293 | | await _context.AppendAuditEntryAsync(audit, cancellationToken); |
| | 20 | 294 | | context.Summary.StandaloneNotesCreated++; |
| | 20 | 295 | | return true; |
| | 28 | 296 | | } |
| | | 297 | | |
| | | 298 | | private async Task<Result<bool>> ProcessApplicationAsync( |
| | | 299 | | TrackerImportContext context, |
| | | 300 | | ICsvRecord row, |
| | | 301 | | DateOnly defaultDate, |
| | | 302 | | string? reviewFlags, |
| | | 303 | | CancellationToken cancellationToken) |
| | | 304 | | { |
| | 56 | 305 | | var rawCompanyName = TrackerImportTextSanitizer.SanitizePlainText(row["company"])?.Trim(); |
| | 56 | 306 | | var rawTitle = (TrackerImportTextSanitizer.SanitizePlainText(row["title"]) ?? TrackerImportTextSanitizer.Sanitiz |
| | 56 | 307 | | var rawReq = (TrackerImportTextSanitizer.SanitizePlainText(row["req"]) ?? TrackerImportTextSanitizer.SanitizePla |
| | 56 | 308 | | var appliedOn = (TrackerImportTextSanitizer.SanitizePlainText(row["applied_on"]) ?? TrackerImportTextSanitizer.S |
| | 56 | 309 | | var rejectedStr = TrackerImportTextSanitizer.SanitizePlainText(row["rejected"])?.Trim(); |
| | 56 | 310 | | var isRejected = false; |
| | 56 | 311 | | if (!string.IsNullOrWhiteSpace(rejectedStr)) |
| | | 312 | | { |
| | 54 | 313 | | var s = rejectedStr.Trim().ToLowerInvariant(); |
| | 54 | 314 | | if (s is "true" or "yes" or "1" or "t" or "y") |
| | | 315 | | { |
| | 12 | 316 | | isRejected = true; |
| | | 317 | | } |
| | 42 | 318 | | else if (s is "false" or "no" or "0" or "f" or "n") |
| | | 319 | | { |
| | 40 | 320 | | isRejected = false; |
| | | 321 | | } |
| | | 322 | | else |
| | | 323 | | { |
| | 2 | 324 | | context.Summary.RecordUnmappedValue("rejected", rejectedStr); |
| | | 325 | | } |
| | | 326 | | } |
| | 56 | 327 | | var rejectedDateMd = TrackerImportTextSanitizer.SanitizePlainText(row["rejected_date_md"])?.Trim(); |
| | | 328 | | |
| | 56 | 329 | | var companyName = TrackerImportFieldLimiter.LimitCompanyName(rawCompanyName, context.Summary); |
| | 56 | 330 | | var title = TrackerImportFieldLimiter.LimitTitle(rawTitle, context.Summary) ?? "Role"; |
| | 56 | 331 | | var req = TrackerImportFieldLimiter.LimitRequisitionId(rawReq, context.Summary); |
| | | 332 | | |
| | | 333 | | // Also limit optional free-text inputs for referral, fit, resume_variant |
| | 56 | 334 | | var referralRaw = TrackerImportTextSanitizer.SanitizePlainText(row["referral"])?.Trim(); |
| | 56 | 335 | | TrackerImportFieldLimiter.LimitReferral(referralRaw, context.Summary); |
| | 56 | 336 | | var isReferral = false; |
| | 56 | 337 | | if (!string.IsNullOrWhiteSpace(referralRaw)) |
| | | 338 | | { |
| | 36 | 339 | | var s = referralRaw.Trim().ToLowerInvariant(); |
| | 36 | 340 | | if (s is "true" or "yes" or "1" or "t" or "y") |
| | | 341 | | { |
| | 10 | 342 | | isReferral = true; |
| | | 343 | | } |
| | 26 | 344 | | else if (s is "false" or "no" or "0" or "f" or "n") |
| | | 345 | | { |
| | 24 | 346 | | isReferral = false; |
| | | 347 | | } |
| | | 348 | | else |
| | | 349 | | { |
| | 2 | 350 | | context.Summary.RecordUnmappedValue("referral", referralRaw); |
| | | 351 | | } |
| | | 352 | | } |
| | | 353 | | |
| | 56 | 354 | | var fitRaw = TrackerImportTextSanitizer.SanitizePlainText(row["fit"])?.Trim(); |
| | 56 | 355 | | TrackerImportFieldLimiter.LimitFit(fitRaw, context.Summary); |
| | 56 | 356 | | decimal? fitScore = null; |
| | 56 | 357 | | string? fitNoteText = null; |
| | 56 | 358 | | if (!string.IsNullOrWhiteSpace(fitRaw)) |
| | | 359 | | { |
| | 36 | 360 | | var cleanFit = fitRaw.TrimEnd('.'); |
| | 36 | 361 | | if (decimal.TryParse(cleanFit, NumberStyles.Any, CultureInfo.InvariantCulture, out var parsedScore) && |
| | 36 | 362 | | parsedScore is >= 0.0m and <= 10.0m) |
| | | 363 | | { |
| | 6 | 364 | | fitScore = parsedScore; |
| | | 365 | | } |
| | | 366 | | else |
| | | 367 | | { |
| | 30 | 368 | | context.Summary.RecordUnmappedValue("fit", fitRaw); |
| | | 369 | | } |
| | 36 | 370 | | fitNoteText = $"fit: {cleanFit}"; |
| | 36 | 371 | | context.Summary.MappedToEventNotes++; |
| | | 372 | | } |
| | | 373 | | |
| | 56 | 374 | | string? referralNoteText = null; |
| | 56 | 375 | | if (isReferral) |
| | | 376 | | { |
| | 10 | 377 | | referralNoteText = "referral=true"; |
| | 10 | 378 | | context.Summary.MappedToEventNotes++; |
| | | 379 | | } |
| | | 380 | | |
| | 56 | 381 | | var rvRaw = TrackerImportFieldLimiter.LimitResumeVariant(TrackerImportTextSanitizer.SanitizePlainText(row["resum |
| | | 382 | | ResumeVariant resumeVariant; |
| | 56 | 383 | | string? resumeVariantNoteText = null; |
| | 56 | 384 | | if (string.IsNullOrWhiteSpace(rvRaw)) |
| | | 385 | | { |
| | 20 | 386 | | resumeVariant = ResumeVariant.AsIs; |
| | 20 | 387 | | resumeVariantNoteText = "resume variant unspecified"; |
| | 20 | 388 | | context.Summary.ResumeVariantsDefaulted++; |
| | | 389 | | } |
| | 36 | 390 | | else if (TrackingEnumExtensions.TryParseResumeVariant(rvRaw, out var parsedRv)) |
| | | 391 | | { |
| | 30 | 392 | | resumeVariant = parsedRv; |
| | | 393 | | } |
| | | 394 | | else |
| | | 395 | | { |
| | 6 | 396 | | context.Summary.RecordUnmappedValue("resume_variant", rvRaw); |
| | 6 | 397 | | resumeVariant = ResumeVariant.AsIs; |
| | 6 | 398 | | resumeVariantNoteText = "resume variant unspecified"; |
| | 6 | 399 | | context.Summary.ResumeVariantsDefaulted++; |
| | | 400 | | } |
| | | 401 | | |
| | 56 | 402 | | var rawSalary = TrackerImportTextSanitizer.SanitizePlainText(row["desired_salary"])?.Trim(); |
| | 56 | 403 | | DesiredSalary? desiredSalary = null; |
| | 56 | 404 | | string? unparseableSalaryNote = null; |
| | 56 | 405 | | if (!string.IsNullOrWhiteSpace(rawSalary)) |
| | | 406 | | { |
| | 46 | 407 | | if (decimal.TryParse(rawSalary, NumberStyles.Any, CultureInfo.InvariantCulture, out var directDecimal) && di |
| | | 408 | | { |
| | 2 | 409 | | desiredSalary = new DesiredSalary(directDecimal, directDecimal, "USD"); |
| | | 410 | | } |
| | | 411 | | else |
| | | 412 | | { |
| | 44 | 413 | | var (salMin, salMax) = PostingsJsonStep.TryParseCompensationRange(rawSalary); |
| | 44 | 414 | | if (salMin.HasValue) |
| | | 415 | | { |
| | 40 | 416 | | desiredSalary = new DesiredSalary(salMin.Value, salMax ?? salMin.Value, "USD"); |
| | | 417 | | } |
| | | 418 | | else |
| | | 419 | | { |
| | 4 | 420 | | context.Summary.RecordUnmappedValue("desired_salary", rawSalary); |
| | 4 | 421 | | unparseableSalaryNote = $"desired_salary: {rawSalary}"; |
| | | 422 | | } |
| | | 423 | | } |
| | | 424 | | } |
| | | 425 | | |
| | 56 | 426 | | var dateOutcome = DateInferenceRule.Resolve(appliedOn, defaultDate); |
| | 56 | 427 | | TrackDateInference(context, dateOutcome); |
| | | 428 | | |
| | 56 | 429 | | ResolvedDateOutcome? rejectedDateOutcome = null; |
| | 56 | 430 | | if (isRejected) |
| | | 431 | | { |
| | 12 | 432 | | var res = DateInferenceRule.Resolve(rejectedDateMd, defaultDate); |
| | 12 | 433 | | rejectedDateOutcome = res; |
| | 12 | 434 | | TrackDateInference(context, res); |
| | | 435 | | } |
| | | 436 | | |
| | 56 | 437 | | var isDateStatedFlag = !string.IsNullOrWhiteSpace(reviewFlags) && |
| | 56 | 438 | | reviewFlags.Contains("date_is_stated_not_submitted", StringComparison.OrdinalIgnoreCase); |
| | | 439 | | |
| | 56 | 440 | | var statedFlagText = isDateStatedFlag ? "date_is_stated_not_submitted" : null; |
| | 56 | 441 | | var rawNotes = TrackerImportTextSanitizer.SanitizeFreeText(!string.IsNullOrWhiteSpace(row["corrected_notes"]) ? |
| | 392 | 442 | | var combinedNotes = string.Join("; ", new[] { statedFlagText, fitNoteText, referralNoteText, unparseableSalaryNo |
| | | 443 | | |
| | 56 | 444 | | var canonicalCompany = !string.IsNullOrWhiteSpace(companyName) && context.CompanyAliases.TryGetValue(companyName |
| | 56 | 445 | | ? alias |
| | 56 | 446 | | : companyName; |
| | | 447 | | |
| | | 448 | | // Resolve matching posting: req first, then company + title (only if candidate has no req or matching req) |
| | 56 | 449 | | Posting? foundPosting = null; |
| | 56 | 450 | | if (!string.IsNullOrWhiteSpace(req)) |
| | | 451 | | { |
| | 40 | 452 | | if (!string.IsNullOrWhiteSpace(canonicalCompany) && context.PostingsByCompanyAndReq.TryGetValue($"{canonical |
| | | 453 | | { |
| | 8 | 454 | | foundPosting = byReq; |
| | | 455 | | } |
| | 32 | 456 | | else if (!string.IsNullOrWhiteSpace(canonicalCompany)) |
| | | 457 | | { |
| | 32 | 458 | | Company? cObj = null; |
| | 32 | 459 | | if (context.CanonicalCompanies.TryGetValue(canonicalCompany, out var foundComp)) |
| | | 460 | | { |
| | 10 | 461 | | cObj = foundComp; |
| | | 462 | | } |
| | | 463 | | else |
| | | 464 | | { |
| | 22 | 465 | | var existingCompRes = await _context.Companies.GetByNormalizedNameAsync(context.OwnerId, canonicalCo |
| | 22 | 466 | | if (existingCompRes.IsSuccess && existingCompRes.Value is not null) |
| | | 467 | | { |
| | 0 | 468 | | cObj = existingCompRes.Value; |
| | | 469 | | } |
| | | 470 | | } |
| | | 471 | | |
| | 32 | 472 | | if (cObj is not null) |
| | | 473 | | { |
| | 10 | 474 | | var dedupC = $"{cObj.Id:D}|{req.Trim()}"; |
| | 10 | 475 | | var byCRes = await _context.Postings.GetByDedupKeyCAsync(context.OwnerId, dedupC, cancellationToken) |
| | 10 | 476 | | if (byCRes.IsSuccess && byCRes.Value is not null) |
| | | 477 | | { |
| | 0 | 478 | | foundPosting = byCRes.Value; |
| | | 479 | | } |
| | | 480 | | } |
| | 32 | 481 | | } |
| | | 482 | | } |
| | | 483 | | |
| | 56 | 484 | | if (foundPosting is null && !string.IsNullOrWhiteSpace(canonicalCompany) && !string.IsNullOrWhiteSpace(title)) |
| | | 485 | | { |
| | 48 | 486 | | var titleKey = $"{canonicalCompany}|{TitleNormalizer.Normalize(title)}"; |
| | 48 | 487 | | if (context.PostingsByCompanyAndTitle.TryGetValue(titleKey, out var byTitle)) |
| | | 488 | | { |
| | 24 | 489 | | if (string.IsNullOrWhiteSpace(byTitle.RequisitionId) || string.Equals(byTitle.RequisitionId, req, String |
| | | 490 | | { |
| | 24 | 491 | | foundPosting = byTitle; |
| | | 492 | | } |
| | | 493 | | } |
| | | 494 | | else |
| | | 495 | | { |
| | 24 | 496 | | Company? cObj = null; |
| | 24 | 497 | | if (context.CanonicalCompanies.TryGetValue(canonicalCompany, out var foundComp)) |
| | | 498 | | { |
| | 2 | 499 | | cObj = foundComp; |
| | | 500 | | } |
| | | 501 | | else |
| | | 502 | | { |
| | 22 | 503 | | var existingCompRes = await _context.Companies.GetByNormalizedNameAsync(context.OwnerId, canonicalCo |
| | 22 | 504 | | if (existingCompRes.IsSuccess && existingCompRes.Value is not null) |
| | | 505 | | { |
| | 0 | 506 | | cObj = existingCompRes.Value; |
| | | 507 | | } |
| | | 508 | | } |
| | | 509 | | |
| | 24 | 510 | | if (cObj is not null) |
| | | 511 | | { |
| | 2 | 512 | | var candRes = await _context.Postings.FindCandidatesByCompanyAndTitleAsync(context.OwnerId, cObj.Id, |
| | 2 | 513 | | if (candRes.IsSuccess && candRes.Value is { Count: > 0 } candidates) |
| | | 514 | | { |
| | 0 | 515 | | foreach (var c in candidates) |
| | | 516 | | { |
| | 0 | 517 | | var byIdRes = await _context.Postings.GetByIdAsync(context.OwnerId, c.Id, cancellationToken) |
| | 0 | 518 | | if (byIdRes.IsSuccess && byIdRes.Value is not null) |
| | | 519 | | { |
| | 0 | 520 | | if (string.IsNullOrWhiteSpace(byIdRes.Value.RequisitionId) || string.Equals(byIdRes.Valu |
| | | 521 | | { |
| | 0 | 522 | | foundPosting = byIdRes.Value; |
| | 0 | 523 | | break; |
| | | 524 | | } |
| | | 525 | | } |
| | | 526 | | } |
| | | 527 | | } |
| | | 528 | | } |
| | 24 | 529 | | } |
| | | 530 | | } |
| | | 531 | | |
| | | 532 | | Guid postingId; |
| | 56 | 533 | | var appliedDateTime = dateOutcome.ResolvedDate.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc); |
| | | 534 | | |
| | 56 | 535 | | if (foundPosting is not null) |
| | | 536 | | { |
| | 32 | 537 | | foundPosting.TransitionToApplied(appliedDateTime); |
| | 32 | 538 | | if (isRejected) |
| | | 539 | | { |
| | 8 | 540 | | var rejDateTime = (rejectedDateOutcome?.ResolvedDate ?? dateOutcome.ResolvedDate) |
| | 8 | 541 | | .ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc); |
| | 8 | 542 | | foundPosting.SynchronizeFromApplicationEvent(PostingDisposition.Rejected, "Rejected", rejDateTime); |
| | | 543 | | } |
| | | 544 | | |
| | 32 | 545 | | await _context.Postings.UpsertPostingAsync(foundPosting, cancellationToken); |
| | | 546 | | |
| | 32 | 547 | | var auditPosting = AuditLogEntry.CreateForTracking( |
| | 32 | 548 | | ownerId: context.OwnerId, |
| | 32 | 549 | | actor: ImportActor, |
| | 32 | 550 | | operation: AuditOperation.ImportPostingTransition, |
| | 32 | 551 | | entityType: "posting", |
| | 32 | 552 | | entityId: foundPosting.Id, |
| | 32 | 553 | | resultingVersionToken: foundPosting.VersionToken, |
| | 32 | 554 | | occurredAtUtc: DateTime.UtcNow, |
| | 32 | 555 | | details: new AuditDetails( |
| | 32 | 556 | | ChangedFields: ["disposition"], |
| | 32 | 557 | | After: new Dictionary<string, object?> |
| | 32 | 558 | | { |
| | 32 | 559 | | ["disposition"] = foundPosting.Disposition.ToString() |
| | 32 | 560 | | })); |
| | | 561 | | |
| | 32 | 562 | | await _context.AppendAuditEntryAsync(auditPosting, cancellationToken); |
| | 32 | 563 | | context.Summary.PostingsUpdated++; |
| | 32 | 564 | | context.ClaimedPostingIds.Add(foundPosting.Id); |
| | | 565 | | |
| | 32 | 566 | | if (context.Summary.UnclaimedAppliedPostingTitles.Remove(foundPosting.Title)) |
| | | 567 | | { |
| | 18 | 568 | | context.Summary.UnclaimedAppliedPostings = context.Summary.UnclaimedAppliedPostingTitles.Count; |
| | | 569 | | } |
| | | 570 | | |
| | 32 | 571 | | postingId = foundPosting.Id; |
| | 32 | 572 | | context.IndexPosting(foundPosting, canonicalCompany); |
| | | 573 | | } |
| | | 574 | | else |
| | | 575 | | { |
| | | 576 | | // Auto-create company and posting if missing |
| | 24 | 577 | | var companyId = Guid.NewGuid(); |
| | 24 | 578 | | if (!string.IsNullOrWhiteSpace(canonicalCompany)) |
| | | 579 | | { |
| | 24 | 580 | | if (!context.CanonicalCompanies.TryGetValue(canonicalCompany, out var company)) |
| | | 581 | | { |
| | 22 | 582 | | var existingComp = await _context.Companies.GetByNormalizedNameAsync(context.OwnerId, canonicalCompa |
| | 22 | 583 | | if (existingComp.IsSuccess && existingComp.Value is not null) |
| | | 584 | | { |
| | 0 | 585 | | company = existingComp.Value; |
| | | 586 | | } |
| | | 587 | | else |
| | | 588 | | { |
| | 22 | 589 | | company = Company.Create( |
| | 22 | 590 | | ownerId: context.OwnerId, |
| | 22 | 591 | | name: canonicalCompany, |
| | 22 | 592 | | status: CompanyStatus.Neutral, |
| | 22 | 593 | | description: string.Empty); |
| | | 594 | | |
| | 22 | 595 | | await _context.Companies.UpsertCompanyAsync(company, cancellationToken); |
| | | 596 | | |
| | 22 | 597 | | var auditC = AuditLogEntry.CreateForTracking( |
| | 22 | 598 | | ownerId: context.OwnerId, |
| | 22 | 599 | | actor: ImportActor, |
| | 22 | 600 | | operation: AuditOperation.ImportCompanyCreate, |
| | 22 | 601 | | entityType: "company", |
| | 22 | 602 | | entityId: company.Id, |
| | 22 | 603 | | resultingVersionToken: company.VersionToken, |
| | 22 | 604 | | occurredAtUtc: DateTime.UtcNow, |
| | 22 | 605 | | details: new AuditDetails( |
| | 22 | 606 | | ChangedFields: ["name", "status"], |
| | 22 | 607 | | After: new Dictionary<string, object?> |
| | 22 | 608 | | { |
| | 22 | 609 | | ["name"] = company.Name, |
| | 22 | 610 | | ["status"] = company.Status.ToString() |
| | 22 | 611 | | })); |
| | | 612 | | |
| | 22 | 613 | | await _context.AppendAuditEntryAsync(auditC, cancellationToken); |
| | 22 | 614 | | context.Summary.CompaniesCreated++; |
| | 22 | 615 | | context.Summary.AutoCreatedCompanies.Add(canonicalCompany); |
| | | 616 | | } |
| | | 617 | | |
| | 22 | 618 | | context.CanonicalCompanies[canonicalCompany] = company; |
| | | 619 | | } |
| | | 620 | | |
| | 24 | 621 | | companyId = company.Id; |
| | 24 | 622 | | } |
| | | 623 | | |
| | 24 | 624 | | var newPosting = Posting.Create( |
| | 24 | 625 | | ownerId: context.OwnerId, |
| | 24 | 626 | | companyId: companyId, |
| | 24 | 627 | | title: title, |
| | 24 | 628 | | sourceKind: SourceKind.Aggregator, |
| | 24 | 629 | | originalUrl: null, |
| | 24 | 630 | | requisitionId: req, |
| | 24 | 631 | | remoteType: RemoteType.Unknown, |
| | 24 | 632 | | score: fitScore, |
| | 24 | 633 | | disposition: isRejected ? PostingDisposition.Rejected : PostingDisposition.Applied, |
| | 24 | 634 | | dispositionReason: isRejected ? "Rejected" : null, |
| | 24 | 635 | | now: appliedDateTime); |
| | | 636 | | |
| | 24 | 637 | | await _context.Postings.UpsertPostingAsync(newPosting, cancellationToken); |
| | | 638 | | |
| | 24 | 639 | | var auditP = AuditLogEntry.CreateForTracking( |
| | 24 | 640 | | ownerId: context.OwnerId, |
| | 24 | 641 | | actor: ImportActor, |
| | 24 | 642 | | operation: AuditOperation.ImportPostingCreate, |
| | 24 | 643 | | entityType: "posting", |
| | 24 | 644 | | entityId: newPosting.Id, |
| | 24 | 645 | | resultingVersionToken: newPosting.VersionToken, |
| | 24 | 646 | | occurredAtUtc: DateTime.UtcNow, |
| | 24 | 647 | | details: new AuditDetails( |
| | 24 | 648 | | ChangedFields: ["title", "disposition"], |
| | 24 | 649 | | After: new Dictionary<string, object?> |
| | 24 | 650 | | { |
| | 24 | 651 | | ["title"] = newPosting.Title, |
| | 24 | 652 | | ["disposition"] = newPosting.Disposition.ToString() |
| | 24 | 653 | | })); |
| | | 654 | | |
| | 24 | 655 | | await _context.AppendAuditEntryAsync(auditP, cancellationToken); |
| | 24 | 656 | | context.Summary.PostingsCreated++; |
| | 24 | 657 | | postingId = newPosting.Id; |
| | 24 | 658 | | context.IndexPosting(newPosting, canonicalCompany); |
| | 24 | 659 | | } |
| | | 660 | | |
| | 56 | 661 | | if (!context.ClaimedPostingIdsInRun.Add(postingId)) |
| | | 662 | | { |
| | 2 | 663 | | return Result<bool>.Failure( |
| | 2 | 664 | | ErrorCode.ValidationError, |
| | 2 | 665 | | "Conflicting application: multiple application rows resolve to the same posting."); |
| | | 666 | | } |
| | | 667 | | |
| | 54 | 668 | | var submittedDateStr = dateOutcome.ResolvedDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); |
| | 54 | 669 | | var outcome = isRejected ? ApplicationOutcome.Rejected : ApplicationOutcome.Applied; |
| | 54 | 670 | | var outcomeReasonRaw = isRejected ? (!string.IsNullOrWhiteSpace(combinedNotes) ? combinedNotes : "Rejected") : n |
| | 54 | 671 | | var outcomeReason = TrackerImportFieldLimiter.LimitOutcomeReason(outcomeReasonRaw, context.Summary); |
| | | 672 | | |
| | 54 | 673 | | var existingAppRes = await _context.Applications.GetByPostingIdAsync(context.OwnerId, postingId, cancellationTok |
| | 54 | 674 | | if (existingAppRes.IsSuccess && existingAppRes.Value is not null) |
| | | 675 | | { |
| | 4 | 676 | | var existingApp = existingAppRes.Value; |
| | 4 | 677 | | var isIdentical = |
| | 4 | 678 | | string.Equals(existingApp.SubmittedDate, submittedDateStr, StringComparison.Ordinal) && |
| | 4 | 679 | | existingApp.ResumeVariant == resumeVariant && |
| | 4 | 680 | | existingApp.Outcome == outcome; |
| | | 681 | | |
| | 4 | 682 | | if (isIdentical) |
| | | 683 | | { |
| | 4 | 684 | | context.Summary.ApplicationsUnchanged++; |
| | 4 | 685 | | return Result<bool>.Success(false); |
| | | 686 | | } |
| | | 687 | | |
| | 0 | 688 | | return Result<bool>.Failure( |
| | 0 | 689 | | ErrorCode.ValidationError, |
| | 0 | 690 | | "Conflicting application: existing application for posting has conflicting data."); |
| | | 691 | | } |
| | | 692 | | |
| | 50 | 693 | | var application = RoleRadar.Domain.Tracking.Application.Create( |
| | 50 | 694 | | ownerId: context.OwnerId, |
| | 50 | 695 | | postingId: postingId, |
| | 50 | 696 | | submittedDate: submittedDateStr, |
| | 50 | 697 | | resumeVariant: resumeVariant, |
| | 50 | 698 | | desiredSalary: desiredSalary, |
| | 50 | 699 | | outcome: outcome, |
| | 50 | 700 | | outcomeReason: outcomeReason, |
| | 50 | 701 | | now: appliedDateTime); |
| | | 702 | | |
| | 48 | 703 | | await _context.Applications.UpsertApplicationAsync(application, cancellationToken); |
| | | 704 | | |
| | 48 | 705 | | if (_faultInjectionHook is not null) |
| | | 706 | | { |
| | 6 | 707 | | await _faultInjectionHook(row.LineNumber); |
| | | 708 | | } |
| | | 709 | | |
| | 46 | 710 | | var auditApp = AuditLogEntry.CreateForTracking( |
| | 46 | 711 | | ownerId: context.OwnerId, |
| | 46 | 712 | | actor: ImportActor, |
| | 46 | 713 | | operation: AuditOperation.ImportApplicationCreate, |
| | 46 | 714 | | entityType: "application", |
| | 46 | 715 | | entityId: application.Id, |
| | 46 | 716 | | resultingVersionToken: application.VersionToken, |
| | 46 | 717 | | occurredAtUtc: DateTime.UtcNow, |
| | 46 | 718 | | details: new AuditDetails( |
| | 46 | 719 | | ChangedFields: ["posting_id", "submitted_date", "outcome"], |
| | 46 | 720 | | After: new Dictionary<string, object?> |
| | 46 | 721 | | { |
| | 46 | 722 | | ["posting_id"] = application.PostingId.ToString(), |
| | 46 | 723 | | ["submitted_date"] = application.SubmittedDate, |
| | 46 | 724 | | ["outcome"] = application.Outcome.ToString() |
| | 46 | 725 | | })); |
| | | 726 | | |
| | 46 | 727 | | await _context.AppendAuditEntryAsync(auditApp, cancellationToken); |
| | 46 | 728 | | context.Summary.ApplicationsCreated++; |
| | | 729 | | |
| | | 730 | | // Add applied event |
| | 46 | 731 | | var appliedNotes = TrackerImportFieldLimiter.LimitEventNotes( |
| | 46 | 732 | | !string.IsNullOrWhiteSpace(combinedNotes) ? combinedNotes : null, |
| | 46 | 733 | | context.Summary); |
| | | 734 | | |
| | 46 | 735 | | var appliedEvent = ApplicationEvent.Create( |
| | 46 | 736 | | ownerId: context.OwnerId, |
| | 46 | 737 | | applicationId: application.Id, |
| | 46 | 738 | | eventDate: submittedDateStr, |
| | 46 | 739 | | eventType: ApplicationEventType.Applied, |
| | 46 | 740 | | notes: appliedNotes, |
| | 46 | 741 | | now: appliedDateTime); |
| | | 742 | | |
| | 46 | 743 | | await _context.Applications.AppendEventAsync(appliedEvent, cancellationToken); |
| | | 744 | | |
| | 46 | 745 | | var auditEvt1 = AuditLogEntry.CreateForTracking( |
| | 46 | 746 | | ownerId: context.OwnerId, |
| | 46 | 747 | | actor: ImportActor, |
| | 46 | 748 | | operation: AuditOperation.ImportApplicationEventAppend, |
| | 46 | 749 | | entityType: "application_event", |
| | 46 | 750 | | entityId: appliedEvent.Id, |
| | 46 | 751 | | resultingVersionToken: application.VersionToken, |
| | 46 | 752 | | occurredAtUtc: DateTime.UtcNow, |
| | 46 | 753 | | details: new AuditDetails( |
| | 46 | 754 | | ChangedFields: ["event_type", "event_date"], |
| | 46 | 755 | | After: new Dictionary<string, object?> |
| | 46 | 756 | | { |
| | 46 | 757 | | ["event_type"] = appliedEvent.EventType.ToString(), |
| | 46 | 758 | | ["event_date"] = appliedEvent.EventDate |
| | 46 | 759 | | })); |
| | | 760 | | |
| | 46 | 761 | | await _context.AppendAuditEntryAsync(auditEvt1, cancellationToken); |
| | | 762 | | |
| | | 763 | | // Add rejected event if rejected |
| | 46 | 764 | | if (isRejected) |
| | | 765 | | { |
| | 12 | 766 | | var rejDateStr = (rejectedDateOutcome?.ResolvedDate ?? dateOutcome.ResolvedDate).ToString("yyyy-MM-dd", Cult |
| | 12 | 767 | | var rejDateTime = (rejectedDateOutcome?.ResolvedDate ?? dateOutcome.ResolvedDate) |
| | 12 | 768 | | .ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc); |
| | | 769 | | |
| | 12 | 770 | | var rejectedNotes = TrackerImportFieldLimiter.LimitEventNotes( |
| | 12 | 771 | | !string.IsNullOrWhiteSpace(rawNotes) ? rawNotes : "Rejected", |
| | 12 | 772 | | context.Summary); |
| | | 773 | | |
| | 12 | 774 | | var rejectedEvent = ApplicationEvent.Create( |
| | 12 | 775 | | ownerId: context.OwnerId, |
| | 12 | 776 | | applicationId: application.Id, |
| | 12 | 777 | | eventDate: rejDateStr, |
| | 12 | 778 | | eventType: ApplicationEventType.Rejected, |
| | 12 | 779 | | notes: rejectedNotes, |
| | 12 | 780 | | now: rejDateTime); |
| | | 781 | | |
| | 12 | 782 | | await _context.Applications.AppendEventAsync(rejectedEvent, cancellationToken); |
| | | 783 | | |
| | 12 | 784 | | var auditEvt2 = AuditLogEntry.CreateForTracking( |
| | 12 | 785 | | ownerId: context.OwnerId, |
| | 12 | 786 | | actor: ImportActor, |
| | 12 | 787 | | operation: AuditOperation.ImportApplicationEventAppend, |
| | 12 | 788 | | entityType: "application_event", |
| | 12 | 789 | | entityId: rejectedEvent.Id, |
| | 12 | 790 | | resultingVersionToken: application.VersionToken, |
| | 12 | 791 | | occurredAtUtc: DateTime.UtcNow, |
| | 12 | 792 | | details: new AuditDetails( |
| | 12 | 793 | | ChangedFields: ["event_type", "event_date"], |
| | 12 | 794 | | After: new Dictionary<string, object?> |
| | 12 | 795 | | { |
| | 12 | 796 | | ["event_type"] = rejectedEvent.EventType.ToString(), |
| | 12 | 797 | | ["event_date"] = rejectedEvent.EventDate |
| | 12 | 798 | | })); |
| | | 799 | | |
| | 12 | 800 | | await _context.AppendAuditEntryAsync(auditEvt2, cancellationToken); |
| | 12 | 801 | | } |
| | | 802 | | |
| | 46 | 803 | | return Result<bool>.Success(true); |
| | 52 | 804 | | } |
| | | 805 | | |
| | | 806 | | private static void TrackDateInference(TrackerImportContext context, ResolvedDateOutcome outcome) |
| | | 807 | | { |
| | 96 | 808 | | if (outcome.Kind == DateResolutionKind.DefaultedBlank) context.Summary.DatesDefaulted++; |
| | 102 | 809 | | if (outcome.Kind is DateResolutionKind.InferredRollback or DateResolutionKind.InferredSameYear) context.Summary. |
| | 102 | 810 | | if (outcome.IsFlagged) context.Summary.DatesFlagged++; |
| | 96 | 811 | | } |
| | | 812 | | } |