Skip to content

Commit

Permalink
Made MetadataDatastream a NokogiriDatastream
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jan 12, 2012
1 parent 2254174 commit a25a5e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions lib/active_fedora/delegating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def delegate(field, args ={})
def create_delegate_accessor(field, args)
define_method field do
ds = self.send(args[:to])
val = if ds.kind_of? ActiveFedora::NokogiriDatastream
val = if ds.kind_of? ActiveFedora::MetadataDatastream
ds.send(:get_values, field)
else
terminology = args[:at] || [field]
ds.send(:term_values, *terminology)
else
ds.send(:get_values, field)
end
args[:unique] ? val.first : val

Expand All @@ -45,11 +45,11 @@ def create_delegate_accessor(field, args)
def create_delegate_setter(field, args)
define_method "#{field}=".to_sym do |v|
ds = self.send(args[:to])
if ds.kind_of? ActiveFedora::NokogiriDatastream
if ds.kind_of? ActiveFedora::MetadataDatastream
ds.send(:set_value, field, v)
else
terminology = args[:at] || [field]
ds.send(:update_indexed_attributes, {terminology => v})
else
ds.send(:set_value, field, v)
end
end
end
Expand Down
25 changes: 25 additions & 0 deletions lib/active_fedora/metadata_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ def to_solr(solr_doc = Hash.new) # :nodoc:
return solr_doc
end

# ** EXPERIMENTAL **
#
# This is utilized by ActiveFedora::Base.load_instance_from_solr to set
# metadata values in this object using the Solr document passed in.
# Any keys in the solr document that map to a metadata field key within a MetadataDatastream object
# are set to the corresponding value. Any others are ignored. ActiveFedora::SolrService.solr_name
# is used to map solr key to field key name.
#
# ====Warning
# Solr must be synchronized with data in Fedora.
def from_solr(solr_doc)
fields.each do |field_key, field_info|
field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
value = (solr_doc[field_symbol].nil? ? solr_doc[field_symbol.to_s]: solr_doc[field_symbol])
unless value.nil?
if value.is_a? Array
update_attributes({field_key=>value})
else
update_indexed_attributes({field_key=>{0=>value}})
end
end
end
end




def update_attributes(params={},opts={})
Expand Down
25 changes: 0 additions & 25 deletions lib/active_fedora/metadata_datastream_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,4 @@ def serialize! # :nodoc:
end
end

# ** EXPERIMENTAL **
#
# This is utilized by ActiveFedora::Base.load_instance_from_solr to set
# metadata values in this object using the Solr document passed in.
# Any keys in the solr document that map to a metadata field key within a MetadataDatastream object
# are set to the corresponding value. Any others are ignored. ActiveFedora::SolrService.solr_name
# is used to map solr key to field key name.
#
# ====Warning
# Solr must be synchronized with data in Fedora.
def from_solr(solr_doc)
fields.each do |field_key, field_info|
field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
value = (solr_doc[field_symbol].nil? ? solr_doc[field_symbol.to_s]: solr_doc[field_symbol])
unless value.nil?
if value.is_a? Array
update_attributes({field_key=>value})
else
update_indexed_attributes({field_key=>{0=>value}})
end
end
end
end


end

0 comments on commit a25a5e9

Please sign in to comment.