dor-services 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
  module Dor
2
4
  class Collection < Dor::Set
3
5
  include Releaseable
@@ -5,6 +7,7 @@ module Dor
5
7
  has_object_type 'collection'
6
8
 
7
9
  self.resource_indexer = CompositeIndexer.new(
10
+ DataIndexer,
8
11
  DescribableIndexer,
9
12
  IdentifiableIndexer,
10
13
  ProcessableIndexer,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Assembleable
3
5
  def initialize_workspace(source = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Contentable
3
5
  extend ActiveSupport::Concern
@@ -7,6 +9,7 @@ module Dor
7
9
  xml = datastreams['contentMetadata'].ng_xml
8
10
  # make sure the resource exists
9
11
  raise 'resource doesnt exist.' if xml.search('//resource[@id=\'' + resource + '\']').length == 0
12
+
10
13
  sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, :auth_methods => ['publickey'])
11
14
  druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
12
15
  location = druid_tools.path(file_name)
@@ -15,7 +18,7 @@ module Dor
15
18
  sha1 = Digest::SHA1.file(file.path).hexdigest
16
19
  size = File.size?(file.path)
17
20
  # update contentmd
18
- file_hash = {:name => file_name, :md5 => md5, :publish => publish, :shelve => shelve, :preserve => preserve, :size => size.to_s, :sha1 => sha1, :mime_type => mime_type}
21
+ file_hash = { :name => file_name, :md5 => md5, :publish => publish, :shelve => shelve, :preserve => preserve, :size => size.to_s, :sha1 => sha1, :mime_type => mime_type }
19
22
  begin
20
23
  sftp.stat!(location.gsub(file_name, ''))
21
24
  begin
@@ -49,7 +52,7 @@ module Dor
49
52
  sha1 = Digest::SHA1.file(file.path).hexdigest
50
53
  size = File.size?(file.path)
51
54
  # update contentmd
52
- file_hash = {:name => file_name, :md5 => md5, :size => size.to_s, :sha1 => sha1}
55
+ file_hash = { :name => file_name, :md5 => md5, :size => size.to_s, :sha1 => sha1 }
53
56
  begin
54
57
  sftp.stat!(location)
55
58
  sftp.upload!(file.path, location)
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Describable
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  MODS_TO_DC_XSLT = Nokogiri::XSLT(File.new(File.expand_path(File.dirname(__FILE__) + "/mods2dc.xslt")))
6
- XMLNS_OAI_DC = 'http://www.openarchives.org/OAI/2.0/oai_dc/'.freeze
7
- XMLNS_DC = 'http://purl.org/dc/elements/1.1/'.freeze
8
+ XMLNS_OAI_DC = 'http://www.openarchives.org/OAI/2.0/oai_dc/'
9
+ XMLNS_DC = 'http://purl.org/dc/elements/1.1/'
8
10
 
9
11
  class CrosswalkError < Exception; end
10
12
 
@@ -35,6 +37,7 @@ module Dor
35
37
  def build_descMetadata_datastream(ds)
36
38
  content = fetch_descMetadata_datastream
37
39
  return nil if content.nil?
40
+
38
41
  ds.dsLabel = 'Descriptive Metadata'
39
42
  ds.ng_xml = Nokogiri::XML(content)
40
43
  ds.ng_xml.normalize_text!
@@ -56,6 +59,7 @@ module Dor
56
59
  dc_doc.xpath('/oai_dc:dc/*[count(text()) = 0]', oai_dc: XMLNS_OAI_DC).remove # Remove empty nodes
57
60
  raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no root):\n#{dc_doc.to_xml}" if dc_doc.root.nil?
58
61
  raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no children):\n#{dc_doc.to_xml}" if dc_doc.root.children.size == 0
62
+
59
63
  dc_doc
60
64
  end
61
65
 
@@ -70,6 +74,7 @@ module Dor
70
74
  unless force || descMetadata.new?
71
75
  raise 'Cannot proceed, there is already content in the descriptive metadata datastream: ' + descMetadata.content.to_s
72
76
  end
77
+
73
78
  label = self.label
