| | | 1 | | using RoleRadar.Domain.Notes; |
| | | 2 | | using RoleRadar.Domain.Tracking; |
| | | 3 | | using ApplicationEntity = RoleRadar.Domain.Tracking.Application; |
| | | 4 | | |
| | | 5 | | namespace RoleRadar.Application.Tracking.Import; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Enforces domain-level length constraints on free-text inputs across all tracker import steps. |
| | | 9 | | /// Truncates inputs to their domain limits, records each truncation in the summary and report, |
| | | 10 | | /// and prevents unbounded strings from triggering validation exceptions in domain factories. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class TrackerImportFieldLimiter |
| | | 13 | | { |
| | | 14 | | public const int CompanyDescriptionLimit = Company.MaxDescriptionLength; // 300 |
| | | 15 | | public const int CompanyNameLimit = Company.MaxNameLength; // 150 |
| | | 16 | | public const int PostingTitleLimit = Posting.MaxTitleLength; // 200 |
| | | 17 | | public const int PostingLocationLimit = Posting.MaxLocationLength; // 150 |
| | | 18 | | public const int CompensationTextLimit = Posting.MaxCompensationTextLength; // 300 |
| | | 19 | | public const int CultureSummaryLimit = Posting.MaxCultureSummaryLength; // 500 |
| | | 20 | | public const int DispositionReasonLimit = Posting.MaxDispositionReasonLength; // 500 |
| | | 21 | | public const int OutcomeReasonLimit = ApplicationEntity.MaxOutcomeReasonLength; // 500 |
| | | 22 | | public const int UrlLimit = Posting.MaxUrlLength; // 1000 |
| | | 23 | | public const int RequisitionIdLimit = Posting.MaxRequisitionIdLength; // 100 |
| | | 24 | | public const int NoteTitleLimit = Note.MaxTitleChars; // 300 |
| | | 25 | | public const int NoteBodyLimit = Note.MaxBodyBytes; // 8 * 1024 * 1024 (8 MiB) |
| | | 26 | | public const int EventNotesLimit = ApplicationEvent.MaxNotesLength; // 500 |
| | | 27 | | public const int ResumePointerLimit = ApplicationEntity.MaxResumePointerLength; // 300 |
| | | 28 | | public const int ReferralLimit = 100; |
| | | 29 | | public const int FitLimit = 100; |
| | | 30 | | public const int ResumeVariantLimit = 100; |
| | | 31 | | public const int CriteriaKeyLimit = Criterion.MaxKeyLength; // 100 |
| | | 32 | | public const int CriteriaValueLimit = Criterion.MaxValueLength; // 500 |
| | | 33 | | |
| | | 34 | | public static string? Limit(string? value, int maxLength, string fieldName, TrackerImportSummary summary) |
| | | 35 | | { |
| | 1956 | 36 | | ArgumentNullException.ThrowIfNull(summary); |
| | 1956 | 37 | | ArgumentException.ThrowIfNullOrWhiteSpace(fieldName); |
| | | 38 | | |
| | 1956 | 39 | | if (value is null) |
| | | 40 | | { |
| | 370 | 41 | | return null; |
| | | 42 | | } |
| | | 43 | | |
| | 1586 | 44 | | if (value.Length > maxLength) |
| | | 45 | | { |
| | 44 | 46 | | summary.RecordFieldTruncation(fieldName); |
| | 44 | 47 | | return value[..maxLength]; |
| | | 48 | | } |
| | | 49 | | |
| | 1542 | 50 | | return value; |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public static string LimitRequired(string value, int maxLength, string fieldName, TrackerImportSummary summary) |
| | | 54 | | { |
| | 52 | 55 | | ArgumentNullException.ThrowIfNull(value); |
| | 52 | 56 | | ArgumentNullException.ThrowIfNull(summary); |
| | 52 | 57 | | ArgumentException.ThrowIfNullOrWhiteSpace(fieldName); |
| | | 58 | | |
| | 52 | 59 | | if (value.Length > maxLength) |
| | | 60 | | { |
| | 0 | 61 | | summary.RecordFieldTruncation(fieldName); |
| | 0 | 62 | | return value[..maxLength]; |
| | | 63 | | } |
| | | 64 | | |
| | 52 | 65 | | return value; |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | public static string? LimitCompanyDescription(string? value, TrackerImportSummary summary) => |
| | 54 | 69 | | Limit(value, CompanyDescriptionLimit, "company_description", summary); |
| | | 70 | | |
| | | 71 | | public static string? LimitCompanyName(string? value, TrackerImportSummary summary) => |
| | 270 | 72 | | Limit(value, CompanyNameLimit, "company_name", summary); |
| | | 73 | | |
| | | 74 | | public static string? LimitTitle(string? value, TrackerImportSummary summary) => |
| | 272 | 75 | | Limit(value, PostingTitleLimit, "title", summary); |
| | | 76 | | |
| | | 77 | | public static string? LimitLocation(string? value, TrackerImportSummary summary) => |
| | 112 | 78 | | Limit(value, PostingLocationLimit, "location", summary); |
| | | 79 | | |
| | | 80 | | public static string? LimitCompensationText(string? value, TrackerImportSummary summary) => |
| | 118 | 81 | | Limit(value, CompensationTextLimit, "compensation", summary); |
| | | 82 | | |
| | | 83 | | public static string? LimitCultureSummary(string? value, TrackerImportSummary summary) => |
| | 36 | 84 | | Limit(value, CultureSummaryLimit, "culture_summary", summary); |
| | | 85 | | |
| | | 86 | | public static string? LimitDispositionReason(string? value, TrackerImportSummary summary) => |
| | 200 | 87 | | Limit(value, DispositionReasonLimit, "disposition_reason", summary); |
| | | 88 | | |
| | | 89 | | public static string? LimitOutcomeReason(string? value, TrackerImportSummary summary) => |
| | 56 | 90 | | Limit(value, OutcomeReasonLimit, "outcome_reason", summary); |
| | | 91 | | |
| | | 92 | | public static string? LimitUrl(string? value, TrackerImportSummary summary) => |
| | 112 | 93 | | Limit(value, UrlLimit, "url", summary); |
| | | 94 | | |
| | | 95 | | public static string? LimitRequisitionId(string? value, TrackerImportSummary summary) |
| | | 96 | | { |
| | 276 | 97 | | var limited = Limit(value, RequisitionIdLimit, "requisition_id", summary); |
| | 276 | 98 | | if (string.IsNullOrWhiteSpace(limited)) |
| | | 99 | | { |
| | 126 | 100 | | return null; |
| | | 101 | | } |
| | | 102 | | |
| | 150 | 103 | | if (!limited.Any(char.IsDigit)) |
| | | 104 | | { |
| | 8 | 105 | | summary.RecordUnmappedValue("req (no digit)", limited); |
| | 8 | 106 | | return null; |
| | | 107 | | } |
| | | 108 | | |
| | 142 | 109 | | return limited; |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | public static string? LimitNoteTitle(string? value, TrackerImportSummary summary) => |
| | 54 | 113 | | Limit(value, NoteTitleLimit, "note_title", summary); |
| | | 114 | | |
| | | 115 | | public static string? LimitNoteBody(string? value, TrackerImportSummary summary) => |
| | 52 | 116 | | Limit(value, NoteBodyLimit, "notes", summary); |
| | | 117 | | |
| | | 118 | | public static string? LimitEventNotes(string? value, TrackerImportSummary summary) => |
| | 60 | 119 | | Limit(value, EventNotesLimit, "event_notes", summary); |
| | | 120 | | |
| | | 121 | | public static string? LimitReferral(string? value, TrackerImportSummary summary) => |
| | 58 | 122 | | Limit(value, ReferralLimit, "referral", summary); |
| | | 123 | | |
| | | 124 | | public static string? LimitFit(string? value, TrackerImportSummary summary) => |
| | 58 | 125 | | Limit(value, FitLimit, "fit", summary); |
| | | 126 | | |
| | | 127 | | public static string? LimitResumeVariant(string? value, TrackerImportSummary summary) => |
| | 58 | 128 | | Limit(value, ResumeVariantLimit, "resume_variant", summary); |
| | | 129 | | |
| | | 130 | | public static string? LimitCriteriaKey(string? value, TrackerImportSummary summary) => |
| | 2 | 131 | | Limit(value, CriteriaKeyLimit, "criteria_key", summary); |
| | | 132 | | |
| | | 133 | | public static string? LimitCriteriaValue(string? value, TrackerImportSummary summary) => |
| | 2 | 134 | | Limit(value, CriteriaValueLimit, "criteria_value", summary); |
| | | 135 | | } |