dor-services 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dor-services.rb +7 -6
  3. data/lib/dor/certificate_authenticated_rest_resource_factory.rb +2 -1
  4. data/lib/dor/config.rb +38 -37
  5. data/lib/dor/datastreams/administrative_metadata_ds.rb +98 -98
  6. data/lib/dor/datastreams/content_metadata_ds.rb +26 -17
  7. data/lib/dor/datastreams/datastream_spec_solrizer.rb +4 -2
  8. data/lib/dor/datastreams/default_object_rights_ds.rb +10 -7
  9. data/lib/dor/datastreams/desc_metadata_ds.rb +6 -6
  10. data/lib/dor/datastreams/embargo_metadata_ds.rb +94 -94
  11. data/lib/dor/datastreams/events_ds.rb +55 -54
  12. data/lib/dor/datastreams/geo_metadata_ds.rb +7 -6
  13. data/lib/dor/datastreams/identity_metadata_ds.rb +128 -125
  14. data/lib/dor/datastreams/provenance_metadata_ds.rb +3 -1
  15. data/lib/dor/datastreams/rights_metadata_ds.rb +4 -4
  16. data/lib/dor/datastreams/role_metadata_ds.rb +42 -42
  17. data/lib/dor/datastreams/simple_dublin_core_ds.rb +45 -43
  18. data/lib/dor/datastreams/technical_metadata_ds.rb +3 -1
  19. data/lib/dor/datastreams/version_metadata_ds.rb +12 -5
  20. data/lib/dor/datastreams/workflow_definition_ds.rb +74 -73
  21. data/lib/dor/datastreams/workflow_ds.rb +12 -7
  22. data/lib/dor/exceptions.rb +2 -0
  23. data/lib/dor/indexers/data_indexer.rb +16 -0
  24. data/lib/dor/indexers/describable_indexer.rb +2 -0
  25. data/lib/dor/indexers/editable_indexer.rb +2 -0
  26. data/lib/dor/indexers/identifiable_indexer.rb +23 -8
  27. data/lib/dor/indexers/processable_indexer.rb +2 -0
  28. data/lib/dor/indexers/releasable_indexer.rb +2 -0
  29. data/lib/dor/models/abstract.rb +2 -0
  30. data/lib/dor/models/admin_policy_object.rb +2 -0
  31. data/lib/dor/models/agreement.rb +2 -0
  32. data/lib/dor/models/collection.rb +3 -0
  33. data/lib/dor/models/concerns/assembleable.rb +2 -0
  34. data/lib/dor/models/concerns/contentable.rb +5 -2
  35. data/lib/dor/models/concerns/describable.rb +7 -2
  36. data/lib/dor/models/concerns/editable.rb +28 -21
  37. data/lib/dor/models/concerns/embargoable.rb +4 -0
  38. data/lib/dor/models/concerns/eventable.rb +2 -0
  39. data/lib/dor/models/concerns/geoable.rb +2 -0
  40. data/lib/dor/models/concerns/governable.rb +7 -2
  41. data/lib/dor/models/concerns/identifiable.rb +33 -34
  42. data/lib/dor/models/concerns/itemizable.rb +4 -1
  43. data/lib/dor/models/concerns/preservable.rb +2 -0
  44. data/lib/dor/models/concerns/processable.rb +15 -9
  45. data/lib/dor/models/concerns/publishable.rb +9 -4
  46. data/lib/dor/models/concerns/releaseable.rb +21 -11
  47. data/lib/dor/models/concerns/rightsable.rb +2 -0
  48. data/lib/dor/models/concerns/shelvable.rb +6 -2
  49. data/lib/dor/models/concerns/versionable.rb +8 -4
  50. data/lib/dor/models/item.rb +2 -0
  51. data/lib/dor/models/set.rb +2 -0
  52. data/lib/dor/models/workflow_object.rb +5 -1
  53. data/lib/dor/rest_resource_factory.rb +2 -0
  54. data/lib/dor/services/cleanup_reset_service.rb +2 -1
  55. data/lib/dor/services/cleanup_service.rb +2 -1
  56. data/lib/dor/services/digital_stacks_service.rb +3 -1
  57. data/lib/dor/services/indexing_service.rb +3 -1
  58. data/lib/dor/services/merge_service.rb +6 -4
  59. data/lib/dor/services/metadata_handlers/catalog_handler.rb +2 -0
  60. data/lib/dor/services/metadata_service.rb +4 -4
  61. data/lib/dor/services/public_desc_metadata_service.rb +16 -8
  62. data/lib/dor/services/public_xml_service.rb +7 -4
  63. data/lib/dor/services/registration_service.rb +25 -20
  64. data/lib/dor/services/reset_workspace_service.rb +4 -4
  65. data/lib/dor/services/sdr_ingest_service.rb +4 -2
  66. data/lib/dor/services/search_service.rb +8 -9
  67. data/lib/dor/services/suri_service.rb +3 -2
  68. data/lib/dor/services/technical_metadata_service.rb +15 -9
  69. data/lib/dor/services/thumbnail_service.rb +14 -10
  70. data/lib/dor/utils/hydrus_shims.rb +2 -0
  71. data/lib/dor/utils/ng_tidy.rb +3 -7
  72. data/lib/dor/utils/predicate_patch.rb +2 -0
  73. data/lib/dor/utils/sdr_client.rb +3 -0
  74. data/lib/dor/utils/solr_doc_helper.rb +4 -2
  75. data/lib/dor/version.rb +3 -1
  76. data/lib/dor/workflow/document.rb +113 -108
  77. data/lib/dor/workflow/process.rb +90 -87
  78. data/lib/tasks/rdoc.rake +4 -3
  79. metadata +4 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rest-client'
