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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cddc117f7297f0e5610b46e5ef181dba30fb0fcd57d7a4f21309cd68a5d5eee8
4
- data.tar.gz: 203483f92135bffbb04b40be6e4673153863eb305518f87922b8a7027797abe8
3
+ metadata.gz: '07199060c4d04ee110cd61aff79d908be4d75a4c9dc2393519b5a591490b15ea'
4
+ data.tar.gz: 8b7d431a98aafbad4ea03501ef1bbbc89ca0eee839f4b3d653ff4c97f0dd2c64
5
5
  SHA512:
6
- metadata.gz: 14cdd9ea0fa92d23c000de0f992209d9ceff820e143716b0c479ffde26c26c822c73f51f8d799e0ce6820f50beced8e2f0c69f0aca3266227a0341782f1a50ca
7
- data.tar.gz: 4056a91b565637a56a126c35998ddbf1f1a8653821587d1a4ddba823a33df82b3a626a6747b0bc6bd6b8bd0cd6efb4e42c82178a698fbca300b33e9782198d37
6
+ metadata.gz: 06ed4c473c5616f84d1beb3b877e0d4d5d860c0a4b13ecc9b91fbc519708392d78bca9a5cdcda31b63e1a9f17f994cd5c1e58f84d15eb72c4e6f05aebbbe46c8
7
+ data.tar.gz: 7ae86baac69973b6b1fd00ac04b7a9a6e4c4bb8dabc29979656897ff19c7dfc5f51ce8bc77f6683707afb391a27609c770f792b48d0cbe5b2795077db2425441
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_fedora'
2
4
  require 'active_fedora/version'
3
5
  require 'active_support/core_ext/module/attribute_accessors'
@@ -8,10 +10,9 @@ module Dor
8
10
  extend ActiveSupport::Autoload
9
11
  @@registered_classes = {}
10
12
  mattr_reader :registered_classes
11
- INDEX_VERSION_FIELD = 'dor_services_version_ssi'.freeze
13
+ INDEX_VERSION_FIELD = 'dor_services_version_ssi'
12
14
 
13
15
  class << self
14
-
15
16
  def configure(*args, &block)
16
17
  Dor::Config.configure *args, &block
17
18
  end
@@ -57,10 +58,10 @@ module Dor
57
58
  def logger
58
59
  require 'logger'
59
60
  @logger ||= if defined?(::Rails) && ::Rails.respond_to?(:logger)
60
- Rails.logger
61
- else
62
- Logger.new(STDOUT)
63
- end
61
+ Rails.logger
62
+ else
63
+ Logger.new(STDOUT)
64
+ end
64
65
  end
65
66
  end
66
67
 
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dor/rest_resource_factory'
2
4
  # Creates RestClient::Resources with client ssl keys for various connections
3
5
  module Dor
4
6
  class CertificateAuthenticatedRestResourceFactory < RestResourceFactory
5
-
6
7
  private
7
8
 
8
9
  # @return [Hash] options for creating a RestClient::Resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'confstruct/configuration'
2
4
  require 'rsolr'
3
5
  require 'yaml'
@@ -11,7 +13,7 @@ module Dor
11
13
 
12
14
  def initialize(*args)
13
15
  super *args
14
- run_callbacks(:initialize) { }
16
+ run_callbacks(:initialize) {}
15
17
  end
16
18
 
17
19
  # Call the super method with callbacks and with $VERBOSE temporarily disabled
@@ -48,7 +50,6 @@ module Dor
48
50
  end
49
51
  deprecation_deprecate :make_rest_client
50
52
 
51
-
52
53
  def make_solr_connection(add_opts = {})
