active-fedora 3.0.7 → 3.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +39 -10
  3. data/History.txt +0 -4
  4. data/active-fedora.gemspec +4 -3
  5. data/lib/active_fedora.rb +9 -9
  6. data/lib/active_fedora/base.rb +92 -163
  7. data/lib/active_fedora/datastream.rb +59 -60
  8. data/lib/active_fedora/datastream_hash.rb +18 -0
  9. data/lib/active_fedora/metadata_datastream.rb +3 -2
  10. data/lib/active_fedora/metadata_datastream_helper.rb +3 -15
  11. data/lib/active_fedora/model.rb +3 -3
  12. data/lib/active_fedora/nokogiri_datastream.rb +305 -302
  13. data/lib/active_fedora/qualified_dublin_core_datastream.rb +24 -19
  14. data/lib/active_fedora/rels_ext_datastream.rb +39 -37
  15. data/lib/active_fedora/rubydora_connection.rb +40 -0
  16. data/lib/active_fedora/semantic_node.rb +1 -1
  17. data/lib/active_fedora/solr_service.rb +1 -1
  18. data/lib/active_fedora/version.rb +1 -1
  19. data/lib/ruby-fedora.rb +0 -8
  20. data/lib/tasks/active_fedora.rake +14 -9
  21. data/lib/tasks/active_fedora_dev.rake +23 -40
  22. data/spec/integration/base_loader_spec.rb +4 -21
  23. data/spec/integration/base_spec.rb +300 -310
  24. data/spec/integration/bug_spec.rb +9 -10
  25. data/spec/integration/datastream_spec.rb +12 -12
  26. data/spec/integration/metadata_datastream_helper_spec.rb +7 -10
  27. data/spec/integration/model_spec.rb +3 -2
  28. data/spec/integration/rels_ext_datastream_spec.rb +9 -15
  29. data/spec/spec_helper.rb +2 -29
  30. data/spec/unit/active_fedora_spec.rb +5 -5
  31. data/spec/unit/base_cma_spec.rb +0 -7
  32. data/spec/unit/base_datastream_management_spec.rb +8 -67
  33. data/spec/unit/base_delegate_spec.rb +26 -9
  34. data/spec/unit/base_extra_spec.rb +5 -3
  35. data/spec/unit/base_file_management_spec.rb +10 -17
  36. data/spec/unit/base_named_datastream_spec.rb +76 -199
  37. data/spec/unit/base_spec.rb +152 -69
  38. data/spec/unit/content_model_spec.rb +1 -1
  39. data/spec/unit/datastream_concurrency_spec.rb +5 -4
  40. data/spec/unit/datastream_spec.rb +28 -48
  41. data/spec/unit/has_many_collection_spec.rb +2 -0
  42. data/spec/unit/inheritance_spec.rb +6 -6
  43. data/spec/unit/metadata_datastream_spec.rb +12 -28
  44. data/spec/unit/model_spec.rb +10 -10
  45. data/spec/unit/nokogiri_datastream_spec.rb +31 -33
  46. data/spec/unit/qualified_dublin_core_datastream_spec.rb +15 -15
  47. data/spec/unit/rels_ext_datastream_spec.rb +35 -29
  48. data/spec/unit/rubydora_connection_spec.rb +26 -0
  49. data/spec/unit/semantic_node_spec.rb +12 -17
  50. data/spec/unit/solr_config_options_spec.rb +13 -14
  51. data/spec/unit/solr_service_spec.rb +14 -17
  52. metadata +59 -55
  53. data/lib/fedora/base.rb +0 -38
  54. data/lib/fedora/connection.rb +0 -218
  55. data/lib/fedora/datastream.rb +0 -67
  56. data/lib/fedora/fedora_object.rb +0 -161
  57. data/lib/fedora/formats.rb +0 -30
  58. data/lib/fedora/generic_search.rb +0 -71
  59. data/lib/fedora/repository.rb +0 -298
  60. data/spec/integration/datastreams_crud_spec.rb +0 -208
  61. data/spec/integration/fedora_object_spec.rb +0 -77
  62. data/spec/integration/repository_spec.rb +0 -301
  63. data/spec/integration/rf_fedora_object_spec.rb +0 -95
  64. data/spec/unit/connection_spec.rb +0 -25
  65. data/spec/unit/fedora_object_spec.rb +0 -74
  66. data/spec/unit/repository_spec.rb +0 -143
  67. data/spec/unit/rf_datastream_spec.rb +0 -63