74
79
  builder = Nokogiri::XML::Builder.new { |xml|
75
80
  xml.mods(Dor::DescMetadataDS::MODS_HEADER_CONFIG) {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  ## This is basically used just by APOs. Arguably "editable" is the wrong name.
3
5
  module Editable
@@ -18,29 +20,29 @@ module Dor
18
20
  # TODO: need some way to do versioning. for instance, what happens when a new version of an existing license comes
19
21
  # out, since it will presumably use the same license code, but a different title and URI?
20
22
  CREATIVE_COMMONS_USE_LICENSES = {
21
- 'by' => { :human_readable => 'Attribution 3.0 Unported',
22
- :uri => 'https://creativecommons.org/licenses/by/3.0/' },
23
- 'by-sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported',
24
- :uri => 'https://creativecommons.org/licenses/by-sa/3.0/' },
25
- 'by_sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported',
26
- :uri => 'https://creativecommons.org/licenses/by-sa/3.0/',
27
- :deprecation_warning => 'license code "by_sa" was a typo in argo, prefer "by-sa"' },
28
- 'by-nd' => { :human_readable => 'Attribution No Derivatives 3.0 Unported',
29
- :uri => 'https://creativecommons.org/licenses/by-nd/3.0/' },
30
- 'by-nc' => { :human_readable => 'Attribution Non-Commercial 3.0 Unported',
31
- :uri => 'https://creativecommons.org/licenses/by-nc/3.0/' },
23
+ 'by' => { :human_readable => 'Attribution 3.0 Unported',
24
+ :uri => 'https://creativecommons.org/licenses/by/3.0/' },
25
+ 'by-sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported',
26
+ :uri => 'https://creativecommons.org/licenses/by-sa/3.0/' },
27
+ 'by_sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported',
28
+ :uri => 'https://creativecommons.org/licenses/by-sa/3.0/',
29
+ :deprecation_warning => 'license code "by_sa" was a typo in argo, prefer "by-sa"' },
30
+ 'by-nd' => { :human_readable => 'Attribution No Derivatives 3.0 Unported',
31
+ :uri => 'https://creativecommons.org/licenses/by-nd/3.0/' },
32
+ 'by-nc' => { :human_readable => 'Attribution Non-Commercial 3.0 Unported',
33
+ :uri => 'https://creativecommons.org/licenses/by-nc/3.0/' },
32
34
  'by-nc-sa' => { :human_readable => 'Attribution Non-Commercial Share Alike 3.0 Unported',
33
35
  :uri => 'https://creativecommons.org/licenses/by-nc-sa/3.0/' },
34
36
  'by-nc-nd' => { :human_readable => 'Attribution Non-Commercial, No Derivatives 3.0 Unported',
35
37
  :uri => 'https://creativecommons.org/licenses/by-nc-nd/3.0/' },
36
- 'pdm' => { :human_readable => 'Public Domain Mark 1.0',
37
- :uri => 'https://creativecommons.org/publicdomain/mark/1.0/'}
38
+ 'pdm' => { :human_readable => 'Public Domain Mark 1.0',
39
+ :uri => 'https://creativecommons.org/publicdomain/mark/1.0/' }
38
40
  }.freeze
39
41
  OPEN_DATA_COMMONS_USE_LICENSES = {
40
- 'pddl' => { :human_readable => 'Open Data Commons Public Domain Dedication and License 1.0',
41
- :uri => 'http://opendatacommons.org/licenses/pddl/1.0/' },
42
- 'odc-by' => { :human_readable => 'Open Data Commons Attribution License 1.0',
43
- :uri => 'http://opendatacommons.org/licenses/by/1.0/' },
42
+ 'pddl' => { :human_readable => 'Open Data Commons Public Domain Dedication and License 1.0',
43
+ :uri => 'http://opendatacommons.org/licenses/pddl/1.0/' },
44
+ 'odc-by' => { :human_readable => 'Open Data Commons Attribution License 1.0',
45
+ :uri => 'http://opendatacommons.org/licenses/by/1.0/' },
44
46
  'odc-odbl' => { :human_readable => 'Open Data Commons Open Database License 1.0',
45
47
  :uri => 'http://opendatacommons.org/licenses/odbl/1.0/' }
46
48
  }.freeze
@@ -87,7 +89,7 @@ module Dor
87
89
  end
88
90
 
89
91
  def mods_title=(val)
90
- descMetadata.update_values({[:title_info, :main_title] => val})
92
+ descMetadata.update_values({ [:title_info, :main_title] => val })
91
93
  end
92
94
 
93
95
  # get all collections listed for this APO, used during registration
@@ -139,7 +141,7 @@ module Dor
139
141
  administrativeMetadata.ng_xml_will_change!
140
142
  administrativeMetadata.add_child_node(administrativeMetadata, :descMetadata)
141
143
  end
