Skip to content

Commit

Permalink
added missing method for BagIt parser (#516)
Browse files Browse the repository at this point in the history
* added missing method for BagIt parser

* added a conditional for rdf entries

* WIP bagit rdfentry
  • Loading branch information
kirkkwang authored May 20, 2022
1 parent ca71d9d commit 6160439
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
27 changes: 1 addition & 26 deletions app/models/bulkrax/csv_file_set_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@

module Bulkrax
class CsvFileSetEntry < CsvEntry
def factory_class
::FileSet
end

def add_path_to_file
parsed_metadata['file'].each_with_index do |filename, i|
path_to_file = ::File.join(parser.path_to_files, filename)

parsed_metadata['file'][i] = path_to_file
end
raise ::StandardError, "one or more file paths are invalid: #{parsed_metadata['file'].join(', ')}" unless parsed_metadata['file'].map { |file_path| ::File.file?(file_path) }.all?

parsed_metadata['file']
end

def validate_presence_of_filename!
return if parsed_metadata&.[]('file')&.map(&:present?)&.any?

raise StandardError, 'File set must have a filename'
end

def validate_presence_of_parent!
return if parsed_metadata[related_parents_parsed_mapping]&.map(&:present?)&.any?

raise StandardError, 'File set must be related to at least one work'
end
include FileSetEntryBehavior
end
end
7 changes: 7 additions & 0 deletions app/models/bulkrax/rdf_file_set_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Bulkrax
class RdfFileSetEntry < RdfEntry
include FileSetEntryBehavior
end
end
32 changes: 32 additions & 0 deletions app/models/concerns/bulkrax/file_set_entry_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Bulkrax
module FileSetEntryBehavior
def factory_class
::FileSet
end

def add_path_to_file
parsed_metadata['file'].each_with_index do |filename, i|
path_to_file = ::File.join(parser.path_to_files, filename)

parsed_metadata['file'][i] = path_to_file
end
raise ::StandardError, "one or more file paths are invalid: #{parsed_metadata['file'].join(', ')}" unless parsed_metadata['file'].map { |file_path| ::File.file?(file_path) }.all?

parsed_metadata['file']
end

def validate_presence_of_filename!
return if parsed_metadata&.[]('file')&.map(&:present?)&.any?

raise StandardError, 'File set must have a filename'
end

def validate_presence_of_parent!
return if parsed_metadata[related_parents_parsed_mapping]&.map(&:present?)&.any?

raise StandardError, 'File set must be related to at least one work'
end
end
end
5 changes: 5 additions & 0 deletions app/parsers/bulkrax/bagit_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def collection_entry_class
Entry
end

def file_set_entry_class
csv_format = Bulkrax::Importer.last.parser_fields['metadata_format'] == "Bulkrax::CsvEntry"
csv_format ? CsvFileSetEntry : RdfFileSetEntry
end

# Take a random sample of 10 metadata_paths and work out the import fields from that
def import_fields
raise StandardError, 'No metadata files were found' if metadata_paths.blank?
Expand Down

0 comments on commit 6160439

Please sign in to comment.