53
54
  opts = Dor::Config.solr.opts.merge(add_opts).merge(
54
55
  :url => Dor::Config.solr.url
@@ -58,41 +59,41 @@ module Dor
58
59
 
59
60
  set_callback :initialize, :after do |config|
60
61
  config.deep_merge!({
61
- :fedora => {
62
- :client => Confstruct.deferred { |c| CertificateAuthenticatedRestResourceFactory.create(:fedora) },
63
- :safeurl => Confstruct.deferred { |c|
64
- begin
65
- fedora_uri = URI.parse(config.fedora.url)
66
- fedora_uri.user = fedora_uri.password = nil
67
- fedora_uri.to_s
68
- rescue URI::InvalidURIError
69
- nil
70
- end
71
- }
72
- },
73
- :dor_services => {
74
- :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:dor_services) }
75
- },
76
- :purl_services => {
77
- :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:purl_services) }
78
- },
79
- :sdr => {
80
- :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:sdr) }
81
- },
82
- :workflow => {
83
- :client => Confstruct.deferred do |c|
84
- Dor::WorkflowService.configure c.url, logger: c.client_logger, timeout: c.timeout, dor_services_url: config.dor_services.url
85
- Dor::WorkflowService
86
- end,
87
- :client_logger => Confstruct.deferred do |c|
88
- if c.logfile && c.shift_age
89
- Logger.new(c.logfile, c.shift_age)
90
- elsif c.logfile
91
- Logger.new(c.logfile)
92
- end
93
- end
94
- }
95
- })
62
+ :fedora => {
63
+ :client => Confstruct.deferred { |c| CertificateAuthenticatedRestResourceFactory.create(:fedora) },
64
+ :safeurl => Confstruct.deferred { |c|
65
+ begin
66
+ fedora_uri = URI.parse(config.fedora.url)
67
+ fedora_uri.user = fedora_uri.password = nil
68
+ fedora_uri.to_s
69
+ rescue URI::InvalidURIError
70
+ nil
71
+ end
72
+ }
73
+ },
74
+ :dor_services => {
75
+ :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:dor_services) }
76
+ },
77
+ :purl_services => {
78
+ :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:purl_services) }
79
+ },
80
+ :sdr => {
81
+ :rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:sdr) }
82
+ },
83
+ :workflow => {
84
+ :client => Confstruct.deferred do |c|
85
+ Dor::WorkflowService.configure c.url, logger: c.client_logger, timeout: c.timeout, dor_services_url: config.dor_services.url
86
+ Dor::WorkflowService
87
+ end,
88
+ :client_logger => Confstruct.deferred do |c|
89
+ if c.logfile && c.shift_age
90
+ Logger.new(c.logfile, c.shift_age)
91
+ elsif c.logfile
92
+ Logger.new(c.logfile)
93
+ end
94
+ end
95
+ }
96
+ })
96
97
  true
97
98
  end
98
99
 
@@ -1,124 +1,124 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
- class AdministrativeMetadataDS < ActiveFedora::OmDatastream
3
-
4
- set_terminology do |t|
5
- t.root :path => 'administrativeMetadata', :index_as => [:not_searchable]
6
- t.metadata_format :path => 'descMetadata/format'
7
- t.admin_metadata_format :path => 'descMetadata/format', :index_as => [:symbol]
8
- t.metadata_source :path => 'descMetadata/source', :index_as => [:symbol]
9
- t.descMetadata do
10
- t.source
11
- t.format
12
- end
13
- # Placeholders for existing defined stanzas to be fleshed out as needed
14
- t.contact :index_as => [:not_searchable]
15
- t.rights :index_as => [:not_searchable]
16
- t.relationships :index_as => [:not_searchable]
17
- t.registration :index_as => [:not_searchable] do
18
- t.agreementId
19
- t.itemTag
20
- t.workflow_id :path => 'workflow/@id', :index_as => [:symbol]
21
- t.default_collection :path => 'collection/@id'
22
- end
23
- t.workflow :path => 'registration/workflow'
24
- t.deposit :index_as => [:not_searchable]
4
+ class AdministrativeMetadataDS < ActiveFedora::OmDatastream
5
+ set_terminology do |t|
6
+ t.root :path => 'administrativeMetadata', :index_as => [:not_searchable]
7
+ t.metadata_format :path => 'descMetadata/format'
8
+ t.admin_metadata_format :path => 'descMetadata/format', :index_as => [:symbol]
9
+ t.metadata_source :path => 'descMetadata/source', :index_as => [:symbol]
10
+ t.descMetadata do
11
+ t.source
12
+ t.format
13
+ end
14
+ # Placeholders for existing defined stanzas to be fleshed out as needed
15
+ t.contact :index_as => [:not_searchable]
16
+ t.rights :index_as => [:not_searchable]
17
+ t.relationships :index_as => [:not_searchable]
18
+ t.registration :index_as => [:not_searchable] do
19
+ t.agreementId
20
+ t.itemTag
21
+ t.workflow_id :path => 'workflow/@id', :index_as => [:symbol]
22
+ t.default_collection :path => 'collection/@id'
23
+ end
24
+ t.workflow :path => 'registration/workflow'
25
+ t.deposit :index_as => [:not_searchable]
25
26
 
