moab-versioning 2.5.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41ec2f0776c2777c5d2e7b23a1379591b9723553
4
- data.tar.gz: 0eb3da4d667fec45dbd14e312fa25daa27ab4446
3
+ metadata.gz: 0cbc9f88a390634b7acc77dacc9839b89849835b
4
+ data.tar.gz: 815ef9d707ebeea48a711ca985a6a7a28e82c784
5
5
  SHA512:
6
- metadata.gz: 5942fa4c9eb29214113599227b0e28e1bab30f1fd91312c5fe01b39f0fafad1bd8b959ad914382505078d76bb53d454aabeb7a05112bf0396a1d55aece59c278
7
- data.tar.gz: 0bb71c5116b53775d43b7875448f0cff95058cdca065b46ca1b945423a054facd48b0e50bcf6ba43f293f8817ebbe78bcdd09c6717a7701ba027cb88b8acdd68
6
+ metadata.gz: c002027ea5b5047ae4024e9f914e8949a652bc067f49e3cff3dee02b8b602f1111c5086a951af9ad2d8c82935da9aa88bbc72eaf75c68d598e0d9bb404845540
7
+ data.tar.gz: 19a800a7e7b20acb2e14726ce5127d96f30ae05ed3eced4d6a50ae6c7b016298163caa2beb6bcbdab07a8a4868cae7b5fa21e6458b1ad03a7236751d030a8d43
@@ -1,14 +1,17 @@
1
1
  require 'moab'
2
+ require 'set'
2
3
 
3
4
  module Moab
4
5
  # Given a druid path, are the contents actually a well-formed Moab?
5
6
  # Shameless green: repetitious code included.
6
7
  class StorageObjectValidator
7
8
 
8
- EXPECTED_DATA_SUB_DIRS = ["content", "metadata"].freeze
9
- IMPLICIT_DIRS = ['.', '..'].freeze # unlike Find.find, Dir.entries returns these
10
- DATA_DIR_NAME = "data".freeze
11
- EXPECTED_VERSION_SUB_DIRS = [DATA_DIR_NAME, "manifests"].freeze
9
+ METADATA_DIR = "metadata".freeze
10
+ CONTENT_DIR = "content".freeze
11
+ EXPECTED_DATA_SUB_DIRS = [CONTENT_DIR, METADATA_DIR].freeze
12
+ IMPLICIT_DIRS = ['.', '..', '.keep'].freeze # unlike Find.find, Dir.entries returns the current/parent dirs
13
+ DATA_DIR = "data".freeze
14
+ EXPECTED_VERSION_SUB_DIRS = [DATA_DIR, "manifests"].freeze
12
15
  MANIFEST_INVENTORY_PATH = 'manifests/manifestInventory.xml'.freeze
13
16
  SIGNATURE_CATALOG_PATH = 'manifests/signatureCatalog.xml'.freeze
14
17
 
@@ -19,9 +22,13 @@ module Moab
19
22
  VERSION_DIR_BAD_FORMAT = 3
20
23
  NO_SIGNATURE_CATALOG = 4
21
24
  NO_MANIFEST_INVENTORY = 5
22
- NO_XML_FILES = 6
25
+ NO_FILES_IN_MANIFEST_DIR= 6
23
26
  VERSIONS_NOT_IN_ORDER = 7
24
- FILES_IN_VERSION_DIR = 8
27
+ METADATA_SUB_DIRS_DETECTED = 8
28
+ FILES_IN_VERSION_DIR = 9
29
+ NO_FILES_IN_METADATA_DIR = 10
30
+ NO_FILES_IN_CONTENT_DIR = 11
31
+ CONTENT_SUB_DIRS_DETECTED = 12
25
32
 
26
33
  attr_reader :storage_obj_path
27
34
 
@@ -48,8 +55,12 @@ module Moab
48
55
  FILES_IN_VERSION_DIR => "Top level should contain only sequential version directories. Also contains files: %{addl}",
49
56
  NO_SIGNATURE_CATALOG => "Version: %{addl} Missing signatureCatalog.xml",
50
57
  NO_MANIFEST_INVENTORY => "Version: %{addl} Missing manifestInventory.xml",
51
- NO_XML_FILES => "Version: %{addl} Missing all required metadata files",
52
- VERSIONS_NOT_IN_ORDER => "Should contain only sequential version directories. Current directories: %{addl}"
58
+ NO_FILES_IN_MANIFEST_DIR => "Version: %{addl} No files present in manifest dir",
59
+ METADATA_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the metadata directory",
60
+ VERSIONS_NOT_IN_ORDER => "Should contain only sequential version directories. Current directories: %{addl}",
61
+ NO_FILES_IN_METADATA_DIR => "Version: %{addl} No files present in metadata dir",
62
+ NO_FILES_IN_CONTENT_DIR => "Version: %{addl} No files present in content dir",
63
+ CONTENT_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the content directory"
53
64
  }.freeze
54
65
  end
55
66
 
@@ -63,6 +74,7 @@ module Moab
63
74
 
64
75
  def check_correctly_named_version_dirs
65
76
  errors = []
77
+ errors << result_hash(MISSING_DIR, 'no versions exist') unless version_directories.count > 0
66
78
  version_directories.each do |version_dir|
67
79
  errors << result_hash(VERSION_DIR_BAD_FORMAT) unless version_dir =~ /^[v]\d{4}$/
68
80
  end
@@ -88,34 +100,75 @@ module Moab
88
100
  version_directories.each do |version_dir|
89
101
  version_path = "#{storage_obj_path}/#{version_dir}"
90
102
  version_sub_dirs = sub_dirs(version_path)