@@ -1,30 +0,0 @@
1
- module Fedora
2
- module XmlFormat
3
- extend self
4
-
5
- def extension
6
- "xml"
7
- end
8
-
9
- def mime_type
10
- "text/xml"
11
- end
12
-
13
- def encode(hash)
14
- hash.to_xml
15
- end
16
-
17
- def decode(xml)
18
- from_xml_data(Hash.from_xml(xml))
19
- end
20
-
21
- private
22
- def from_xml_data(data)
23
- if data.is_a?(Hash) && data.keys.size == 1
24
- data.values.first
25
- else
26
- data
27
- end
28
- end
29
- end
30
- end
@@ -1,71 +0,0 @@
1
- #
2
- # @Creator Matt Zumwalt, MediaShelf LLC
3
- # @Copyright Matt Zumwalt, 2007. All Rights Reserved.
4
- #
5
-
6
- module Fedora
7
- class GenericSearch
8
-
9
- def initialize(uri, service_name)
10
- @uri = "#{uri}/#{service_name}"
11
- @client = HTTPClient.new(@uri)
12
- @extheader = {'User-Agent'=>"RubyFedora"}
13
- end
14
-
15
- def call_resource
16
-
17
- end
18
-
19
- # TODO: Handle ruby-tyle params, camel-casing them before passing to call_resource...
20
- def update_index(params)
21
- query = {:action=>action,:value=>value,:repositoryName=>repository_name,:indexName=>indexname,:restXslt=>"copyXML"}.merge(params)
22
- query.merge {:operation> "updateIndex"}
23
-
24
- @client.get(@uri, query, @extheader)
25
- return "update_index Not Implemented."
26
- end
27
-
28
-
29
- def browse_index(params)
30
- # Sample: /fedoragsearch/rest?operation=browseIndex&startTerm=&fieldName=PID&termPageSize=20&indexName=FedoraIndex&restXslt=copyXml&resultPageXslt=browseIndexToResultPage
31
- query = {:startTerm=>URLEncoder.encode(start_term, "UTF-8"),:fieldName=>"",:indexName=>"",:termPageSize=>"", :restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
32
- query.merge {:operation> "browseIndex"}
33
- @client.get(@uri, query, @extheader)
34
- return "browse_index Not Implemented."
35
- end
36
-
37
- def gfind_objects(params)
38
- # Sample: /fedoragsearch/rest?operation=gfindObjects&query=test&hitPageSize=10&restXslt=copyXml
39
- # fieldMaxLength limits the number of characters returned from the value of each object field.
40
- # Snippets will highlight matched words within the search results. To keep the xml as simple as possible, set snippetsMax to 0.
41
- query = {:query=>URLEncoder.encode(query, "UTF-8"),:value=>value,:indexName=>indexname,:hitPageStart=>"",:hitPageSize=>"",:snippetsMax=>"0",:fieldMaxLength=>"",:restXslt=>"copyXML",:resultPageXslt=>""}.merge(params)
42
- query.merge {:operation> "gfindObjects"}
43
- @client.get(@uri, query, @extheader)
44
- return "gfind_objects Not Implemented."
45
- end
46
-
47
- def get_index_info(params)
48
- # Sample: /fedoragsearch/rest?operation=getIndexInfo&restXslt=copyXml
49
- query = {:indexName=>"",:restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
50
- query.merge {:operation> "getIndexInfo"}
51
- @client.get(@uri, query, @extheader)
52
- return "get_index_info Not Implemented."
53
- end
54
-
55
- def get_repository_info(params)
56
- # Sample: /fedoragsearch/rest?operation=getRepositoryInfo&restXslt=copyXml
57
- query = {:repositoryName=>"",:restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
58
- query.merge {:operation> "getRepositoryInfo"}
59
- @client.get(@uri, query, @extheader)
60
- return "get_repository_info Not Implemented."
61
- end
62
-
63
- def configure(params)
64
- query = {:configName=>""}.merge(params)
65
- query.merge {:operation> "configure"}
66
- @client.get(@uri, query, @extheader)
67
- return "configure Not Implemented."
68
- end
69
-
70
- end
71
- end
@@ -1,298 +0,0 @@
1
-
2
- require 'fedora/base'
3
- require 'fedora/connection'
4
- require 'fedora/formats'
5
- require 'fedora/fedora_object'
6
- require 'fedora/datastream'
7
- require "nokogiri"
8
-
9
- module Fedora
10
- NAMESPACE = "fedora:info/"
11
- ALL_FIELDS = [
12
- :pid, :label, :fType, :cModel, :state, :ownerId, :cDate, :mDate, :dcmDate,
13
- :bMech, :title, :creator, :subject, :description, :contributor,
14
- :date, :type, :format, :identifier, :source, :language, :relation, :coverage, :rights
15
- ]
16
-
17
- class Repository
18
-
19
- attr_accessor :repository_name, :base_url, :fedora_version, :pid_namespace, :pid_delimiter
20
-
21
- def self.flush
22
- Thread.current[:repo]=nil
23
- end
24
- def self.register(url, surrogate=nil)
25
- url = url.to_s.chop if url.to_s =~ /\/\Z/
26
- Thread.current[:repo]= Fedora::Repository.new(url, surrogate)
27
- begin
28
- repo = Thread.current[:repo]
29
- attributes = repo.describe_repository
30
- repo.repository_name = attributes["repositoryName"].first
31
- repo.base_url = attributes["repositoryBaseURL"].first
32
- repo.fedora_version = attributes["repositoryVersion"].first
33
- repo.pid_namespace = attributes["repositoryPID"].first["PID-namespaceIdentifier"].first
34
- repo.pid_delimiter = attributes["repositoryPID"].first["PID-delimiter"].first
35
- rescue
36
- end
37
- Thread.current[:repo]
38
- end
39
- def self.instance
40
- raise "did you register a repo?" unless Thread.current[:repo]
41
- Thread.current[:repo]
42
- end
43
- class StringResponse < String
44
- attr_reader :content_type
45
-
46
- def initialize(s, content_type)
47
- super(s)
48
- @content_type = content_type
49
- end
50
- end
51
-
52
- attr_accessor :fedora_url
53
-
54
- def initialize(fedora_url, surrogate=nil)
55
- @fedora_url = fedora_url.is_a?(URI) ? fedora_url : URI.parse(fedora_url)
56
- @surrogate = surrogate
57
- @connection = nil
58
- end
59
-
60
- # Fetch the raw content of either a fedora object or datastream
61
- def fetch_content(object_uri)
62
- response = connection.raw_get("#{url_for(object_uri)}?format=xml")
63
- StringResponse.new(response.body, response.content_type)
64
- end
65
-
66
-
67
-
68
- # Find fedora objects with http://www.fedora.info/wiki/index.php/API-A-Lite_findObjects
69
- #
70
- # == Parameters
71
- # query<String>:: the query string to be sent to Fedora.
72
- # options<Hash>:: see below
73
- #
74
- # == Options<Hash> keys
75
- # limit<String|Number>:: set the maxResults parameter in fedora
76
- # select<Symbol|Array>:: the fields to returned. To include all fields, pass :all as the value.
77
- # The field "pid" is always included.
78
- #
79
- # == Examples
80
- # find_objects("label=Image1")
81
- # find_objects("pid~demo:*", "label=test")
82
- # find_objects("label=Image1", :include => :all)
83
- # find_objects("label=Image1", :include => [:label])
84
- #-
85
- def find_objects(*args)
86
- raise ArgumentError, "Missing query string" unless args.length >= 1
87
- options = args.last.is_a?(Hash) ? args.pop : {}
88
-
89
- fields = options[:select]
90
- fields = (fields.nil? || (fields == :all)) ? ALL_FIELDS : ([:pid] + ([fields].flatten! - [:pid]))
91
-
92
- query = args.join(' ')
93
- params = { :resultFormat => 'xml', :query => query }
94
- params[:maxResults] = options[:limit] if options[:limit]
95
- params[:sessionToken] = options[:sessionToken] if options[:sessionToken]
96
- includes = fields.inject("") { |s, f| s += "&#{f}=true"; s }
97
-
98
- convert_xml(connection.get("#{fedora_url.path}/objects?#{params.to_fedora_query}#{includes}"))
99
- end
100
-
101
- # Retrieve an object from fedora and load it as an instance of the given model/class
102
- #
103
- # @param pid of the Fedora object to retrieve and deserialize
104
- # @param klazz the Model whose deserialize method the object's FOXML will be passed into
105
- def find_model(pid, klazz)
106
- obj = self.find_objects("pid=#{pid}").first
107
- if obj.nil?
108
- raise ActiveFedora::ObjectNotFoundError, "The repository does not have an object with pid #{pid}. The repository URL is #{self.base_url}"
109
- end
110
- doc = Nokogiri::XML::Document.parse(obj.object_xml)
111
- klazz.deserialize(doc)
112
- end
113
-
114
- # Create the given object if it's new (not obtained from a find method). Otherwise update the object.
115
- #
116
- # == Return
117
- # boolean:: whether the operation is successful
118
- #-
119
- def save(object)
120
- object.new_object? ? create(object) : update(object)
121
- end
122
-
123
- def nextid(attrs={})
124
- request_url = fedora_url.path+"/management/getNextPID?xml=true"
125
- request_url += "&namespace=#{attrs[:namespace]}" if attrs[:namespace]
126
- d = REXML::Document.new(connection.post(request_url).body)
127
- d.elements['//pid'].text
128
- end
129
-
130
-
131
- def create(object)
132
- case object
133
- when Fedora::FedoraObject
134
- pid = (object.pid ? object : 'new')
135
- response = connection.post("#{url_for(pid)}?" + object.attributes.to_fedora_query, object.blob)
136
- if response.code == '201'
137
- object.pid = extract_pid(response)
138
- object.new_object = false
139
- true
140
- else
141
- false
142
- end
143
- when Fedora::Datastream
144
- raise ArgumentError, "Missing dsID attribute" if object.dsid.nil?
145
- extra_headers = {}
146
- extra_headers['Content-Type'] = object.attributes[:mimeType] if object.attributes[:mimeType]
147
- response = connection.post("#{url_for(object)}?" + object.attributes.to_fedora_query,
148
- object.blob, extra_headers)
149
- if response.code == '201'
150
- object.new_object = false
151
- true
152
- else
153
- false
154
- end
155
- else
156
- raise ArgumentError, "Unknown object type"
157
- end
158
-
159
- end
160
-
161
- # Update the given object
162
- # == Return
163
- # boolean:: whether the operation is successful
164
- #-
165
- def update(object)
166
- raise ArgumentError, "Missing pid attribute" if object.nil? || object.pid.nil?
167
- case object
168
- when Fedora::FedoraObject
169
- response = connection.put("#{url_for(object)}?" + object.attributes.to_fedora_query)
170
- response.code == '200' || '307'
171
- when Fedora::Datastream
172
- raise ArgumentError, "Missing dsID attribute" if object.dsid.nil?
173
- response = connection.put("#{url_for(object)}?" + object.attributes.to_fedora_query, object.blob)
174
- response.code == '200' || '201'
175
- return response.code
176
- else
177
- raise ArgumentError, "Unknown object type"
178
- end
179
- end
180
-
181
- # Delete the given pid
182
- # == Parameters
183
- # object<Object|String>:: The object to delete.
184
- # This can be a uri String ("demo:1", "fedora:info/demo:1") or any object that responds uri method.
185
- #
186
- # == Return
187
- # boolean:: whether the operation is successful
188
- #-
189
- def delete(object)
190
- raise ArgumentError, "Object must not be nil" if object.nil?
191
- response = connection.delete("#{url_for(object)}")
192
- response.code == '200' or response.code == '204' # Temporary hack around error in Fedora 3.0 Final's REST API
193
- end
194
-
195
- # Export the given object
196
- # == Parameters
197
- # object<String|Object>:: a fedora uri, pid, FedoraObject instance
198
- # method<Symbol>:: the method to fetch such as :export, :history, :versions, etc
199
- # extra_params<Hash>:: any other extra parameters to pass to fedora
200
- #
201
- def export(object, extra_params={})
202
- extra_params = {:format=>:foxml, :context=>:archive}.merge!(extra_params)
203
- if extra_params[:format].kind_of?(String)
204
- format = extra_params[:format]
205
- else
206
- format = case extra_params[:format]
207
- when :atom then "info:fedora/fedora-system:ATOM-1.1"
208
- when :atom_zip then "info:fedora/fedora-system:ATOMZip-1.1"
209
- when :mets then "info:fedora/fedora-system:METSFedoraExt-1.1"
210
- when :foxml then "info:fedora/fedora-system:FOXML-1.1"
211
- else "info:fedora/fedora-system:FOXML-1.1"
212
- end
213
- end
214
- fetch_custom(object, "export", :format=>format, :context=>extra_params[:context].to_s)
215
- end
216
-
217
- def ingest(content_to_ingest, extra_params={})
218
- if extra_params[:pid]
219
- url = url_for(extra_params[:pid])
220
- else
221
- url = url_for("new")
222
- end
223
-
224
- if content_to_ingest.kind_of?(File)
225
- content_to_ingest = content_to_ingest.read
226
- end
227
-
228
- connection.post(url,content_to_ingest)
229
- end
230
-
231
- # Fetch the given object using custom method. This is used to fetch other aspects of a fedora object,
232
- # such as profile, versions, etc...
233
- # == Parameters
234
- # object<String|Object>:: a fedora uri, pid, FedoraObject instance
235
- # method<Symbol>:: the method to fetch such as :export, :history, :versions, etc
236
- # extra_params<Hash>:: any other extra parameters to pass to fedora
237
- #
238
- # == Returns
239
- # This method returns raw xml response from the server
240
- #-
241
- def fetch_custom(object, method, extra_params = { :format => 'xml' })
242
- path = case method
243
- when :profile then ""
244
- else "/#{method}"
245
- end
246
-
247
- extra_params.delete(:format) if method == :export
248
- connection.raw_get("#{url_for(object)}#{path}?#{extra_params.to_fedora_query}").body
249
- end
250
-
251
- def describe_repository
252
- result_body = connection.raw_get("#{fedora_url.path}/describe?xml=true").body
253
- XmlSimple.xml_in(result_body)
254
- end
255
-
256
- private
257
- def convert_xml(response)
258
- results = FedoraObjects.new
259
- return results unless response && response['resultList']
260
-
261
- results.session_token = response['listSession']['token'] if response['listSession']
262
- objectFields = response['resultList']['objectFields']
263
- case objectFields
264
- when Array
265
- objectFields.each { |attrs| results << FedoraObject.new(attrs.rekey!) }
266
- when Hash
267
- results << FedoraObject.new(objectFields.rekey!)
268
- end
269
- results.each {|result| result.new_object = false}
270
- results
271
- end
272
-
273
- def url_for(object)
274
- uri = object.respond_to?(:uri) ? object.uri : object.to_s
275
- uri = (uri[0..NAMESPACE.length-1] == NAMESPACE ? uri[NAMESPACE.length..-1] : uri) # strip of fedora:info namespace
276
- "#{fedora_url.path}/objects/#{uri}"
277
- end
278
-
279
- # Low level access to the remote fedora server
280
- # The +refresh+ parameter toggles whether or not the connection is refreshed at every request
281
- # or not (defaults to +false+).
282
- def connection(refresh = false)
283
- if refresh || @connection.nil?
284
- @connection = Fedora::Connection.new(@fedora_url, Fedora::XmlFormat, @surrogate)
285
- end
286
- @connection
287
- end
288
-
289
- def extract_pid(response)
290
- CGI.unescape(response['Location'].split('/').last)
291
- end
292
- end
293
- end
294
-
295
- class FedoraObjects < Array
296
- attr_accessor :session_token
297
- end
298
-
@@ -1,208 +0,0 @@
1
- require File.join( File.dirname(__FILE__), "../spec_helper" )
2
- # Datastream API:
3
- # - To list datastream
4
- # curl -i http://localhost:8080/fedora/objects/test:02/datastreams
5
- # curl -i http://localhost:8080/fedora/objects/test:02/datastreams?format=xml
6
- #
7
- # invalid: curl -i http://localhost:8080/fedora/objects/test:02/datastreams.xml
8
- #
9
- # - To obtain a datastream
10
- # curl -i http://localhost:8080/fedora/objects/test:02/datastreams/DC
11
- # curl -i http://localhost:8080/fedora/objects/test:02/datastreams/DS1
12
- #
13
- # - To create create a new datastream
14
- #
15
- # regular post (always creates inline (I) datastream. Will fail if not valid XML):
16
- # curl -i -H "Content-type: text/xml" -XPOST --data-binary @build.xml -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:02/datastreams/DS1?dsLabel=A%20Test%20Datastream&altIDs=3333"
17
- #
18
- # "E" and "R" datastreams
19
- # curl -i -H "Content-type: text/html" -XPOST "http://localhost:8080/fedora/objects/test:02/datastreams/REDIRECT?dsLabel=A%20Redirect%20Datastream&altIDs=3333&controlGroup=R&dsLocation=http://www.yourmediashelf.com" -u fedoraAdmin:fedoraAdmin
20
- # curl -i -H "Content-type: text/html" -XPOST "http://localhost:8080/fedora/objects/test:02/datastreams/EXT?dsLabel=A%20Ext%20Datastream&altIDs=3333&controlGroup=E&dsLocation=http://www.yahoo.com" -u fedoraAdmin:fedoraAdmin
21
- #
22
- # multipart/form-data (always creates managed content (M) datastream):
23
- # curl -i -H -XPOST -F file=@build.xml -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:02/datastreams/DS3?dsLabel=hello&altIDs=3333"
24
- # curl -i -H -XPOST -F file=@dino.jpg -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:02/datastreams/JPEG?dsLabel=hello&altIDs=3333"
25
- # MIME Type is set according to Content Type Header:
26
- # curl -i -H -XPOST -F "file=@01 Float On.m4a;type=audio/mp4a-latm" -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:02/datastreams/Float_On.m4a?dsLabel=hello&altIDs=3333"
27
- # curl -i -H -XPOST -F "file=@educause2004Fedora.ppt;type=application/vnd.ms-powerpoint" -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:02/datastreams/PPT.ppt?dsLabel=hello&altIDs=3333"
28
- #
29
- # mutipart/related is also supported but can only be tested with xform clients.
30
- #
31
- # - To update a datastream
32
- # curl -i -H "Content-type: text/xml" -XPUT "http://localhost:8080/fedora/objects/test:02/datastreams/DS1?dsLabel=hello&altIDs=3333" --data-binary @build.xml -u fedoraAdmin:fedoraAdmin
33
- # curl -i -H "Content-type: text/xml" -XPOST "http://localhost:8080/fedora/objects/test:02/datastreams/DS1?dsLabel=hello&altIDs=3333" --data-binary @build.xml -u fedoraAdmin:fedoraAdmin
34
- #
35
- # - To delete a datastream
36
- # curl -i -XDELETE "http://localhost:8080/fedora/objects/test:02/datastreams/DS1" -u fedoraAdmin:fedoraAdmin
37
- #
38
- # curl -i -H -XPOST -F file=@test/fixtures/minivan-in-minneapolis.jpg -u fedoraAdmin:fedoraAdmin "http://localhost:8080/fedora/objects/test:test_xml_post/datastreams/FOO"
39
- #
40
- # curl -i -XDELETE -u admin:muradora "http://localhost:9090/fedora/objects/test:test:test_object_1"
41
- #
42
- # curl -i -H "Content-type: text/xml" -XPOST --data-binary @test/fixtures/mods-mskcc-filledsample.xml -u fedoraAdmin:fedoraAdmin "http://localhost:9090/fedora/objects/test:02/datastreams/DS1?dsLabel=A%20Test%20Datastream"
43
- #
44
- # curl -i -H "Content-type: image/jpeg" -XPOST -F file=@test/fixtures/dino.jpg -u admin:muradora "http://localhost:9090/fedora/objects/test:02/datastreams/DINO?dsLabel=A%20Test%20Datastream"
45
- describe Fedora::Repository do
46
- def sample_mods
47
- xml = <<-EOS
48
- <mods:mods xmlns:xlink="http://www.w3.org/1999/xlink" version="3.2"
49
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mods="http://www.loc.gov/mods/v3"
50
- xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"
51
- xmlns="http://www.w3.org/1999/xhtml">
52
- <mods:identifier>mskcc:2045</mods:identifier>
53
- <mods:titleInfo authority="" displayLabel="">
54
- <mods:title>Sample Title</mods:title>
55
- <mods:subTitle>Sample SubTitle</mods:subTitle>
56
- </mods:titleInfo>
57
- <mods:name type="personal" authority="" ID="owner">
58
- <mods:namePart type="family">Smith</mods:namePart>
59
- <mods:namePart type="given">John</mods:namePart>
60
- <mods:namePart type="termsOfAddress">Mr.</mods:namePart>
61
- <mods:affiliation>Surgery</mods:affiliation>
62
- <mods:role>
63
- <mods:roleTerm type="text" authority="">Owner</mods:roleTerm>
64
- </mods:role>
65
- </mods:name>
66
- <mods:name type="personal" authority="non-owner">
67
- <mods:namePart type="family">Rushdie</mods:namePart>
68
- <mods:namePart type="given">Salman</mods:namePart>
69
- <mods:namePart type="termsOfAddress">Mr.</mods:namePart>
70
- <mods:affiliation>Surgery</mods:affiliation>
71
- <mods:role>
72
- <mods:roleTerm type="text" authority="">Contributor</mods:roleTerm>
73
- </mods:role>
74
- </mods:name>
75
- <mods:originInfo>
76
- <mods:place>
77
- <mods:placeTerm type="text">Sample Place of Creation</mods:placeTerm>
78
- </mods:place>
79
- <mods:publisher>MSKCC</mods:publisher>
80
- <mods:dateIssued encoding="" keydate="" qualifier="" point=""/>
81
- <mods:dateCreated encoding="" keydate="" qualifier="" point=""/>
82
- <mods:dateModified encoding="" keydate="" qualifier="" point=""/>
83
- <mods:copyrightDate encoding="" keydate="" qualifier="" point=""/>
84
- <mods:dateOther encoding="" keydate="" qualifier="" point=""/>
85
- </mods:originInfo>
86
- <mods:abstract displayLabel="" type=""></mods:abstract>
87
- <mods:note type=""/>
88
- <mods:subject authority="lcsh">
89
- <mods:topic>carcinoma</mods:topic>
90
- <mods:topic>adinoma</mods:topic>
91
- </mods:subject>
92
- <!-- part, extension -->
93
- </mods:mods>
94
- EOS
95
- end
96
-
97
- before(:all) do
98
- Fedora::Repository.register(ActiveFedora.fedora_config[:url])
99
- @fedora = Fedora::Repository.instance
100
- end
101
-
102
- before(:each) do
103
- @test_object = Fedora::FedoraObject.new(:label => 'test',
104
- :contentModel => 'Image',
105
- :state => 'A',
106
- :ownerID => 'fedoraAdmin')
107
-
108
- @fedora.save(@test_object).should be_true
109
- end
110
-
111
- after(:each) do
112
- @fedora.delete(@test_object).should be_true
113
- end
114
-
115
- def fetch_content(pid, dsID)
116
- content = @fedora.fetch_content("#{pid}/datastreams/#{dsID}/content")
117
- end
118
-
119
- it "should create/update xml datastream" do
120
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo', :altIDs => '3333',
121
- :blob => sample_mods)
122
- @fedora.save(ds).should be_true
123
-
124
- ds.attributes[:dsLabel] = 'bar'
125
- @fedora.save(ds).should be_true
126
- end
127
-
128
- it "should be able to save file objects" do
129
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
130
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
131
-
132
- ds.control_group.should == 'M'
133
- @fedora.save(ds).should be_true
134
- end
135
-
136
- it "should be able to save StringIO objects" do
137
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333', :controlGroup => 'M', :blob => StringIO.new("hi there"))
138
-
139
- @fedora.save(ds).should be_true
140
- end
141
-
142
- it "should create/update image/file datastream" do
143
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
144
- :controlGroup => 'M', :blob => fixture('dino.jpg').read, :mimeType=>'image/jpeg')
145
-
146
- @fedora.save(ds).should be_true
147
-
148
- content = fetch_content(@test_object.pid, 'DS1')
149
- content.content_type.should == 'image/jpeg'
150
-
151
- ds.blob = fixture('minivan.jpg')
152
- @fedora.save(ds).should be_true
153
- end
154
-
155
- it "should set controlGroup to 'M' if mimeType is specified" do
156
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo',
157
- :mimeType => 'text/plain', :blob => "This is plain text")
158
- end
159
-
160
- it "should create datastream with custom mimeType for text blob" do
161
- blob = "This is plain text"
162
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo',
163
- :mimeType => 'text/plain', :blob => blob)
164
- @fedora.save(ds).should be_true
165
-
166
- content = @fedora.fetch_content("#{@test_object.pid}/datastreams/DS1/content")
167
- content.should == blob
168
- content.content_type.should == 'text/plain'
169
- end
170
-
171
- it "should create datastream with custom mimeType for file blob" do
172
- blob = "This is plain text"
173
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo',
174
- :mimeType => 'image/jpeg', :blob => fixture('dino.jpg'))
175
- @fedora.save(ds).should be_true
176
-
177
- content = fetch_content(@test_object.pid, "DS1")
178
- content.content_type.should == 'image/jpeg'
179
- end
180
-
181
- it "should delete datastream by ref" do
182
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo', :altIDs => '3333', :blob => sample_mods)
183
- @fedora.save(ds).should be_true
184
- @fedora.delete(ds).should be_true
185
- end
186
-
187
- it "should delete datastream by uri" do
188
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'foo', :altIDs => '3333', :blob => sample_mods)
189
- @fedora.save(ds).should be_true
190
- @fedora.delete(ds.uri).should be_true
191
- end
192
-
193
- it "should fetch thumbnail jpg for Image of Coliseum in Rome" do
194
- # Have to check for two possible sizes because the image size changed between Fedora 3.0 and Fedora 3.1
195
- fetch_content("demo:26", "TEI_SOURCE").length.should satisfy{ |l| l == 1098 || 1086}
196
- end
197
-
198
- describe ".label" do
199
- it "should apply to the dsLabel when you save the datastream" do
200
- ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DSLabelTest', :blob => sample_mods)
201
- ds.label = "My Test dsLabel"
202
- @fedora.save(ds)
203
- object_rexml = REXML::Document.new(@test_object.object_xml)
204
- #puts object_rexml.root.elements["foxml:datastream[@ID='DSLabelTest']/foxml:datastreamVersion"].inspect
205
- object_rexml.root.elements["foxml:datastream[@ID='DSLabelTest']/foxml:datastreamVersion[last()]"].attributes["LABEL"].should == ds.label
206
- end
207
- end
208
- end