active-fedora 3.0.7 → 3.1.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -1
- data/Gemfile.lock +39 -10
- data/History.txt +0 -4
- data/active-fedora.gemspec +4 -3
- data/lib/active_fedora.rb +9 -9
- data/lib/active_fedora/base.rb +92 -163
- data/lib/active_fedora/datastream.rb +59 -60
- data/lib/active_fedora/datastream_hash.rb +18 -0
- data/lib/active_fedora/metadata_datastream.rb +3 -2
- data/lib/active_fedora/metadata_datastream_helper.rb +3 -15
- data/lib/active_fedora/model.rb +3 -3
- data/lib/active_fedora/nokogiri_datastream.rb +305 -302
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +24 -19
- data/lib/active_fedora/rels_ext_datastream.rb +39 -37
- data/lib/active_fedora/rubydora_connection.rb +40 -0
- data/lib/active_fedora/semantic_node.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/lib/ruby-fedora.rb +0 -8
- data/lib/tasks/active_fedora.rake +14 -9
- data/lib/tasks/active_fedora_dev.rake +23 -40
- data/spec/integration/base_loader_spec.rb +4 -21
- data/spec/integration/base_spec.rb +300 -310
- data/spec/integration/bug_spec.rb +9 -10
- data/spec/integration/datastream_spec.rb +12 -12
- data/spec/integration/metadata_datastream_helper_spec.rb +7 -10
- data/spec/integration/model_spec.rb +3 -2
- data/spec/integration/rels_ext_datastream_spec.rb +9 -15
- data/spec/spec_helper.rb +2 -29
- data/spec/unit/active_fedora_spec.rb +5 -5
- data/spec/unit/base_cma_spec.rb +0 -7
- data/spec/unit/base_datastream_management_spec.rb +8 -67
- data/spec/unit/base_delegate_spec.rb +26 -9
- data/spec/unit/base_extra_spec.rb +5 -3
- data/spec/unit/base_file_management_spec.rb +10 -17
- data/spec/unit/base_named_datastream_spec.rb +76 -199
- data/spec/unit/base_spec.rb +152 -69
- data/spec/unit/content_model_spec.rb +1 -1
- data/spec/unit/datastream_concurrency_spec.rb +5 -4
- data/spec/unit/datastream_spec.rb +28 -48
- data/spec/unit/has_many_collection_spec.rb +2 -0
- data/spec/unit/inheritance_spec.rb +6 -6
- data/spec/unit/metadata_datastream_spec.rb +12 -28
- data/spec/unit/model_spec.rb +10 -10
- data/spec/unit/nokogiri_datastream_spec.rb +31 -33
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +15 -15
- data/spec/unit/rels_ext_datastream_spec.rb +35 -29
- data/spec/unit/rubydora_connection_spec.rb +26 -0
- data/spec/unit/semantic_node_spec.rb +12 -17
- data/spec/unit/solr_config_options_spec.rb +13 -14
- data/spec/unit/solr_service_spec.rb +14 -17
- metadata +59 -55
- data/lib/fedora/base.rb +0 -38
- data/lib/fedora/connection.rb +0 -218
- data/lib/fedora/datastream.rb +0 -67
- data/lib/fedora/fedora_object.rb +0 -161
- data/lib/fedora/formats.rb +0 -30
- data/lib/fedora/generic_search.rb +0 -71
- data/lib/fedora/repository.rb +0 -298
- data/spec/integration/datastreams_crud_spec.rb +0 -208
- data/spec/integration/fedora_object_spec.rb +0 -77
- data/spec/integration/repository_spec.rb +0 -301
- data/spec/integration/rf_fedora_object_spec.rb +0 -95
- data/spec/unit/connection_spec.rb +0 -25
- data/spec/unit/fedora_object_spec.rb +0 -74
- data/spec/unit/repository_spec.rb +0 -143
- data/spec/unit/rf_datastream_spec.rb +0 -63
data/.rvmrc
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (3.0.
|
4
|
+
active-fedora (3.1.0.pre1)
|
5
5
|
activeresource (~> 3.0.0)
|
6
6
|
activesupport (~> 3.0.0)
|
7
7
|
equivalent-xml
|
@@ -10,7 +10,8 @@ PATH
|
|
10
10
|
mime-types (>= 1.16)
|
11
11
|
multipart-post (= 1.1.2)
|
12
12
|
nokogiri
|
13
|
-
om (>= 1.
|
13
|
+
om (>= 1.0)
|
14
|
+
rubydora (~> 0.1.6)
|
14
15
|
solr-ruby (>= 0.0.6)
|
15
16
|
solrizer (> 1.0.0)
|
16
17
|
xml-simple (>= 1.0.12)
|
@@ -27,6 +28,8 @@ GEM
|
|
27
28
|
activemodel (= 3.0.10)
|
28
29
|
activesupport (= 3.0.10)
|
29
30
|
activesupport (3.0.10)
|
31
|
+
akami (1.0.0)
|
32
|
+
gyoku (>= 0.4.0)
|
30
33
|
builder (2.1.2)
|
31
34
|
childprocess (0.2.2)
|
32
35
|
ffi (~> 1.0.6)
|
@@ -37,8 +40,12 @@ GEM
|
|
37
40
|
facets (2.9.2)
|
38
41
|
fastercsv (1.5.4)
|
39
42
|
ffi (1.0.9)
|
43
|
+
gyoku (0.4.4)
|
44
|
+
builder (>= 2.1.2)
|
45
|
+
httpi (0.9.5)
|
46
|
+
rack
|
40
47
|
i18n (0.5.0)
|
41
|
-
jettywrapper (1.0.
|
48
|
+
jettywrapper (1.0.0)
|
42
49
|
activesupport (>= 3.0.0)
|
43
50
|
childprocess
|
44
51
|
i18n
|
@@ -54,12 +61,16 @@ GEM
|
|
54
61
|
metaclass (~> 0.0.1)
|
55
62
|
multipart-post (1.1.2)
|
56
63
|
nokogiri (1.5.0)
|
57
|
-
|
64
|
+
nori (1.0.2)
|
65
|
+
om (1.4.2)
|
58
66
|
mediashelf-loggable
|
59
67
|
nokogiri (>= 1.4.2)
|
68
|
+
rack (1.3.4)
|
60
69
|
rake (0.9.2)
|
61
70
|
rbx-require-relative (0.0.5)
|
62
|
-
rcov (0.9.
|
71
|
+
rcov (0.9.10)
|
72
|
+
rest-client (1.6.7)
|
73
|
+
mime-types (>= 1.16)
|
63
74
|
rsolr (1.0.2)
|
64
75
|
builder (>= 2.1.2)
|
65
76
|
rspec (1.3.2)
|
@@ -68,6 +79,22 @@ GEM
|
|
68
79
|
ruby-debug-base (~> 0.10.4.0)
|
69
80
|
ruby-debug-base (0.10.4)
|
70
81
|
linecache (>= 0.3)
|
82
|
+
rubydora (0.1.6)
|
83
|
+
activemodel
|
84
|
+
activesupport
|
85
|
+
fastercsv
|
86
|
+
mime-types
|
87
|
+
nokogiri
|
88
|
+
rest-client
|
89
|
+
savon
|
90
|
+
savon (0.9.7)
|
91
|
+
akami (~> 1.0)
|
92
|
+
builder (>= 2.1.2)
|
93
|
+
gyoku (>= 0.4.0)
|
94
|
+
httpi (~> 0.9)
|
95
|
+
nokogiri (>= 1.4.0)
|
96
|
+
nori (~> 1.0)
|
97
|
+
wasabi (~> 2.0)
|
71
98
|
solr-ruby (0.0.8)
|
72
99
|
solrizer (1.1.2)
|
73
100
|
daemons
|
@@ -76,15 +103,17 @@ GEM
|
|
76
103
|
om (>= 1.4.0)
|
77
104
|
stomp
|
78
105
|
xml-simple
|
79
|
-
solrizer-fedora (1.1.
|
106
|
+
solrizer-fedora (1.1.2)
|
80
107
|
active-fedora (>= 2.3.0)
|
81
108
|
fastercsv
|
82
109
|
rsolr
|
83
110
|
solr-ruby (>= 0.0.6)
|
84
111
|
solrizer (>= 1.0.0)
|
85
112
|
stomp (1.1.9)
|
86
|
-
|
87
|
-
|
113
|
+
wasabi (2.0.0)
|
114
|
+
nokogiri (>= 1.4.0)
|
115
|
+
xml-simple (1.1.0)
|
116
|
+
yard (0.7.2)
|
88
117
|
|
89
118
|
PLATFORMS
|
90
119
|
ruby
|
@@ -92,11 +121,11 @@ PLATFORMS
|
|
92
121
|
DEPENDENCIES
|
93
122
|
RedCloth
|
94
123
|
active-fedora!
|
95
|
-
jettywrapper
|
124
|
+
jettywrapper (>= 1.0.0)
|
96
125
|
mocha (>= 0.9.8)
|
97
126
|
rake
|
98
127
|
rcov
|
99
128
|
rspec (< 2.0.0)
|
100
129
|
ruby-debug
|
101
|
-
solrizer-fedora
|
130
|
+
solrizer-fedora (>= 1.1.2)
|
102
131
|
yard
|
data/History.txt
CHANGED
data/active-fedora.gemspec
CHANGED
@@ -20,19 +20,20 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency('mime-types', '>= 1.16')
|
21
21
|
s.add_dependency('multipart-post', "= 1.1.2")
|
22
22
|
s.add_dependency('nokogiri')
|
23
|
-
s.add_dependency('om', '>= 1.
|
23
|
+
s.add_dependency('om', '>= 1.0')
|
24
24
|
s.add_dependency('solrizer', '>1.0.0')
|
25
25
|
s.add_dependency("activeresource", '~> 3.0.0')
|
26
26
|
s.add_dependency("activesupport", '~> 3.0.0')
|
27
27
|
s.add_dependency("mediashelf-loggable")
|
28
28
|
s.add_dependency("equivalent-xml")
|
29
29
|
s.add_dependency("facets")
|
30
|
+
s.add_dependency("rubydora", '~>0.1.6')
|
30
31
|
s.add_development_dependency("yard")
|
31
32
|
s.add_development_dependency("RedCloth") # for RDoc formatting
|
32
33
|
s.add_development_dependency("rake")
|
33
34
|
s.add_development_dependency("rcov")
|
34
|
-
s.add_development_dependency("solrizer-fedora") # used by the fixtures rake tasks
|
35
|
-
s.add_development_dependency("jettywrapper")
|
35
|
+
s.add_development_dependency("solrizer-fedora", ">=1.1.2") # used by the fixtures rake tasks
|
36
|
+
s.add_development_dependency("jettywrapper", ">=1.0.0")
|
36
37
|
s.add_development_dependency("rspec", "<2.0.0")
|
37
38
|
s.add_development_dependency("mocha", ">= 0.9.8")
|
38
39
|
s.add_development_dependency("ruby-debug")
|
data/lib/active_fedora.rb
CHANGED
@@ -7,12 +7,11 @@ $: << 'lib'
|
|
7
7
|
require 'active_support'
|
8
8
|
require 'active_model'
|
9
9
|
|
10
|
-
|
11
|
-
require 'active_fedora/
|
10
|
+
require 'active_fedora/solr_service'
|
11
|
+
require 'active_fedora/rubydora_connection'
|
12
12
|
require "solrizer"
|
13
13
|
|
14
14
|
require 'ruby-fedora'
|
15
|
-
require 'active_fedora/railtie' if defined? Rails
|
16
15
|
|
17
16
|
SOLR_DOCUMENT_ID = ActiveFedora::SolrService.id_field unless defined?(SOLR_DOCUMENT_ID)
|
18
17
|
ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
|
@@ -27,6 +26,7 @@ module ActiveFedora #:nodoc:
|
|
27
26
|
autoload :ContentModel
|
28
27
|
autoload :Reflection
|
29
28
|
autoload :Relationship
|
29
|
+
autoload :RelationshipsHelper
|
30
30
|
autoload :Datastream
|
31
31
|
autoload :Delegating
|
32
32
|
autoload :Model
|
@@ -79,6 +79,7 @@ module ActiveFedora #:nodoc:
|
|
79
79
|
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
80
80
|
# 3. If it does not find a solr.yml and the fedora.yml does not contain a solr url, it will look in: +Rails.root+/config, +current working directory+/config, then the solr.yml shipped with gem
|
81
81
|
def self.init( options={} )
|
82
|
+
logger.level = Logger::ERROR if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method
|
82
83
|
# Make config_options into a Hash if nil is passed in as the value
|
83
84
|
options = {} if options.nil?
|
84
85
|
|
@@ -164,8 +165,8 @@ module ActiveFedora #:nodoc:
|
|
164
165
|
logger.info("FEDORA: initialized Solr with ActiveFedora.solr_config: #{ActiveFedora::SolrService.instance.inspect}")
|
165
166
|
|
166
167
|
logger.info("FEDORA: initializing Fedora with fedora_config: #{ActiveFedora.fedora_config.inspect}")
|
167
|
-
|
168
|
-
logger.info("FEDORA: initialized Fedora as: #{
|
168
|
+
ActiveFedora::RubydoraConnection.connect(ActiveFedora.fedora_config[:url])
|
169
|
+
logger.info("FEDORA: initialized Fedora as: #{ActiveFedora::RubydoraConnection.instance.inspect}")
|
169
170
|
|
170
171
|
end
|
171
172
|
|
@@ -174,7 +175,7 @@ module ActiveFedora #:nodoc:
|
|
174
175
|
# 2. Rails.env
|
175
176
|
# 3. ENV['environment']
|
176
177
|
# 4. ENV['RAILS_ENV']
|
177
|
-
# 5.
|
178
|
+
# 5. development
|
178
179
|
# @return [String]
|
179
180
|
# @example
|
180
181
|
# ActiveFedora.init(:environment=>"test")
|
@@ -191,7 +192,7 @@ module ActiveFedora #:nodoc:
|
|
191
192
|
ENV['environment'] = ENV['RAILS_ENV']
|
192
193
|
return ENV['environment']
|
193
194
|
else
|
194
|
-
raise "Can't determine what environment to run in!"
|
195
|
+
ENV['environment'] = 'development' #raise "Can't determine what environment to run in!"
|
195
196
|
end
|
196
197
|
end
|
197
198
|
|
@@ -248,7 +249,7 @@ module ActiveFedora #:nodoc:
|
|
248
249
|
end
|
249
250
|
|
250
251
|
def self.fedora
|
251
|
-
|
252
|
+
ActiveFedora::RubydoraConnection.instance
|
252
253
|
end
|
253
254
|
|
254
255
|
def self.predicate_config
|
@@ -284,7 +285,6 @@ module ActiveFedora #:nodoc:
|
|
284
285
|
end
|
285
286
|
|
286
287
|
module ActiveFedora
|
287
|
-
class ServerError < Fedora::ServerError; end # :nodoc:
|
288
288
|
class ObjectNotFoundError < RuntimeError; end # :nodoc:
|
289
289
|
class PredicateMappingsNotFoundError < RuntimeError; end # :nodoc:
|
290
290
|
class UnknownAttributeError < NoMethodError; end; # :nodoc:
|
data/lib/active_fedora/base.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require "solrizer"
|
2
2
|
require 'nokogiri'
|
3
3
|
require "loggable"
|
4
|
+
require 'active_fedora/datastream_hash'
|
4
5
|
|
5
|
-
#require 'active_support/core_ext/kernel/singleton_class'
|
6
|
-
#require 'active_support/core_ext/class/attribute'
|
7
6
|
require 'active_support/core_ext/class/inheritable_attributes'
|
8
|
-
#require 'active_support/inflector'
|
9
|
-
|
10
7
|
SOLR_DOCUMENT_ID = "id" unless (defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?)
|
11
8
|
ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
|
12
9
|
|
@@ -37,7 +34,7 @@ module ActiveFedora
|
|
37
34
|
include SemanticNode
|
38
35
|
class_inheritable_accessor :ds_specs, :class_named_datastreams_desc
|
39
36
|
self.class_named_datastreams_desc = {}
|
40
|
-
self.ds_specs = {}
|
37
|
+
self.ds_specs = {'RELS-EXT'=> [ActiveFedora::RelsExtDatastream, "", nil]}#, 'DC'=> [ActiveFedora::Datastream, "", nil]}
|
41
38
|
attr_accessor :named_datastreams_desc
|
42
39
|
|
43
40
|
|
@@ -48,12 +45,12 @@ module ActiveFedora
|
|
48
45
|
|
49
46
|
# Has this object been saved?
|
50
47
|
def new_object?
|
51
|
-
|
48
|
+
inner_object.new?
|
52
49
|
end
|
53
50
|
|
54
51
|
def new_object=(bool)
|
55
52
|
@new_object = bool
|
56
|
-
inner_object.new_object = bool
|
53
|
+
#inner_object.new_object = bool
|
57
54
|
end
|
58
55
|
|
59
56
|
## Required by associations
|
@@ -83,16 +80,17 @@ module ActiveFedora
|
|
83
80
|
attrs = {} if attrs.nil?
|
84
81
|
unless attrs[:pid]
|
85
82
|
if attrs[:namespace]
|
86
|
-
attrs = attrs.merge!({:pid=>
|
83
|
+
attrs = attrs.merge!({:pid=>RubydoraConnection.instance.nextid({:namespace=>attrs[:namespace]})})
|
87
84
|
else
|
88
|
-
attrs = attrs.merge!({:pid=>
|
85
|
+
attrs = attrs.merge!({:pid=>RubydoraConnection.instance.nextid})
|
89
86
|
end
|
90
87
|
@new_object=true
|
88
|
+
@inner_object = RubydoraConnection.instance.connection.find(attrs[:pid])
|
91
89
|
else
|
92
90
|
@new_object = attrs[:new_object] == false ? false : true
|
91
|
+
@inner_object = RubydoraConnection.instance.connection.find(attrs[:pid])
|
92
|
+
load_datastreams_from_fedora
|
93
93
|
end
|
94
|
-
@inner_object = Fedora::FedoraObject.new(attrs)
|
95
|
-
@datastreams = {}
|
96
94
|
configure_defined_datastreams
|
97
95
|
|
98
96
|
attributes = attrs.dup
|
@@ -127,7 +125,6 @@ module ActiveFedora
|
|
127
125
|
#Saves a Base object, and any dirty datastreams, then updates
|
128
126
|
#the Solr index for this object.
|
129
127
|
def save
|
130
|
-
#@metadata_is_dirty = false
|
131
128
|
# If it's a new object, set the conformsTo relationship for Fedora CMA
|
132
129
|
if new_object?
|
133
130
|
result = create
|
@@ -147,8 +144,7 @@ module ActiveFedora
|
|
147
144
|
# Refreshes the object's info from Fedora
|
148
145
|
# Note: Currently just registers any new datastreams that have appeared in fedora
|
149
146
|
def refresh
|
150
|
-
inner_object.load_attributes_from_fedora
|
151
|
-
@datastreams = datastreams_in_fedora.merge(datastreams_in_memory)
|
147
|
+
# inner_object.load_attributes_from_fedora
|
152
148
|
end
|
153
149
|
|
154
150
|
#Deletes a Base object, also deletes the info indexed in Solr, and
|
@@ -164,7 +160,12 @@ module ActiveFedora
|
|
164
160
|
end
|
165
161
|
end
|
166
162
|
|
167
|
-
Fedora::Repository.instance.delete(@inner_object)
|
163
|
+
#Fedora::Repository.instance.delete(@inner_object)
|
164
|
+
begin
|
165
|
+
@inner_object.delete
|
166
|
+
rescue RestClient::ResourceNotFound =>e
|
167
|
+
raise ObjectNotFoundError, "Unable to find #{pid} in the repository"
|
168
|
+
end
|
168
169
|
if ENABLE_SOLR_UPDATES
|
169
170
|
ActiveFedora::SolrService.instance.conn.delete(pid)
|
170
171
|
# if defined?( Solrizer::Solrizer )
|
@@ -184,35 +185,31 @@ module ActiveFedora
|
|
184
185
|
# Datastreams that have been modified in memory are given preference over
|
185
186
|
# the copy in Fedora.
|
186
187
|
def datastreams
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
188
|
+
@datastreams ||= DatastreamHash.new(self)
|
189
|
+
end
|
190
|
+
|
191
|
+
def datastreams_in_memory
|
192
|
+
ActiveSupport::Deprecation.warn("ActiveFedora::Base.datastreams_in_memory has been deprecated. Use #datastreams instead")
|
193
|
+
datastreams
|
193
194
|
end
|
194
195
|
|
195
|
-
def
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
196
|
+
def load_datastreams_from_fedora
|
197
|
+
inner_object.datastreams.each do |dsid, datastream|
|
198
|
+
ds_spec = self.class.ds_specs[dsid]
|
199
|
+
if (ds_spec)
|
200
|
+
klass = ds_spec.first
|
201
|
+
datastreams[dsid] = klass.new(inner_object, dsid, true)
|
202
|
+
#datastreams[dsid].dsLabel = ds_spec[1] #this shouldn't cause it to be dirty
|
203
|
+
if ds_spec.last.class == Proc
|
204
|
+
ds_spec.last.call(datastreams[dsid])
|
205
|
+
end
|
206
|
+
klass.from_xml(datastreams[dsid].content, datastreams[dsid]) ### TODO, this is loading eagerly, we could load it as needed
|
207
|
+
### TODO, if rubydora could know which klass to use, we could probably skip this step.
|
201
208
|
else
|
202
|
-
|
209
|
+
#TODO, this may be a perfomance hit and we may not need it.
|
210
|
+
datastreams[dsid] =Datastream.new(inner_object, dsid)#, true)
|
203
211
|
end
|
204
|
-
mds[ds["dsid"]].new_object = false
|
205
212
|
end
|
206
|
-
mds
|
207
|
-
end
|
208
|
-
|
209
|
-
def datastreams_in_memory #:ndoc:
|
210
|
-
@datastreams ||= Hash.new
|
211
|
-
end
|
212
|
-
|
213
|
-
#return the datastream xml representation direclty from Fedora
|
214
|
-
def datastreams_xml
|
215
|
-
datastreams_xml = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid, :datastreams))
|
216
213
|
end
|
217
214
|
|
218
215
|
# Adds datastream to the object. Saves the datastream to fedora upon adding.
|
@@ -220,10 +217,9 @@ module ActiveFedora
|
|
220
217
|
# :prefix option will set the prefix on auto-generated DSID
|
221
218
|
# @return [String] dsid of the added datastream
|
222
219
|
def add_datastream(datastream, opts={})
|
223
|
-
datastream.pid = self.pid
|
224
220
|
if datastream.dsid == nil || datastream.dsid.empty?
|
225
221
|
prefix = opts.has_key?(:prefix) ? opts[:prefix] : "DS"
|
226
|
-
datastream.dsid
|
222
|
+
datastream.instance_variable_set :@dsid, generate_dsid(prefix)
|
227
223
|
end
|
228
224
|
datastreams[datastream.dsid] = datastream
|
229
225
|
return datastream.dsid
|
@@ -290,7 +286,7 @@ module ActiveFedora
|
|
290
286
|
# Failing that, creates a new RelsExtDatastream and adds it to the object
|
291
287
|
def rels_ext
|
292
288
|
if !datastreams.has_key?("RELS-EXT")
|
293
|
-
add_datastream(ActiveFedora::RelsExtDatastream.new)
|
289
|
+
add_datastream(ActiveFedora::RelsExtDatastream.new(@inner_object,'RELS-EXT'))
|
294
290
|
end
|
295
291
|
return datastreams["RELS-EXT"]
|
296
292
|
end
|
@@ -313,8 +309,7 @@ module ActiveFedora
|
|
313
309
|
elsif opts.has_key?(:content_type)
|
314
310
|
attrs.merge!({:mimeType=>opts[:content_type]})
|
315
311
|
end
|
316
|
-
|
317
|
-
ds = ActiveFedora::Datastream.new(attrs)
|
312
|
+
ds = create_datastream(ActiveFedora::Datastream, nil, attrs)
|
318
313
|
opts.has_key?(:dsid) ? ds.dsid=(opts[:dsid]) : nil
|
319
314
|
add_datastream(ds)
|
320
315
|
end
|
@@ -413,7 +408,6 @@ module ActiveFedora
|
|
413
408
|
# :dsLocation => holds uri location of datastream. Required only if :controlGroup is type 'E' or 'R'.
|
414
409
|
# :dsid or :dsId => Optional, and used to update an existing datastream with dsid supplied. Will throw an error if dsid does not exist and does not match prefix pattern for datastream name
|
415
410
|
def add_named_datastream(name,opts={})
|
416
|
-
|
417
411
|
unless named_datastreams_desc.has_key?(name) && named_datastreams_desc[name].has_key?(:type)
|
418
412
|
raise "Failed to add datastream. Named datastream #{name} not defined for object #{pid}."
|
419
413
|
end
|
@@ -457,11 +451,7 @@ module ActiveFedora
|
|
457
451
|
|
458
452
|
opts.merge!(:dsLabel => label)
|
459
453
|
|
460
|
-
|
461
|
-
opts.merge!(:dsid=>opts[:dsID]) if opts.has_key?(:dsID)
|
462
|
-
opts.merge!(:dsID=>opts[:dsid]) if opts.has_key?(:dsid)
|
463
|
-
|
464
|
-
ds = create_datastream(named_datastreams_desc[name][:type],opts)
|
454
|
+
ds = create_datastream(named_datastreams_desc[name][:type], opts[:dsid], opts)
|
465
455
|
#Must be of type datastream
|
466
456
|
assert_kind_of 'datastream', ds, ActiveFedora::Datastream
|
467
457
|
#make sure dsid is nil so that it uses the prefix for mapping purposes
|
@@ -525,30 +515,6 @@ module ActiveFedora
|
|
525
515
|
return ds_values
|
526
516
|
end
|
527
517
|
|
528
|
-
# ** EXPERIMENTAL **
|
529
|
-
#
|
530
|
-
# Returns hash of datastream names mapped to another hash
|
531
|
-
# of dsid to attributes for corresponding datastream objects
|
532
|
-
# === Example
|
533
|
-
# For the following has_datastream call, assume we have added one datastream.
|
534
|
-
#
|
535
|
-
# has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
536
|
-
#
|
537
|
-
# It would then return
|
538
|
-
# {"thumbnails"=>{"THUMB1"=>{:prefix=>"VAN", :type=>"ActiveFedora::Datastream", :dsid=>"THUMB1", :dsID=>"THUMB1", :pid=>"changme:33", :mimeType=>"image/jpeg", :dsLabel=>"", :name=>"thumbnails", :content_type=>"image/jpeg", :controlGroup=>"M"}}}
|
539
|
-
def named_datastreams_attributes
|
540
|
-
ds_values = {}
|
541
|
-
self.class.named_datastreams_desc.keys.each do |name|
|
542
|
-
ds_array = self.send("#{name}")
|
543
|
-
result_hash = {}
|
544
|
-
ds_array.each do |ds|
|
545
|
-
result_hash[ds.dsid]=ds.attributes
|
546
|
-
end
|
547
|
-
ds_values.merge!({name=>result_hash})
|
548
|
-
end
|
549
|
-
return ds_values
|
550
|
-
end
|
551
|
-
|
552
518
|
# ** EXPERIMENTAL **
|
553
519
|
#
|
554
520
|
# Returns hash of datastream names mapped to an array
|
@@ -569,18 +535,6 @@ module ActiveFedora
|
|
569
535
|
return dsids
|
570
536
|
end
|
571
537
|
|
572
|
-
# ** EXPERIMENTAL **
|
573
|
-
#
|
574
|
-
# For all datastream objects, this returns hash of dsid mapped to attribute hash within the corresponding
|
575
|
-
# datastream object.
|
576
|
-
def datastreams_attributes
|
577
|
-
ds_values = {}
|
578
|
-
self.datastreams.each_pair do |dsid,ds|
|
579
|
-
ds_values.merge!({dsid=>ds.attributes})
|
580
|
-
end
|
581
|
-
return ds_values
|
582
|
-
end
|
583
|
-
|
584
538
|
# ** EXPERIMENTAL **
|
585
539
|
#
|
586
540
|
# Returns the hash that stores arguments passed to has_datastream calls within an
|
@@ -606,9 +560,30 @@ module ActiveFedora
|
|
606
560
|
self.class.named_datastreams_desc
|
607
561
|
end
|
608
562
|
|
609
|
-
def create_datastream(type,opts={})
|
610
|
-
|
611
|
-
|
563
|
+
def create_datastream(type, dsid, opts={})
|
564
|
+
dsid = generate_dsid(opts[:prefix] || "DS") if dsid == nil
|
565
|
+
klass = type.kind_of?(Class) ? type : type.constantize
|
566
|
+
raise ArgumentError, "Argument dsid must be of type string" unless dsid.kind_of?(String) || dsid.kind_of?(NilClass)
|
567
|
+
ds = klass.new(inner_object, dsid)
|
568
|
+
ds.mimeType = opts[:mimeType]
|
569
|
+
ds.controlGroup = opts[:controlGroup]
|
570
|
+
ds.dsLabel = opts[:dsLabel]
|
571
|
+
ds.dsLocation = opts[:dsLocation]
|
572
|
+
blob = opts[:blob]
|
573
|
+
if blob
|
574
|
+
if !ds.mimeType.present?
|
575
|
+
##TODO, this is all done by rubydora -- remove
|
576
|
+
ds.mimeType = blob.respond_to?(:content_type) ? blob.content_type : "application/octet-stream"
|
577
|
+
end
|
578
|
+
if !ds.dsLabel.present?
|
579
|
+
ds.dsLabel = File.basename(blob.path)
|
580
|
+
# ds.dsLabel = blob.original_filename
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
# blob = blob.read if blob.respond_to? :read
|
585
|
+
ds.content = blob || ""
|
586
|
+
ds
|
612
587
|
end
|
613
588
|
|
614
589
|
# ** EXPERIMENTAL **
|
@@ -779,8 +754,10 @@ module ActiveFedora
|
|
779
754
|
end
|
780
755
|
|
781
756
|
#return the pid of the Fedora Object
|
757
|
+
# if there is no fedora object (loaded from solr) get the instance var
|
758
|
+
# TODO make inner_object a proxy that can hold the pid
|
782
759
|
def pid
|
783
|
-
@inner_object.pid
|
760
|
+
@inner_object ? @inner_object.pid : @pid
|
784
761
|
end
|
785
762
|
|
786
763
|
|
@@ -813,17 +790,18 @@ module ActiveFedora
|
|
813
790
|
|
814
791
|
#return the create_date of the inner object (unless it's a new object)
|
815
792
|
def create_date
|
816
|
-
@inner_object.
|
793
|
+
@inner_object.profile["objCreateDate"] unless @inner_object.new?
|
817
794
|
end
|
818
795
|
|
819
796
|
#return the modification date of the inner object (unless it's a new object)
|
820
797
|
def modified_date
|
821
|
-
@inner_object.
|
798
|
+
@inner_object.profile["objLastModDate"] unless @inner_object.new?
|
822
799
|
end
|
823
800
|
|
824
801
|
#return the error list of the inner object (unless it's a new object)
|
825
802
|
def errors
|
826
|
-
|
803
|
+
#@inner_object.errors
|
804
|
+
[]
|
827
805
|
end
|
828
806
|
|
829
807
|
#return the label of the inner object (unless it's a new object)
|
@@ -832,48 +810,7 @@ module ActiveFedora
|
|
832
810
|
end
|
833
811
|
|
834
812
|
def label=(new_label)
|
835
|
-
@inner_object.
|
836
|
-
end
|
837
|
-
|
838
|
-
# Create an instance of the current Model from the given FOXML
|
839
|
-
# This method is used when you call load_instance on a Model
|
840
|
-
# @param [Nokogiri::XML::Document] doc the FOXML of the object
|
841
|
-
def self.deserialize(doc) #:nodoc:
|
842
|
-
if doc.instance_of?(REXML::Document)
|
843
|
-
pid = doc.elements['/foxml:digitalObject'].attributes['PID']
|
844
|
-
|
845
|
-
proto = self.new(:pid=>pid, :new_object=>false)
|
846
|
-
proto.datastreams.each do |name,ds|
|
847
|
-
doc.elements.each("//foxml:datastream[@ID='#{name}']") do |el|
|
848
|
-
# datastreams remain marked as new if the foxml doesn't have an entry for that datastream
|
849
|
-
ds.new_object = false
|
850
|
-
proto.datastreams[name]=ds.class.from_xml(ds, el)
|
851
|
-
end
|
852
|
-
end
|
853
|
-
proto.inner_object.new_object = false
|
854
|
-
return proto
|
855
|
-
elsif doc.instance_of?(Nokogiri::XML::Document)
|
856
|
-
pid = doc.xpath('/foxml:digitalObject').first["PID"]
|
857
|
-
|
858
|
-
proto = self.new(:pid=>pid, :new_object=>false)
|
859
|
-
proto.datastreams.each do |name,ds|
|
860
|
-
doc.xpath("//foxml:datastream[@ID='#{name}']").each do |node|
|
861
|
-
# datastreams remain marked as new if the foxml doesn't have an entry for that datastream
|
862
|
-
ds.new_object = false
|
863
|
-
# Nokogiri Datstreams use a new syntax for .from_xml (tmpl is optional!) and expects the actual xml content rather than the foxml datstream xml
|
864
|
-
# NB: Base.deserialize, or a separately named method, should set any other info from the foxml if necessary though by this point it's all been grabbed elsewhere...
|
865
|
-
if ds.kind_of?(ActiveFedora::NokogiriDatastream)
|
866
|
-
xml_content = Fedora::Repository.instance.fetch_custom(pid, "datastreams/#{name}/content")
|
867
|
-
# node = node.search('./foxml:datastreamVersion[last()]/foxml:xmlContent/*').first
|
868
|
-
proto.datastreams[name]=ds.class.from_xml(xml_content, ds)
|
869
|
-
else
|
870
|
-
proto.datastreams[name]=ds.class.from_xml(ds, node)
|
871
|
-
end
|
872
|
-
end
|
873
|
-
end
|
874
|
-
proto.inner_object.new_object = false
|
875
|
-
return proto
|
876
|
-
end
|
813
|
+
@inner_object.profile["objLabel"] = new_label
|
877
814
|
end
|
878
815
|
|
879
816
|
#Return a hash of all available metadata fields for all
|
@@ -919,7 +856,6 @@ module ActiveFedora
|
|
919
856
|
solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid, ActiveFedora::SolrService.solr_name(:system_create, :date) => self.create_date, ActiveFedora::SolrService.solr_name(:system_modified, :date) => self.modified_date, ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol) => self.class.inspect)
|
920
857
|
end
|
921
858
|
datastreams.each_value do |ds|
|
922
|
-
# solr_doc = ds.to_solr(solr_doc) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) ||( ds.kind_of?(ActiveFedora::RelsExtDatastream) || ( ds.kind_of?(ActiveFedora::QualifiedDublinCoreDatastream) && !opts[:model_only] )
|
923
859
|
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream) && !opts[:model_only] )
|
924
860
|
end
|
925
861
|
begin
|
@@ -958,9 +894,8 @@ module ActiveFedora
|
|
958
894
|
create_date = solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date).to_s] : solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)]
|
959
895
|
modified_date = solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[ActiveFedora::SolrService.solr_name(:system_modified, :date).to_s] : solr_doc[ActiveFedora::SolrService.solr_name(:system_modified, :date)]
|
960
896
|
obj = self.new({:pid=>solr_doc[SOLR_DOCUMENT_ID],:create_date=>create_date,:modified_date=>modified_date})
|
961
|
-
obj.new_object = false
|
897
|
+
#obj.new_object = false
|
962
898
|
#set by default to load any dependent relationship objects from solr as well
|
963
|
-
obj.load_from_solr = true
|
964
899
|
#need to call rels_ext once so it exists when iterating over datastreams
|
965
900
|
obj.rels_ext
|
966
901
|
obj.datastreams.each_value do |ds|
|
@@ -1035,8 +970,8 @@ module ActiveFedora
|
|
1035
970
|
def update_datastream_attributes(params={}, opts={})
|
1036
971
|
result = params.dup
|
1037
972
|
params.each_pair do |dsid, ds_params|
|
1038
|
-
if
|
1039
|
-
result[dsid] =
|
973
|
+
if datastreams.include?(dsid)
|
974
|
+
result[dsid] = datastreams[dsid].update_indexed_attributes(ds_params)
|
1040
975
|
else
|
1041
976
|
result.delete(dsid)
|
1042
977
|
end
|
@@ -1045,8 +980,8 @@ module ActiveFedora
|
|
1045
980
|
end
|
1046
981
|
|
1047
982
|
def get_values_from_datastream(dsid,field_key,default=[])
|
1048
|
-
if
|
1049
|
-
return
|
983
|
+
if datastreams.include?(dsid)
|
984
|
+
return datastreams[dsid].get_values(field_key,default)
|
1050
985
|
else
|
1051
986
|
return nil
|
1052
987
|
end
|
@@ -1069,17 +1004,17 @@ module ActiveFedora
|
|
1069
1004
|
if self.class.ds_specs
|
1070
1005
|
self.class.ds_specs.each do |name,ar|
|
1071
1006
|
if self.datastreams.has_key?(name)
|
1072
|
-
attributes = self.datastreams[name].attributes
|
1007
|
+
#attributes = self.datastreams[name].attributes
|
1073
1008
|
else
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1009
|
+
ds = ar.first.new(inner_object, name)
|
1010
|
+
ds.dsLabel = ar[1]
|
1011
|
+
# If you called has_metadata with a block, pass the block into the Datastream class
|
1012
|
+
if ar.last.class == Proc
|
1013
|
+
ar.last.call(ds)
|
1014
|
+
end
|
1015
|
+
#ds.attributes = attributes.merge(ds.attributes)
|
1016
|
+
self.add_datastream(ds)
|
1080
1017
|
end
|
1081
|
-
ds.attributes = attributes.merge(ds.attributes)
|
1082
|
-
self.add_datastream(ds)
|
1083
1018
|
end
|
1084
1019
|
end
|
1085
1020
|
end
|
@@ -1089,23 +1024,17 @@ module ActiveFedora
|
|
1089
1024
|
add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(self.class))
|
1090
1025
|
@metadata_is_dirty = true
|
1091
1026
|
update
|
1092
|
-
#@datastreams = datastreams_in_fedora
|
1093
1027
|
end
|
1094
1028
|
|
1095
1029
|
# Pushes the object and all of its new or dirty datastreams into Fedora
|
1096
1030
|
def update
|
1097
|
-
result =
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
@metadata_is_dirty = true
|
1103
|
-
end
|
1104
|
-
result = ds.save
|
1105
|
-
end
|
1106
|
-
end
|
1031
|
+
result = @inner_object.save
|
1032
|
+
datastreams.each {|k, ds| ds.serialize! }
|
1033
|
+
@metadata_is_dirty = datastreams.any? {|k,ds| ds.changed? && (ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) || ds.instance_of?(ActiveFedora::RelsExtDatastream))}
|
1034
|
+
## TODO rubydora is saving datastreams, but not of our subclasses
|
1035
|
+
datastreams.select {|k, ds| ds.changed? }.each do |k, ds| ds.save end
|
1107
1036
|
refresh
|
1108
|
-
return result
|
1037
|
+
return !!result
|
1109
1038
|
end
|
1110
1039
|
|
1111
1040
|
end
|