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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (3.1.0.rc2)
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.1)
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.1)
90
+ rubydora (0.2.3)
91
91
  activemodel
92
92
  activesupport
93
93
  fastercsv
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake/clean'
2
2
  require 'rubygems'
3
3
  require 'bundler'
4
+ require "bundler/setup"
5
+
4
6
 
5
7
  $: << 'lib'
6
8
 
@@ -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.1')
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")
@@ -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
- @inner_object ? @inner_object.pid : @pid
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"] unless @inner_object.new?
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"] unless @inner_object.new?
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) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream) && !opts[:model_only] )
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
- ## TODO rubydora is saving datastreams, but not of our subclasses
1014
- datastreams.select {|k, ds| ds.changed? }.each do |k, ds| ds.save end
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
- result = super
52
- after_save
53
- result
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
- # Callback. Does nothing by default. Override this to insert behaviors before the save method.
57
- def before_save
58
- #check_concurrency
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
- self.dirty = false
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
@@ -13,5 +13,10 @@ module ActiveFedora
13
13
  end
14
14
  super
15
15
  end
16
+
17
+ def []= (key, val)
18
+ @obj.inner_object.datastreams[key]=val# unless @obj.inner_object.new?
19
+ super
20
+ end
16
21
  end
17
22
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.1.0.rc3"
2
+ VERSION = "3.1.0.rc4"
3
3
  end
@@ -69,6 +69,7 @@ namespace :active_fedora do
69
69
  t.rcov_opts << ['--exclude', 'spec']
70
70
  end
71
71
 
72
+ desc "Refresh test fixtres"
72
73
  task :refresh_fixtures do
73
74
  Rake::Task["active_fedora:clean_jetty"].invoke
74
75
  Rake::Task["active_fedora:load_fixtures"].invoke
@@ -74,7 +74,7 @@ describe ActiveFedora::Base do
74
74
 
75
75
  after(:each) do
76
76
  begin
77
- @test_object.delete
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