Class: Longleaf::ValidateMetadataCommand
- Inherits:
-
Object
- Object
- Longleaf::ValidateMetadataCommand
- Includes:
- EventStatusTracking
- Defined in:
- lib/longleaf/commands/validate_metadata_command.rb
Overview
Command for validating file metadata longleaf
Instance Method Summary collapse
-
#execute(file_selector:) ⇒ Integer
Execute the validation command.
-
#initialize(app_manager) ⇒ ValidateMetadataCommand
constructor
A new instance of ValidateMetadataCommand.
Methods included from EventStatusTracking
#record_failure, #record_success, #return_status, #track_failure, #track_status, #track_success
Methods included from Logging
#initialize_logger, initialize_logger, logger, #logger
Constructor Details
#initialize(app_manager) ⇒ ValidateMetadataCommand
Returns a new instance of ValidateMetadataCommand.
11 12 13 |
# File 'lib/longleaf/commands/validate_metadata_command.rb', line 11 def initialize(app_manager) @app_manager = app_manager end |
Instance Method Details
#execute(file_selector:) ⇒ Integer
Execute the validation command
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/longleaf/commands/validate_metadata_command.rb', line 18 def execute(file_selector:) start_time = Time.now logger.info('Performing validate metadata command') begin # Perform metadata validation on each of the file paths provided loop do f_path = file_selector.next_path break if f_path.nil? storage_location = @app_manager.location_manager.get_location_by_path(f_path) begin file_rec = FileRecord.new(f_path, storage_location) unless file_rec. raise MetadataError.new("Cannot validate metadata for #{f_path}, file is not registered.") end @app_manager.md_manager.load(file_rec) record_success("Metadata for file passed validation: #{f_path}") rescue LongleafError => err record_failure(err.) end end rescue RegistrationError, InvalidStoragePathError, StorageLocationUnavailableError => err record_failure(err.) rescue => err record_failure("Encountered error while validating metadata files", error: err) end logger.info("Completed validate metadata command in #{Time.now - start_time}s") return_status end |