Skip to content

Commit

Permalink
Update to rc4. Using rubydora 0.2.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 2, 2011
1 parent 5e11661 commit 7e333d1
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 204 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
om (>= 1.4.3)
rdf
rdf-rdfxml
rubydora (= 0.2.2)
rubydora (= 0.2.3)
solr-ruby (>= 0.0.6)
solrizer (> 1.0.0)
xml-simple (>= 1.0.12)
Expand Down Expand Up @@ -69,7 +69,7 @@ GEM
mediashelf-loggable
nokogiri (>= 1.4.2)
rack (1.3.5)
rake (0.9.2)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rcov (0.9.11)
rdf (0.3.4.1)
Expand All @@ -87,7 +87,7 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rubydora (0.2.2)
rubydora (0.2.3)
activemodel
activesupport
fastercsv
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rake/clean'
require 'rubygems'
require 'bundler'
require "bundler/setup"


$: << 'lib'

Expand Down
2 changes: 1 addition & 1 deletion active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency("mediashelf-loggable")
s.add_dependency("equivalent-xml")
s.add_dependency("facets")
s.add_dependency("rubydora", '0.2.2')
s.add_dependency("rubydora", '0.2.3')
s.add_dependency("rdf")
s.add_dependency("rdf-rdfxml")
s.add_development_dependency("yard")
Expand Down
39 changes: 29 additions & 10 deletions lib/active_fedora/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.has_metadata(args, &block)
def method_missing(name, *args)
if datastreams.has_key? name.to_s
### Create and invoke a proxy method
self.class.class_eval <<-end_eval
self.class.class_eval <<-end_eval, __FILE__, __LINE__
def #{name.to_s}()
datastreams["#{name.to_s}"]
end
Expand Down Expand Up @@ -673,7 +673,7 @@ def self.create_named_datastream_update_methods(name)
# thumbnails - Get array of thumbnail datastreams
# thumbnails_ids - Get array of dsid's for thumbnail datastreams
def self.create_named_datastream_finders(name, prefix)
class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{name}(opts={})
id_array = []
keys = datastreams.keys
Expand Down Expand Up @@ -735,7 +735,8 @@ def inner_object # :nodoc
# if there is no fedora object (loaded from solr) get the instance var
# TODO make inner_object a proxy that can hold the pid
def pid
@inner_object ? @inner_object.pid : @pid
@pid ||= @inner_object.pid
# @inner_object ? @inner_object.pid : @pid
end
Expand Down Expand Up @@ -768,12 +769,12 @@ def owner_id=(owner_id)
#return the create_date of the inner object (unless it's a new object)
def create_date
@inner_object.profile["objCreateDate"] unless @inner_object.new?
@inner_object.new? ? Time.now : @inner_object.profile["objCreateDate"]
end
#return the modification date of the inner object (unless it's a new object)
def modified_date
@inner_object.profile["objLastModDate"] unless @inner_object.new?
@inner_object.new? ? Time.now : @inner_object.profile["objLastModDate"]
end
#return the error list of the inner object (unless it's a new object)
Expand Down Expand Up @@ -835,8 +836,9 @@ def to_solr(solr_doc = Hash.new, opts={})
end
datastreams.each_value do |ds|
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
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] )
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream)
end
solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
begin
#logger.info("PID: '#{pid}' solr_doc put into solr: #{solr_doc.inspect}")
rescue
Expand All @@ -845,6 +847,18 @@ def to_solr(solr_doc = Hash.new, opts={})
return solr_doc
end
# Serialize the datastream's RDF relationships to solr
# @param [Hash] solr_doc @deafult an empty Hash
def solrize_relationships(solr_doc = Hash.new)
relationships.each_statement do |statement|
predicate = RelsExtDatastream.short_predicate(statement.predicate)
literal = statement.object.kind_of?(RDF::Literal)
val = literal ? statement.object.value : statement.object.to_str
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val )
end
return solr_doc
end
# ** EXPERIMENTAL **
#
Expand Down Expand Up @@ -986,7 +1000,7 @@ def configure_defined_datastreams
else
ds = ar.first.new(inner_object, name)
ds.model = self if ar.first == RelsExtDatastream
ds.dsLabel = ar[1]
ds.dsLabel = ar[1] if ar[1].present?
# If you called has_metadata with a block, pass the block into the Datastream class
if ar.last.class == Proc
ar.last.call(ds)
Expand All @@ -1007,11 +1021,16 @@ def create
# Pushes the object and all of its new or dirty datastreams into Fedora
def update
result = @inner_object.save
datastreams.each {|k, ds| ds.serialize! }
@metadata_is_dirty = datastreams.any? {|k,ds| ds.changed? && (ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) || ds.instance_of?(ActiveFedora::RelsExtDatastream))}
## TODO rubydora is saving datastreams, but not of our subclasses
datastreams.select {|k, ds| ds.changed? }.each do |k, ds| ds.save end
result = @inner_object.save
### Rubydora re-inits the datastreams after a save, so ensure our copy stays in synch
@inner_object.datastreams.each do |dsid, ds|
datastreams[dsid] = ds
ds.model = self if ds.kind_of? RelsExtDatastream
end
refresh
return !!result
end
Expand Down
50 changes: 22 additions & 28 deletions lib/active_fedora/datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ def initialize(digital_object, dsid)
super
end

# #Return the xml content representing this Datastream from Fedora
# def content
# result = Fedora::Repository.instance.fetch_custom(self.attributes[:pid], "datastreams/#{self.dsid}/content")
# return result
# end

#set this Datastream's content
def content=(content)
super
self.dirty = true
end

def size
self.profile['dsSize']
end
Expand All @@ -35,29 +23,35 @@ def to_param
end