2
4
 
3
5
  handler = Class.new do
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cache'
2
4
 
3
5
  module Dor
4
- class MetadataError < Exception ; end
6
+ class MetadataError < Exception; end
5
7
 
6
8
  # class MetadataHandler
7
9
  #
@@ -16,7 +18,6 @@ module Dor
16
18
  # end
17
19
 
18
20
  class MetadataService
19
-
20
21
  class << self
21
22
  @@cache = Cache.new(nil, nil, 250, 300)
22
23
 
@@ -64,6 +65,7 @@ module Dor
64
65
  def handler_for(prefix)
65
66
  handler = handlers[prefix.to_sym]
66
67
  raise MetadataError, "Unkown metadata prefix: #{prefix}" if handler.nil?
68
+
67
69
  handler
68
70
  end
69
71
 
@@ -72,9 +74,7 @@ module Dor
72
74
  def handlers
73
75
  @handlers ||= {}
74
76
  end
75
-
76
77
  end
77
-
78
78
  end
79
79
  end
80
80
 
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  class PublicDescMetadataService
3
5
  attr_reader :object
4
-
6
+
5
7
  NOKOGIRI_DEEP_COPY = 1
6
8
 
7
9
  def initialize(object)
8
10
  @object = object
9
11
  end
10
-
12
+
11
13
  def doc
12
14
  @doc ||= object.descMetadata.ng_xml.dup(NOKOGIRI_DEEP_COPY)
13
15
  end
@@ -18,7 +20,7 @@ module Dor
18
20
  add_access_conditions! if include_access_conditions
19
21
  add_constituent_relations!
20
22
  strip_comments!
21
-
23
+
22
24
  new_doc = Nokogiri::XML(doc.to_xml) { |x| x.noblanks }
23
25
  new_doc.encoding = 'UTF-8'
24
26
  new_doc.to_xml
@@ -35,30 +37,36 @@ module Dor
35
37
  # @note this method modifies the passed in doc
36
38
  def add_access_conditions!
37
39
  # clear out any existing accessConditions
38
- doc.xpath('//mods:accessCondition', 'mods' => 'http://www.loc.gov/mods/v3').each {|n| n.remove}
40
+ doc.xpath('//mods:accessCondition', 'mods' => 'http://www.loc.gov/mods/v3').each { |n| n.remove }
39
41
  rights = object.datastreams['rightsMetadata'].ng_xml
40
42
 
41
43
  rights.xpath('//use/human[@type="useAndReproduction"]').each do |use|
42
44
  txt = use.text.strip
