Class: Bulkrax::StepperResponseFormatter
- Inherits:
-
Object
- Object
- Bulkrax::StepperResponseFormatter
- Defined in:
- app/services/bulkrax/stepper_response_formatter.rb
Overview
Formats validation data from CsvParser.validate_csv into the structure expected by the importers_stepper.js frontend component.
This service acts as a presentation layer, transforming raw validation data into a structured response with proper status messages, severity levels, and formatted issue lists that the JavaScript can render correctly.
rubocop:disable Metrics/ClassLength
Class Method Summary collapse
-
.error(message: I18n.t('bulkrax.importer.guided_import.validation.unable_to_process'), summary: nil) ⇒ Hash
Generate an error response for validation failures.
-
.format(data) ⇒ Hash
Format validation data for the stepper frontend.
Instance Method Summary collapse
-
#format ⇒ Hash
Format the validation data with messages structure If data already contains a messages structure, return it as-is.
-
#initialize(data) ⇒ StepperResponseFormatter
constructor
A new instance of StepperResponseFormatter.
Constructor Details
#initialize(data) ⇒ StepperResponseFormatter
Returns a new instance of StepperResponseFormatter.
72 73 74 |
# File 'app/services/bulkrax/stepper_response_formatter.rb', line 72 def initialize(data) @data = data end |
Class Method Details
.error(message: I18n.t('bulkrax.importer.guided_import.validation.unable_to_process'), summary: nil) ⇒ Hash
Generate an error response for validation failures
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/bulkrax/stepper_response_formatter.rb', line 50 def self.error(message: I18n.t('bulkrax.importer.guided_import.validation.unable_to_process'), summary: nil) { totalItems: 0, collections: [], works: [], fileSets: [], isValid: false, hasWarnings: false, messages: { validationStatus: { severity: 'error', icon: 'fa-times-circle', title: I18n.t('bulkrax.importer.guided_import.validation.failed'), summary: summary || , details: I18n.t('bulkrax.importer.guided_import.validation.critical_errors'), defaultOpen: true }, issues: [] } } end |
.format(data) ⇒ Hash
Format validation data for the stepper frontend
41 42 43 |
# File 'app/services/bulkrax/stepper_response_formatter.rb', line 41 def self.format(data) new(data).format end |
Instance Method Details
#format ⇒ Hash
Format the validation data with messages structure If data already contains a messages structure, return it as-is
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/services/bulkrax/stepper_response_formatter.rb', line 80 def format # Check if data is already formatted (has messages structure) return @data if already_formatted? # Build formatted response with messages structure { headers: @data[:headers], missingRequired: @data[:missingRequired], unrecognized: @data[:unrecognized], rowCount: @data[:rowCount], isValid: @data[:isValid], hasWarnings: @data[:hasWarnings], rowErrors: @data[:rowErrors], collections: @data[:collections], works: @data[:works], fileSets: @data[:fileSets], totalItems: @data[:totalItems], fileReferences: @data[:fileReferences], missingFiles: @data[:missingFiles], foundFiles: @data[:foundFiles], zipIncluded: @data[:zipIncluded], messages: } end |