enju_oai 0.1.0.pre18 → 0.1.0.pre19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c43bc35ce6acfb814160534eb055d91f09f5b09c
4
- data.tar.gz: f325d53d05dd7825b2a17a5aa2b6955c3ebee31c
3
+ metadata.gz: f6f952547e6fb1fd17016917dd03c4a2ccb18ca6
4
+ data.tar.gz: 6ff27008468b09fea1e0358866575f7980764ca7
5
5
  SHA512:
6
- metadata.gz: cce3e6a8ef3c0fcb0b8d33c51660410447046f1a8663be57277e9a96c8828eace11135ea450feecebadb797d25d0ab8b39b4b15032b1a1118c41588a31561364
7
- data.tar.gz: 2c9c053b5f2a8716da4dfa67723945f1210bf7a6e6875686ad72b3076c5c779ad169272f2417a2f0e2a80403aa9d912e42e626ca847b2533cd3f787cb9fd963f
6
+ metadata.gz: aa6f72a07db0b9e60668c673d875e26c23c396661bbcc4bbb269c1939ce7dda5f109d7dc8cfa2d6d4723792f9db65ee277593ab59ac4d1400dedac0b3f1ad6a2
7
+ data.tar.gz: b30081617dc9f6017d7ab4c91632200ef7f0e77b40021ca57f46ff590983c2d9226543c44ba91d521a508f9150b284c0b13ca955d7768fbd6dd5fb643ef7af7c
@@ -1,9 +1,9 @@
1
- xml.instruct! :xml, :version=>"1.0"
1
+ xml.instruct! :xml, :version => "1.0"
2
2
  xml.tag! "OAI-PMH", :xmlns => "http://www.openarchives.org/OAI/2.0/",
3
3
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
4
4
  "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd" do
5
5
  xml.responseDate Time.zone.now.utc.iso8601
6
- xml.request manifestations_url(format: :oai), :verb => "ListIdentifiers", :metadataPrefix => "oai_dc"
6
+ xml.request manifestations_url(format: :oai), request_attr(@from_time, @until_time, @oai[:metadataPrefix])
7
7
  @oai[:errors].each do |error|
8
8
  xml.error :code => error
9
9
  end
@@ -20,9 +20,12 @@ xml.tag! "OAI-PMH", :xmlns => "http://www.openarchives.org/OAI/2.0/",
20
20
  end
21
21
  end
22
22
  if @resumption.present?
23
- if @resumption[:cursor].to_i + @manifestations.limit_value < @manifestations.total_count
24
- xml.resumptionToken @resumption[:token], completeListSize: @manifestations.total_count, cursor: @resumption[:cursor], expirationDate: @resumption[:expired_at]
23
+ if @resumption[:cursor].to_i + @manifestations.limit_value <= @count[:query_result]
24
+ token = @resumption[:token]
25
+ else
26
+ token = nil
25
27
  end
28
+ xml.resumptionToken token, completeListSize: @count[:query_result], cursor: @cursor.to_i
26
29
  end
27
30
  end
28
31
  end
@@ -1,18 +1,9 @@
1
- def request_attr(prefix = 'oai_dc')
2
- from_time = @from_time.utc.iso8601 if @from_time
3
- until_time = @until_time.utc.iso8601 if @until_time
4
- attribute = {:metadataPrefix => prefix, :verb => 'ListRecords'}
5
- attribute.merge(:from => from_time) if from_time
6
- attribute.merge(:until => until_time) if until_time
7
- attribute
8
- end
9
-
10
- xml.instruct! :xml, :version=>"1.0"
1
+ xml.instruct! :xml, :version => "1.0"
11
2
  xml.tag! "OAI-PMH", :xmlns => "http://www.openarchives.org/OAI/2.0/",
12
3
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
13
4
  "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd" do
14
5
  xml.responseDate Time.zone.now.utc.iso8601
15
- xml.request manifestations_url(format: :oai), request_attr(@oai[:metadataPrefix])
6
+ xml.request manifestations_url(format: :oai), request_attr(@from_time, @until_time, @oai[:metadataPrefix])
16
7
  @oai[:errors].each do |error|
17
8
  xml.error code: error
18
9
  end
@@ -36,9 +27,12 @@ xml.tag! "OAI-PMH", :xmlns => "http://www.openarchives.org/OAI/2.0/",
36
27
  end
37
28
  end
38
29
  if @resumption.present?
39
- if @resumption[:cursor].to_i + @manifestations.limit_value < @manifestations.total_count
40
- xml.resumptionToken @resumption[:token], completeListSize: @manifestations.total_count, cursor: @resumption[:cursor], expirationDate: @resumption[:expired_at]
30
+ if @resumption[:cursor].to_i + @manifestations.limit_value <= @count[:query_result]
31
+ token = @resumption[:token]
32
+ else
33
+ token = nil
41
34
  end
35
+ xml.resumptionToken token, completeListSize: @count[:query_result], cursor: @cursor.to_i
42
36
  end
43
37
  end
44
38
  end
@@ -1,43 +1,11 @@
1
1
  module EnjuOai
2
2
  module OaiController
3
3
  def self.included(base)
4
- base.send :include, InstanceMethods
4
+ base.send :include, ClassMethods
5
+ base.helper_method :request_attr
5
6
  end
6
7
 
