Class: Hydra::RightsMetadataDatastream
- Inherits:
-
ActiveFedora::NokogiriDatastream
- Object
- Fedora::BaseObject
- Fedora::Datastream
- ActiveFedora::Datastream
- ActiveFedora::NokogiriDatastream
- Hydra::RightsMetadataDatastream
- Defined in:
- lib/active_fedora/samples/hydra-rights_metadata_datastream.rb
Overview
This is an example of a NokogiriDatastream that defines a terminology for Hydra rightsMetadata xml The documentation for Hydra rightsMetadata is on the Hydra wiki at wiki.duraspace.org/display/hydra/Hydra+rights+metadata The real version of this Terminology is part of the hydra-head plugin. See github.com/projecthydra/hydra-head/blob/master/lib/hydra/rights_metadata.rb
The purpose of rightsMetadata is to store information about access controls and licensing for the object that the rightsMetadata is attached to
The most interesting thing going on in this Class is the use of custom methods to access and update permissions in intuitive ways. These methods allow you to do things like
-
Get reports on which groups & individuals have which permissions
-
Update permissions for individuals & groups with straightforward syntax
Another interesting thing in this Class: it extends to_solr, first calling “super” (the default to_solr behavior) and then inserting an additional embargo_release_date_dt field It uses Solrizer::Extractor.insert_solr_field_value to do this. That method handles inserting new values into a Hash while ensuring that you don’t destroy or overwrite any existing values in the hash.
Instance Attribute Summary collapse
-
#embargo_release_date(opts = {}) ⇒ Object
Returns the value of attribute embargo_release_date.
Attributes inherited from ActiveFedora::NokogiriDatastream
Attributes included from ActiveFedora::MetadataDatastreamHelper
Attributes inherited from ActiveFedora::Datastream
#dirty, #fields, #last_modified
Attributes inherited from Fedora::BaseObject
#attributes, #blob, #errors, #new_object, #uri
Class Method Summary collapse
-
.xml_template ⇒ Object
Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml).
Instance Method Summary collapse
-
#groups ⇒ Hash
Reports on which groups have which permissions.
-
#individuals ⇒ Hash
Reports on which groups have which permissions.
-
#permissions(selector, new_access_level = nil) ⇒ Hash
Returns the permissions for the selected person/group If new_access_level is provided, updates the selected person/group access_level to the one specified A new_access_level of “none” will remove all access_levels for the selected person/group.
-
#quick_search_by_type(type) ⇒ Hash
This method limits the response to known access levels (:discover, :read, :edit).
- #to_solr(solr_doc = Hash.new) ⇒ Object
- #under_embargo? ⇒ Boolean
-
#update_permissions(params) ⇒ Object
Updates permissions for all of the persons and groups in a hash Currently restricts actor type to group or person.
Methods inherited from ActiveFedora::NokogiriDatastream
#content=, #from_solr, from_xml, #generate_solr_symbol, #get_values, #get_values_from_solr, #has_solr_name?, #initialize, #is_hierarchical_term_pointer?, #om_term_values, #om_update_values, #term_values, #to_xml, #update_indexed_attributes, #update_values
Methods included from ActiveFedora::MetadataDatastreamHelper
#from_solr, included, #initialize, #save, #set_blob_for_save, #to_xml
Methods inherited from ActiveFedora::Datastream
#after_save, #before_save, #check_concurrency, #content, #content=, delete, #delete, #dirty?, #dsid=, from_xml, #initialize, #last_modified_in_repository, #pid, #pid=, #save, #size, #to_param
Methods inherited from Fedora::Datastream
#control_group, #control_group=, #dsid, #initialize, #label, #label=, #mime_type, #mime_type=, #pid, #uri, #url
Methods inherited from Fedora::BaseObject
#[], #initialize, #new_object?
Constructor Details
This class inherits a constructor from ActiveFedora::NokogiriDatastream
Instance Attribute Details
#embargo_release_date(opts = {}) ⇒ Object
Returns the value of attribute embargo_release_date.
164 165 166 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 164 def @embargo_release_date end |
Class Method Details
.xml_template ⇒ Object
Generates an empty Mods Article (used when you call ModsArticle.new without passing in existing xml)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 53 def self.xml_template builder = Nokogiri::XML::Builder.new do |xml| xml.rightsMetadata(:version=>"0.1", "xmlns"=>"http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1") { xml.copyright { xml.human xml.machine { xml.uvalicense "no" } } xml.access(:type=>"discover") { xml.human xml.machine } xml.access(:type=>"read") { xml.human xml.machine } xml.access(:type=>"edit") { xml.human xml.machine } xml.{ xml.human xml.machine } } end return builder.doc end |
Instance Method Details
#groups ⇒ Hash
Reports on which groups have which permissions
127 128 129 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 127 def groups return quick_search_by_type(:group) end |
#individuals ⇒ Hash
Reports on which groups have which permissions
137 138 139 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 137 def individuals return quick_search_by_type(:person) end |
#permissions(selector, new_access_level = nil) ⇒ Hash
Returns the permissions for the selected person/group If new_access_level is provided, updates the selected person/group access_level to the one specified A new_access_level of “none” will remove all access_levels for the selected person/group
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 97 def (selector, new_access_level=nil) type = selector.keys.first.to_sym actor = selector.values.first if new_access_level.nil? xpath = self.class.terminology.xpath_for(:access, type, actor) nodeset = self.find_by_terms(xpath) if nodeset.empty? return "none" else return nodeset.first.ancestors("access").first.attributes["type"].text end else (selector) unless new_access_level == "none" access_type_symbol = "#{new_access_level}_access".to_sym result = self.update_values([access_type_symbol, type] => {"-1"=>actor}) end self.dirty = true return new_access_level end end |
#quick_search_by_type(type) ⇒ Hash
This method limits the response to known access levels (:discover, :read, :edit). Probably runs a bit faster than #permissions.
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 152 def quick_search_by_type(type) result = {} [{:discover_access=>"discover"},{:read_access=>"read"},{:edit_access=>"edit"}].each do |access_levels_hash| access_level = access_levels_hash.keys.first access_level_name = access_levels_hash.values.first self.find_by_terms(*[access_level, type]).each do |entry| result[entry.text] = access_level_name end end return result end |
#to_solr(solr_doc = Hash.new) ⇒ Object
185 186 187 188 189 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 185 def to_solr(solr_doc=Hash.new) super(solr_doc) ::Solrizer::Extractor.insert_solr_field_value(solr_doc, "embargo_release_date_dt", (:format=>:solr_date)) if solr_doc end |
#under_embargo? ⇒ Boolean
181 182 183 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 181 def ( && Date.today < .to_date) ? true : false end |
#update_permissions(params) ⇒ Object
Updates permissions for all of the persons and groups in a hash Currently restricts actor type to group or person. Any others will be ignored
144 145 146 147 |
# File 'lib/active_fedora/samples/hydra-rights_metadata_datastream.rb', line 144 def (params) params.fetch("group", {}).each_pair {|group_id, access_level| self.({"group"=>group_id}, access_level)} params.fetch("person", {}).each_pair {|group_id, access_level| self.({"person"=>group_id}, access_level)} end |