rubydora 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +573 -0
- data/.travis.yml +6 -6
- data/Gemfile +2 -3
- data/README.md +86 -0
- data/Rakefile +22 -25
- data/VERSION +1 -1
- data/lib/rubydora.rb +3 -6
- data/lib/rubydora/array_with_callback.rb +4 -4
- data/lib/rubydora/audit_trail.rb +7 -7
- data/lib/rubydora/callbacks.rb +9 -9
- data/lib/rubydora/datastream.rb +43 -39
- data/lib/rubydora/digital_object.rb +31 -33
- data/lib/rubydora/fc3_service.rb +10 -14
- data/lib/rubydora/fedora_url_helpers.rb +21 -22
- data/lib/rubydora/models_mixin.rb +4 -4
- data/lib/rubydora/profile_parser.rb +8 -8
- data/lib/rubydora/relationships_mixin.rb +15 -16
- data/lib/rubydora/repository.rb +11 -11
- data/lib/rubydora/resource_index.rb +10 -14
- data/lib/rubydora/rest_api_client.rb +52 -53
- data/lib/rubydora/transactions.rb +42 -51
- data/rubydora.gemspec +25 -25
- data/spec/audit_trail_spec.rb +1 -1
- data/spec/lib/datastream_spec.rb +34 -32
- data/spec/lib/digital_object_spec.rb +13 -10
- data/spec/lib/integration_test_spec.rb +116 -119
- data/spec/lib/profile_parser_spec.rb +1 -1
- data/spec/lib/repository_spec.rb +5 -5
- data/spec/lib/rest_api_client_spec.rb +60 -66
- data/spec/lib/transactions_spec.rb +4 -6
- data/spec/spec_helper.rb +2 -9
- metadata +30 -31
- data/.gitmodules +0 -0
- data/README.rdoc +0 -79
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -1,6 +1,6 @@
|
|
1
1
|
module Rubydora
|
2
2
|
#
|
3
|
-
# This model inject RELS-EXT-based helper methods
|
3
|
+
# This model inject RELS-EXT-based helper methods
|
4
4
|
# for Fedora objects
|
5
5
|
#
|
6
6
|
module RelationshipsMixin
|
@@ -32,9 +32,9 @@ module Rubydora
|
|
32
32
|
# generate accessor methods for each RELS_EXT property
|
33
33
|
def self.included(base)
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# FIXME: ugly, but functional..
|
36
|
+
RELS_EXT.each do |name, property|
|
37
|
+
base.class_eval <<-RUBY
|
38
38
|
def #{name.to_s} args = {}
|
39
39
|
relationships[:#{name}] = nil if args.delete(:refetch)
|
40
40
|
relationships[:#{name}] ||= relationship('#{property}', args)
|
@@ -49,9 +49,9 @@ module Rubydora
|
|
49
49
|
arr
|
50
50
|
end
|
51
51
|
RUBY
|
52
|
-
|
52
|
+
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
##
|
56
56
|
# Provides an accessor to the `predicate` RELS-EXT relationship
|
57
57
|
# Using ArrayWithCallback, will commit any changes to Fedora
|
@@ -60,14 +60,13 @@ module Rubydora
|
|
60
60
|
# @param [Hash] args
|
61
61
|
# @option args [Array] :values if nil, will query the resource index for related objects
|
62
62
|
# @return [ArrayWithCallback<Rubydora::DigitalObject>] an array that will call the #relationship_changed callback when values are modified
|
63
|
-
def relationship
|
63
|
+
def relationship(predicate, args = {})
|
64
64
|
arr = ArrayWithCallback.new(args[:values] || repository.find_by_sparql_relationship(fqpid, predicate))
|
65
|
-
arr.on_change << lambda { |arr, diff| relationship_changed(predicate, diff, arr) }
|
65
|
+
arr.on_change << lambda { |arr, diff| relationship_changed(predicate, diff, arr) }
|
66
66
|
|
67
67
|
arr
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
70
|
##
|
72
71
|
# Given a predicate and a diff between before and after states
|
73
72
|
# commit the appropriate changes to Fedora
|
@@ -77,24 +76,24 @@ module Rubydora
|
|
77
76
|
# @option diff [Hash] :+ additions
|
78
77
|
# @option diff [Hash] :- deletions
|
79
78
|
# @param [Array] arr the current relationship state
|
80
|
-
def relationship_changed
|
79
|
+
def relationship_changed(predicate, diff, arr = [])
|
81
80
|
diff[:+] ||= []
|
82
81
|
diff[:-] ||= []
|
83
82
|
|
84
|
-
diff[:+].each do |o|
|
83
|
+
diff[:+].each do |o|
|
85
84
|
add_relationship(predicate, o)
|
86
|
-
end
|
85
|
+
end
|
87
86
|
|
88
|
-
diff[:-].each do |o|
|
87
|
+
diff[:-].each do |o|
|
89
88
|
purge_relationship(predicate, o)
|
90
|
-
end
|
89
|
+
end
|
91
90
|
end
|
92
91
|
|
93
92
|
# Add a relationship for this object
|
94
93
|
# @param [String] predicate
|
95
94
|
# @param [String, Rubydora::DigitalObject] object
|
96
95
|
# @return self
|
97
|
-
def add_relationship
|
96
|
+
def add_relationship(predicate, object)
|
98
97
|
obj_uri = (( object.fqpid if object.respond_to? :fqpid ) || ( object.uri if object.respond_to? :uri ) || (object.to_s if object.respond_to? :to_s?) || object )
|
99
98
|
repository.add_relationship :subject => fqpid, :predicate => predicate, :object => obj_uri
|
100
99
|
self
|
@@ -104,7 +103,7 @@ module Rubydora
|
|
104
103
|
# @param [String] predicate
|
105
104
|
# @param [String, Rubydora::DigitalObject] object
|
106
105
|
# @return self
|
107
|
-
def purge_relationship
|
106
|
+
def purge_relationship(predicate, object)
|
108
107
|
obj_uri = (( object.fqpid if object.respond_to? :fqpid ) || ( object.uri if object.respond_to? :uri ) || (object.to_s if object.respond_to? :to_s?) || object )
|
109
108
|
repository.purge_relationship :subject => fqpid, :predicate => predicate, :object => obj_uri
|
110
109
|
end
|
data/lib/rubydora/repository.rb
CHANGED
@@ -31,18 +31,18 @@ module Rubydora
|
|
31
31
|
# @option options [String] :user
|
32
32
|
# @option options [String] :password
|
33
33
|
# @option options [Boolean] :validateChecksum
|
34
|
-
def initialize
|
34
|
+
def initialize(options = {}, api = nil)
|
35
35
|
@config = options.symbolize_keys
|
36
36
|
@api = api if api
|
37
37
|
check_repository_version!
|
38
38
|
end
|
39
39
|
|
40
40
|
# {include:DigitalObject.find}
|
41
|
-
def find
|
41
|
+
def find(pid)
|
42
42
|
DigitalObject.find(pid, self)
|
43
43
|
end
|
44
44
|
|
45
|
-
def find_or_initialize
|
45
|
+
def find_or_initialize(pid)
|
46
46
|
DigitalObject.find_or_initialize(pid, self)
|
47
47
|
end
|
48
48
|
|
@@ -51,22 +51,22 @@ module Rubydora
|
|
51
51
|
# @params [String] query
|
52
52
|
# @params [Hash] options
|
53
53
|
# @yield [DigitalObject] Yield a DigitalObject for each search result, skipping forbidden objects
|
54
|
-
def search
|
54
|
+
def search(query, options = {}, &block)
|
55
55
|
return to_enum(:search, query, options).to_a unless block_given?
|
56
|
-
|
57
|
-
sessionToken = nil
|
56
|
+
|
57
|
+
sessionToken = nil
|
58
58
|
doc = nil
|
59
59
|
|
60
|
-
begin
|
60
|
+
begin
|
61
61
|
sessionOptions = {}
|
62
|
-
sessionOptions[:sessionToken] = sessionToken unless sessionToken.nil?
|
62
|
+
sessionOptions[:sessionToken] = sessionToken unless sessionToken.nil? || sessionToken.blank?
|
63
63
|
|
64
64
|
response = self.find_objects(options.merge(:query => query, :resultFormat => 'xml', :pid => true).merge(sessionOptions))
|
65
65
|
|
66
66
|
doc = Nokogiri::XML(response)
|
67
67
|
doc.xpath('//xmlns:objectFields/xmlns:pid', doc.namespaces).each do |pid|
|
68
68
|
begin
|
69
|
-
obj = self.find(pid.text)
|
69
|
+
obj = self.find(pid.text)
|
70
70
|
rescue RestClient::Unauthorized
|
71
71
|
next
|
72
72
|
end
|
@@ -74,12 +74,12 @@ module Rubydora
|
|
74
74
|
end
|
75
75
|
|
76
76
|
sessionToken = doc.xpath('//xmlns:listSession/xmlns:token', doc.namespaces).text
|
77
|
-
end until sessionToken.nil?
|
77
|
+
end until sessionToken.nil? || sessionToken.empty? || doc.xpath('//xmlns:resultList/xmlns:objectFields', doc.namespaces).empty?
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
81
|
# {include:DigitalObject.create}
|
82
|
-
def create
|
82
|
+
def create(pid, options = {})
|
83
83
|
DigitalObject.create(pid, options = {}, self)
|
84
84
|
end
|
85
85
|
|
@@ -5,45 +5,41 @@ module Rubydora
|
|
5
5
|
module ResourceIndex
|
6
6
|
# Find new objects using a sparql query
|
7
7
|
# @param [String] query SPARQL query
|
8
|
-
# @param [Hash] options
|
8
|
+
# @param [Hash] options
|
9
9
|
# @option options [String] :binding the SPARQL binding name to create new objects from
|
10
10
|
# @return [Array<Rubydora::DigitalObject>]
|
11
|
-
def find_by_sparql
|
11
|
+
def find_by_sparql(query, options = { :binding => 'pid' })
|
12
12
|
return to_enum(:find_by_sparql, query, options).to_a unless block_given?
|
13
13
|
|
14
|
-
self.sparql(query).each do |x|
|
14
|
+
self.sparql(query).each do |x|
|
15
15
|
obj = self.find(x[options[:binding]]) rescue nil
|
16
16
|
yield obj if obj
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
# Find new objects by their relationship to a subject
|
21
|
-
# @param [String] subject Subject URI
|
21
|
+
# @param [String] subject Subject URI
|
22
22
|
# @param [String] predicate Predicate URI
|
23
23
|
# @return [Array<Rubydora::DigitalObject>]
|
24
|
-
def find_by_sparql_relationship
|
24
|
+
def find_by_sparql_relationship(subject, predicate)
|
25
25
|
find_by_sparql <<-RELSEXT
|
26
26
|
SELECT ?pid FROM <#ri> WHERE {
|
27
|
-
<#{subject}> <#{predicate}> ?pid
|
27
|
+
<#{subject}> <#{predicate}> ?pid
|
28
28
|
}
|
29
29
|
RELSEXT
|
30
30
|
end
|
31
31
|
|
32
32
|
# Run a raw SPARQL query and return a FasterCSV object
|
33
33
|
# @param [String] query SPARQL query
|
34
|
-
# @return [
|
35
|
-
def sparql
|
36
|
-
|
37
|
-
FasterCSV.parse(self.risearch(query), :headers => true)
|
38
|
-
else
|
39
|
-
CSV.parse(self.risearch(query), :headers => true)
|
40
|
-
end
|
34
|
+
# @return [CSV::Table]
|
35
|
+
def sparql(query)
|
36
|
+
CSV.parse(self.risearch(query), :headers => true)
|
41
37
|
end
|
42
38
|
|
43
39
|
# Run a raw query against the Fedora risearch resource index
|
44
40
|
# @param [String] query
|
45
41
|
# @param [Hash] options
|
46
|
-
def risearch
|
42
|
+
def risearch(query, options = {})
|
47
43
|
request_params = { :dt => 'on', :format => 'CSV', :lang => 'sparql', :limit => nil, :query => query, :type => 'tuples' }.merge(options)
|
48
44
|
|
49
45
|
self.client['risearch'].post request_params
|
@@ -6,10 +6,10 @@ module Rubydora
|
|
6
6
|
|
7
7
|
# Provide low-level access to the Fedora Commons REST API
|
8
8
|
module RestApiClient
|
9
|
-
|
9
|
+
|
10
10
|
include Rubydora::FedoraUrlHelpers
|
11
11
|
extend ActiveSupport::Concern
|
12
|
-
include ActiveSupport::Benchmarkable
|
12
|
+
include ActiveSupport::Benchmarkable
|
13
13
|
extend Deprecation
|
14
14
|
|
15
15
|
DEFAULT_CONTENT_TYPE = "application/octet-stream"
|
@@ -19,7 +19,6 @@ module Rubydora
|
|
19
19
|
included do
|
20
20
|
include ActiveSupport::Rescuable
|
21
21
|
|
22
|
-
|
23
22
|
rescue_from RestClient::InternalServerError do |e|
|
24
23
|
if Rubydora.logger
|
25
24
|
Rubydora.logger.error e.response
|
@@ -49,13 +48,13 @@ module Rubydora
|
|
49
48
|
# @option config [String] :password
|
50
49
|
# @return [RestClient::Resource]
|
51
50
|
#TODO trap for these errors specifically: RestClient::Request::Unauthorized, Errno::ECONNREFUSED
|
52
|
-
def client
|
51
|
+
def client(config = {})
|
53
52
|
client_config = self.config.merge(config)
|
54
53
|
client_config.symbolize_keys!
|
55
|
-
if config.empty?
|
54
|
+
if config.empty? || @config_hash.nil? || (client_config.hash == @config_hash)
|
56
55
|
@config_hash = client_config.hash
|
57
56
|
url = client_config[:url]
|
58
|
-
client_config.delete_if { |k,v|
|
57
|
+
client_config.delete_if { |k,v| !VALID_CLIENT_OPTIONS.include?(k) }
|
59
58
|
client_config[:open_timeout] ||= client_config[:timeout]
|
60
59
|
@client ||= RestClient::Resource.new(url, client_config)
|
61
60
|
else
|
@@ -63,7 +62,7 @@ module Rubydora
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
def describe
|
65
|
+
def describe(options = {})
|
67
66
|
query_options = options.dup
|
68
67
|
query_options[:xml] ||= 'true'
|
69
68
|
client[describe_repository_url(query_options)].get
|
@@ -74,7 +73,7 @@ module Rubydora
|
|
74
73
|
# {include:RestApiClient::API_DOCUMENTATION}
|
75
74
|
# @param [Hash] options
|
76
75
|
# @return [String]
|
77
|
-
def next_pid
|
76
|
+
def next_pid(options = {})
|
78
77
|
query_options = options.dup
|
79
78
|
query_options[:format] ||= 'xml'
|
80
79
|
client[next_pid_url(query_options)].post nil
|
@@ -85,15 +84,15 @@ module Rubydora
|
|
85
84
|
# {include:RestApiClient::API_DOCUMENTATION}
|
86
85
|
# @param [Hash] options
|
87
86
|
# @return [String]
|
88
|
-
def find_objects
|
87
|
+
def find_objects(options = {}, &block_response)
|
89
88
|
query_options = options.dup
|
90
|
-
raise ArgumentError,"Cannot have both :terms and :query parameters" if query_options[:terms]
|
89
|
+
raise ArgumentError,"Cannot have both :terms and :query parameters" if query_options[:terms] && query_options[:query]
|
91
90
|
query_options[:resultFormat] ||= 'xml'
|
92
91
|
|
93
92
|
resource = client[find_objects_url(query_options)]
|
94
93
|
if block_given?
|
95
94
|
resource.query_options[:block_response] = block_response
|
96
|
-
end
|
95
|
+
end
|
97
96
|
return resource.get
|
98
97
|
rescue Exception => exception
|
99
98
|
rescue_with_handler(exception) || raise
|
@@ -103,20 +102,20 @@ module Rubydora
|
|
103
102
|
# @param [Hash] options
|
104
103
|
# @option options [String] :pid
|
105
104
|
# @return [String]
|
106
|
-
def object
|
105
|
+
def object(options = {})
|
107
106
|
query_options = options.dup
|
108
107
|
pid = query_options.delete(:pid)
|
109
108
|
query_options[:format] ||= 'xml'
|
110
109
|
client[object_url(pid, query_options)].get
|
111
110
|
rescue Exception => exception
|
112
|
-
|
111
|
+
rescue_with_handler(exception) || raise
|
113
112
|
end
|
114
113
|
|
115
114
|
# {include:RestApiClient::API_DOCUMENTATION}
|
116
115
|
# @param [Hash] options
|
117
116
|
# @option options [String] :pid
|
118
117
|
# @return [String]
|
119
|
-
def ingest
|
118
|
+
def ingest(options = {})
|
120
119
|
query_options = options.dup
|
121
120
|
pid = query_options.delete(:pid)
|
122
121
|
|
@@ -129,10 +128,10 @@ module Rubydora
|
|
129
128
|
run_hook :after_ingest, :pid => assigned_pid, :file => file, :options => options
|
130
129
|
assigned_pid
|
131
130
|
rescue Exception => exception
|
132
|
-
|
131
|
+
rescue_with_handler(exception) || raise
|
133
132
|
end
|
134
133
|
|
135
|
-
def mint_pid_and_ingest
|
134
|
+
def mint_pid_and_ingest(options = {})
|
136
135
|
query_options = options.dup
|
137
136
|
file = query_options.delete(:file)
|
138
137
|
|
@@ -140,74 +139,74 @@ module Rubydora
|
|
140
139
|
run_hook :after_ingest, :pid => assigned_pid, :file => file, :options => options
|
141
140
|
assigned_pid
|
142
141
|
rescue Exception => exception
|
143
|
-
|
142
|
+
rescue_with_handler(exception) || raise
|
144
143
|
end
|
145
144
|
|
146
145
|
# {include:RestApiClient::API_DOCUMENTATION}
|
147
146
|
# @param [Hash] options
|
148
147
|
# @option options [String] :pid
|
149
148
|
# @return [String]
|
150
|
-
def export
|
149
|
+
def export(options = {})
|
151
150
|
query_options = options.dup
|
152
151
|
pid = query_options.delete(:pid)
|
153
152
|
raise ArgumentError, "Must have a pid" unless pid
|
154
153
|
client[export_object_url(pid, query_options)].get
|
155
154
|
rescue Exception => exception
|
156
|
-
|
155
|
+
rescue_with_handler(exception) || raise
|
157
156
|
end
|
158
157
|
|
159
158
|
# {include:RestApiClient::API_DOCUMENTATION}
|
160
159
|
# @param [Hash] options
|
161
160
|
# @option options [String] :pid
|
162
161
|
# @return [String]
|
163
|
-
def modify_object
|
162
|
+
def modify_object(options = {})
|
164
163
|
query_options = options.dup
|
165
164
|
pid = query_options.delete(:pid)
|
166
165
|
run_hook :before_modify_object, :pid => pid, :options => options
|
167
166
|
ProfileParser.canonicalize_date_string(client[object_url(pid, query_options)].put(nil))
|
168
167
|
rescue Exception => exception
|
169
|
-
|
168
|
+
rescue_with_handler(exception) || raise
|
170
169
|
end
|
171
170
|
|
172
171
|
# {include:RestApiClient::API_DOCUMENTATION}
|
173
172
|
# @param [Hash] options
|
174
173
|
# @option options [String] :pid
|
175
174
|
# @return [String]
|
176
|
-
def purge_object
|
175
|
+
def purge_object(options = {})
|
177
176
|
query_options = options.dup
|
178
177
|
pid = query_options.delete(:pid)
|
179
178
|
run_hook :before_purge_object, :pid => pid, :options => options
|
180
179
|
client[object_url(pid, query_options)].delete
|
181
180
|
rescue Exception => exception
|
182
|
-
|
181
|
+
rescue_with_handler(exception) || raise
|
183
182
|
end
|
184
183
|
|
185
184
|
# {include:RestApiClient::API_DOCUMENTATION}
|
186
185
|
# @param [Hash] options
|
187
186
|
# @option options [String] :pid
|
188
187
|
# @return [String]
|
189
|
-
def object_versions
|
188
|
+
def object_versions(options = {})
|
190
189
|
query_options = options.dup
|
191
190
|
pid = query_options.delete(:pid)
|
192
191
|
query_options[:format] ||= 'xml'
|
193
192
|
raise ArgumentError, "Must have a pid" unless pid
|
194
193
|
client[object_versions_url(pid, query_options)].get
|
195
194
|
rescue Exception => exception
|
196
|
-
|
195
|
+
rescue_with_handler(exception) || raise
|
197
196
|
end
|
198
197
|
|
199
198
|
# {include:RestApiClient::API_DOCUMENTATION}
|
200
199
|
# @param [Hash] options
|
201
200
|
# @option options [String] :pid
|
202
201
|
# @return [String]
|
203
|
-
def object_xml
|
202
|
+
def object_xml(options = {})
|
204
203
|
query_options = options.dup
|
205
204
|
pid = query_options.delete(:pid)
|
206
205
|
raise ArgumentError, "Missing required parameter :pid" unless pid
|
207
206
|
query_options[:format] ||= 'xml'
|
208
207
|
client[object_xml_url(pid, query_options)].get
|
209
208
|
rescue Exception => exception
|
210
|
-
|
209
|
+
rescue_with_handler(exception) || raise
|
211
210
|
end
|
212
211
|
|
213
212
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -217,7 +216,7 @@ module Rubydora
|
|
217
216
|
# @option options [String] :asOfDateTime
|
218
217
|
# @option options [String] :validateChecksum
|
219
218
|
# @return [String]
|
220
|
-
def datastream
|
219
|
+
def datastream(options = {})
|
221
220
|
query_options = options.dup
|
222
221
|
pid = query_options.delete(:pid)
|
223
222
|
dsid = query_options.delete(:dsid)
|
@@ -239,10 +238,10 @@ module Rubydora
|
|
239
238
|
Rubydora.logger.error "Unauthorized at #{client.url}/#{datastream_url(pid, dsid, query_options)}" if Rubydora.logger
|
240
239
|
raise e
|
241
240
|
rescue Exception => exception
|
242
|
-
|
241
|
+
rescue_with_handler(exception) || raise
|
243
242
|
end
|
244
243
|
|
245
|
-
def datastreams
|
244
|
+
def datastreams(options = {})
|
246
245
|
unless options[:dsid].nil?
|
247
246
|
#raise ArgumentError, "Missing required parameter :dsid" unless dsid
|
248
247
|
Deprecation.warn(RestApiClient, "Calling Rubydora::RestApiClient#datastreams with a :dsid is deprecated, use #datastream instead")
|
@@ -262,7 +261,7 @@ module Rubydora
|
|
262
261
|
Rubydora.logger.error "Unauthorized at #{client.url}/#{datastreams_url(pid, query_options)}" if Rubydora.logger
|
263
262
|
raise e
|
264
263
|
rescue Exception => exception
|
265
|
-
|
264
|
+
rescue_with_handler(exception) || raise
|
266
265
|
|
267
266
|
end
|
268
267
|
|
@@ -271,14 +270,14 @@ module Rubydora
|
|
271
270
|
# @option options [String] :pid
|
272
271
|
# @option options [String] :dsid
|
273
272
|
# @return [String]
|
274
|
-
def set_datastream_options
|
273
|
+
def set_datastream_options(options = {})
|
275
274
|
query_options = options.dup
|
276
275
|
pid = query_options.delete(:pid)
|
277
276
|
dsid = query_options.delete(:dsid)
|
278
277
|
run_hook :before_set_datastream_options, :pid => pid, :dsid => dsid, :options => options
|
279
278
|
client[datastream_url(pid, dsid, query_options)].put nil
|
280
279
|
rescue Exception => exception
|
281
|
-
|
280
|
+
rescue_with_handler(exception) || raise
|
282
281
|
end
|
283
282
|
|
284
283
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -286,7 +285,7 @@ module Rubydora
|
|
286
285
|
# @option options [String] :pid
|
287
286
|
# @option options [String] :dsid
|
288
287
|
# @return [String]
|
289
|
-
def datastream_versions
|
288
|
+
def datastream_versions(options = {})
|
290
289
|
query_options = options.dup
|
291
290
|
pid = query_options.delete(:pid)
|
292
291
|
dsid = query_options.delete(:dsid)
|
@@ -297,7 +296,7 @@ module Rubydora
|
|
297
296
|
#404 Resource Not Found: No datastream history could be found. There is no datastream history for the digital object "changeme:1" with datastream ID of "descMetadata
|
298
297
|
return nil
|
299
298
|
rescue Exception => exception
|
300
|
-
|
299
|
+
rescue_with_handler(exception) || raise
|
301
300
|
end
|
302
301
|
|
303
302
|
alias_method :datastream_history, :datastream_versions
|
@@ -307,7 +306,7 @@ module Rubydora
|
|
307
306
|
# @option options [String] :pid
|
308
307
|
# @option options [String] :dsid
|
309
308
|
# @return [String]
|
310
|
-
def datastream_dissemination
|
309
|
+
def datastream_dissemination(options = {}, &block_response)
|
311
310
|
query_options = options.dup
|
312
311
|
pid = query_options.delete(:pid)
|
313
312
|
dsid = query_options.delete(:dsid)
|
@@ -325,7 +324,7 @@ module Rubydora
|
|
325
324
|
end
|
326
325
|
val
|
327
326
|
rescue Exception => exception
|
328
|
-
|
327
|
+
rescue_with_handler(exception) || raise
|
329
328
|
end
|
330
329
|
|
331
330
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -333,7 +332,7 @@ module Rubydora
|
|
333
332
|
# @option options [String] :pid
|
334
333
|
# @option options [String] :dsid
|
335
334
|
# @return [String]
|
336
|
-
def add_datastream
|
335
|
+
def add_datastream(options = {})
|
337
336
|
query_options = options.dup
|
338
337
|
pid = query_options.delete(:pid)
|
339
338
|
dsid = query_options.delete(:dsid)
|
@@ -344,7 +343,7 @@ module Rubydora
|
|
344
343
|
file.rewind if file.respond_to?(:rewind)
|
345
344
|
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].post(str, :content_type => content_type.to_s, :multipart => true))
|
346
345
|
rescue Exception => exception
|
347
|
-
|
346
|
+
rescue_with_handler(exception) || raise
|
348
347
|
end
|
349
348
|
|
350
349
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -352,7 +351,7 @@ module Rubydora
|
|
352
351
|
# @option options [String] :pid
|
353
352
|
# @option options [String] :dsid
|
354
353
|
# @return [String]
|
355
|
-
def modify_datastream
|
354
|
+
def modify_datastream(options = {})
|
356
355
|
query_options = options.dup
|
357
356
|
pid = query_options.delete(:pid)
|
358
357
|
dsid = query_options.delete(:dsid)
|
@@ -370,7 +369,7 @@ module Rubydora
|
|
370
369
|
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].put(str, rest_client_options))
|
371
370
|
|
372
371
|
rescue Exception => exception
|
373
|
-
|
372
|
+
rescue_with_handler(exception) || raise
|
374
373
|
end
|
375
374
|
|
376
375
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -378,54 +377,54 @@ module Rubydora
|
|
378
377
|
# @option options [String] :pid
|
379
378
|
# @option options [String] :dsid
|
380
379
|
# @return [String]
|
381
|
-
def purge_datastream
|
380
|
+
def purge_datastream(options = {})
|
382
381
|
query_options = options.dup
|
383
382
|
pid = query_options.delete(:pid)
|
384
383
|
dsid = query_options.delete(:dsid)
|
385
384
|
run_hook :before_purge_datastream, :pid => pid, :dsid => dsid
|
386
385
|
client[datastream_url(pid, dsid, query_options)].delete
|
387
386
|
rescue Exception => exception
|
388
|
-
|
387
|
+
rescue_with_handler(exception) || raise
|
389
388
|
end
|
390
389
|
|
391
390
|
# {include:RestApiClient::API_DOCUMENTATION}
|
392
391
|
# @param [Hash] options
|
393
392
|
# @option options [String] :pid
|
394
393
|
# @return [String]
|
395
|
-
def relationships
|
394
|
+
def relationships(options = {})
|
396
395
|
query_options = options.dup
|
397
396
|
pid = query_options.delete(:pid) || query_options[:subject]
|
398
397
|
raise ArgumentError, "Missing required parameter :pid" unless pid
|
399
398
|
query_options[:format] ||= 'xml'
|
400
399
|
client[object_relationship_url(pid, query_options)].get
|
401
400
|
rescue Exception => exception
|
402
|
-
|
401
|
+
rescue_with_handler(exception) || raise
|
403
402
|
end
|
404
403
|
|
405
404
|
# {include:RestApiClient::API_DOCUMENTATION}
|
406
405
|
# @param [Hash] options
|
407
406
|
# @option options [String] :pid
|
408
407
|
# @return [String]
|
409
|
-
def add_relationship
|
408
|
+
def add_relationship(options = {})
|
410
409
|
query_options = options.dup
|
411
410
|
pid = query_options.delete(:pid) || query_options[:subject]
|
412
411
|
run_hook :before_add_relationship, :pid => pid, :options => options
|
413
412
|
client[new_object_relationship_url(pid, query_options)].post nil
|
414
413
|
rescue Exception => exception
|
415
|
-
|
414
|
+
rescue_with_handler(exception) || raise
|
416
415
|
end
|
417
416
|
|
418
417
|
# {include:RestApiClient::API_DOCUMENTATION}
|
419
418
|
# @param [Hash] options
|
420
419
|
# @option options [String] :pid
|
421
420
|
# @return [String]
|
422
|
-
def purge_relationship
|
421
|
+
def purge_relationship(options = {})
|
423
422
|
query_options = options.dup
|
424
423
|
pid = query_options.delete(:pid) || query_options[:subject]
|
425
424
|
run_hook :before_purge_relationship, :pid => pid, :options => options
|
426
425
|
client[object_relationship_url(pid, query_options)].delete
|
427
426
|
rescue Exception => exception
|
428
|
-
|
427
|
+
rescue_with_handler(exception) || raise
|
429
428
|
end
|
430
429
|
|
431
430
|
# {include:RestApiClient::API_DOCUMENTATION}
|
@@ -434,12 +433,12 @@ module Rubydora
|
|
434
433
|
# @option options [String] :sdef
|
435
434
|
# @option options [String] :method
|
436
435
|
# @return [String]
|
437
|
-
def dissemination
|
436
|
+
def dissemination(options = {}, &block_response)
|
438
437
|
query_options = options.dup
|
439
438
|
pid = query_options.delete(:pid)
|
440
439
|
sdef = query_options.delete(:sdef)
|
441
440
|
method = query_options.delete(:method)
|
442
|
-
query_options[:format] ||= 'xml' unless pid
|
441
|
+
query_options[:format] ||= 'xml' unless pid && sdef && method
|
443
442
|
if block_given?
|
444
443
|
resource = safe_subresource(dissemination_url(pid,sdef,method,query_options), :block_response => block_response)
|
445
444
|
else
|
@@ -448,10 +447,10 @@ module Rubydora
|
|
448
447
|
resource.get
|
449
448
|
|
450
449
|
rescue Exception => exception
|
451
|
-
|
450
|
+
rescue_with_handler(exception) || raise
|
452
451
|
|
453
452
|
end
|
454
|
-
|
453
|
+
|
455
454
|
def safe_subresource(subresource, options=Hash.new)
|
456
455
|
url = client.concat_urls(client.url, subresource)
|
457
456
|
options = client.options.dup.merge! options
|