# Test whether this datastream been modified since it was last saved?
# TODO deprecate this, just use changed?
def dirty?
@dirty || changed?
end

def new_object?
new?
end

# Save the datastream into fedora.
# Also triggers {#before_save} and {#after_save} callbacks

def save
before_save
raise "No content #{dsid}" if @content.nil?
result = super
after_save
result
run_callbacks :save do
return create if new?
repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
reset_profile_attributes
#Datastream.new(digital_object, dsid)
self
end
end

# Callback. Does nothing by default. Override this to insert behaviors before the save method.
def before_save
#check_concurrency

def create
run_callbacks :create do
repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
reset_profile_attributes
self
end
end



# serializes any changed data into the content field
def serialize!
end
Expand All @@ -70,10 +64,10 @@ def self.from_xml(tmpl, node)
tmpl
end

# Callback. Override this to insert behaviors after the save method. By default, sets self.dirty = false
def after_save
self.dirty = false
end
# # Callback. Override this to insert behaviors after the save method. By default, sets self.dirty = false
# def after_save
# self.dirty = false
# end

# returns a datetime in the standard W3C DateTime Format.
# ie 2008-10-17T00:17:18.194Z
Expand Down
5 changes: 5 additions & 0 deletions lib/active_fedora/datastream_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ def [] (key)
end
super
end

def []= (key, val)
@obj.inner_object.datastreams[key]=val# unless @obj.inner_object.new?
super
end
end
end
19 changes: 19 additions & 0 deletions lib/active_fedora/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ def self.find(original_class, pid)
obj
end

# def datastreams
# @datastreams ||= begin
# h = Hash.new { |h,k| h[k] = datastream_object_for(k) }

# begin
# datastreams_xml = repository.datastreams(:pid => pid)
# datastreams_xml.gsub! '<objectDatastreams', '<objectDatastreams xmlns="http://www.fedora.info/definitions/1/0/access/"' unless datastreams_xml =~ /xmlns=/
# doc = Nokogiri::XML(datastreams_xml)
# doc.xpath('//access:datastream', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).each do |ds|
# h[ds['dsid']] = datastream_object_for ds['dsid']
# end
# rescue RestClient::ResourceNotFound
# end

# h
# end
# end


def datastream_object_for dsid
klass = original_class.datastream_class_for_name(dsid)
klass.new self, dsid
Expand Down
4 changes: 2 additions & 2 deletions lib/active_fedora/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ def attribute_get(name)
end
def create_property_getter(property) # :nodoc:

class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{property.name}
attribute_get("#{property.name}")
end
END
end

def create_property_setter(property)# :nodoc:
class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{property.name}=(value)
attribute_set("#{property.name}", value)
end
Expand Down
11 changes: 0 additions & 11 deletions lib/active_fedora/rels_ext_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ def self.short_predicate(predicate)
end
end

# Serialize the datastream's RDF relationships to solr
# @param [Hash] solr_doc @deafult an empty Hash
def to_solr(solr_doc = Hash.new)
model.relationships.each_statement do |statement|
predicate = self.class.short_predicate(statement.predicate)
literal = statement.object.kind_of?(RDF::Literal)
val = literal ? statement.object.value : statement.object.to_str
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val )
end
return solr_doc
end

# ** EXPERIMENTAL **
#
Expand Down
6 changes: 3 additions & 3 deletions lib/active_fedora/semantic_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def create_bidirectional_named_relationship_methods(name,outbound_name)


def create_inbound_relationship_finders(name, predicate, opts = {})
class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{name}(opts={})
load_inbound_relationship('#{name}', '#{predicate}', opts)
end
Expand All @@ -437,7 +437,7 @@ def #{name}_query
end

def create_outbound_relationship_finders(name, predicate, opts = {})
class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{name}(opts={})
load_outbound_relationship(#{name.inspect}, #{predicate.inspect}, opts)
end
Expand Down Expand Up @@ -471,7 +471,7 @@ def create_bidirectional_relationship_finders(name, outbound_predicate, inbound_
#create methods that mirror the outbound append and remove with our bidirectional name, assume just add and remove locally
create_bidirectional_relationship_name_methods(name,outbound_method_name)

class_eval <<-END
class_eval <<-END, __FILE__, __LINE__
def #{name}(opts={})
load_bidirectional("#{name}", :#{inbound_method_name}, :#{outbound_method_name}, opts)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveFedora
VERSION = "3.1.0.rc3"
VERSION = "3.1.0.rc4"
end
4 changes: 2 additions & 2 deletions spec/integration/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def configure_defined_datastreams

after(:each) do
begin
@test_object.delete
@test_object.delete
rescue
end
begin
Expand Down Expand Up @@ -758,7 +758,6 @@ def configure_defined_datastreams
describe '#update_named_datastream' do
it 'should update a named datastream to have a new file' do
@test_object2 = MockAFBaseDatastream.new
# @test_object2.new_object = true
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
minivan = f.read
f.rewind
Expand Down Expand Up @@ -814,6 +813,7 @@ def configure_defined_datastreams
@test_object2.named_datastreams_ids.should == {"high"=>[], "thumbnail"=>["THUMB1", "THUMB2"]}
end
end


# describe '#load_instance_from_solr' do
# it 'should populate an instance of an ActiveFedora::Base object using solr instead of Fedora' do
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
ENV["environment"] ||= 'test'
require "bundler/setup"
require 'active-fedora'
require 'spec'
require 'equivalent-xml/rspec_matchers'

require 'support/mock_fedora'


logger.level = Logger::WARN if logger.respond_to? :level ###MediaShelf StubLogger doesn't have a level= method

Expand Down
Loading

0 comments on commit 7e333d1

Please sign in to comment.