142
- administrativeMetadata.update_values({[:descMetadata, :source] => val})
144
+ administrativeMetadata.update_values({ [:descMetadata, :source] => val })
143
145
  end
144
146
 
145
147
  def use_statement
@@ -177,18 +179,21 @@ module Dor
177
179
  def use_license
178
180
  return creative_commons_license unless creative_commons_license.blank?
179
181
  return open_data_commons_license unless open_data_commons_license.blank?
182
+
180
183
  nil
181
184
  end
182
185
 
183
186
  def use_license_uri
184
187
  return defaultObjectRights.creative_commons.uri.first unless defaultObjectRights.creative_commons.uri.blank?
185
188
  return defaultObjectRights.open_data_commons.uri.first unless defaultObjectRights.open_data_commons.uri.blank?
189
+
186
190
  nil
187
191
  end
188
192
 
189
193
  def use_license_human
190
194
  return creative_commons_license_human unless creative_commons_license_human.blank?
191
195
  return open_data_commons_license_human unless open_data_commons_license_human.blank?
196
+
192
197
  nil
193
198
  end
194
199
 
@@ -293,7 +298,7 @@ module Dor
293
298
  administrativeMetadata.ng_xml_will_change!
294
299
  administrativeMetadata.add_child_node(administrativeMetadata.ng_xml.root, :metadata_format)
295
300
  end
296
- administrativeMetadata.update_values({[:metadata_format] => format})
301
+ administrativeMetadata.update_values({ [:metadata_format] => format })
297
302
  end
298
303
 
299
304
  def desc_metadata_source
@@ -306,7 +311,7 @@ module Dor
306
311
  administrativeMetadata.ng_xml_will_change!
307
312
  administrativeMetadata.add_child_node(administrativeMetadata.ng_xml.root, :metadata_source)
308
313
  end
309
- administrativeMetadata.update_values({[:metadata_source] => format})
314
+ administrativeMetadata.update_values({ [:metadata_source] => format })
310
315
  end
311
316
 
312
317
  # List of default workflows, used to provide choices at registration
@@ -319,6 +324,7 @@ module Dor
319
324
  # @param wf [String] the name of the workflow, ex. 'digitizationWF'
320
325
  def default_workflow=(wf)
321
326
  fail ArgumentError, 'Must have a valid workflow for default' if wf.blank?
327
+
322
328
  xml = administrativeMetadata.ng_xml
323
329
  administrativeMetadata.ng_xml_will_change!
324
330
  nodes = xml.search('//registration/workflow')
@@ -343,6 +349,7 @@ module Dor
343
349
 
344
350
  def agreement=(val)
345
351
  fail ArgumentError, 'agreement must have a valid druid' if val.blank?
352
+
346
353
  self.agreement_object = Dor.find val.to_s, :cast => true
347
354
  end
348
355
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Embargoable
3
5
  extend ActiveSupport::Concern
@@ -68,6 +70,7 @@ module Dor
68
70
  if new_date.past?
69
71
  raise ArgumentError, 'You cannot set the embargo date to a past date.'
70
72
  end
73
+
71
74
  updated = false
72
75
  rightsMetadata.ng_xml.search('//embargoReleaseDate').each do |node|
73
76
  node.content = new_date.beginning_of_day.utc.xmlschema
@@ -76,6 +79,7 @@ module Dor
76
79
  rightsMetadata.ng_xml_will_change!
77
80
  rightsMetadata.save
78
81
  raise 'No release date in rights metadata, cannot proceed!' unless updated
82
+
79
83
  embargoMetadata.ng_xml.xpath('//releaseDate').each do |node|
80
84
  node.content = new_date.beginning_of_day.utc.xmlschema
81
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Eventable
3
5
  extend ActiveSupport::Concern
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Geoable
3
5
  extend ActiveSupport::Concern
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Governable
3
5
  extend ActiveSupport::Concern
@@ -16,13 +18,14 @@ module Dor
16
18
  # and APO, or if the APO does not have a default_lane
17
19
  # @return [String] the lane id
18
20
  def default_workflow_lane
19
- return 'default' if admin_policy_object.nil? # TODO: log warning?
21
+ return 'default' if admin_policy_object.nil? # TODO: log warning?
20
22
 
21
23
  admin_md = admin_policy_object.datastreams['administrativeMetadata']
22
24
  return 'default' unless admin_md.respond_to?(:default_workflow_lane) # Some APOs don't have this datastream
23
25
 
24
26
  lane = admin_md.default_workflow_lane
