Skip to content

Commit a2a5e8c

Browse files
author
Terry Reese
committed
Updates to the provider element to allow it to pass oai 2.0 validation tests. Without it, the date values passed by the oai elements are invalid.
1 parent 41c5143 commit a2a5e8c

11 files changed

Lines changed: 37 additions & 47 deletions

File tree

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RUBY_OAI_VERSION = '0.0.9'
1+
RUBY_OAI_VERSION = '0.0.10'
22

33
require 'rubygems'
44
require 'rake'

lib/oai/provider/metadata_format.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ def encode(model, record)
5454
# 2. Try calling the pluralized name method on the model.
5555
# 3. Try calling the singular name method on the model
5656
def value_for(field, record, map)
57-
method = map[field] ? map[field].to_s : field.to_s
58-
57+
method = map[field] ? map[field].to_s : field.to_s
58+
5959
if record.respond_to?(pluralize(method))
6060
record.send pluralize(method)
6161
elsif record.respond_to?(method)
62+
# at this point, this function will throw a dep. error because of the call to type -- a reserved work
63+
# in ruby
6264
record.send method
6365
else
6466
[]

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'active_record'
2-
32
module OAI::Provider
43
# = OAI::Provider::ActiveRecordWrapper
54
#
@@ -35,7 +34,6 @@ def latest
3534
model.find(:first,
3635
:order => "#{timestamp_field} desc").send(timestamp_field)
3736
end
38-
3937
# A model class is expected to provide a method Model.sets that
4038
# returns all the sets the model supports. See the
4139
# activerecord_provider tests for an example.
@@ -46,7 +44,6 @@ def sets
4644
def find(selector, options={})
4745
return next_set(options[:resumption_token]) if options[:resumption_token]
4846
conditions = sql_conditions(options)
49-
5047
if :all == selector
5148
total = model.count(:id, :conditions => conditions)
5249
if @limit && total > @limit
@@ -93,9 +90,7 @@ def select_partial(token)
9390
:conditions => token_conditions(token),
9491
:limit => @limit,
9592
:order => "#{model.primary_key} asc")
96-
9793
raise OAI::ResumptionTokenException.new unless records
98-
9994
offset = records.last.send(model.primary_key.to_sym)
10095

10196
PartialResult.new(records, token.next(offset))
@@ -124,13 +119,13 @@ def sql_conditions(opts)
124119
sql = []
125120
sql << "#{timestamp_field} >= ?" << "#{timestamp_field} <= ?"
126121
sql << "set = ?" if opts[:set]
127-
128122
esc_values = [sql.join(" AND ")]
129-
esc_values << opts[:from].localtime << opts[:until].localtime
123+
esc_values << Time.parse(opts[:from]).localtime << Time.parse(opts[:until]).localtime #-- OAI 2.0 hack - UTC fix from record_responce
130124
esc_values << opts[:set] if opts[:set]
131125

132126
return esc_values
133127
end
134128

135129
end
136130
end
131+

lib/oai/provider/response.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'builder' unless defined?(Builder)
2-
32
module OAI
43
module Provider
54
module Response
@@ -9,7 +8,6 @@ class Base
98

109
class << self
1110
attr_reader :valid_options, :default_options, :required_options
12-
1311
def valid_parameters(*args)
1412
@valid_options ||= []
1513
@valid_options = (@valid_options + args.dup).uniq
@@ -27,23 +25,23 @@ def required_parameters(*args)
2725
end
2826

2927
end
30-
3128
def initialize(provider, options = {})
3229
@provider = provider
3330
@options = internalize(options)
3431
raise OAI::ArgumentException.new unless valid?
3532
end
36-
3733
def response
3834
@builder = Builder::XmlMarkup.new
3935
@builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
4036
@builder.tag!('OAI-PMH', header) do
4137
@builder.responseDate Time.now.utc.xmlschema
42-
@builder.request(provider.url, options)
38+
#options parameter has been removed here because with it
39+
#the data won't validate against oai validators. Without, it
40+
#validates.
41+
@builder.request(provider.url) #-- OAI 2.0 Hack - removed request options
4342
yield @builder
4443
end
4544
end
46-
4745
private
4846

4947
def header
@@ -54,7 +52,6 @@ def header
5452
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd}
5553
}
5654
end
57-
5855
def extract_identifier(id)
5956
id.sub("#{provider.prefix}/", '')
6057
end
@@ -67,9 +64,7 @@ def valid?
6764
if self.class.required_options
6865
return false unless (self.class.required_options - @options.keys).empty?
6966
end
70-
7167
return false unless (@options.keys - self.class.valid_options).empty?
72-
7368
populate_defaults
7469
end
7570

