Skip to content

Commit

Permalink
Merge pull request #43 from ualbertalib/cds/handle-identifier-param-i…
Browse files Browse the repository at this point in the history
…n-lmf

Handle identifier param in list metadata formats
  • Loading branch information
ConnorSheremeta authored Aug 26, 2020
2 parents 887bbf9 + f8f2efb commit 480f3bd
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ gemspec
# gem 'byebug', group: [:development, :test]

# RDF stuff
gem 'acts_as_rdfable', github: 'ualbertalib/acts_as_rdfable', ref: '37915a9581713524f95f28425a10fdfee4335d06'
gem 'acts_as_rdfable', github: 'ualbertalib/acts_as_rdfable', tag: 'v0.2.3'
gem 'builder_deferred_tagging', github: 'ualbertalib/builder_deferred_tagging', tag: 'v0.01'
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/ualbertalib/acts_as_rdfable.git
revision: 37915a9581713524f95f28425a10fdfee4335d06
ref: 37915a9581713524f95f28425a10fdfee4335d06
revision: bb4e1aa72a07cfd96219da96851d9d85b777942f
tag: v0.2.3
specs:
acts_as_rdfable (0.2.1)
rails (>= 5.2.3)
Expand Down
25 changes: 21 additions & 4 deletions app/controllers/oaisys/pmh_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ def list_sets
resumption_token_provided: resumption_token_provided }
end

# TODO: Handle the identifier argument.
def list_metadata_formats
parameters = expect_args optional: [:identifier]

if parameters[:identifier].blank?
formats = SUPPORTED_FORMATS
else
# Assumption here that an object cannot be both an item and thesis.
identifier_format = if Thesis.find_by(id: params[:identifier]).present?
'oai_etdms'
elsif Item.find_by(id: params[:identifier]).present?
'oai_dc'
end

raise Oaisys::IdDoesNotExistError.new(parameters: parameters) if identifier_format.nil?

formats = SUPPORTED_FORMATS.select { |supported_format| supported_format[:metadataPrefix] == identifier_format }
raise Oaisys::NoMetadataFormatsError.new(parameters: parameters) if formats.empty?
end

render :list_metadata_formats,
formats: :xml, locals: { supported_formats: SUPPORTED_FORMATS, parameters: parameters }
formats: :xml, locals: { formats: formats, parameters: parameters }
end

def list_records
Expand Down Expand Up @@ -99,9 +114,9 @@ def get_record

metadata_format = params[:metadataPrefix]
model = model_for_verb_format(verb: :get_record, format: metadata_format)
obj = model.find(params[:identifier])
obj = model.find_by(id: params[:identifier])

raise IdDoesNotExistError.new(paramerters: params) if obj.blank?
raise Oaisys::IdDoesNotExistError.new(parameters: params) if obj.blank?

render :get_record, formats: :xml, locals: { item: obj, metadata_format: metadata_format }
end
Expand Down Expand Up @@ -143,6 +158,8 @@ def expect_no_args
end

def expect_args(required: [], optional: [], exclusive: [])
params[:identifier]&.slice! 'oai:era.library.ualberta.ca:'

# This makes the strong assumption that there's only one exclusive param per verb (which is the resumption token.)
if params.key?(exclusive.first)
params.require([:verb])
Expand Down
2 changes: 1 addition & 1 deletion app/views/oaisys/pmh/error.xml.builder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xml.push_deferred_attribute(error_header(error_code: error_code))

xml.tag!('request', parameters)
xml.tag!('request', parameters, 'https://era.library.ualberta.ca/oai')
xml.error(error_message, code: error_code)
8 changes: 4 additions & 4 deletions app/views/oaisys/pmh/list_metadata_formats.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ xml.push_deferred_attribute('xmlns:dc': 'http://purl.org/dc/elements/1.1/',

xml.tag!('request', parameters, 'https://era.library.ualberta.ca/oai')
xml.tag!('ListMetadataFormats') do
supported_formats.each do |supported_format|
formats.each do |format|
xml.tag!('metadataFormat') do
xml.metadataPrefix supported_format[:metadataPrefix]
xml.schema supported_format[:schema]
xml.metadataNamespace supported_format[:metadataNamespace]
xml.metadataPrefix format[:metadataPrefix]
xml.schema format[:schema]
xml.metadataNamespace format[:metadataNamespace]
end
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ en:
unavailable_metadata_format: 'Unavailable metadata format'
unknown_verb: "Unknown verb '%{bad_verb}'"
id_does_not_exist: 'No matching identifier'
no_metadata_formats: 'There are no metadata formats available for the specified item.'
2 changes: 2 additions & 0 deletions lib/oaisys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ module Oaisys
require 'oaisys/cannot_disseminate_format_error'
require 'oaisys/no_records_match_error'
require 'oaisys/bad_resumption_token_error'
require 'oaisys/id_does_not_exist_error'
require 'oaisys/no_metadata_formats_error'
require 'oaisys/redis_connection'
end
2 changes: 1 addition & 1 deletion lib/oaisys/id_does_not_exist_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Oaisys::IdDoesNotExist < Oaisys::PMHError
class Oaisys::IdDoesNotExistError < Oaisys::PMHError

attr_reader :parameters

Expand Down
17 changes: 17 additions & 0 deletions lib/oaisys/no_metadata_formats_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Oaisys::NoMetadataFormatsError < Oaisys::PMHError

attr_reader :parameters

def initialize(parameters:)
@parameters = parameters
end

def error_code
:noMetadataFormats
end

def error_message
I18n.t('error_messages.no_metadata_formats')
end

end

0 comments on commit 480f3bd

Please sign in to comment.