25
27
  return 'default' if lane.blank?
28
+
26
29
  lane
27
30
  end
28
31
 
@@ -81,8 +84,10 @@ module Dor
81
84
  def rights
82
85
  return nil unless self.respond_to? :rightsMetadata
83
86
  return nil if rightsMetadata.nil?
87
+
84
88
  xml = rightsMetadata.ng_xml
85
- return nil if xml.search('//rightsMetadata').length != 1 # ORLY?
89
+ return nil if xml.search('//rightsMetadata').length != 1 # ORLY?
90
+
86
91
  if xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length == 1
87
92
  'Stanford'
88
93
  elsif xml.search('//rightsMetadata/access[@type=\'read\']/machine/world').length == 1
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Identifiable
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  # ids for previous and current catkeys
6
- CATKEY_TYPE_ID = 'catkey'.freeze
7
- PREVIOUS_CATKEY_TYPE_ID = 'previous_catkey'.freeze
8
+ CATKEY_TYPE_ID = 'catkey'
9
+ PREVIOUS_CATKEY_TYPE_ID = 'previous_catkey'
8
10
 
9
11
  included do
10
12
  has_metadata :name => 'DC', :type => SimpleDublinCoreDs, :label => 'Dublin Core Record for self object'
@@ -22,6 +24,7 @@ module Dor
22
24
  # than the default Fedora sequence
23
25
  def assign_pid(_obj)
24
26
  return Dor::SuriService.mint_id if Dor::Config.suri.mint_ids
27
+
25
28
  super
26
29
  end
27
30
  end
@@ -33,7 +36,7 @@ module Dor
33
36
 
34
37
  # helper method to get just the content type tag
35
38
  def content_type_tag
36
- content_tag = tags.select {|tag| tag.include?('Process : Content Type')}
39
+ content_tag = tags.select { |tag| tag.include?('Process : Content Type') }
37
40
  content_tag.size == 1 ? content_tag[0].split(':').last.strip : ''
38
41
  end
39
42
 
@@ -62,7 +65,6 @@ module Dor
62
65
  # @param [String] catkey the new source identifier
63
66
  # @return [String] same value, as per Ruby assignment convention
64
67
  def catkey=(val)
65
-
66
68
  if val != catkey && !catkey.blank? # if there was already a catkey in the record, store that in the "previous" spot (assuming there is no change)
67
69
  identityMetadata.add_otherId("#{PREVIOUS_CATKEY_TYPE_ID}:#{catkey}")
68
70
  end
@@ -70,9 +72,9 @@ module Dor
70
72
  if val.blank? # if we are setting the catkey to blank, remove the node from XML
71
73
  remove_other_Id(CATKEY_TYPE_ID)
72
74
  elsif catkey.blank? # if there is no current catkey, then add it
73
- add_other_Id(CATKEY_TYPE_ID,val)
74
- elsif # if there is a current catkey, update the current catkey to the new value
75
- update_other_Id(CATKEY_TYPE_ID,val)
75
+ add_other_Id(CATKEY_TYPE_ID, val)
76
+ else # if there is a current catkey, update the current catkey to the new value
77
+ update_other_Id(CATKEY_TYPE_ID, val)
76
78
  end
77
79
 
78
80
  val
@@ -88,29 +90,30 @@ module Dor
88
90
  if identityMetadata.otherId(type).length > 0
89
91
  raise 'There is an existing entry for ' + type + ', consider using update_other_Id().'
90
92
  end
93
+
91
94
  identityMetadata.add_otherId(type + ':' + val)
92
95
  end
93
96
 
94
97
  def update_other_Id(type, new_val, val = nil)
95
98
  identityMetadata.ng_xml.search('//otherId[@name=\'' + type + '\']')
96
- .select { |node| val.nil? || node.content == val }
97
- .each { identityMetadata.ng_xml_will_change! }
98
- .each { |node| node.content = new_val }
99
- .any?
99
+ .select { |node| val.nil? || node.content == val }
100
+ .each { identityMetadata.ng_xml_will_change! }
101
+ .each { |node| node.content = new_val }
102
+ .any?
100
103
  end
101
104
 
102
105
  def remove_other_Id(type, val = nil)
103
106
  identityMetadata.ng_xml.search('//otherId[@name=\'' + type + '\']')