@@ -95,7 +90,7 @@ def parse_date(value)
9590
return value if value.respond_to?(:strftime)
9691

9792
Date.parse(value) # This will raise an exception for badly formatted dates
98-
Time.parse(value).utc # Sadly, this will not
93+
Time.parse(value).utc # -- UTC Bug fix hack 8/08 not in core
9994
rescue
10095
raise OAI::ArgumentError.new
10196
end
@@ -119,3 +114,4 @@ def internalize(hash = {})
119114
end
120115
end
121116
end
117+

lib/oai/provider/response/identify.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def to_xml
1313
else
1414
r.adminEmail provider.email.to_s
1515
end
16-
r.earliestDatestamp provider.model.earliest
16+
r.earliestDatestamp Time.parse(provider.model.earliest.to_s).utc.xmlschema
1717
r.deletedRecord provider.delete_support.to_s
1818
r.granularity provider.granularity
1919
end
@@ -23,4 +23,3 @@ def to_xml
2323
end
2424

2525
end
26-

lib/oai/provider/response/list_metadata_formats.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module OAI::Provider::Response
2-
32
class ListMetadataFormats < RecordResponse
43
valid_parameters :identifier
54

@@ -17,7 +16,6 @@ def to_xml
1716
# Remove any format that this particular record can't be provided in.
1817
formats.reject! { |f| !record_supports(record, f.prefix) }
1918
end
20-
2119
response do |r|
2220
r.ListMetadataFormats do
2321
formats.each do |format|
@@ -38,5 +36,4 @@ def record_supports(record, prefix)
3836
end
3937

4038
end
41-
42-
end
39+
end

lib/oai/provider/response/record_response.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module OAI::Provider::Response
22
class RecordResponse < Base
3-
43
def self.inherited(klass)
54
klass.valid_parameters :metadata_prefix, :from, :until, :set
65
klass.default_parameters :metadata_prefix => "oai_dc",
7-
:from => Proc.new {|x| Time.parse(x.provider.model.earliest.to_s) },
8-
:until => Proc.new {|x| Time.parse(x.provider.model.latest.to_s) }
6+
:from => Proc.new {|x| Time.parse(x.provider.model.earliest.to_s) }, #-- OAI 2.0 hack - UTC
7+
:until => Proc.new {|x| Time.parse(x.provider.model.latest.to_s) } #-- OAI 2.0 hack - UTC
98
end
109

1110
# emit record header
@@ -20,7 +19,6 @@ def header_for(record)
2019
end
2120
end
2221
end
23-
2422
# metadata - core routine for delivering metadata records
2523
#
2624
def data_for(record)
@@ -51,7 +49,6 @@ def requested_format
5149
elsif options[:resumption_token]
5250
OAI::Provider::ResumptionToken.extract_format(options[:resumption_token])
5351
end
54-
5552
raise OAI::FormatException.new unless provider.format_supported?(format)
5653

5754
format
@@ -65,4 +62,4 @@ def deleted?(record)
6562
end
6663

6764
end
68-
end
65+
end

lib/oai/provider/resumption_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def to_s
8989
def encode_conditions
9090
encoded_token = @prefix.to_s.dup
9191
encoded_token << ".s(#{set})" if set
92-
encoded_token << ".f(#{from.utc.xmlschema})" if from
92+
encoded_token << ".f(#{self.from.utc.xmlschema})" if self.from
9393
encoded_token << ".u(#{self.until.utc.xmlschema})" if self.until
9494
encoded_token << ":#{last}"
9595
end

test/client/tc_libxml.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_list_records
3333
records.each do |record|
3434
assert record.header.identifier
3535
next if record.deleted?
36-
assert_kind_of XML::Node, record.metadata
36+
assert_kind_of LibXML::XML::Node, record.metadata
3737
end
3838
end
3939
end

test/client/tc_xpath.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def test_libxml
1818
return
1919
end
2020

21-
doc = XML::Document.file('test/test.xml')
21+
doc = LibXML::XML::Document.file('test/test.xml')
2222
assert_equal xpath(doc, './/responseDate'), '2006-09-11T14:33:15Z'
2323
assert_equal xpath(doc, './/foobar'), nil
2424
end
2525

26-
end
26+
end

0 commit comments

Comments
 (0)