Skip to content

Dive Into Curation Concerns

Esmé Cowles edited this page Apr 29, 2016 · 13 revisions

esmé cowles

originally presented at the dc fedora users group, 2016-04-28

the hydra/curation concerns stack

  • AF: provides ActiveRecord-style modeling for Fedora
  • Hydra::PCDM: provides the basic PCDM classes and relationships
  • Hydra::Works: adds Works and FileSets, plus a Swiss Army Knife of repository functionality
  • CurationConcerns: adds a Rails engine, views, controllers, etc.
  • Sufia 7: rebuilding Sufia on top of CurationConcerns, adds dashboards, reporting, and other IR functionality

a note about solr_wrapper and fcrepo_wrapper

  • standard hydra test/development infrastructure
  • download solr and fcrepo and quickly spin up with minimal config
  • do not use in production: they delete data

production infrastructure

  • fedora
    • separate machine with tomcat or jetty
    • files on network storage
    • relational database for metadata
    • event-based workflow
  • solr
    • solr 5+ standalone app
    • might be shared with other applications
    • fast disk and/or enough memory to keep index in memory

start vagrant environment

  • install dependencies and download the curation-concerns-vagrant environment

    https://github.com/escowles/curation-concerns-vagrant/archive/dc-fug-2016-04-28.zip

  • start the vagrant environment

    $ unzip curation-concerns-vagrant-dc-fug-2016-04-28.zip
    $ cd curation-concerns-vagrant-dc-fug-2016-04-28
    $ vagrant up
    
  • start the curation-concerns-demo application

    $ vagrant ssh
    $ cd curation-concerns-demo
    $ rails s -b 0.0.0.0
    

stock curation concerns

http://localhost:3000/

customizing curation concerns

  • basic customization
    • adding a property to a model
    • adding to edit and show forms
  • how the framework is organized
    • models, views, controllers
    • forms, indexers, presenters

adding a property

  • model defines the property
  • form wraps the model
  • view provides HTML UI

add a property to the Book model

app/models/book.rb

  class Book < ActiveFedora::Base
    include ::CurationConcerns::WorkBehavior
    include ::CurationConcerns::BasicMetadata
    validates :title, presence: { message: 'Your work must have a title.' }
+   property :copyright, predicate: ::RDF::URI('http://www.loc.gov/premis/rdf/v1#hasCopyrightStatus')
  end

add the property to the Book form

app/forms/curation_concerns/book_form.rb

  module CurationConcerns
    class BookForm < CurationConcerns::Forms::WorkForm
      self.model_class = ::Book
+     delegate :copyright, to: :model
+     self.terms += [:copyright]
    end
  end

create a custom view for create/edit forms

app/views/curation_concerns/books/_form_additional_information.html.erb

+ <fieldset class="optional prompt">
+   <legend>Additional Information</legend>
+   <%= f.input :subject,         as: :multi_value, input_html: { class: 'form-control' } %>
+   <%= f.input :publisher,       as: :multi_value, input_html: { class: 'form-control' } %>
+   <%= f.input :source,          as: :multi_value, input_html: { class: 'form-control' } %>
+   <%= f.input :language,        as: :multi_value, input_html: { class: 'form-control' } %>
+   <%= f.input :copyright,       as: :multi_value, input_html: { class: 'form-control' } %>
+ </fieldset>

create or edit a record to see the new field

  • create or edit a record
  • add a copyright value
  • view the copyright value in fedora
  • but it doesn't show up in solr

indexing in Solr

  • indexer maps from the model to Solr
  • model defines which indexer to use

create a custom indexer

$ mkdir app/indexers

app/indexers/book_indexer.rb

+ class BookIndexer < CurationConcerns::WorkIndexer
+   def generate_solr_document
+     super.tap do |solr_doc|
+       Solrizer.set_field(solr_doc, 'copyright', object.copyright, :displayable)
+     end
+   end
+ end

update the Book model to use the custom indexer

app/models/book.rb

  class Book < ActiveFedora::Base
    include ::CurationConcerns::WorkBehavior
    include ::CurationConcerns::BasicMetadata
    validates :title, presence: { message: 'Your work must have a title.' }
    property :copyright, predicate: ::RDF::URI('http://www.loc.gov/premis/rdf/v1#hasCopyrightStatus')
+   def self.indexer
+     ::BookIndexer
+   end
  end

update the object and check the solr index

  • update the object to trigger reindexing
  • view the copyright field in solr
  • still not showing up on the show page

showing to end users

  • presenter maps from Solr to the form
  • controller defines which presenter to use
  • view provides HTML UI

create a custom presenter

$ mkdir app/presenters

app/presenters/book_presenter.rb

+ class BookPresenter < CurationConcerns::WorkShowPresenter
+   delegate :copyright, to: :solr_document
+ end

map the field in to solr

app/models/solr_document.rb

  ...
+   def copyright
+     fetch('copyright_ssm', [])
+   end
  end

tell the controller to use the custom presenter

app/controllers/curation_concerns/books_controller.rb

  class CurationConcerns::BooksController < ApplicationController
    include CurationConcerns::CurationConcernController
    self.curation_concern_type = Book
+   def show_presenter
+     ::BookPresenter
+   end
  end

add the property to the show view

app/views/curation_concerns/books/_attribute_rows.html.erb

+ <%= presenter.attribute_to_html(:description) %>
+ <%= presenter.attribute_to_html(:creator, catalog_search_link: true ) %>
+ <%= presenter.attribute_to_html(:contributor, label: 'Contributors', catalog_search_link: true) %>
+ <%= presenter.attribute_to_html(:subject, catalog_search_link: true) %>
+ <%= presenter.attribute_to_html(:publisher) %>
+ <%= presenter.attribute_to_html(:language) %>
+ <%= presenter.attribute_to_html(:copyright) %>

reload the record to see the copyright field

  • reload the show page
  • see the copyright value displayed to end users

adding a facet

  • update the indexer to index as facetable
  • update the search controller to display the facet

update the indexer to make copyright facetable

app/indexers/book_indexer.rb

  class BookIndexer < CurationConcerns::WorkIndexer
    def generate_solr_document
      super.tap do |solr_doc|
-       Solrizer.set_field(solr_doc, 'copyright', object.copyright, :displayable)
+       Solrizer.set_field(solr_doc, 'copyright', object.copyright, :displayable, :facetable)
      end
    end
  end

tell the controller to use the facet

app/controllers/catalog_controller.rb

  class CatalogController < ApplicationController
    include CurationConcerns::CatalogController
    configure_blacklight do |config|
      ...
      config.add_facet_field solr_name('based_near', :facetable), limit: 5
      config.add_facet_field solr_name('publisher', :facetable), limit: 5
      config.add_facet_field solr_name('file_format', :facetable), limit: 5
      config.add_facet_field 'generic_type_sim', show: false, single: true
+     config.add_facet_field solr_name('copyright', :facetable), limit: 5, label: 'Copyright'
      ...
  end

update a record and search to view the facet

  • update a record with copyright
  • perform a search
  • see copyright facet in the sidebar

thanks to justin coyne for great tutorials:

Clone this wiki locally