43
45
  next if txt.empty?
46
+
44
47
  doc.root.element_children.last.add_next_sibling doc.create_element('accessCondition', txt, :type => 'useAndReproduction')
45
48
  end
46
49
  rights.xpath('//copyright/human[@type="copyright"]').each do |cr|
47
50
  txt = cr.text.strip
48
51
  next if txt.empty?
52
+
49
53
  doc.root.element_children.last.add_next_sibling doc.create_element('accessCondition', txt, :type => 'copyright')
50
54
  end
51
55
  rights.xpath("//use/machine[#{ci_compare('type', 'creativecommons')}]").each do |lic_type|
52
56
  next if lic_type.text =~ /none/i
57
+
53
58
  lic_text = rights.at_xpath("//use/human[#{ci_compare('type', 'creativecommons')}]").text.strip
54
59
  next if lic_text.empty?
60
+
55
61
  new_text = "CC #{lic_type.text}: #{lic_text}"
56
62
  doc.root.element_children.last.add_next_sibling doc.create_element('accessCondition', new_text, :type => 'license')
57
63
  end
58
64
  rights.xpath("//use/machine[#{ci_compare('type', 'opendatacommons')}]").each do |lic_type|
59
65
  next if lic_type.text =~ /none/i
66
+
60
67
  lic_text = rights.at_xpath("//use/human[#{ci_compare('type', 'opendatacommons')}]").text.strip
61
68
  next if lic_text.empty?
69
+
62
70
  new_text = "ODC #{lic_type.text}: #{lic_text}"
63
71
  doc.root.element_children.last.add_next_sibling doc.create_element('accessCondition', new_text, :type => 'license')
64
72
  end
@@ -69,8 +77,8 @@ module Dor
69
77
  # @return [Void]
70
78
  def add_constituent_relations!