26
- t.accessioning :index_as => [:not_searchable] do
27
- t.workflow_id :path => 'workflow/@id', :index_as => [:symbol]
28
- end
27
+ t.accessioning :index_as => [:not_searchable] do
28
+ t.workflow_id :path => 'workflow/@id', :index_as => [:symbol]
29
+ end
29
30
 
30
- t.preservation :index_as => [:not_searchable]
31
- t.dissemination :index_as => [:not_searchable] do
32
- t.harvester
33
- t.releaseDelayLimit
34
- end
35
- t.defaults do
36
- t.initiate_workflow :path => 'initiateWorkflow' do
37
- t.lane :path => { :attribute => 'lane' }
31
+ t.preservation :index_as => [:not_searchable]
32
+ t.dissemination :index_as => [:not_searchable] do
33
+ t.harvester
34
+ t.releaseDelayLimit
38
35
  end
39
- t.shelving :path => 'shelving' do
40
- t.path :path => { :attribute => 'path'}
36
+ t.defaults do
37
+ t.initiate_workflow :path => 'initiateWorkflow' do
38
+ t.lane :path => { :attribute => 'lane' }
39
+ end
40
+ t.shelving :path => 'shelving' do
41
+ t.path :path => { :attribute => 'path' }
42
+ end
41
43
  end
42
44
  end
43
- end
44
45
 
