Skip to content
simonlamb edited this page Mar 12, 2012 · 1 revision

This is a list of questions developer using active_fedora might ask, and where to find the appropriate documentation.

Add Fedora disseminator method support to my Active-Fedora models?

Suppose you have a ‘JournalArticle’ ActiveFedora model, with an equivalent ‘hydra-cModel:JournalArticle’ Content model in your Fedora Repository. You may have utilised the Fedora-commons Content Model Architecture to create some disseminators that are relevant to that type of object.

Active-Fedora enables you to utilise these disseminator methods within your Ruby models by adding a service mapping to the configuration file ‘service-mappings.yml’.

For example, if your JournalArticle Content Model has a disseminator method called ‘getJournalMetadata’ you would add the following to the service_mappings.yml:-

:service_mapping:
"hydra-sDef:JournalArticle":
  :journal_metadata: getJournalMetadata

In this case ‘journal_metadata’ will be the method added to your model to retrieve the journal metadata, ‘getJournalMetadata’ would be the Dissem method specified in the Fedora JournalArticle sDef/sDep objects.

Add disseminator method support when my Fedora objects conform to more than one ContentModel?

The method described above enables you to create mappings for all of the Disseminator methods within JournalArticle content model. However, if you want to add support for calling non-primary (the Fedora content model that maps to your Ruby/Active-Fedora model) content model disseminator methods, you need to add a little bit more code.

Lets take the example that your JournalArticle ruby model creates Fedora objects that conforms to the following content models:-

info:fedora/hydra-cModel:JournalArticle
info:fedora/hydra-cModel:commonMetadata
info:fedora/hydra-cModel:compoundContent

Within the ‘hydra-cModel:commonMetadata’ there may be various dissem methods including ‘getOAI_DC’, ‘getDescMetadata’ etc…
If we want to add support for the ‘getOAI_DC’ dissem we would add the commonMetadata mapping to our service_mappings.yml:-

:service_mapping:
"hydra-sDef:JournalArticle":
  :journal_metadata: getJournalMetadata
"hydra-sDef:commonMetadata":
  :oai_dc: getOAI_DC

We then add a mixin to enable the calling of ‘oai_dc’ in our JournalArticle model, so first we will create a simple module ‘common_metadata_sdef.rb’ with the following:-

module CommonMetadataSdef
   def self.included(mod)
      #This adds the commonMetadata service_definition to our model - this enables us to add all the commonMetadata dissem methods to service_mappings.yml... 
      mod.has_service_definition "hydra-sDef:commonMetadata"
 
      # You can deliberately call the (Service_definition) add_method direct if you just want to use one method from the dissem
      # This saves a call to fedora to retrieve all the commonMetadata methods when we know we just want 'getOAI_DC' 
      # mod.add_method! "hydra-sDef:commonMetadata", "getOAI_DC"
   end
end

In our JournalArticle ruby model (or any other models that subscribe to commonMetadata) we include the ‘CommonMetadataSdef’ mixin…

require "hydra"

class JournalArticle < ActiveFedora::Base
  
  include Hydra::ModelMethods
  include ActiveFedora::ServiceDefinitions
  include CommonMetadataSdef

  has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => RightsMetadata 
  
  has_metadata :name => "descMetadata", :label=>"MODS metadata", :type => Hydra::ModsJournalArticle, :control_group=>'M'

  has_metadata :name => "contentMetadata", :label=>"Content metadata", :type => ContentMetadata, :control_group=>'M'

We can then call the disseminator in our ruby code like:-

@journal_article.oai_dc
Clone this wiki locally