71
79
  object.public_relationships.search('//rdf:RDF/rdf:Description/fedora:isConstituentOf',
72
- 'fedora' => 'info:fedora/fedora-system:def/relations-external#',
73
- 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' ).each do |parent|
80
+ 'fedora' => 'info:fedora/fedora-system:def/relations-external#',
81
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#').each do |parent|
74
82
  # fetch the parent object to get title
75
83
  druid = parent['rdf:resource'].gsub(/^info:fedora\//, '')
76
84
  parent_item = Dor.find(druid)
@@ -106,8 +114,8 @@ module Dor
106
114
  # @note this method modifies the passed in doc
107
115
  def add_collection_reference!
108
116
  collections = object.public_relationships.search('//rdf:RDF/rdf:Description/fedora:isMemberOfCollection',
109
- 'fedora' => 'info:fedora/fedora-system:def/relations-external#',
110
- 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
117
+ 'fedora' => 'info:fedora/fedora-system:def/relations-external#',
118
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
111
119
  return if collections.empty?
112
120
 
113
121
  remove_related_item_nodes_for_collections!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  class PublicXmlService
3
5
  attr_reader :object
@@ -35,7 +37,7 @@ module Dor
35
37
  # @return [String] The XML release node as a string, with ReleaseDigest as the root document
36
38
  def release_xml
37
39
  @release_xml ||= begin
38
- builder = Nokogiri::XML::Builder.new do |xml|
40
+ builder = Nokogiri::XML::Builder.new do |xml|
39
41
  xml.releaseData {
40
42
  object.released_for.each do |project, released_value|
41
43
  xml.release(released_value['release'], :to => project)
@@ -65,14 +67,15 @@ module Dor
65
67
  # @return [Nokogiri::XML::Document] sanitized for public consumption
66
68
  def public_content_metadata
67
69
  return Nokogiri::XML::Document.new unless object.datastreams['contentMetadata']
70
+
68
71
  @public_content_metadata ||= begin
69
72
  result = object.datastreams['contentMetadata'].ng_xml.clone
70
73
 
71
74
  # remove any resources or attributes that are not destined for the public XML
72
75
  result.xpath('/contentMetadata/resource[not(file[(@deliver="yes" or @publish="yes")]|externalFile)]').each(&:remove)
73
- result.xpath('/contentMetadata/resource/file[not(@deliver="yes" or @publish="yes")]' ).each(&:remove)
74
- result.xpath('/contentMetadata/resource/file').xpath('@preserve|@shelve|@publish|@deliver' ).each(&:remove)
75
- result.xpath('/contentMetadata/resource/file/checksum' ).each(&:remove)
76
+ result.xpath('/contentMetadata/resource/file[not(@deliver="yes" or @publish="yes")]').each(&:remove)
77
+ result.xpath('/contentMetadata/resource/file').xpath('@preserve|@shelve|@publish|@deliver').each(&:remove)
78
+ result.xpath('/contentMetadata/resource/file/checksum').each(&:remove)
76
79
 
77
80
  # support for dereferencing links via externalFile element(s) to the source (child) item - see JUMBO-19
78
81
  result.xpath('/contentMetadata/resource/externalFile').each do |externalFile|
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uuidtools'
2
4
 
3
5
  module Dor
4
6
  class RegistrationService
5
-
6
7
  class << self
7
-
8
8
  # @TODO: Why isn't all this logic in, for example, Dor::Item.create? or Dor::Base.create? or Dor::Creatable.create?
9
9
  # @TODO: these duplicate checks could be combined into 1 query
10
10
 
@@ -13,10 +13,12 @@ module Dor
13
13
  # @raise [Dor::DuplicateIdError]
14
14
  def unduplicated_pid(pid = nil)
15
15
  return Dor::SuriService.mint_id unless pid
16
+
16
17
  existing_pid = SearchService.query_by_id(pid).first
17
18
  unless existing_pid.nil?
18
19
  raise Dor::DuplicateIdError.new(existing_pid), "An object with the PID #{pid} has already been registered."
19
20
  end
21
+
20
22
  pid
21
23
  end
22
24
 
@@ -28,6 +30,7 @@ module Dor
28
30
  unless SearchService.query_by_id("#{source_id_string}").first.nil?
29
31
  raise Dor::DuplicateIdError.new(source_id_string), "An object with the source ID '#{source_id_string}' has already been registered."
30
32
  end
33
+
31
34
  source_id_string
32
35
  end
33
36
 
@@ -50,9 +53,10 @@ module Dor
50
53
  raise Dor::ParameterError, "#{required_param.inspect} must be specified in call to #{name}.register_object" unless params[required_param]
51
54
  end
52
55
  metadata_source = params[:metadata_source]
53
- if params[:label].length < 1 && (metadata_source == 'label' || metadata_source == 'none')
56
+ if params[:label].length < 1 && %w[label none].include?(metadata_source)
54
57
  raise Dor::ParameterError, "label cannot be empty to call #{name}.register_object"
55
58
  end
59
+
56
60
  object_type = params[:object_type]
57
61
  item_class = Dor.registered_classes[object_type]
58
62
  raise Dor::ParameterError, "Unknown item type: '#{object_type}'" if item_class.nil?
@@ -108,7 +112,7 @@ module Dor
108
112
  if rights && %w(item collection).include?(object_type)
109
113
  rights_xml = apo_object.defaultObjectRights.ng_xml
110
114
  new_item.datastreams['rightsMetadata'].content = rights_xml.to_s
111
- new_item.set_read_rights(rights) unless rights == 'default' # already defaulted to default!
115
+ new_item.set_read_rights(rights) unless rights == 'default' # already defaulted to default!
112
116
  end
113
117
  # create basic mods from the label
114
118
  if metadata_source == 'label'
@@ -126,7 +130,7 @@ module Dor
126
130
  workflow_priority = params[:workflow_priority] ? params[:workflow_priority].to_i : 0
127
131
 
128
132
  Array(params[:seed_datastream]).each { |datastream_name| new_item.build_datastream(datastream_name) }
129
- Array(params[:initiate_workflow]).each { |workflow_id| new_item.create_workflow(workflow_id, !new_item.new_record?, workflow_priority)}
133
+ Array(params[:initiate_workflow]).each { |workflow_id| new_item.create_workflow(workflow_id, !new_item.new_record?, workflow_priority) }
130
134
 
131
135
  new_item.assert_content_model
132
136
 
@@ -157,21 +161,21 @@ module Dor
157
161
  end
158
162
 
159
163
  dor_params = {
160
- :pid => params[:pid],
161
- :admin_policy => params[:admin_policy],
162
- :content_model => params[:model],
163
- :label => params[:label],
164
- :object_type => params[:object_type],
165
- :other_ids => ids_to_hash(other_ids),
166
- :parent => params[:parent],
167
- :source_id => ids_to_hash(params[:source_id]),
168
- :tags => params[:tag] || [],
169
- :seed_datastream => params[:seed_datastream],
170
- :initiate_workflow => Array(params[:initiate_workflow]) + Array(params[:workflow_id]),
171
- :rights => params[:rights],
172
- :metadata_source => params[:metadata_source],
173
- :collection => params[:collection],
174
- :workflow_priority => params[:workflow_priority]
164
+ :pid => params[:pid],
165
+ :admin_policy => params[:admin_policy],
166
+ :content_model => params[:model],
167
+ :label => params[:label],
168
+ :object_type => params[:object_type],
169
+ :other_ids => ids_to_hash(other_ids),
170
+ :parent => params[:parent],
171
+ :source_id => ids_to_hash(params[:source_id]),
172
+ :tags => params[:tag] || [],
173
+ :seed_datastream => params[:seed_datastream],
174
+ :initiate_workflow => Array(params[:initiate_workflow]) + Array(params[:workflow_id]),
175
+ :rights => params[:rights],
176
+ :metadata_source => params[:metadata_source],
177
+ :collection => params[:collection],
178
+ :workflow_priority => params[:workflow_priority]
175
179
  }
176
180
  dor_params.delete_if { |k, v| v.nil? }
177
181
 
@@ -185,6 +189,7 @@ module Dor
185
189
 
186
190
  def ids_to_hash(ids)
187
191
  return nil if ids.nil?
192
+
188
193
  Hash[Array(ids).map { |id| id.split(':', 2) }]
189
194
  end
190
195
  end
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  # Rename the druid trees at the end of the accessionWF in order to be cleaned/deleted later.
3
5
  class ResetWorkspaceService
4
-
5
6
  def self.reset_workspace_druid_tree(druid, version, workspace_root)
6
7
  druid_tree_path = DruidTools::Druid.new(druid, workspace_root).pathname.to_s
7
8
 
8
- raise "The archived directory #{druid_tree_path}_v#{version} already existed." if File.exist?("#{druid_tree_path}_v#{version}")
9
+ raise "The archived directory #{druid_tree_path}_v#{version} already existed." if File.exist?("#{druid_tree_path}_v#{version}")
9
10
 
10
11
  if File.exist?(druid_tree_path)
11
12
  FileUtils.mv(druid_tree_path, "#{druid_tree_path}_v#{version}")
@@ -16,7 +17,7 @@ module Dor
16
17
  id = druid.split(':').last
17
18
  bag_dir = File.join(export_root, id)
18
19
 
19
- raise "The archived bag #{bag_dir}_v#{version} already existed." if File.exist?("#{bag_dir}_v#{version}")
20
+ raise "The archived bag #{bag_dir}_v#{version} already existed." if File.exist?("#{bag_dir}_v#{version}")
20
21
 
21
22
  FileUtils.mv(bag_dir, "#{bag_dir}_v#{version}") if File.exist?(bag_dir)
22
23
 
@@ -24,6 +25,5 @@ module Dor
24
25
  FileUtils.mv("#{bag_dir}.tar", "#{bag_dir}_v#{version}.tar")
25
26
  end
26
27
  end
27
-
28
28
  end
29
29
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'moab/stanford'
2
4
 
3
5
  module Dor
4
6
  # Note: This should probably live in common-accessioning robot sdr-ingest-transfer
5
7
  # as that is the only robot that uses it. See also preservable concern.
6
8
  class SdrIngestService
7
-
8
9
  # @param [Dor::Item] dor_item The representation of the digital object
9
10
  # @param [String] agreement_id depreciated, included for backward compatability with common-accessoning
10
11
  # @return [void] Create the Moab/bag manifests for new version, export data to BagIt bag, kick off the SDR preservation workflow
@@ -95,6 +96,7 @@ module Dor
95
96
  # @param [Integer] found The version number that is actually in the file
96
97
  def self.verify_version_id(pathname, expected, found)
97
98
  raise "Version mismatch in #{pathname}, expected #{expected}, found #{found}" unless expected == found
99
+
98
100
  true
99
101
  end
100
102
 
@@ -165,8 +167,8 @@ module Dor
165
167
  # @return [Boolean] true if file exists, raises exception if not
166
168
  def self.verify_pathname(pathname)
167
169
  raise "#{pathname.basename} not found at #{pathname}" unless pathname.exist?
170
+
168
171
  true
169
172
  end
170
-
171
173
  end
172
174
  end
@@ -1,14 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'active_support/core_ext'
3
5
 
4
6
  module Dor
5
7
  class SearchService
6
-
7
- RISEARCH_TEMPLATE = "select $object from <#ri> where $object <dc:identifier> '%s'".freeze
8
+ RISEARCH_TEMPLATE = "select $object from <#ri> where $object <dc:identifier> '%s'"
8
9
  @@index_version = nil
9
10
 
10
11
  class << self
11
-
12
12
  def index_version
13
13
  Dor::VERSION
14
14
  end
@@ -17,12 +17,12 @@ module Dor
17
17
  client = Config.fedora.client['risearch']
18
18
  client.options[:timeout] = opts.delete(:timeout)
19
19
  query_params = {
20
- :type => 'tuples',
21
- :lang => 'itql',
20
+ :type => 'tuples',
21
+ :lang => 'itql',
22
22
  :format => 'CSV',
23
- :limit => '1000',
23
+ :limit => '1000',
24
24
  :stream => 'on',
25
- :query => query
25
+ :query => query
26
26
  }.merge(opts)
27
27
  result = client.post(query_params)
28
28
  result.split(/\n/)[1..-1].collect { |pid| pid.chomp.sub(/^info:fedora\//, '') }
@@ -50,6 +50,7 @@ module Dor
50
50
  params[:start] ||= 0
51
51
  resp = solr.get 'select', params: params
52
52
  return resp unless block_given?
53
+
53
54
  cont = true
54
55
  while cont && resp['response']['docs'].length > 0
55
56
  cont = yield(resp)
@@ -92,8 +93,6 @@ module Dor
92
93
  r['response']['docs'].first[:id]
93
94
  end
94
95
  end
95
-
96
96
  end
97
-
98
97
  end
99
98
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rest-client'
2
4
  require 'active_fedora'
3
5
 
@@ -13,7 +15,7 @@ module Dor
13
15
  if Config.suri.mint_ids
14
16
  # Post with no body
15
17
  resource = RestClient::Resource.new("#{Config.suri.url}/suri2/namespaces/#{Config.suri.id_namespace}",
16
- :user => Config.suri.user, :password => Config.suri.pass)
18
+ :user => Config.suri.user, :password => Config.suri.pass)
17
19
  ids = resource["identifiers?quantity=#{quantity}"].post('').chomp.split(/\n/).collect { |id| "#{Config.suri.id_namespace}:#{id.strip}" }
18
20
  else
19
21
  repo = ActiveFedora::Base.respond_to?(:connection_for_pid) ? ActiveFedora::Base.connection_for_pid(0) : ActiveFedora.fedora.connection
@@ -32,6 +34,5 @@ module Dor
32
34
  # Rails.logger.error("Unable to mint id from suri: #{e.to_s}")
33
35
  # raise e
34
36
  end
35
-
36
37
  end
37
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'moab/stanford'
3
5
  require 'jhove_service'
@@ -5,7 +7,6 @@ require 'dor-services'
5
7
 
6
8
  module Dor
7
9
  class TechnicalMetadataService
8
-
9
10
  # @param [Dor::Item] dor_item The DOR item being processed by the technical metadata robot
10
11
  # @return [Boolean] True if technical metadata is correctly added or updated
11
12
  def self.add_update_technical_metadata(dor_item)
@@ -71,6 +72,7 @@ module Dor
71
72
  def self.get_old_technical_metadata(dor_item)
72
73
  sdr_techmd = get_sdr_technical_metadata(dor_item.pid)
73
74
  return sdr_techmd unless sdr_techmd.nil?
75
+
74
76
  get_dor_technical_metadata(dor_item)
75
77
  end
76
78
 
@@ -81,6 +83,7 @@ module Dor
81
83
  sdr_techmd = get_sdr_metadata(druid, 'technicalMetadata')
82
84
  return sdr_techmd if sdr_techmd =~ /<technicalMetadata/
83
85
  return ::JhoveService.new.upgrade_technical_metadata(sdr_techmd) if sdr_techmd =~ /<jhove/
86
+
84
87
  nil
85
88
  end
86
89
 
@@ -90,9 +93,11 @@ module Dor
90
93
  def self.get_dor_technical_metadata(dor_item)
91
94
  ds = 'technicalMetadata'
92
95
  return nil unless dor_item.datastreams.keys.include?(ds) && !dor_item.datastreams[ds].new?
96
+
93
97
  dor_techmd = dor_item.datastreams[ds].content
94
98
  return dor_techmd if dor_techmd =~ /<technicalMetadata/
95
99
  return ::JhoveService.new.upgrade_technical_metadata(dor_techmd) if dor_techmd =~ /<jhove/
100
+
96
101
  nil
97
102
  end
98
103
 
@@ -108,6 +113,7 @@ module Dor
108
113
  # @return [String] The technicalMetadata datastream for the new files of the new digital object version
109
114
  def self.get_new_technical_metadata(druid, new_files)
110
115
  return nil if new_files.nil? || new_files.empty?
116
+
111
117
  workspace = DruidTools::Druid.new(druid, Dor::Config.sdr.local_workspace_root)
112
118
  content_dir = workspace.find_filelist_parent('content', new_files)
113
119
  temp_dir = workspace.temp_dir
@@ -124,7 +130,7 @@ module Dor
124
130
  # @return [Pathname] Save the new_files list to a text file and return that file's name
125
131
  def self.write_fileset(temp_dir, new_files)
126
132
  fileset_pathname = Pathname(temp_dir).join('jhove_fileset.txt')
127
- fileset_pathname.open('w') {|f| f.puts(new_files) }
133
+ fileset_pathname.open('w') { |f| f.puts(new_files) }
128
134
  fileset_pathname
129
135
  end
130
136
 
@@ -163,6 +169,7 @@ module Dor
163
169
  def self.get_file_nodes(technical_metadata)
164
170
  file_hash = {}
165
171
  return file_hash if technical_metadata.nil?
172
+
166
173
  current_file = []
167
174
  path = nil
168
175
  in_file = false
@@ -188,16 +195,15 @@ module Dor
188
195
  # @param [Hash<String,Nokogiri::XML::Node>] merged_nodes The complete set of technicalMetadata nodes for the digital object, indexed by filename
189
196
  # @return [String] The finalized technicalMetadata datastream contents for the new object version
190
197
  def self.build_technical_metadata(druid, merged_nodes)
191
- techmd_root = <<-EOF
192
- <technicalMetadata objectId='#{druid}' datetime='#{Time.now.utc.iso8601}'
193
- xmlns:jhove='http://hul.harvard.edu/ois/xml/ns/jhove'
194
- xmlns:mix='http://www.loc.gov/mix/v10'
195
- xmlns:textmd='info:lc/xmlns/textMD-v3'>
198
+ techmd_root = +<<~EOF
199
+ <technicalMetadata objectId='#{druid}' datetime='#{Time.now.utc.iso8601}'
200
+ xmlns:jhove='http://hul.harvard.edu/ois/xml/ns/jhove'
201
+ xmlns:mix='http://www.loc.gov/mix/v10'
202
+ xmlns:textmd='info:lc/xmlns/textMD-v3'>
196
203
  EOF
197
204
  doc = techmd_root
198
- merged_nodes.keys.sort.each {|path| doc << merged_nodes[path] }
205
+ merged_nodes.keys.sort.each { |path| doc << merged_nodes[path] }
199
206
  doc + '</technicalMetadata>'
200
207
  end
201
-
202
208
  end
203
209
  end