Skip to content

Models Defining a Custom Hydra Model

ndushay edited this page May 9, 2012 · 13 revisions

Models – Defining a Custom Hydra Model

General Introduction/Tutorial

The Getting Started Building Your Own Hydra Application tutorial includes a detailed section on defining a JournalArticle model. Read that to get a sense of how to create a working Hydra Model.

Steps to Defining Your Model

  1. Pick xml schema(s)
  2. Create “fixture” XML
  3. Define or reuse OM Terminologies & Datastream Classes for your XML
  4. Write rspec tests for your Datastream classes
  5. Define the Model
  6. Write rspec tests for your Model
  7. Decide what relationships your Model will have & which predicates to use
  8. Add relationship methods to your Model

Set up rightsMetadata and Depositor/Owner Permissions

  1. make sure objects have a rightsMetadata datastream
  2. include Hydra::ModelMethods in your model

OM Topics:

  • namespaces
  • Indexing
    • index_as
    • suppressing fields
    • advanced indexing with custom solr schemas (:displayable and :searchable)
  • retrieving Terms & Values

rightsMetadata and Depositor/Owner Permissions

Two steps are necessary in order to ensure that your controllers will be able to set the permissions on your Assets. If you don’t follow these steps, users will be able to create objects but won’t be able to edit them.

Before reading this, make sure to read the page on Hydra Access Controls

(1) make sure objects have a rightsMetadata datastream

If you are adhering to the formal Hydra commonMetadata cModel, which says that you must have a descMetadata datastream and a rightsMetadata datastream, you can put this line in your model:

  # This model adheres to the formal Hydra commonMetadata cModel, meaning that it has a descMetadata datastream and a rightsMetadata datastream
  include Hydra::ModelMixins::CommonMetadata

If you are not adhering to the formal Hydra commonMetadata cModel and simply want to have a rightsMetadata datastream, declare the datastream directly in your Model

  # Explicitly declaring rightsMetadata datastream
  has_metadata :name => "rightsMetadata", :type => Hydra::RightsMetadata

(2) include Hydra::ModelMethods in your model or define custom apply_depositor_metadata method on your Model

{Hydra::ModelMethods} will provide {Hydra::ModelMethods#apply_depositor_metadata} method within your Controllers.

You might want to override that method with model-specific behavior. The most important behavior to retain is adding depositor_id to the asset’s individual edit permissions if the asset has a rightsMetadata datastream.

  # in your model
  include Hydra::ModelMethods

More Information

Further questions? Ask the hydra-tech list or join the freenode #projecthydra IRC channel.