active-fedora 3.1.0.rc3 → 3.1.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -4
- data/Rakefile +2 -0
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora/base.rb +29 -10
- data/lib/active_fedora/datastream.rb +22 -28
- data/lib/active_fedora/datastream_hash.rb +5 -0
- data/lib/active_fedora/digital_object.rb +19 -0
- data/lib/active_fedora/model.rb +2 -2
- data/lib/active_fedora/rels_ext_datastream.rb +0 -15
- data/lib/active_fedora/semantic_node.rb +3 -3
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +1 -0
- data/spec/integration/base_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/support/mock_fedora.rb +37 -0
- data/spec/unit/base_datastream_management_spec.rb +2 -1
- data/spec/unit/base_extra_spec.rb +5 -2
- data/spec/unit/base_named_datastream_spec.rb +1 -1
- data/spec/unit/base_spec.rb +90 -87
- data/spec/unit/content_model_spec.rb +3 -1
- data/spec/unit/datastream_spec.rb +7 -24
- data/spec/unit/nokogiri_datastream_spec.rb +1 -1
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +4 -0
- data/spec/unit/rels_ext_datastream_spec.rb +0 -27
- data/spec/unit/solr_config_options_spec.rb +2 -1
- metadata +81 -79
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (3.1.0.
|
4
|
+
active-fedora (3.1.0.rc4)
|
5
5
|
activeresource (~> 3.0.0)
|
6
6
|
activesupport (~> 3.0.0)
|
7
7
|
equivalent-xml
|
@@ -13,7 +13,7 @@ PATH
|
|
13
13
|
om (>= 1.4.3)
|
14
14
|
rdf
|
15
15
|
rdf-rdfxml
|
16
|
-
rubydora (= 0.2.
|
16
|
+
rubydora (= 0.2.3)
|
17
17
|
solr-ruby (>= 0.0.6)
|
18
18
|
solrizer (> 1.0.0)
|
19
19
|
xml-simple (>= 1.0.12)
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
mediashelf-loggable
|
70
70
|
nokogiri (>= 1.4.2)
|
71
71
|
rack (1.3.5)
|
72
|
-
rake (0.9.2)
|
72
|
+
rake (0.9.2.2)
|
73
73
|
rbx-require-relative (0.0.5)
|
74
74
|
rcov (0.9.11)
|
75
75
|
rdf (0.3.4.1)
|
@@ -87,7 +87,7 @@ GEM
|
|
87
87
|
ruby-debug-base (~> 0.10.4.0)
|
88
88
|
ruby-debug-base (0.10.4)
|
89
89
|
linecache (>= 0.3)
|
90
|
-
rubydora (0.2.
|
90
|
+
rubydora (0.2.3)
|
91
91
|
activemodel
|
92
92
|
activesupport
|
93
93
|
fastercsv
|
data/Rakefile
CHANGED
data/active-fedora.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
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.2.
|
30
|
+
s.add_dependency("rubydora", '0.2.3')
|
31
31
|
s.add_dependency("rdf")
|
32
32
|
s.add_dependency("rdf-rdfxml")
|
33
33
|
s.add_development_dependency("yard")
|
data/lib/active_fedora/base.rb
CHANGED
@@ -112,7 +112,7 @@ module ActiveFedora
|
|
112
112
|
def method_missing(name, *args)
|
113
113
|
if datastreams.has_key? name.to_s
|
114
114
|
### Create and invoke a proxy method
|
115
|
-
self.class.class_eval <<-end_eval
|
115
|
+
self.class.class_eval <<-end_eval, __FILE__, __LINE__
|
116
116
|
def #{name.to_s}()
|
117
117
|
datastreams["#{name.to_s}"]
|
118
118
|
end
|
@@ -673,7 +673,7 @@ module ActiveFedora
|
|
673
673
|
# thumbnails - Get array of thumbnail datastreams
|
674
674
|
# thumbnails_ids - Get array of dsid's for thumbnail datastreams
|
675
675
|
def self.create_named_datastream_finders(name, prefix)
|
676
|
-
class_eval <<-END
|
676
|
+
class_eval <<-END, __FILE__, __LINE__
|
677
677
|
def #{name}(opts={})
|
678
678
|
id_array = []
|
679
679
|
keys = datastreams.keys
|
@@ -735,7 +735,8 @@ module ActiveFedora
|
|
735
735
|
# if there is no fedora object (loaded from solr) get the instance var
|
736
736
|
# TODO make inner_object a proxy that can hold the pid
|
737
737
|
def pid
|
738
|
-
@
|
738
|
+
@pid ||= @inner_object.pid
|
739
|
+
# @inner_object ? @inner_object.pid : @pid
|
739
740
|
end
|
740
741
|
|
741
742
|
|
@@ -768,12 +769,12 @@ module ActiveFedora
|
|
768
769
|
|
769
770
|
#return the create_date of the inner object (unless it's a new object)
|
770
771
|
def create_date
|
771
|
-
@inner_object.profile["objCreateDate"]
|
772
|
+
@inner_object.new? ? Time.now : @inner_object.profile["objCreateDate"]
|
772
773
|
end
|
773
774
|
|
774
775
|
#return the modification date of the inner object (unless it's a new object)
|
775
776
|
def modified_date
|
776
|
-
@inner_object.profile["objLastModDate"]
|
777
|
+
@inner_object.new? ? Time.now : @inner_object.profile["objLastModDate"]
|
777
778
|
end
|
778
779
|
|
779
780
|
#return the error list of the inner object (unless it's a new object)
|
@@ -835,8 +836,9 @@ module ActiveFedora
|
|
835
836
|
end
|
836
837
|
datastreams.each_value do |ds|
|
837
838
|
ds.ensure_xml_loaded if ds.respond_to? :ensure_xml_loaded ### Can't put this in the model because it's often implemented in Solrizer::XML::TerminologyBasedSolrizer
|
838
|
-
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream)
|
839
|
+
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream)
|
839
840
|
end
|
841
|
+
solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
|
840
842
|
begin
|
841
843
|
#logger.info("PID: '#{pid}' solr_doc put into solr: #{solr_doc.inspect}")
|
842
844
|
rescue
|
@@ -845,6 +847,18 @@ module ActiveFedora
|
|
845
847
|
return solr_doc
|
846
848
|
end
|
847
849
|
|
850
|
+
# Serialize the datastream's RDF relationships to solr
|
851
|
+
# @param [Hash] solr_doc @deafult an empty Hash
|
852
|
+
def solrize_relationships(solr_doc = Hash.new)
|
853
|
+
relationships.each_statement do |statement|
|
854
|
+
predicate = RelsExtDatastream.short_predicate(statement.predicate)
|
855
|
+
literal = statement.object.kind_of?(RDF::Literal)
|
856
|
+
val = literal ? statement.object.value : statement.object.to_str
|
857
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val )
|
858
|
+
end
|
859
|
+
return solr_doc
|
860
|
+
end
|
861
|
+
|
848
862
|
|
849
863
|
# ** EXPERIMENTAL **
|
850
864
|
#
|
@@ -986,7 +1000,7 @@ module ActiveFedora
|
|
986
1000
|
else
|
987
1001
|
ds = ar.first.new(inner_object, name)
|
988
1002
|
ds.model = self if ar.first == RelsExtDatastream
|
989
|
-
ds.dsLabel = ar[1]
|
1003
|
+
ds.dsLabel = ar[1] if ar[1].present?
|
990
1004
|
# If you called has_metadata with a block, pass the block into the Datastream class
|
991
1005
|
if ar.last.class == Proc
|
992
1006
|
ar.last.call(ds)
|
@@ -1007,11 +1021,16 @@ module ActiveFedora
|
|
1007
1021
|
|
1008
1022
|
# Pushes the object and all of its new or dirty datastreams into Fedora
|
1009
1023
|
def update
|
1010
|
-
result = @inner_object.save
|
1011
1024
|
datastreams.each {|k, ds| ds.serialize! }
|
1012
1025
|
@metadata_is_dirty = datastreams.any? {|k,ds| ds.changed? && (ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) || ds.instance_of?(ActiveFedora::RelsExtDatastream))}
|
1013
|
-
|
1014
|
-
|
1026
|
+
|
1027
|
+
result = @inner_object.save
|
1028
|
+
|
1029
|
+
### Rubydora re-inits the datastreams after a save, so ensure our copy stays in synch
|
1030
|
+
@inner_object.datastreams.each do |dsid, ds|
|
1031
|
+
datastreams[dsid] = ds
|
1032
|
+
ds.model = self if ds.kind_of? RelsExtDatastream
|
1033
|
+
end
|
1015
1034
|
refresh
|
1016
1035
|
return !!result
|
1017
1036
|
end
|
@@ -11,18 +11,6 @@ module ActiveFedora
|
|
11
11
|
super
|
12
12
|
end
|
13
13
|
|
14
|
-
# #Return the xml content representing this Datastream from Fedora
|
15
|
-
# def content
|
16
|
-
# result = Fedora::Repository.instance.fetch_custom(self.attributes[:pid], "datastreams/#{self.dsid}/content")
|
17
|
-
# return result
|
18
|
-
# end
|
19
|
-
|
20
|
-
#set this Datastream's content
|
21
|
-
def content=(content)
|
22
|
-
super
|
23
|
-
self.dirty = true
|
24
|
-
end
|
25
|
-
|
26
14
|
def size
|
27
15
|
self.profile['dsSize']
|
28
16
|
end
|
@@ -35,6 +23,7 @@ module ActiveFedora
|
|
35
23
|
end
|
36
24
|
|
37
25
|
# Test whether this datastream been modified since it was last saved?
|
26
|
+
# TODO deprecate this, just use changed?
|
38
27
|
def dirty?
|
39
28
|
@dirty || changed?
|
40
29
|
end
|
@@ -42,22 +31,27 @@ module ActiveFedora
|
|
42
31
|
def new_object?
|
43
32
|
new?
|
44
33
|
end
|
45
|
-
|
46
|
-
# Save the datastream into fedora.
|
47
|
-
# Also triggers {#before_save} and {#after_save} callbacks
|
34
|
+
|
48
35
|
def save
|
49
|
-
before_save
|
50
36
|
raise "No content #{dsid}" if @content.nil?
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
run_callbacks :save do
|
38
|
+
return create if new?
|
39
|
+
repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
|
40
|
+
reset_profile_attributes
|
41
|
+
#Datastream.new(digital_object, dsid)
|
42
|
+
self
|
43
|
+
end
|
54
44
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
45
|
+
|
46
|
+
def create
|
47
|
+
run_callbacks :create do
|
48
|
+
repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
|
49
|
+
reset_profile_attributes
|
50
|
+
self
|
51
|
+
end
|
59
52
|
end
|
60
|
-
|
53
|
+
|
54
|
+
|
61
55
|
# serializes any changed data into the content field
|
62
56
|
def serialize!
|
63
57
|
end
|
@@ -70,10 +64,10 @@ module ActiveFedora
|
|
70
64
|
tmpl
|
71
65
|
end
|
72
66
|
|
73
|
-
# Callback. Override this to insert behaviors after the save method. By default, sets self.dirty = false
|
74
|
-
def after_save
|
75
|
-
|
76
|
-
end
|
67
|
+
# # Callback. Override this to insert behaviors after the save method. By default, sets self.dirty = false
|
68
|
+
# def after_save
|
69
|
+
# self.dirty = false
|
70
|
+
# end
|
77
71
|
|
78
72
|
# returns a datetime in the standard W3C DateTime Format.
|
79
73
|
# ie 2008-10-17T00:17:18.194Z
|
@@ -9,6 +9,25 @@ module ActiveFedora
|
|
9
9
|
obj
|
10
10
|
end
|
11
11
|
|
12
|
+
# def datastreams
|
13
|
+
# @datastreams ||= begin
|
14
|
+
# h = Hash.new { |h,k| h[k] = datastream_object_for(k) }
|
15
|
+
|
16
|
+
# begin
|
17
|
+
# datastreams_xml = repository.datastreams(:pid => pid)
|
18
|
+
# datastreams_xml.gsub! '<objectDatastreams', '<objectDatastreams xmlns="http://www.fedora.info/definitions/1/0/access/"' unless datastreams_xml =~ /xmlns=/
|
19
|
+
# doc = Nokogiri::XML(datastreams_xml)
|
20
|
+
# doc.xpath('//access:datastream', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).each do |ds|
|
21
|
+
# h[ds['dsid']] = datastream_object_for ds['dsid']
|
22
|
+
# end
|
23
|
+
# rescue RestClient::ResourceNotFound
|
24
|
+
# end
|
25
|
+
|
26
|
+
# h
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
|
12
31
|
def datastream_object_for dsid
|
13
32
|
klass = original_class.datastream_class_for_name(dsid)
|
14
33
|
klass.new self, dsid
|
data/lib/active_fedora/model.rb
CHANGED
@@ -226,7 +226,7 @@ module ActiveFedora
|
|
226
226
|
end
|
227
227
|
def create_property_getter(property) # :nodoc:
|
228
228
|
|
229
|
-
class_eval <<-END
|
229
|
+
class_eval <<-END, __FILE__, __LINE__
|
230
230
|
def #{property.name}
|
231
231
|
attribute_get("#{property.name}")
|
232
232
|
end
|
@@ -234,7 +234,7 @@ module ActiveFedora
|
|
234
234
|
end
|
235
235
|
|
236
236
|
def create_property_setter(property)# :nodoc:
|
237
|
-
class_eval <<-END
|
237
|
+
class_eval <<-END, __FILE__, __LINE__
|
238
238
|
def #{property.name}=(value)
|
239
239
|
attribute_set("#{property.name}", value)
|
240
240
|
end
|
@@ -10,10 +10,6 @@ module ActiveFedora
|
|
10
10
|
include Solrizer::FieldNameMapper
|
11
11
|
attr_accessor :model
|
12
12
|
|
13
|
-
def changed?
|
14
|
-
(model && model.relationships_are_dirty) || super
|
15
|
-
end
|
16
|
-
|
17
13
|
def serialize!
|
18
14
|
self.content = to_rels_ext() if model.relationships_are_dirty
|
19
15
|
model.relationships_are_dirty = false
|
@@ -70,17 +66,6 @@ module ActiveFedora
|
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
73
|
-
# Serialize the datastream's RDF relationships to solr
|
74
|
-
# @param [Hash] solr_doc @deafult an empty Hash
|
75
|
-
def to_solr(solr_doc = Hash.new)
|
76
|
-
model.relationships.each_statement do |statement|
|
77
|
-
predicate = self.class.short_predicate(statement.predicate)
|
78
|
-
literal = statement.object.kind_of?(RDF::Literal)
|
79
|
-
val = literal ? statement.object.value : statement.object.to_str
|
80
|
-
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val )
|
81
|
-
end
|
82
|
-
return solr_doc
|
83
|
-
end
|
84
69
|
|
85
70
|
# ** EXPERIMENTAL **
|
86
71
|
#
|
@@ -420,7 +420,7 @@ module ActiveFedora
|
|
420
420
|
|
421
421
|
|
422
422
|
def create_inbound_relationship_finders(name, predicate, opts = {})
|
423
|
-
class_eval <<-END
|
423
|
+
class_eval <<-END, __FILE__, __LINE__
|
424
424
|
def #{name}(opts={})
|
425
425
|
load_inbound_relationship('#{name}', '#{predicate}', opts)
|
426
426
|
end
|
@@ -437,7 +437,7 @@ module ActiveFedora
|
|
437
437
|
end
|
438
438
|
|
439
439
|
def create_outbound_relationship_finders(name, predicate, opts = {})
|
440
|
-
class_eval <<-END
|
440
|
+
class_eval <<-END, __FILE__, __LINE__
|
441
441
|
def #{name}(opts={})
|
442
442
|
load_outbound_relationship(#{name.inspect}, #{predicate.inspect}, opts)
|
443
443
|
end
|
@@ -471,7 +471,7 @@ module ActiveFedora
|
|
471
471
|
#create methods that mirror the outbound append and remove with our bidirectional name, assume just add and remove locally
|
472
472
|
create_bidirectional_relationship_name_methods(name,outbound_method_name)
|
473
473
|
|
474
|
-
class_eval <<-END
|
474
|
+
class_eval <<-END, __FILE__, __LINE__
|
475
475
|
def #{name}(opts={})
|
476
476
|
load_bidirectional("#{name}", :#{inbound_method_name}, :#{outbound_method_name}, opts)
|
477
477
|
end
|
@@ -74,7 +74,7 @@ describe ActiveFedora::Base do
|
|
74
74
|
|
75
75
|
after(:each) do
|
76
76
|
begin
|
77
|
-
|
77
|
+
@test_object.delete
|
78
78
|
rescue
|
79
79
|
end
|
80
80
|
begin
|
@@ -758,7 +758,6 @@ describe ActiveFedora::Base do
|
|
758
758
|
describe '#update_named_datastream' do
|
759
759
|
it 'should update a named datastream to have a new file' do
|
760
760
|
@test_object2 = MockAFBaseDatastream.new
|
761
|
-
# @test_object2.new_object = true
|
762
761
|
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
763
762
|
minivan = f.read
|
764
763
|
f.rewind
|
@@ -814,6 +813,7 @@ describe ActiveFedora::Base do
|
|
814
813
|
@test_object2.named_datastreams_ids.should == {"high"=>[], "thumbnail"=>["THUMB1", "THUMB2"]}
|
815
814
|
end
|
816
815
|
end
|
816
|
+
|
817
817
|
|
818
818
|
# describe '#load_instance_from_solr' do
|
819
819
|
# it 'should populate an instance of an ActiveFedora::Base object using solr instead of Fedora' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
ENV["environment"] ||= 'test'
|
2
|
+
require "bundler/setup"
|
2
3
|
require 'active-fedora'
|
3
4
|
require 'spec'
|
4
5
|
require 'equivalent-xml/rspec_matchers'
|
5
6
|
|
7
|
+
require 'support/mock_fedora'
|
8
|
+
|
6
9
|
|
7
10
|
logger.level = Logger::WARN if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method
|
8
11
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
def mock_client
|
2
|
+
return @mock_client if @mock_client
|
3
|
+
@mock_client = mock("client")
|
4
|
+
@getter = mock("getter")
|
5
|
+
@getter.stubs(:get).returns('')
|
6
|
+
@mock_client
|
7
|
+
end
|
8
|
+
|
9
|
+
def stub_get(pid, record_exists=false)
|
10
|
+
pid.gsub!(/:/, '%3A')
|
11
|
+
mock_client.stubs(:[]).with("objects/#{pid}?format=xml").returns(stub('get getter', :get=>'foobar')) if record_exists
|
12
|
+
# @mock_client.expects(:[]).with("objects/#{pid}?format=xml").raises(RestClient::ResourceNotFound) unless record_exists
|
13
|
+
mock_client.stubs(:[]).with("objects/#{pid}/datastreams?format=xml").returns(@getter)
|
14
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
15
|
+
mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def stub_ingest(pid)
|
19
|
+
mock_client.stubs(:[]).with("objects/#{pid || 'new'}").returns(stub("ingester", :post=>pid))
|
20
|
+
end
|
21
|
+
|
22
|
+
def stub_add_ds(pid, dsids)
|
23
|
+
dsids.each do |dsid|
|
24
|
+
client = mock_client.stubs(:[]).with do |params|
|
25
|
+
/objects\/#{pid}\/datastreams\/#{dsid}/.match(params)
|
26
|
+
end
|
27
|
+
client.returns(stub("ds_adder", :post=>pid, :get=>''))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_get_content(pid, dsids)
|
32
|
+
pid.gsub!(/:/, '%3A')
|
33
|
+
dsids.each do |dsid|
|
34
|
+
mock_client.stubs(:[]).with { |params| /objects\/#{pid}\/datastreams\/#{dsid}\/content/.match(params)}.returns(stub("content_accessor", :post=>pid, :get=>''))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -3,9 +3,10 @@ require File.join( File.dirname(__FILE__), "../spec_helper" )
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
+
stub_get('__nextid__')
|
6
7
|
ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
|
8
|
+
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
7
9
|
@test_object = ActiveFedora::Base.new
|
8
|
-
#Fedora::Repository.instance.delete(@test_object.inner_object)
|
9
10
|
end
|
10
11
|
|
11
12
|
describe '.generate_dsid' do
|