Module: ActiveFedora::Persistence
- Defined in:
- lib/active_fedora/persistence.rb
Overview
Active Fedora Persistence
Instance Method Summary collapse
-
#assert_content_model ⇒ Object
This can be overriden to assert a different model It’s normally called once in the lifecycle, by #create#.
-
#delete ⇒ Object
Deletes a Base object, also deletes the info indexed in Solr, and the underlying inner_object.
- #dependent_objects ⇒ Object
- #destroy ⇒ Object
-
#refresh ⇒ Object
Refreshes the object’s info from Fedora Note: Currently just registers any new datastreams that have appeared in fedora.
-
#save ⇒ Object
Saves a Base object, and any dirty datastreams, then updates the Solr index for this object.
- #save! ⇒ Object
- #update_attributes(properties) ⇒ Object
-
#update_index ⇒ Object
Updates Solr index with self.
Instance Method Details
#assert_content_model ⇒ Object
This can be overriden to assert a different model It’s normally called once in the lifecycle, by #create#
25 26 27 |
# File 'lib/active_fedora/persistence.rb', line 25 def assert_content_model add_relationship(:has_model, self.class.to_class_uri) end |
#delete ⇒ Object
Deletes a Base object, also deletes the info indexed in Solr, and the underlying inner_object. If this object is held in any relationships (ie inbound relationships outside of this object it will remove it from those items rels-ext as well
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_fedora/persistence.rb', line 54 def delete dependent_objects.each_pair do |predicate, objects| objects.each do |obj| if obj.respond_to?(:remove_relationship) obj.remove_relationship(predicate,self) obj.save end end end #Fedora::Repository.instance.delete(@inner_object) pid = self.pid ## cache so it's still available after delete begin @inner_object.delete rescue RestClient::ResourceNotFound =>e raise ObjectNotFoundError, "Unable to find #{pid} in the repository" end if ENABLE_SOLR_UPDATES solr = ActiveFedora::SolrService.instance.conn solr.delete_by_id(pid) solr.commit end end |
#dependent_objects ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_fedora/persistence.rb', line 40 def dependent_objects # Loop over all the inbound associations (has_many reflections) results = {} reflections.each_pair do |name, reflection| if reflection.macro == :has_many results[reflection.[:property]] = send(name) end end results.merge (inbound_relationships(:object) ) end |
#destroy ⇒ Object
78 79 80 |
# File 'lib/active_fedora/persistence.rb', line 78 def destroy delete end |
#refresh ⇒ Object
Refreshes the object’s info from Fedora Note: Currently just registers any new datastreams that have appeared in fedora
36 37 38 |
# File 'lib/active_fedora/persistence.rb', line 36 def refresh # inner_object.load_attributes_from_fedora end |
#save ⇒ Object
Saves a Base object, and any dirty datastreams, then updates the Solr index for this object.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_fedora/persistence.rb', line 7 def save(*) # If it's a new object, set the conformsTo relationship for Fedora CMA if new_record? result = create update_index if create_needs_index? else result = update update_index if update_needs_index? end return result end |
#save! ⇒ Object
19 20 21 |
# File 'lib/active_fedora/persistence.rb', line 19 def save!(*) save end |
#update_attributes(properties) ⇒ Object
29 30 31 32 |
# File 'lib/active_fedora/persistence.rb', line 29 def update_attributes(properties) self.attributes=properties save end |
#update_index ⇒ Object
Updates Solr index with self.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_fedora/persistence.rb', line 83 def update_index if defined?( Solrizer::Fedora::Solrizer ) #logger.info("Trying to solrize pid: #{pid}") solrizer = Solrizer::Fedora::Solrizer.new solrizer.solrize( self ) else SolrService.add(self.to_solr) SolrService.commit end end |