104
- .select { |node| val.nil? || node.content == val }
105
- .each { identityMetadata.ng_xml_will_change! }
106
- .each(&:remove)
107
- .any?
107
+ .select { |node| val.nil? || node.content == val }
108
+ .each { identityMetadata.ng_xml_will_change! }
109
+ .each(&:remove)
110
+ .any?
108
111
  end
109
112
 
110
113
  # turns a tag string into an array with one element per tag part.
111
114
  # split on ":", disregard leading and trailing whitespace on tokens.
112
115
  def split_tag_to_arr(tag_str)
113
- tag_str.split(':').map {|str| str.strip}
116
+ tag_str.split(':').map { |str| str.strip }
114
117
  end
115
118
 
116
119
  # turn a tag array back into a tag string with a standard format
@@ -136,6 +139,7 @@ module Dor
136
139
  if dupe_existing_tag
137
140
  raise "An existing tag (#{dupe_existing_tag}) is the same, consider using update_tag?"
138
141
  end
142
+
139
143
  normalized_tag
140
144
  end
141
145
 
@@ -147,9 +151,10 @@ module Dor
147
151
  if tag_arr.length < 2
148
152
  raise ArgumentError, "Invalid tag structure: tag '#{tag_str}' must have at least 2 elements"
149
153
  end
150
- if tag_arr.detect {|str| str.empty?}
154
+ if tag_arr.detect { |str| str.empty? }
151
155
  raise ArgumentError, "Invalid tag structure: tag '#{tag_str}' contains empty elements"
152
156
  end
157
+
153
158
  tag_arr
154
159
  end
155
160
 
@@ -164,25 +169,19 @@ module Dor
164
169
  def remove_tag(tag)
165
170
  normtag = normalize_tag(tag)
166
171
  identityMetadata.ng_xml.search('//tag')
167
- .select { |node| normalize_tag(node.content) == normtag }
168
- .each { identityMetadata.ng_xml_will_change! }
169
- .each(&:remove)
170
- .any?
172
+ .select { |node| normalize_tag(node.content) == normtag }
173
+ .each { identityMetadata.ng_xml_will_change! }
174
+ .each(&:remove)
175
+ .any?
171
176
  end
172
177
 
173
178
  def update_tag(old_tag, new_tag)
174
179
  normtag = normalize_tag(old_tag)
175
180
  identityMetadata.ng_xml.search('//tag')
176
- .select { |node| normalize_tag(node.content) == normtag }
177
- .each { identityMetadata.ng_xml_will_change! }
178
- .each { |node| node.content = normalize_tag(new_tag) }
179
- .any?
180
- end
181
-
182
- def get_related_obj_display_title(related_obj, default_title)
183
- return default_title unless related_obj
184
-
185
- related_obj.full_title || default_title
181
+ .select { |node| normalize_tag(node.content) == normtag }
182
+ .each { identityMetadata.ng_xml_will_change! }
183
+ .each { |node| node.content = normalize_tag(new_tag) }
184
+ .any?
186
185
  end
187
186
 
188
187
  # a regex that can be used to identify the last part of a druid (e.g. oo000oo0001)
@@ -199,9 +198,9 @@ module Dor
199
198
 
200
199
  # Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
201
200
  # @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
202
- def remove_druid_prefix(druid=id)
203
- result=druid.match(/#{pid_regex}/)
204
- result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
201
+ def remove_druid_prefix(druid = id)
202
+ result = druid.match(/#{pid_regex}/)
203
+ result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
205
204
  end
206
205
 
207
206
  # Override ActiveFedora::Core#adapt_to_cmodel (used with associations, among other places) to
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'uri'
3
5
 
@@ -9,13 +11,14 @@ module Dor
9
11
  has_metadata :name => 'contentMetadata', :type => Dor::ContentMetadataDS, :label => 'Content Metadata', :control_group => 'M'
10
12
  end
11
13
 
12
- DIFF_FILENAME = 'cm_inv_diff'.freeze
14
+ DIFF_FILENAME = 'cm_inv_diff'
13
15
 
14
16
  # Deletes all cm_inv_diff files in the workspace for the Item
15
17
  def clear_diff_cache
16
18
  if Dor::Config.stacks.local_workspace_root.nil?
17
19
  raise ArgumentError, 'Missing Dor::Config.stacks.local_workspace_root'
18
20
  end
21
+
19
22
  druid = DruidTools::Druid.new(pid, Dor::Config.stacks.local_workspace_root)
20
23
  diff_pattern = File.join(druid.temp_dir, DIFF_FILENAME + '.*')
21
24
  FileUtils.rm_f Dir.glob(diff_pattern)