|
1 | 1 | package ca.bc.gov.nrs.ilcr.codetable.dto; |
2 | 2 |
|
| 3 | +import jakarta.validation.constraints.NotBlank; |
| 4 | +import jakarta.validation.constraints.NotNull; |
| 5 | +import jakarta.validation.constraints.Size; |
3 | 6 | import java.time.LocalDate; |
4 | 7 |
|
5 | 8 | /** |
6 | 9 | * One row of a lookup code table (Story 24.3 / UC-CODE-001, BR-02): a code, its description, and the |
7 | 10 | * effective/expiry window that gates whether downstream schedules offer it for a given year (BR-07). |
8 | 11 | * |
9 | | - * @param code the code value (the table's primary key); {@code null}/blank for a Contractual add |
10 | | - * @param description the human-readable label |
11 | | - * @param effectiveDate first day the code is offered (inclusive); {@code null} = no lower bound |
| 12 | + * <p>Declarative constraints (Story 29.13) give the {@code saveEntry} write path a uniform 400 |
| 13 | + * {@code ProblemDetail} for shape violations via {@code @Valid} — the same error shape as the rest of |
| 14 | + * the API — WITHOUT replacing the authoritative service-layer checks. {@code CodeTableService.validate} |
| 15 | + * still owns the required/length/date-order rules and their verbatim legacy message keys (FLD-001..005, |
| 16 | + * BR-06); these annotations are a declarative front line, not a replacement. |
| 17 | + * |
| 18 | + * <p>The {@code @Size} caps are deliberately OUTER BOUNDS — the maximum across every table |
| 19 | + * ({@code CodeTableRegistry}: code ≤ 20, description ≤ 500) — because a record-level annotation carries |
| 20 | + * one number but the real caps are PER-TABLE ({@code table.codeMaxLength()} / |
| 21 | + * {@code descriptionMaxLength()}). Keeping the annotation at the outer bound means the exact per-table |
| 22 | + * length rejection still comes from {@code validate()} with its verbatim message; the annotation only |
| 23 | + * catches absurd input early. Do NOT tighten these to a single table's cap. |
| 24 | + * |
| 25 | + * @param code the code value (the table's primary key); required + within the table's code cap on save |
| 26 | + * @param description the human-readable label; required + within the table's description cap on save |
| 27 | + * @param effectiveDate first day the code is offered (inclusive); required on save |
12 | 28 | * @param expiryDate last day the code is offered (inclusive); {@code null} = never expires |
13 | 29 | */ |
14 | 30 | public record CodeTableEntry( |
15 | | - String code, String description, LocalDate effectiveDate, LocalDate expiryDate) { |
| 31 | + @NotBlank(message = "{codeRequiredErrorMsg}") @Size(max = 20) String code, |
| 32 | + @NotBlank(message = "{descriptionRequiredErrorMsg}") @Size(max = 500) String description, |
| 33 | + @NotNull(message = "{effectiveDateRequiredErrorMsg}") LocalDate effectiveDate, |
| 34 | + LocalDate expiryDate) { |
16 | 35 | } |
0 commit comments