Class: Moab::StorageObjectValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/moab/storage_object_validator.rb

Overview

Given a druid path, are the contents actually a well-formed Moab? Shameless green: repetitious code included.

Direct Known Subclasses

Stanford::StorageObjectValidator

Constant Summary collapse

METADATA_DIR =
'metadata'
CONTENT_DIR =
'content'
EXPECTED_DATA_SUB_DIRS =
[CONTENT_DIR, METADATA_DIR].freeze
IMPLICIT_DIRS =

unlike Find.find, Dir.entries returns the current/parent dirs

['.', '..'].freeze
DATA_DIR =
'data'
MANIFESTS_DIR =
'manifests'
EXPECTED_VERSION_SUB_DIRS =
[DATA_DIR, MANIFESTS_DIR].freeze
MANIFEST_INVENTORY_PATH =
File.join(MANIFESTS_DIR, 'manifestInventory.xml').freeze
SIGNATURE_CATALOG_PATH =
File.join(MANIFESTS_DIR, 'signatureCatalog.xml').freeze
VERSION_DIR_PATTERN =
/^v\d{4}$/
INCORRECT_DIR_CONTENTS =

error codes

0
MISSING_DIR =
1
EXTRA_CHILD_DETECTED =
2
VERSION_DIR_BAD_FORMAT =
3
NO_SIGNATURE_CATALOG =
4
NO_MANIFEST_INVENTORY =
5
NO_FILES_IN_MANIFEST_DIR =
6
TEST_OBJECT_VERSIONS_NOT_IN_ORDER =
7
METADATA_SUB_DIRS_DETECTED =
8
FILES_IN_VERSION_DIR =
9
NO_FILES_IN_METADATA_DIR =
10
NO_FILES_IN_CONTENT_DIR =
11
CONTENT_SUB_DIRS_DETECTED =
12

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage_object) ⇒ StorageObjectValidator

Returns a new instance of StorageObjectValidator.



38
39
40
41
# File 'lib/moab/storage_object_validator.rb', line 38

def initialize(storage_object)
  @storage_obj_path = storage_object.object_pathname
  @directory_entries_hash = {}
end

Instance Attribute Details

#storage_obj_pathObject (readonly)

Returns the value of attribute storage_obj_path.



36
37
38
# File 'lib/moab/storage_object_validator.rb', line 36

def storage_obj_path
  @storage_obj_path
end

Class Method Details

.error_code_to_messagesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/moab/storage_object_validator.rb', line 51

def self.error_code_to_messages
  @error_code_to_messages ||=
    {
      INCORRECT_DIR_CONTENTS => 'Incorrect items under %<addl>s directory',
      MISSING_DIR => 'Missing directory: %<addl>s',
      EXTRA_CHILD_DETECTED => 'Unexpected item in path: %<addl>s',
      VERSION_DIR_BAD_FORMAT => "Version directory name not in 'v00xx' format: %<addl>s",
      FILES_IN_VERSION_DIR => 'Version directory %<addl>s should not contain files; only the manifests and data directories',
      NO_SIGNATURE_CATALOG => 'Version %<addl>s: Missing signatureCatalog.xml',
      NO_MANIFEST_INVENTORY => 'Version %<addl>s: Missing manifestInventory.xml',
      NO_FILES_IN_MANIFEST_DIR => 'Version %<addl>s: No files present in manifest dir',
      METADATA_SUB_DIRS_DETECTED => 'Version %<version>s: metadata directory should only contain files, not directories. Found directory: %<dir>s',
      TEST_OBJECT_VERSIONS_NOT_IN_ORDER => 'Should contain only sequential version directories. Current directories: %<addl>s',
      NO_FILES_IN_METADATA_DIR => 'Version %<addl>s: No files present in metadata dir',
      NO_FILES_IN_CONTENT_DIR => 'Version %<addl>s: No files present in content dir',
      CONTENT_SUB_DIRS_DETECTED => 'Version %<version>s: content directory should only contain files, not directories. Found directory: %<dir>s'
    }.freeze
end

Instance Method Details

#validation_errors(allow_content_subdirs = true) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/moab/storage_object_validator.rb', line 43

def validation_errors(allow_content_subdirs = true)
  errors = []
  errors.concat check_correctly_named_version_dirs
  errors.concat check_sequential_version_dirs if errors.empty?
  errors.concat check_correctly_formed_moab(allow_content_subdirs) if errors.empty?
  errors
end