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.
- checksums.yaml +4 -4
- data/lib/dor-services.rb +7 -6
- data/lib/dor/certificate_authenticated_rest_resource_factory.rb +2 -1
- data/lib/dor/config.rb +38 -37
- data/lib/dor/datastreams/administrative_metadata_ds.rb +98 -98
- data/lib/dor/datastreams/content_metadata_ds.rb +26 -17
- data/lib/dor/datastreams/datastream_spec_solrizer.rb +4 -2
- data/lib/dor/datastreams/default_object_rights_ds.rb +10 -7
- data/lib/dor/datastreams/desc_metadata_ds.rb +6 -6
- data/lib/dor/datastreams/embargo_metadata_ds.rb +94 -94
- data/lib/dor/datastreams/events_ds.rb +55 -54
- data/lib/dor/datastreams/geo_metadata_ds.rb +7 -6
- data/lib/dor/datastreams/identity_metadata_ds.rb +128 -125
- data/lib/dor/datastreams/provenance_metadata_ds.rb +3 -1
- data/lib/dor/datastreams/rights_metadata_ds.rb +4 -4
- data/lib/dor/datastreams/role_metadata_ds.rb +42 -42
- data/lib/dor/datastreams/simple_dublin_core_ds.rb +45 -43
- data/lib/dor/datastreams/technical_metadata_ds.rb +3 -1
- data/lib/dor/datastreams/version_metadata_ds.rb +12 -5
- data/lib/dor/datastreams/workflow_definition_ds.rb +74 -73
- data/lib/dor/datastreams/workflow_ds.rb +12 -7
- data/lib/dor/exceptions.rb +2 -0
- data/lib/dor/indexers/data_indexer.rb +16 -0
- data/lib/dor/indexers/describable_indexer.rb +2 -0
- data/lib/dor/indexers/editable_indexer.rb +2 -0
- data/lib/dor/indexers/identifiable_indexer.rb +23 -8
- data/lib/dor/indexers/processable_indexer.rb +2 -0
- data/lib/dor/indexers/releasable_indexer.rb +2 -0
- data/lib/dor/models/abstract.rb +2 -0
- data/lib/dor/models/admin_policy_object.rb +2 -0
- data/lib/dor/models/agreement.rb +2 -0
- data/lib/dor/models/collection.rb +3 -0
- data/lib/dor/models/concerns/assembleable.rb +2 -0
- data/lib/dor/models/concerns/contentable.rb +5 -2
- data/lib/dor/models/concerns/describable.rb +7 -2
- data/lib/dor/models/concerns/editable.rb +28 -21
- data/lib/dor/models/concerns/embargoable.rb +4 -0
- data/lib/dor/models/concerns/eventable.rb +2 -0
- data/lib/dor/models/concerns/geoable.rb +2 -0
- data/lib/dor/models/concerns/governable.rb +7 -2
- data/lib/dor/models/concerns/identifiable.rb +33 -34
- data/lib/dor/models/concerns/itemizable.rb +4 -1
- data/lib/dor/models/concerns/preservable.rb +2 -0
- data/lib/dor/models/concerns/processable.rb +15 -9
- data/lib/dor/models/concerns/publishable.rb +9 -4
- data/lib/dor/models/concerns/releaseable.rb +21 -11
- data/lib/dor/models/concerns/rightsable.rb +2 -0
- data/lib/dor/models/concerns/shelvable.rb +6 -2
- data/lib/dor/models/concerns/versionable.rb +8 -4
- data/lib/dor/models/item.rb +2 -0
- data/lib/dor/models/set.rb +2 -0
- data/lib/dor/models/workflow_object.rb +5 -1
- data/lib/dor/rest_resource_factory.rb +2 -0
- data/lib/dor/services/cleanup_reset_service.rb +2 -1
- data/lib/dor/services/cleanup_service.rb +2 -1
- data/lib/dor/services/digital_stacks_service.rb +3 -1
- data/lib/dor/services/indexing_service.rb +3 -1
- data/lib/dor/services/merge_service.rb +6 -4
- data/lib/dor/services/metadata_handlers/catalog_handler.rb +2 -0
- data/lib/dor/services/metadata_service.rb +4 -4
- data/lib/dor/services/public_desc_metadata_service.rb +16 -8
- data/lib/dor/services/public_xml_service.rb +7 -4
- data/lib/dor/services/registration_service.rb +25 -20
- data/lib/dor/services/reset_workspace_service.rb +4 -4
- data/lib/dor/services/sdr_ingest_service.rb +4 -2
- data/lib/dor/services/search_service.rb +8 -9
- data/lib/dor/services/suri_service.rb +3 -2
- data/lib/dor/services/technical_metadata_service.rb +15 -9
- data/lib/dor/services/thumbnail_service.rb +14 -10
- data/lib/dor/utils/hydrus_shims.rb +2 -0
- data/lib/dor/utils/ng_tidy.rb +3 -7
- data/lib/dor/utils/predicate_patch.rb +2 -0
- data/lib/dor/utils/sdr_client.rb +3 -0
- data/lib/dor/utils/solr_doc_helper.rb +4 -2
- data/lib/dor/version.rb +3 -1
- data/lib/dor/workflow/document.rb +113 -108
- data/lib/dor/workflow/process.rb +90 -87
- data/lib/tasks/rdoc.rake +4 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '07199060c4d04ee110cd61aff79d908be4d75a4c9dc2393519b5a591490b15ea'
|
4
|
+
data.tar.gz: 8b7d431a98aafbad4ea03501ef1bbbc89ca0eee839f4b3d653ff4c97f0dd2c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ed4c473c5616f84d1beb3b877e0d4d5d860c0a4b13ecc9b91fbc519708392d78bca9a5cdcda31b63e1a9f17f994cd5c1e58f84d15eb72c4e6f05aebbbe46c8
|
7
|
+
data.tar.gz: 7ae86baac69973b6b1fd00ac04b7a9a6e4c4bb8dabc29979656897ff19c7dfc5f51ce8bc77f6683707afb391a27609c770f792b48d0cbe5b2795077db2425441
|
data/lib/dor-services.rb
CHANGED
@@ -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'
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
data/lib/dor/config.rb
CHANGED
@@ -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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
27
|
+
t.accessioning :index_as => [:not_searchable] do
|
28
|
+
t.workflow_id :path => 'workflow/@id', :index_as => [:symbol]
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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.
|
40
|
-
t.
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
68
|
-
xml.administrativeMetadata {
|
62
|
+
define_template :metadata_format do |xml|
|
69
63
|
xml.descMetadata {
|
70
|
-
xml.
|
64
|
+
xml.format
|
71
65
|
}
|
72
|
-
|
73
|
-
end
|
66
|
+
end
|
74
67
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
84
|
+
define_template :default_collection do |xml|
|
85
|
+
xml.administrativeMetadata {
|
86
|
+
xml.registration {
|
87
|
+
xml.collection
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
96
91
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
92
|
+
def self.xml_template
|
93
|
+
Nokogiri::XML::Builder.new do |xml|
|
94
|
+
xml.administrativeMetadata {}
|
95
|
+
end.doc
|
96
|
+
end
|
101
97
|
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
103
|
+
def default_workflow_lane=(lane)
|
104
|
+
defaults.initiate_workflow.lane = lane
|
105
|
+
end
|
109
106
|
|
110
|
-
|
111
|
-
|
112
|
-
|
107
|
+
def default_workflow_lane
|
108
|
+
defaults.initiate_workflow.lane.first
|
109
|
+
end
|
113
110
|
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
def default_shelving_path=(path)
|
112
|
+
defaults.shelving.path = path
|
113
|
+
end
|
117
114
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
115
|
+
def default_shelving_path
|
116
|
+
defaults.shelving.path.first
|
117
|
+
end
|
122
118
|
|
123
|
-
|
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'
|
109
|
-
solr_doc['content_file_mimetypes_ssim'
|
110
|
-
solr_doc['content_file_count_itsi'
|
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'
|
113
|
-
solr_doc['preserved_size_dbtsi'
|
114
|
-
solr_doc['shelved_size_dbtsi'
|
115
|
-
solr_doc['resource_types_ssim'
|
116
|
-
solr_doc['content_file_roles_ssim'
|
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'
|
140
|
-
file_node['publish'
|
141
|
-
file_node['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'
|
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]
|
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'
|
249
|
-
file_node['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
|