Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Adding holding location backed by bibdata location service - closes #389 #394

Merged
merged 1 commit into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/authorities/holding_location_authority.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class HoldingLocationAuthority
include Qa::Authorities::WebServiceBase

def all
get_json(url).each { |loc| loc['id'] = loc['url'].sub(/\.json$/, '') }
end

def find(id)
(all.select { |obj| obj['id'] == id } || []).first
end

private

def url
Plum.config['locations_url']
end
end
2 changes: 1 addition & 1 deletion app/forms/curation_concerns/curation_concerns_form.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CurationConcerns
class CurationConcernsForm < CurationConcerns::Forms::WorkForm
self.terms += [:access_policy, :rights_statement, :rights_note, :source_metadata_identifier, :portion_note, :description, :state, :workflow_note, :collection_ids]
self.terms += [:access_policy, :holding_location, :rights_statement, :rights_note, :source_metadata_identifier, :portion_note, :description, :state, :workflow_note, :collection_ids]

def notable_rights_statement?
RightsStatementService.notable?(model.rights_statement)
Expand Down
3 changes: 3 additions & 0 deletions app/models/concerns/common_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module CommonMetadata
property :workflow_note, predicate: ::RDF::Vocab::MODS.note do |index|
index.as :stored_searchable, :symbol
end
property :holding_location, predicate: ::RDF::Vocab::Bibframe.heldBy, multiple: false do |index|
index.as :stored_searchable
end

# IIIF
apply_schema IIIFBookSchema, ActiveFedora::SchemaIndexingStrategy.new(
Expand Down
4 changes: 4 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ def rights_statement
def rights_note
self[Solrizer.solr_name('rights_note')]
end

def holding_location
self[Solrizer.solr_name('holding_location')]
end
end
4 changes: 4 additions & 0 deletions app/presenters/curation_concerns_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def rights_statement
RightsStatementRenderer.new(solr_document.rights_statement, solr_document.rights_note).render
end

def holding_location
HoldingLocationRenderer.new(solr_document.holding_location).render
end

private

def logical_order_factory
Expand Down
13 changes: 13 additions & 0 deletions app/renderers/holding_location_renderer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class HoldingLocationRenderer < CurationConcerns::AttributeRenderer
def initialize(value, options = {})
super(:location, value, options)
end

private

def attribute_value_to_html(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more efficient to change the API to location_service = HoldingLocationService.new(value) (or .find), and then have instance methods for email/label/phone?

loc = HoldingLocationService.find(value)
li_value %(#{loc.label}<br/>Contact at <a href="mailto:#{loc.email}">#{loc.email}</a>,
<a href="tel:#{loc.phone}">#{loc.phone}</a>)
end
end
30 changes: 30 additions & 0 deletions app/services/holding_location_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module HoldingLocationService
mattr_accessor :authority
self.authority = HoldingLocationAuthority.new

def self.select_options
authority.all.map { |element| [element['label'], element['id']] }.sort
end

def self.find(id)
HoldingLocation.new(authority.find(id))
end

class HoldingLocation
def initialize(hash)
@holding_location = hash || {}
end

def email
@holding_location['contact_email']
end

def label
@holding_location['label']
end

def phone
@holding_location['phone_number']
end
end
end
3 changes: 3 additions & 0 deletions app/views/curation_concerns/base/_attributes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<% if @presenter.respond_to? :rights_statement %>
<%= @presenter.rights_statement %>
<% end %>
<% if @presenter.respond_to? :holding_location %>
<%= @presenter.holding_location %>
<% end %>
<%= @presenter.attribute_to_html(:identifier) %>
<%= render partial: '/curation_concerns/base/collection_list' %>
<% if can? :edit, @presenter.id %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/curation_concerns/base/_form_access_policy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@

<%= f.input :rights_note, as: :text, label: 'Rights Note',
input_html: { class: 'rights-note', readonly: !@form.notable_rights_statement? } %>

<%= f.input :holding_location,
as: :select,
collection: HoldingLocationService.select_options,
input_html: { class: 'form-control' },
label: 'Holding Location' %>
</fieldset>
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defaults: &defaults
locations_url: https://bibdata.princeton.edu/locations/digital_locations.json
notifier_email_address: plum@princeton.edu
iiif_url: <%= ENV["PLUM_IIIF_URL"] || "http://192.168.99.100:5004" %>
jp2_recipes:
Expand Down
43 changes: 43 additions & 0 deletions spec/authorities/holding_location_authority_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

RSpec.describe HoldingLocationAuthority do
subject { described_class.new }
let(:json) {
'[{
"label":"Plasma Physics Library",
"phone_number":"609-243-3565",
"contact_email":"ppllib@princeton.edu",
"url":"https://bibdata.princeton.edu/locations/delivery_locations/1.json"
},{
"label":"Architecture Library",
"phone_number":"609-258-3256",
"contact_email":"ues@princeton.edu",
"url":"https://bibdata.princeton.edu/locations/delivery_locations/3.json"
}]'
}
let(:id) { 'https://bibdata.princeton.edu/locations/delivery_locations/3' }
let(:obj) {
{
label: "Architecture Library",
phone_number: "609-258-3256",
contact_email: "ues@princeton.edu",
url: "https://bibdata.princeton.edu/locations/delivery_locations/3.json",
id: "https://bibdata.princeton.edu/locations/delivery_locations/3"
}
}

before do
allow(RestClient).to receive(:get).and_return(json)
end

context "with data" do
it "finds a holding location by id" do
expect(subject.find(id)).to eq(obj.stringify_keys)
end

it "lists all of the holding locations" do
expect(subject.all.length).to eq(2)
expect(subject.all).to include(obj.stringify_keys)
end
end
end
97 changes: 96 additions & 1 deletion spec/cassettes/bibdata.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions spec/cassettes/ezid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading