moab-versioning 4.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- require 'moab/stanford'
2
-
3
1
  module Stanford
4
2
  # Utility Class for extracting content or other information from a Fedora Instance
5
3
  #
@@ -1,5 +1,3 @@
1
- require 'moab/stanford'
2
-
3
1
  module Stanford
4
2
  # Stanford-specific utility methods for transforming contentMetadata to versionInventory and doing comparisons
5
3
  #
@@ -62,7 +60,7 @@ module Stanford
62
60
  # @param node [Nokogiri::XML::Node] The XML node containing file information
63
61
  # @return [FileSignature] The {FileSignature} object generated from the XML data
64
62
  def generate_signature(node)
65
- signature = Moab::FileSignature.new()
63
+ signature = Moab::FileSignature.new
66
64
  signature.size = node.attributes['size'].content
67
65
  checksum_nodes = node.xpath('checksum')
68
66
  checksum_nodes.each do |checksum_node|
@@ -82,9 +80,13 @@ module Stanford
82
80
  # @param node (see #generate_signature)
83
81
  # @return [FileInstance] The {FileInstance} object generated from the XML data
84
82
  def generate_instance(node)
85
- instance = Moab::FileInstance.new()
83
+ instance = Moab::FileInstance.new
86
84
  instance.path = node.attributes['id'].content
87
- instance.datetime = node.attributes['datetime'].content rescue nil
85
+ instance.datetime = begin
86
+ node.attributes['datetime'].content
87
+ rescue
88
+ nil
89
+ end
88
90
  instance
89
91
  end
90
92
 
@@ -94,8 +96,8 @@ module Stanford
94
96
  # @example {include:file:spec/features/stanford/content_metadata_write_spec.rb}
95
97
  def generate_content_metadata(file_group, object_id, version_id)
96
98
  cm = Nokogiri::XML::Builder.new do |xml|
97
- xml.contentMetadata(:type => "sample", :objectId => object_id) {
98
- xml.resource(:type => "version", :sequence => "1", :id => "version-#{version_id}") {
99
+ xml.contentMetadata(:type => "sample", :objectId => object_id) do
100
+ xml.resource(:type => "version", :sequence => "1", :id => "version-#{version_id}") do
99
101
  file_group.files.each do |file_manifestation|
100
102
  signature = file_manifestation.signature
101
103
  file_manifestation.instances.each do |instance|
@@ -106,16 +108,16 @@ module Stanford
106
108
  :shelve => 'yes',
107
109
  :publish => 'yes',
108
110
  :preserve => 'yes'
109
- ) {
111
+ ) do
110
112
  fixity = signature.fixity
111
113
  xml.checksum(:type => "MD5") { xml.text signature.md5 } if fixity[:md5]
112
114
  xml.checksum(:type => "SHA-1") { xml.text signature.sha1 } if fixity[:sha1]
113
115
  xml.checksum(:type => "SHA-256") { xml.text signature.sha256 } if fixity[:sha256]
114
- }
116
+ end
115
117
  end
116
118
  end
117
- }
118
- }
119
+ end
120
+ end
119
121
  end
120
122
  cm.to_xml
121
123
  end
@@ -124,7 +126,7 @@ module Stanford
124
126
  # @return [Boolean] True if contentMetadata has essential file attributes, else raise exception
125
127
  def validate_content_metadata(content_metadata)
126
128
  result = validate_content_metadata_details(content_metadata)
127
- raise Moab::InvalidMetadataException, result[0] + " ..." if result.size > 0
129
+ raise Moab::InvalidMetadataException, result[0] + " ..." unless result.empty?
128
130
  true
129
131
  end
130
132
 
@@ -145,7 +147,7 @@ module Stanford
145
147
  end
146
148
  nodeset = content_metadata_doc.xpath("//file")
147
149
  nodeset.each do |file_node|
148
- missing = ['id', 'size', 'md5', 'sha1']
150
+ missing = %w[id size md5 sha1]
149
151
  missing.delete('id') if file_node.has_attribute?('id')
150
152
  missing.delete('size') if file_node.has_attribute?('size')
151
153
  checksum_nodes = file_node.xpath('checksum')
@@ -159,7 +161,7 @@ module Stanford
159
161
  end
160
162
  if missing.include?('id')
161
163
  result << "File node #{nodeset.index(file_node)} is missing #{missing.join(',')}"
162
- elsif missing.size > 0
164
+ elsif !missing.empty?
163
165
  id = file_node['id']
164
166
  result << "File node having id='#{id}' is missing #{missing.join(',')}"
165
167
  end
@@ -173,11 +175,11 @@ module Stanford
173
175
  # @see http://blog.slashpoundbang.com/post/1454850669/how-to-pretty-print-xml-with-nokogiri
174
176
  def remediate_content_metadata(content_metadata, content_group)
175
177
  return nil if content_metadata.nil?
176
- return content_metadata if content_group.nil? or content_group.files.size < 1
178
+ return content_metadata if content_group.nil? || content_group.files.empty?
177
179
  signature_for_path = content_group.path_hash
178
180
  @type_for_name = Moab::FileSignature.checksum_type_for_name
179
181
  @names_for_type = Moab::FileSignature.checksum_names_for_type
180
- ng_doc = Nokogiri::XML(content_metadata) { |x| x.noblanks }
182
+ ng_doc = Nokogiri::XML(content_metadata, &:noblanks)
181
183
  nodeset = ng_doc.xpath("//file")
182
184
  nodeset.each do |file_node|
183
185
  filepath = file_node['id']
@@ -193,7 +195,7 @@ module Stanford
193
195
  # @return [void] update the file size attribute if missing, raise exception if inconsistent
194
196
  def remediate_file_size(file_node, signature)
195
197
  file_size = file_node['size']
196
- if file_size.nil? or file_size.empty?
198
+ if file_size.nil? || file_size.empty?
197
199
  file_node['size'] = signature.size.to_s
198
200
  elsif file_size != signature.size.to_s
199
201
  raise "Inconsistent size for #{file_node['id']}: #{file_size} != #{signature.size}"
@@ -205,14 +207,14 @@ module Stanford
205
207
  # @return [void] update the file's checksum elements if data missing, raise exception if inconsistent
206
208
  def remediate_checksum_nodes(file_node, signature)
207
209
  # collect <checksum> elements for checksum types that are already present
208
- checksum_nodes = Hash.new
210
+ checksum_nodes = {}
209
211
  file_node.xpath('checksum').each do |checksum_node|
210
212
  type = @type_for_name[checksum_node['type']]
211
213
  checksum_nodes[type] = checksum_node
212
214
  end
213
215
  # add new <checksum> elements for the other checksum types that were missing
214
216
  @names_for_type.each do |type, names|
215
- unless checksum_nodes.has_key?(type)
217
+ unless checksum_nodes.key?(type)
216
218
  checksum_node = Nokogiri::XML::Element.new('checksum', file_node.document)
217
219
  checksum_node['type'] = names[0]
218
220
  file_node << checksum_node
@@ -223,7 +225,7 @@ module Stanford
223
225
  checksum_nodes.each do |type, checksum_node|
224
226
  cm_checksum = checksum_node.content
225
227
  sig_checksum = signature.checksums[type]
226
- if cm_checksum.nil? or cm_checksum.empty?
228
+ if cm_checksum.nil? || cm_checksum.empty?
227
229
  checksum_node.content = sig_checksum
228
230
  elsif cm_checksum != sig_checksum
229
231
  raise "Inconsistent #{type} for #{file_node['id']}: #{cm_checksum} != #{sig_checksum}"
@@ -1,5 +1,3 @@
1
- require 'moab/stanford'
2
-
3
1
  module Stanford
4
2
  # Stanford-specific utility methods for interfacing with DOR metadata files
5
3
  #
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Stanford
4
2
  # druids are Stanford specific entities
5
3
  class StorageObjectValidator < Moab::StorageObjectValidator
@@ -1,4 +1,3 @@
1
- require 'moab/stanford'
2
1
  require 'druid-tools'
3
2
 
4
3
  module Stanford
@@ -22,7 +21,7 @@ module Stanford
22
21
  end
23
22
 
24
23
  # @param object_id [String] The identifier of the digital object
25
- # @return [Pathname] The branch segment of the object deposit path
24
+ # @return [String] The branch segment of the object deposit path
26
25
  def deposit_branch(object_id)
27
26
  object_id.split(/:/)[-1]
28
27
  end
@@ -1,5 +1,3 @@
1
- require 'moab/stanford'
2
-
3
1
  module Stanford
4
2
  # An interface class to support access to SDR storage via a RESTful server
5
3
  class StorageServices < Moab::StorageServices
@@ -17,9 +15,9 @@ module Stanford
17
15
  new_inventory = Stanford::ContentInventory.new.inventory_from_cm(new_content_metadata, object_id, subset)
18
16
  begin
19
17
  # ObjectNotFoundException is raised if the object does not exist in storage
20
- base_version ||= self.current_version(object_id)
18
+ base_version ||= current_version(object_id)
21
19
  # FileNotFoundException is raised if object exists but has no contentMetadata file
22
- base_cm_pathname = self.retrieve_file('metadata', 'contentMetadata.xml', object_id, base_version)
20
+ base_cm_pathname = retrieve_file('metadata', 'contentMetadata.xml', object_id, base_version)
23
21
  base_inventory = Stanford::ContentInventory.new.inventory_from_cm(base_cm_pathname.read, object_id, subset, base_version)
24
22
  rescue Moab::ObjectNotFoundException, Moab::FileNotFoundException
25
23
  # Create a skeletal FileInventory object, containing no file entries
@@ -41,7 +39,7 @@ module Stanford
41
39
  new_inventory = Stanford::ContentInventory.new.inventory_from_cm(new_content_metadata, object_id, 'preserve')
42
40
  begin
43
41
  # ObjectNotFoundException is raised if the object does not exist in storage
44
- version_id ||= self.current_version(object_id)
42
+ version_id ||= current_version(object_id)
45
43
  storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
46
44
  signature_catalog = storage_object_version.signature_catalog
47
45
  rescue Moab::ObjectNotFoundException
@@ -56,8 +54,8 @@ module Stanford
56
54
  # @param version_id [Integer] The ID of the version whose file data is to be used, if nil use latest version
57
55
  # @return [String] Returns a remediated copy of the contentMetadata with fixity data filled in
58
56
  def self.cm_remediate(object_id, version_id = nil)
59
- cm = self.retrieve_file('metadata', 'contentMetadata.xml', object_id, version_id)
60
- group = self.retrieve_file_group('content', object_id, version_id)
57
+ cm = retrieve_file('metadata', 'contentMetadata.xml', object_id, version_id)
58
+ group = retrieve_file_group('content', object_id, version_id)
61
59
  Stanford::ContentInventory.new.remediate_content_metadata(cm, group)
62
60
  end
63
61
  end
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: 4.2.1
4
+ version: 4.2.2
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: 2018-04-10 00:00:00.000000000 Z
14
+ date: 2018-05-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: confstruct
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  requirements: []
247
247
  rubyforge_project:
248
- rubygems_version: 2.6.11
248
+ rubygems_version: 2.6.13
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: Ruby implementation of digital object versioning toolkit used by the SULAIR