Skip to content

Commit

Permalink
Merge pull request #47 from ualbertalib/cds/fix-dates-and-scope
Browse files Browse the repository at this point in the history
proper dates and until argument fixes
  • Loading branch information
ConnorSheremeta authored Sep 29, 2020
2 parents 09d0a11 + db5fe85 commit ac1d7be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
15 changes: 12 additions & 3 deletions app/controllers/oaisys/pmh_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def list_metadata_formats
end

render :list_metadata_formats,
formats: :xml, locals: { formats: formats, parameters: parameters }
formats: :xml, locals: { formats: formats, parameters: prep_identifiers(parameters) }
end

def list_records
Expand Down Expand Up @@ -118,7 +118,7 @@ def get_record

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

render :get_record, formats: :xml, locals: { item: obj, metadata_format: metadata_format }
render :get_record, formats: :xml, locals: { item: obj, parameters: prep_identifiers(params) }
end
# rubocop:enable Naming/AccessorMethodName

Expand Down Expand Up @@ -218,7 +218,11 @@ def public_items_for_metadata_format(verb:, format:, page:, restricted_to_set: n
model = model.public_items.belongs_to_path(restricted_to_set.tr(':', '/')) if restricted_to_set.present?

model = model.updated_on_or_after(from_date) if from_date.present?
model = model.updated_on_or_before(until_date) if until_date.present?

if until_date.present?
just_after_until_date = (until_date.to_time + 1.second).utc.xmlschema
model = model.updated_before(just_after_until_date)
end

items_per_request = Oaisys::Engine.config.items_per_request
model = model.page(page).per(items_per_request)
Expand Down Expand Up @@ -269,4 +273,9 @@ def check_resumption_token(model, resumption_token_provided, total_count, parame
raise Oaisys::BadResumptionTokenError.new, I18n.t('error_messages.resumption_token_invalid')
end

def prep_identifiers(parameters)
parameters['identifier'].prepend('oai:era.library.ualberta.ca:') if parameters['identifier'].present?
parameters
end

end
9 changes: 4 additions & 5 deletions app/views/oaisys/pmh/get_record.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ xml.push_deferred_attribute('xmlns:dc': 'http://purl.org/dc/elements/1.1/',
'http://www.ndltd.org/standards/metadata/etdms/1-0/etdms.xsd '\
'http://www.w3.org/2005/Atom')

xml.tag!('request', 'https://era.library.ualberta.ca/oai', verb: 'GetRecord', metadataPrefix: metadata_format,
identifier: item.id)
xml.tag!('request', parameters, 'https://era.library.ualberta.ca/oai')

xml.GetRecord do |get_record|
get_record.record do |record|
record.header do |header|
header.identifier "oai:era.library.ualberta.ca:#{item.id}"
header.datestamp item.updated_at
header.identifier parameters[:identifier]
header.datestamp item.updated_at.utc.xmlschema
item.member_of_paths.each { |path| header.setSpec path.tr('/', ':') }
end
record.metadata do |metadata_xml|
item.serialize_metadata(format: metadata_format, into_document: metadata_xml)
item.serialize_metadata(format: parameters[:metadataPrefix], into_document: metadata_xml)
end
end
end
2 changes: 1 addition & 1 deletion app/views/oaisys/pmh/list_records.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ xml.ListRecords do |list_records|
list_records.record do |record|
record.header do |header|
header.identifier "oai:era.library.ualberta.ca:#{item.id}"
header.datestamp item.updated_at
header.datestamp item.updated_at.utc.xmlschema
item.member_of_paths.each { |path| header.setSpec path.tr('/', ':') }
end
record.metadata do |metadata_xml|
Expand Down

0 comments on commit ac1d7be

Please sign in to comment.