7
- module InstanceMethods
8
- def render_oai(oai, params)
9
- if params[:format] == 'oai'
10
- oai_search = true
11
- from_and_until_times = set_from_and_until(Manifestation, params[:from], params[:until])
12
- from_time = @from_time = from_and_until_times[:from]
13
- until_time = @until_time = from_and_until_times[:until]
14
- # OAI-PMHのデフォルトの件数
15
- per_page = 200
16
- if params[:resumptionToken]
17
- current_token = get_resumption_token(params[:resumptionToken])
18
- if current_token
19
- page = (current_token[:cursor].to_i + per_page).div(per_page) + 1
20
- else
21
- @oai[:errors] << 'badResumptionToken'
22
- end
23
- end
24
- page ||= 1
25
-
26
- if params[:verb] == 'GetRecord' and params[:identifier]
27
- begin
28
- @manifestation = Manifestation.find_by_oai_identifier(params[:identifier])
29
- rescue ActiveRecord::RecordNotFound
30
- @oai[:errors] << "idDoesNotExist"
31
- render :formats => :oai, :layout => false
32
- return
33
- end
34
- render :template => 'manifestations/show', :formats => :oai, :layout => false
35
- return
36
- end
37
- end
38
- end
39
-
40
- private
8
+ module ClassMethods
41
9
  def check_oai_params(params)
42
10
  oai = {}
43
11
  if params[:format] == 'oai'
@@ -86,57 +54,50 @@ module EnjuOai
86
54
  true
87
55
  end
88
56
  end
89
- end
90
-
91
- def get_resumption_token(token)
92
- if token.present?
93
- resumption = Rails.cache.read(token)
57
+
58
+ def request_attr(from_time, until_time, prefix = 'oai_dc')
59
+ attribute = {metadataPrefix: prefix, verb: 'ListRecords'}
60
+ attribute.merge(from: from_time.utc.iso8601) if from_time
61
+ attribute.merge(:until => until_time.utc.iso8601) if until_time
62
+ attribute
94
63
  end
95
- rescue
96
- nil
97
- end
98
-
99
- def set_resumption_token(token, from_time, until_time, per_page = 10)
100
- return nil unless Rails.env.to_s == 'production'
101
- if token.present?
102
- latest_resumption = Rails.cache.read(token)
103
- if latest_resumption
104
- cursor = latest_resumption[:cursor] + per_page
64
+
65
+ def set_resumption_token(token, from_time, until_time, per_page = 200)
66
+ if token
67
+ cursor = token.split(',').reverse.first.to_i + per_page
68
+ else
69
+ cursor = per_page
105
70
  end
71
+ {
72
+ token: "f(#{from_time.utc.iso8601.to_s}),u(#{until_time.utc.iso8601.to_s}),#{cursor}",
73
+ cursor: cursor
74
+ }
106
75
  end
107
- cursor ||= 0
108
- resumption = {
109
- :token => "f(#{from_time.utc.iso8601.to_s}).u(#{until_time.utc.iso8601.to_s}):#{cursor}",
110
- :cursor => cursor,
111
- # memcachedの使用が前提
112
- :expired_at => ENV['ENJU_OAI_TTL'].to_i.seconds.from_now.utc.iso8601
113
- }
114
- Rails.cache.fetch(resumption[:token]){resumption}
115
- end
116
-
117
- def set_from_and_until(klass, from_t, until_t)
118
- if klass.first and klass.last
119
- from_t ||= klass.last.updated_at.to_s
120
- until_t ||= klass.first.updated_at.to_s
121
- else
122
- from_t ||= Time.zone.now.to_s
123
- until_t ||= Time.zone.now.to_s
124
- end
125
-
126
- times = {}
127
- if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ from_t
128
- times[:from] = Time.zone.parse(from_t).beginning_of_day
129
- else
130
- times[:from] = Time.zone.parse(from_t)
131
- end
132
- if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ until_t
133
- times[:until] = Time.zone.parse(until_t).beginning_of_day
134
- else
135
- times[:until] = Time.zone.parse(until_t)
76
+
77
+ def set_from_and_until(klass, from_t, until_t)
78
+ if klass.first and klass.last
79
+ from_t ||= klass.order(:updated_at).first.updated_at.to_s
80
+ until_t ||= klass.order(:updated_at).last.updated_at.to_s
81
+ else
82
+ from_t ||= Time.zone.now.to_s
83
+ until_t ||= Time.zone.now.to_s
84
+ end
85
+
86
+ times = {}
87
+ if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ from_t
88
+ times[:from] = Time.zone.parse(from_t).beginning_of_day
89
+ else
90
+ times[:from] = Time.zone.parse(from_t)
91
+ end
92
+ if /^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/ =~ until_t
93
+ times[:until] = Time.zone.parse(until_t).beginning_of_day
94
+ else
95
+ times[:until] = Time.zone.parse(until_t)
96
+ end
97
+ times[:from] ||= Time.zone.parse(from_t)
98
+ times[:until] ||= Time.zone.parse(until_t)
99
+ times
136
100
  end
137
- times[:from] ||= Time.zone.parse(from_t)
138
- times[:until] ||= Time.zone.parse(until_t)
139
- times
140
101
  end
141
102
  end
142
103
  end
@@ -1,3 +1,3 @@
1
1
  module EnjuOai
2
- VERSION = "0.1.0.pre18"
2
+ VERSION = "0.1.0.pre19"
3
3
  end
data/lib/enju_oai.rb CHANGED
@@ -4,3 +4,5 @@ require 'enju_oai/oai_controller'
4
4
 
5
5
  module EnjuOai
6
6
  end
7
+
8
+ ActionController::Base.send :include, EnjuOai::OaiController
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_oai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre18
4
+ version: 0.1.0.pre19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kosuke Tanabe
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0.pre68
19
+ version: 0.1.0.pre69
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0.pre68
26
+ version: 0.1.0.pre69
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: enju_subject
29
29
  requirement: !ruby/object:Gem::Requirement