45
- define_template :default_collection do |xml|
46
- xml.administrativeMetadata {
47
- xml.registration {
48
- xml.collection(:id => '')
46
+ define_template :default_collection do |xml|
47
+ xml.administrativeMetadata {
48
+ xml.registration {
49
+ xml.collection(:id => '')
50
+ }
49
51
  }
50
- }
51
- end
52
+ end
52
53
 
53
- define_template :agreementId do |xml|
54
- xml.administrativeMetadata {
55
- xml.registration {
56
- xml.agreementId
54
+ define_template :agreementId do |xml|
55
+ xml.administrativeMetadata {
56
+ xml.registration {
57
+ xml.agreementId
58
+ }
57
59
  }
58
- }
59
- end
60
-
61
- define_template :metadata_format do |xml|
62
- xml.descMetadata {
63
- xml.format
64
- }
65
- end
60
+ end
66
61
 
67
- define_template :metadata_source do |xml|
68
- xml.administrativeMetadata {
62
+ define_template :metadata_format do |xml|
69
63
  xml.descMetadata {
70
- xml.source
64
+ xml.format
71
65
  }
72
- }
73
- end
66
+ end
74
67
 
75
- define_template :registration do |xml|
76
- xml.administrativeMetadata {
77
- xml.registration {
78
- xml.workflow(:id => '')
68
+ define_template :metadata_source do |xml|
69
+ xml.administrativeMetadata {
70
+ xml.descMetadata {
71
+ xml.source
72
+ }
79
73
  }
80
- }
81
- end
74
+ end
82
75
 
83
- define_template :default_collection do |xml|
84
- xml.administrativeMetadata {
85
- xml.registration {
86
- xml.collection
76
+ define_template :registration do |xml|
77
+ xml.administrativeMetadata {
78
+ xml.registration {
79
+ xml.workflow(:id => '')
80
+ }
87
81
  }
88
- }
89
- end
82
+ end
90
83
 
91
- def self.xml_template
92
- Nokogiri::XML::Builder.new do |xml|
93
- xml.administrativeMetadata { }
94
- end.doc
95
- end
84
+ define_template :default_collection do |xml|
85
+ xml.administrativeMetadata {
86
+ xml.registration {
87
+ xml.collection
88
+ }
89
+ }
90
+ end
96
91
 
97
- #################################################################################
98
- # Convenience methods to get and set properties
99
- # Hides complexity/verbosity of OM TermOperators for simple, non-repeating values
100
- #################################################################################
92
+ def self.xml_template
93
+ Nokogiri::XML::Builder.new do |xml|
94
+ xml.administrativeMetadata {}
95
+ end.doc
96
+ end
101
97
 
102
- def default_workflow_lane=(lane)
103
- defaults.initiate_workflow.lane = lane
104
- end
98
+ #################################################################################
99
+ # Convenience methods to get and set properties
100
+ # Hides complexity/verbosity of OM TermOperators for simple, non-repeating values
101
+ #################################################################################
105
102
 
106
- def default_workflow_lane
107
- defaults.initiate_workflow.lane.first
108
- end
103
+ def default_workflow_lane=(lane)
104
+ defaults.initiate_workflow.lane = lane
105
+ end
109
106
 
110
- def default_shelving_path=(path)
111
- defaults.shelving.path = path
112
- end
107
+ def default_workflow_lane
108
+ defaults.initiate_workflow.lane.first
109
+ end
113
110
 
114
- def default_shelving_path
115
- defaults.shelving.path.first
116
- end
111
+ def default_shelving_path=(path)
112
+ defaults.shelving.path = path
113
+ end
117
114
 
118
- # maintain AF < 8 indexing behavior
119
- def prefix
120
- ''
121
- end
115
+ def default_shelving_path
116
+ defaults.shelving.path.first
117
+ end
122
118
 
123
- end
119
+ # maintain AF < 8 indexing behavior
120
+ def prefix
121
+ ''
122
+ end
123
+ end
124
124
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Dor
4
6
  class ContentMetadataDS < ActiveFedora::OmDatastream
5
-
6
7
  set_terminology do |t|
7
8
  t.root :path => 'contentMetadata', :index_as => [:not_searchable]
8
9
  t.contentType :path => '/contentMetadata/@type', :index_as => [:not_searchable]
@@ -27,7 +28,7 @@ module Dor
27
28
  t.type_ :path => { :attribute => 'type' }
28
29
  end
29
30
  end
30
- t.shelved_file(:path => 'file', :attributes => {:shelve => 'yes'}, :index_as => [:not_searchable]) do
31
+ t.shelved_file(:path => 'file', :attributes => { :shelve => 'yes' }, :index_as => [:not_searchable]) do
31
32
  t.id_ :path => { :attribute => 'id' }, :index_as => [:displayable, :stored_searchable]
32
33
  end
33
34
  end
@@ -45,6 +46,7 @@ module Dor
45
46
  len = node.length
46
47
  raise "#{xpath} not found" if len < 1
47
48
  raise "#{xpath} duplicated: #{len} found" if len != 1
49
+
48
50
  node.first
49
51
  end
50
52
 
@@ -105,15 +107,15 @@ module Dor
105
107
  file_roles << file['role'] if file['role']
106
108
  end
107
109
  end
108
- solr_doc['content_type_ssim' ] = doc.root['type']
109
- solr_doc['content_file_mimetypes_ssim' ] = mime_types.to_a
110
- solr_doc['content_file_count_itsi' ] = counts['content_file']
110
+ solr_doc['content_type_ssim'] = doc.root['type']
111
+ solr_doc['content_file_mimetypes_ssim'] = mime_types.to_a
112
+ solr_doc['content_file_count_itsi'] = counts['content_file']
111
113
  solr_doc['shelved_content_file_count_itsi'] = counts['shelved_file']
112
- solr_doc['resource_count_itsi' ] = counts['resource']
113
- solr_doc['preserved_size_dbtsi' ] = preserved_size # double (trie) to support very large sizes
114
- solr_doc['shelved_size_dbtsi' ] = shelved_size # double (trie) to support very large sizes
115
- solr_doc['resource_types_ssim' ] = resource_type_counts.keys if resource_type_counts.size > 0
116
- solr_doc['content_file_roles_ssim' ] = file_roles.to_a if file_roles.size > 0
114
+ solr_doc['resource_count_itsi'] = counts['resource']
115
+ solr_doc['preserved_size_dbtsi'] = preserved_size # double (trie) to support very large sizes
116
+ solr_doc['shelved_size_dbtsi'] = shelved_size # double (trie) to support very large sizes
117
+ solr_doc['resource_types_ssim'] = resource_type_counts.keys if resource_type_counts.size > 0
118
+ solr_doc['content_file_roles_ssim'] = file_roles.to_a if file_roles.size > 0
117
119
  resource_type_counts.each do |key, count|
118
120
  solr_doc["#{key}_resource_count_itsi"] = count
119
121
  end
@@ -131,24 +133,26 @@ module Dor
131
133
  def add_file(file, resource_name)
132
134
  resource_nodes = ng_xml.search('//resource[@id=\'' + resource_name + '\']')
133
135
  raise 'resource doesnt exist.' if resource_nodes.length == 0
136
+
134
137
  self.ng_xml_will_change!
135
138
 
136
139
  node = resource_nodes.first
137
140
  file_node = Nokogiri::XML::Node.new('file', ng_xml)
138
141
  file_node['id'] = file[:name]
139
- file_node['shelve' ] = file[:shelve ] ? file[:shelve ] : ''
140
- file_node['publish' ] = file[:publish ] ? file[:publish ] : ''
141
- file_node['preserve'] = file[:preserve] ? file[:preserve] : ''
142
+ file_node['shelve'] = file[:shelve] || ''
143
+ file_node['publish'] = file[:publish] || ''
144
+ file_node['preserve'] = file[:preserve] || ''
142
145
  node.add_child(file_node)
143
146
 
144
147
  [:md5, :sha1].each do |algo|
145
148
  next unless file[algo]
149
+
146
150
  checksum_node = Nokogiri::XML::Node.new('checksum', ng_xml)
147
151
  checksum_node['type'] = algo.to_s
148
152
  checksum_node.content = file[algo]
149
153
  file_node.add_child(checksum_node)
150
154
  end
151
- file_node['size' ] = file[:size ] if file[:size ]
155
+ file_node['size'] = file[:size] if file[:size]
152
156
  file_node['mimetype'] = file[:mime_type] if file[:mime_type]
153
157
  file_node['role'] = file[:role] if file[:role]
154
158
  file_node
@@ -186,6 +190,7 @@ module Dor
186
190
  # @return [Nokogiri::XML::Node] the new resource that was added to the contentMetadata
187
191
  def add_resource(files, resource_name, position, type = 'file')
188
192
  raise "resource #{resource_name} already exists" if ng_xml.search('//resource[@id=\'' + resource_name + '\']').length > 0
193
+
189
194
  self.ng_xml_will_change!
190
195
  max = ng_xml.search('//resource').map { |node| node['sequence'].to_i }.max
191
196
  # renumber all of the resources that will come after the newly added one
@@ -200,12 +205,13 @@ module Dor
200
205
  node['type'] = type
201
206
  files.each do |file|
202
207
  file_node = Nokogiri::XML::Node.new('file', ng_xml)
203
- %w(shelve publish preserve).each {|x| file_node[x] = file[x.to_sym] ? file[x.to_sym] : '' }
208
+ %w(shelve publish preserve).each { |x| file_node[x] = file[x.to_sym] || '' }
204
209
  file_node['id'] = file[:name]
205
210
  node.add_child(file_node)
206
211
 
207
212
  [:md5, :sha1].each { |algo|
208
213
  next if file[algo].nil?
214
+
209
215
  checksum_node = Nokogiri::XML::Node.new('checksum', ng_xml)
210
216
  checksum_node['type'] = algo.to_s
211
217
  checksum_node.content = file[algo]
@@ -227,6 +233,7 @@ module Dor
227
233
  loop do
228
234
  res = ng_xml.search('//resource[@sequence=\'' + position.to_s + '\']')
229
235
  break if res.length == 0
236
+
230
237
  res['sequence'] = position.to_s
231
238
  position += 1
232
239
  end
@@ -245,8 +252,8 @@ module Dor
245
252
  def update_attributes(file_name, publish, shelve, preserve, attributes = {})
246
253
  self.ng_xml_will_change!
247
254
  file_node = ng_xml.search('//file[@id=\'' + file_name + '\']').first
248
- file_node['publish' ] = publish
249
- file_node['shelve' ] = shelve
255
+ file_node['publish'] = publish
256
+ file_node['shelve'] = shelve
250
257
  file_node['preserve'] = preserve
251
258
  attributes.each do |key, value|
252
259
  file_node[key] = value
@@ -261,6 +268,7 @@ module Dor
261
268
  file_node['id'] = file[:name]
262
269
  [:md5, :sha1].each { |algo|
263
270
  next if file[algo].nil?
271
+
264
272
  checksum_node = ng_xml.search('//file[@id=\'' + old_file_id + '\']/checksum[@type=\'' + algo.to_s + '\']').first
265
273
  if checksum_node.nil?
266
274
  checksum_node = Nokogiri::XML::Node.new('checksum', ng_xml)
@@ -321,6 +329,7 @@ module Dor
321
329
  position = node['sequence'].to_i
322
330
  new_position = new_position.to_i # tolerate strings as a Legacy behavior
323
331
  return node if position == new_position
332
+
324
333
  # otherwise, is the resource being moved earlier in the sequence or later?
325
334
  up = new_position > position
326
335
  others = new_position..(up ? position - 1 : position + 1) # a range