|
| 1 | +--- |
| 2 | +feature_id: record-validation |
| 3 | +title: Record Validation Against Specifications |
| 4 | +updated: 2026-02-18 |
| 5 | +--- |
| 6 | + |
| 7 | +# Record Validation Against Specifications |
| 8 | + |
| 9 | +## What it does |
| 10 | +Provides programmatic validation of MARC bibliographic and authority records against specification definitions, checking records for compliance with field structures, indicator values, subfield requirements, and all enabled validation rules. Returns detailed validation errors with severity levels (WARN or ERROR) that determine whether the record can be saved or must be corrected. |
| 11 | + |
| 12 | +## Why it exists |
| 13 | +Enables applications (primarily quickMARC) to validate MARC records during cataloging workflows (create/derive/edit operations), ensuring records conform to MARC standards and institution-specific cataloging rules. Supports quality control by catching validation errors early while allowing catalogers to proceed with warnings when appropriate. |
| 14 | + |
| 15 | +## Entry point(s) |
| 16 | +This is a **library feature** provided by the `mod-record-specifications-validator` module, not a REST API endpoint. Applications integrate the validator programmatically: |
| 17 | + |
| 18 | +```java |
| 19 | +SpecificationValidator validator = new MarcSpecificationValidator(translationProvider, converter); |
| 20 | +List<ValidationError> errors = validator.validate(marcRecord, specification); |
| 21 | +``` |
| 22 | + |
| 23 | +## Business rules and constraints |
| 24 | +- **Supported formats**: MARC bibliographic and authority records (MARC4J `Record` objects or custom `MarcRecord` model) |
| 25 | +- **Primary use case**: Validation for quickMARC create/derive/edit workflows |
| 26 | +- **Validation scope**: Only enabled rules for the specification are enforced (disabled rules are skipped) |
| 27 | +- **Validation behavior**: |
| 28 | + - **PREVENT SAVE (ERROR severity)**: Critical violations that prevent record from being saved |
| 29 | + - Required field is missing |
| 30 | + - Non-repeatable field appears multiple times |
| 31 | + - Required subfield is missing |
| 32 | + - Non-repeatable subfield appears multiple times |
| 33 | + - **WARN (WARNING severity)**: Non-critical violations that allow saving with warning |
| 34 | + - Invalid indicator code (not specified in rules) |
| 35 | + - Invalid subfield code (not specified in rules) |
| 36 | + - Undefined field (field not in validation list) |
| 37 | + - Deprecated field/subfield usage |
| 38 | +- **Validation categories**: |
| 39 | + - **Field-level validation**: Field presence, repeatability, deprecation, tag validity, 1XX field constraints |
| 40 | + - **Indicator validation**: Invalid indicator values, undefined indicator codes |
| 41 | + - **Subfield validation**: Subfield presence, repeatability, deprecation, undefined subfields, LCCN structure validation |
| 42 | +- **System fields** (validation rules cannot be changed): Leader, 001, 005, 245 (bib), 999, and control fields 006/007/008 |
| 43 | +- **Validation errors include**: |
| 44 | + - `path`: Location in the record (e.g., `001`, `245$a`, `100[1]$d`) |
| 45 | + - `severity`: ERROR (prevent save) or WARNING (allow save with warning) |
| 46 | + - `definitionType`: Type of definition violated (FIELD, INDICATOR, SUBFIELD) |
| 47 | + - `definitionId`: UUID of the violated definition |
| 48 | + - `ruleCode`: Code of the violated rule (e.g., `undefinedField`, `missingSubfield`) |
| 49 | + - `message`: Localized human-readable error message |
| 50 | +- **Custom converters**: Applications can provide custom converters to validate non-standard MARC representations |
| 51 | +- **Translation support**: Error messages support internationalization via `TranslationProvider` |
| 52 | + |
| 53 | +## Available Validation Rules |
| 54 | + |
| 55 | +The validator enforces the following rules when enabled in the specification (see [Specification Rule Management](specification-rule-management.md) for complete rule descriptions): |
| 56 | + |
| 57 | +### Field-Level Rules (8) |
| 58 | +- `undefinedField`, `deprecatedField`, `nonRepeatableField`, `missingField` |
| 59 | +- `invalidFieldValue`, `invalidFieldTag` |
| 60 | +- `nonRepeatable1XXField`, `nonRepeatableRequired1XXField` |
| 61 | + |
| 62 | +### Indicator Rules (2) |
| 63 | +- `invalidIndicator`, `undefinedIndicatorCode` |
| 64 | + |
| 65 | +### Subfield Rules (6) |
| 66 | +- `undefinedSubfield`, `deprecatedSubfield`, `nonRepeatableSubfield` |
| 67 | +- `missingSubfield`, `invalidSubfieldValue`, `invalidLccnSubfieldValue` |
| 68 | + |
| 69 | +## API response statuses |
| 70 | +- **Invalid input**: Throws `IllegalArgumentException` if record type is unsupported or converter fails |
| 71 | +- **Validation success**: Returns empty list when record is valid |
| 72 | +- **Validation failures**: Returns list of `ValidationError` objects describing all violations |
| 73 | +- **Rule evaluation**: Only enabled rules are evaluated; disabled rules are silently skipped |
| 74 | + |
| 75 | +## Configuration |
| 76 | +No configuration required. Validation behavior is entirely controlled by: |
| 77 | +- The specification definition provided at validation time |
| 78 | +- Which rules are enabled in that specification |
| 79 | +- The `TranslationProvider` implementation for error message localization |
| 80 | + |
| 81 | +## Dependencies and interactions |
| 82 | +- **Input dependencies**: |
| 83 | + - `SpecificationDto`: Complete specification with fields, subfields, indicators, and enabled rules (obtained from specification retrieval APIs) |
| 84 | + - MARC record: MARC4J `Record` object or custom `MarcRecord` model |
| 85 | + - `TranslationProvider`: For localizing validation error messages |
| 86 | +- **Output**: List of `ValidationError` objects |
| 87 | +- **Library dependencies**: |
| 88 | + - `marc4j`: For MARC record parsing and conversion |
| 89 | + - `mod-record-specifications-dto`: For specification and error DTOs |
| 90 | +- **Integration pattern**: Applications retrieve specifications via [Specification Retrieval](specification-retrieval.md), then validate records programmatically using this library |
0 commit comments