Refactor validation service#1154
Merged
laritakr merged 21 commits intobulkrax-v2-importerfrom Mar 27, 2026
Merged
Conversation
Add CsvTemplate:: namespace as re-namespaced copy of template-generation components Copies all template-generation service objects from CsvValidationService::* into a new CsvTemplate:: module under app/services/bulkrax/csv_template/. No behaviour changes — the originals remain in place. This is the first step in moving template generation into a CsvParser concern (upstream integration of refactor/validation-lambdas).
Introduces app/parsers/concerns/bulkrax/csv_parser/csv_template_generation.rb with a TemplateContext that drives the CsvTemplate:: components. Includes the concern in CsvParser and updates CsvValidationService.generate_template to delegate to CsvParser.generate_template — the service is now a thin shim for template generation.
Introduces app/parsers/concerns/bulkrax/csv_parser/csv_validation.rb with CsvParser.validate_csv as a class method. Uses CsvEntry.read_data (not CSV.read) to preserve blank-row filtering and header normalisation identical to a real import. Adds four callable validator modules under app/validators/bulkrax/csv_row/: DuplicateIdentifier, ParentReference, RequiredValues, and ControlledVocabulary. Not yet wired in — no behaviour change.
Includes CsvParser::CsvValidation in CsvParser, making CsvParser.validate_csv available. Adds Bulkrax.csv_row_validators (defaulting to the four CsvRow:: modules) and Bulkrax.register_csv_row_validator to lib/bulkrax.rb as the new extensibility point for per-row validation. CsvValidationService.validate still drives its own path — delegation happens in Step 7.
Updates the rights_statement spec stubs in csv_validation_service_spec and csv_validation_service_end_to_end_spec to target CsvTemplate::FieldAnalyzer directly, since validation now runs through CsvParser.validate_csv. Removes the dead additional_validators: parameter from CsvValidationService.validate and initialize — use Bulkrax.register_csv_row_validator instead.
Switches CsvValidationService instance to use CsvTemplate:: classes (MappingManager, FieldAnalyzer, ModelLoader, CsvBuilder, FileValidator, FilePathGenerator, ColumnBuilder). Deletes the 12 duplicate files from the old csv_validation_service/ namespace and migrates their specs to spec/services/bulkrax/csv_template/. Updates all remaining spec stubs and doubles that referenced the old namespace.
Deletes CsvValidationService and all subclasses — validation was never in production. Controllers now call CsvParser.validate_csv and CsvParser.generate_template directly. Removes row_validator_service config from lib/bulkrax.rb. Deletes all associated specs; the CsvParser concerns and CsvTemplate:: specs are the new home.
orangewolf
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR integrates the upstream
refactor/validation-lambdasbranch intobulkrax-v2-importer, eliminating the ~3,200-lineCsvValidationServicenamespace that re-implemented CSV parsing, column resolution, field mapping, and row categorization already handled byCsvParserandCsvEntry. Validation and template generation are now concerns onCsvParseritself, backed by focused service classes and callable validator modules.Changes
Architecture
CsvParser::CsvValidationconcern — all validation logic lives here, usingCsvParser.validate_csvas the single entry point. UsesCsvEntry.read_data(notCSV.read) to preserve blank-row filtering identical to a real import.CsvParser::CsvTemplateGenerationconcern — template generation extracted cleanly, with a nestedTemplateContextclass wiring theCsvTemplate::*componentsBulkrax::CsvRow::*validators — 4 callable modules inapp/validators/(DuplicateIdentifier,ParentReference,RequiredValues,ControlledVocabulary), each implementingself.call(record, row_number, context)Bulkrax::CsvTemplate::*— template sub-components re-namespaced fromCsvValidationService::toCsvTemplate::, with no logic changesBulkrax.config— validators now configurable viacsv_row_validators/register_csv_row_validatorGuidedImportsController— replaces the oldGuidedImportcontroller concern; routes updated accordinglydocs/—CSV_SERVICE_ARCHITECTURE.mdrewritten,STEPPER_IMPLEMENTATION.mdupdated to reflect current architectureDeleted
CsvValidationServicefacade and all duplicative sub-components (CsvParser,ColumnResolver,ItemExtractor,Validator,RowValidatorService+ 5 sub-validators,MappingManager)row_validator_serviceconfig accessor (replaced bycsv_row_validators)spec/services/bulkrax/csv_validation_service/Preserved
Notes
Built extensively on prior PR #1152
We used the upstream PR code directly for:
We diverged from upstream in cases where it missed something or was wrong: