Class: Moab::DepositBagValidator
- Inherits:
-
Object
- Object
- Moab::DepositBagValidator
- Defined in:
- lib/moab/deposit_bag_validator.rb
Overview
Given a deposit bag, ensures the contents valid for becoming a StorageObjectVersion this is a Shameless Green implementation, combining code from:
- sdr-preservation-core/lib/sdr_ingest/validate_bag <-- old preservation robots
- archive-utils/lib/bagit_bag <-- gem only used by sdr-preservation-robots
- archive-utils/lib/file_fixity
- archive-utils/lib/fixity
this code adds duplication to this gem (see github issue #119); for example, computing checksums is done
- deposit_bag_validator
- file_signature
Constant Summary collapse
- BAG_DIR_NOT_FOUND =
:bag_dir_not_found
- CHECKSUM_MISMATCH =
:checksum_mismatch
- CHECKSUM_TYPE_UNRECOGNIZED =
:checksum_type_unrecognized
- INVALID_VERSION_XXX_XML =
:invalid_versionXxx_xml
- PAYLOAD_SIZE_MISMATCH =
:payload_size_mismatch
- REQUIRED_FILE_NOT_FOUND =
:required_file_not_found
- VERSION_MISMATCH_TO_MOAB =
:version_mismatch_to_moab
- VERSION_MISSING_FROM_FILE =
:version_missing_from_file
- ERROR_CODE_TO_MESSAGES =
{ BAG_DIR_NOT_FOUND => "Deposit bag directory %{bag_dir} does not exist", CHECKSUM_MISMATCH => "Failed %{manifest_type} verification. Differences: \n%{diffs}", CHECKSUM_TYPE_UNRECOGNIZED => "Checksum type unrecognized: %{checksum_type}; file: %{filename}", INVALID_VERSION_XXX_XML => "Unable to parse %{file_pathname}: %{err_info}", PAYLOAD_SIZE_MISMATCH => "Failed payload size verification. Expected: %{bag_info_sizes}; found: %{generated_sizes}", REQUIRED_FILE_NOT_FOUND => "Deposit bag required file %{file_pathname} not found", VERSION_MISMATCH_TO_MOAB => "Version mismatch in %{file_pathname}: Moab expected %{new_version}; found %{file_version}", VERSION_MISSING_FROM_FILE => "Version xml file %{version_file} missing data at %{xpath} containing version id" }.freeze
- REQUIRED_MANIFEST_CHECKSUM_TYPE =
'sha256'.freeze
- RECOGNIZED_CHECKSUM_ALGORITHMS =
%i[md5 sha1 sha256 sha384 sha512].freeze
- TAGMANIFEST =
'tagmanifest'.freeze
- MANIFEST =
'manifest'.freeze
- DATA_DIR_BASENAME =
'data'.freeze
- BAG_INFO_TXT_BASENAME =
'bag-info.txt'.freeze
- VERSION_ADDITIONS_BASENAME =
'versionAdditions.xml'.freeze
- VERSION_INVENTORY_BASENAME =
'versionInventory.xml'.freeze
- VERSION_METADATA_PATH =
"#{DATA_DIR_BASENAME}/metadata/versionMetadata.xml".freeze
- REQUIRED_BAG_FILES =
[ DATA_DIR_BASENAME, 'bagit.txt'.freeze, BAG_INFO_TXT_BASENAME, "#{MANIFEST}-#{REQUIRED_MANIFEST_CHECKSUM_TYPE}.txt".freeze, "#{TAGMANIFEST}-#{REQUIRED_MANIFEST_CHECKSUM_TYPE}.txt".freeze, VERSION_ADDITIONS_BASENAME, VERSION_INVENTORY_BASENAME, VERSION_METADATA_PATH ].freeze
Instance Attribute Summary collapse
-
#deposit_bag_pathname ⇒ Object
readonly
Returns the value of attribute deposit_bag_pathname.
-
#expected_new_version ⇒ Object
readonly
Returns the value of attribute expected_new_version.
-
#result_array ⇒ Object
readonly
Returns the value of attribute result_array.
Instance Method Summary collapse
-
#initialize(storage_object) ⇒ DepositBagValidator
constructor
A new instance of DepositBagValidator.
-
#validation_errors ⇒ Object
returns Array of tiny error hashes, allowing multiple occurrences of a single error code.
Constructor Details
#initialize(storage_object) ⇒ DepositBagValidator
Returns a new instance of DepositBagValidator.
57 58 59 60 61 |
# File 'lib/moab/deposit_bag_validator.rb', line 57 def initialize(storage_object) @deposit_bag_pathname = storage_object.deposit_bag_pathname @expected_new_version = storage_object.current_version_id + 1 @result_array = [] end |
Instance Attribute Details
#deposit_bag_pathname ⇒ Object (readonly)
Returns the value of attribute deposit_bag_pathname.
55 56 57 |
# File 'lib/moab/deposit_bag_validator.rb', line 55 def deposit_bag_pathname @deposit_bag_pathname end |
#expected_new_version ⇒ Object (readonly)
Returns the value of attribute expected_new_version.
55 56 57 |
# File 'lib/moab/deposit_bag_validator.rb', line 55 def expected_new_version @expected_new_version end |
#result_array ⇒ Object (readonly)
Returns the value of attribute result_array.
55 56 57 |
# File 'lib/moab/deposit_bag_validator.rb', line 55 def result_array @result_array end |
Instance Method Details
#validation_errors ⇒ Object
returns Array of tiny error hashes, allowing multiple occurrences of a single error code
64 65 66 67 68 69 70 71 72 |
# File 'lib/moab/deposit_bag_validator.rb', line 64 def validation_errors return [single_error_hash(BAG_DIR_NOT_FOUND, bag_dir: deposit_bag_pathname)] unless deposit_bag_pathname.exist? return result_array unless required_bag_files_exist? verify_version verify_tagmanifests verify_payload_size verify_payload_manifests result_array # attr that accumulates any errors encountered along the way end |