91
- before_result_size = errors.size
92
- errors.concat check_sub_dirs(version_sub_dirs, version_dir, EXPECTED_VERSION_SUB_DIRS)
93
- after_result_size = errors.size
94
- # run the following checks if this version dir passes check_sub_dirs, even if some prior version dirs didn't
95
- if before_result_size == after_result_size
96
- data_dir_path = "#{version_path}/#{DATA_DIR_NAME}"
97
- data_sub_dirs = sub_dirs(data_dir_path)
98
- errors.concat check_sub_dirs(data_sub_dirs, version_dir, EXPECTED_DATA_SUB_DIRS)
99
- errors.concat check_required_manifest_files(version_path, version_dir)
100
- end
103
+ version_error_count = errors.size
104
+ errors.concat check_version_sub_dirs(version_sub_dirs, version_dir)
105
+ errors.concat check_required_manifest_files(version_path, version_dir) if version_error_count == errors.size
106
+ errors.concat check_data_directory(version_path, version_dir) if version_error_count == errors.size
107
+ end
108
+ errors
109
+ end
110
+
111
+ def check_version_sub_dirs(version_sub_dirs, version)
112
+ errors = []
113
+ version_sub_dir_count = version_sub_dirs.size
114
+ if version_sub_dir_count == EXPECTED_VERSION_SUB_DIRS.size
115
+ errors.concat expected_dirs(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
116
+ elsif version_sub_dir_count > EXPECTED_VERSION_SUB_DIRS.size
117
+ errors.concat found_unexpected(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
118
+ elsif version_sub_dir_count < EXPECTED_VERSION_SUB_DIRS.size
119
+ errors.concat missing_dir(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
101
120
  end
121
+ errors
122
+ end
102
123
 
124
+ def check_data_directory(version_path, version)
125
+ errors = []
126
+ data_dir_path = "#{version_path}/#{DATA_DIR}"
127
+ data_sub_dirs = sub_dirs(data_dir_path)
128
+ errors.concat check_data_sub_dirs(version, data_sub_dirs)
129
+ errors.concat check_metadata_dir_files_only(version_path) if errors.empty?
130
+ errors.concat check_optional_content_dir_files_only(version_path) if data_sub_dirs.include?('content') && errors.empty?
103
131
  errors
104
132
  end
105
133
 
106
- def check_sub_dirs(sub_dirs, version, required_sub_dirs)
134
+ def check_data_sub_dirs(version, data_sub_dirs)
107
135
  errors = []
108
- sub_dir_count = sub_dirs.size
109
- if sub_dir_count == required_sub_dirs.size
110
- errors.concat expected_dirs(sub_dirs, version, required_sub_dirs)
111
- elsif sub_dir_count > required_sub_dirs.size
112
- errors.concat found_unexpected(sub_dirs, version, required_sub_dirs)
113
- elsif sub_dir_count < required_sub_dirs.size
114
- errors.concat missing_dir(sub_dirs, version, required_sub_dirs)
136
+ if data_sub_dirs.size > EXPECTED_DATA_SUB_DIRS.size
137
+ errors.concat found_unexpected(data_sub_dirs, version, EXPECTED_DATA_SUB_DIRS)
138
+ else
139
+ errors.concat missing_dir(data_sub_dirs, version, [METADATA_DIR]) unless data_sub_dirs.include?(METADATA_DIR)
140
+ errors.concat found_unexpected(data_sub_dirs, version, EXPECTED_DATA_SUB_DIRS) unless subset?(data_sub_dirs,
141
+ EXPECTED_DATA_SUB_DIRS)
115
142
  end
116
143
  errors
117
144
  end
118
145
 
146
+ def check_optional_content_dir_files_only(version_path)
147
+ errors = []
148
+ dir_list = []
149
+ content_dir_path = "#{version_path}/#{DATA_DIR}/#{CONTENT_DIR}"
150
+ content_sub_dirs = sub_dirs(content_dir_path)
151
+ content_sub_dirs.each { |item| dir_list << File.directory?("#{content_dir_path}/#{item}") }
152
+ errors << result_hash(NO_FILES_IN_CONTENT_DIR) if directory_entries(content_dir_path).empty?
153
+ errors << result_hash(CONTENT_SUB_DIRS_DETECTED) if dir_list.include?(true)
154
+ errors
155
+ end
156
+
157
+ def subset?(first_array, second_array)
158
+ first_array.to_set.subset?(second_array.to_set)
159
+ end
160
+
161
+ def check_metadata_dir_files_only(version_path)
162
+ errors = []
163
+ dir_list = []
164
+ metadata_dir_path = "#{version_path}/#{DATA_DIR}/#{METADATA_DIR}"
165
+ metadata_sub_dirs = sub_dirs(metadata_dir_path)
166
+ metadata_sub_dirs.each { |item| dir_list << File.directory?("#{metadata_dir_path}/#{item}") }
167
+ errors << result_hash(NO_FILES_IN_METADATA_DIR) if directory_entries(metadata_dir_path).empty?
168
+ errors << result_hash(METADATA_SUB_DIRS_DETECTED) if dir_list.include?(true)
169
+ errors
170
+ end
171
+
119
172
  # This method removes the implicit '.' and '..' directories.
120
173
  # Returns an array of strings.
121
174
  def directory_entries(path)
@@ -174,7 +227,7 @@ module Moab
174
227
  elsif !has_manifest_inventory && has_signature_catalog
175
228
  result_hash(NO_MANIFEST_INVENTORY, version)
176
229
  else
177
- result_hash(NO_XML_FILES, version)
230
+ result_hash(NO_FILES_IN_MANIFEST_DIR, version)
178
231
  end
179
232
  errors << result if result
180
233
  errors
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moab-versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Weber
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-11-09 00:00:00.000000000 Z
14
+ date: 2017-11-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: confstruct
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  version: '0'
302
302
  requirements: []
303
303
  rubyforge_project:
304
- rubygems_version: 2.6.13
304
+ rubygems_version: 2.6.11
305
305
  signing_key:
306
306
  specification_version: 4
307
307
  summary: Ruby implementation of digital object versioning toolkit used by the SULAIR