Class: OaiController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/oai_controller.rb

Instance Method Summary collapse

Instance Method Details

#providerObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/oai_controller.rb', line 4

def provider
  @oai = check_oai_params(params)
  if params[:verb] == 'GetRecord'
    get_record; return
  else
    from_and_until_times = set_from_and_until(Manifestation, params[:from], params[:until])
    from_time = @from_time = from_and_until_times[:from]
    until_time = @until_time = from_and_until_times[:until]

    if params[:resumptionToken]
      token = params[:resumptionToken]
    else
      token = '*'
    end

    # OAI-PMHのデフォルトの件数
    oai_per_page = 500
    search = Manifestation.search do
      order_by :updated_at, :desc
      paginate cursor: token, per_page: oai_per_page
      with(:updated_at).between(from_time..until_time)
      with(:required_role_id).equal_to Role.default_role.id
    end
    @manifestations = search.execute!.results

    if @manifestations.empty?
      @oai[:errors] << 'noRecordsMatch'
    end
  end

  respond_to do |format|
    format.xml {
      if @oai[:errors].empty?
        case params[:verb]
        when 'Identify'
          render template: 'oai/identify', content_type: 'text/xml'
        when 'ListMetadataFormats'
          render template: 'oai/list_metadata_formats', content_type: 'text/xml'
        when 'ListSets'
          @series_statements = SeriesStatement.select([:id, :original_title])
          render template: 'oai/list_sets', content_type: 'text/xml'
        when 'ListIdentifiers'
          render template: 'oai/list_identifiers', content_type: 'text/xml'
        when 'ListRecords'
          render template: 'oai/list_records', content_type: 'text/xml'
        else
          render template: 'oai/provider', content_type: 'text/xml'
        end
      else
        render template: 'oai/provider', content_type: 'text/xml'
      end
    }
  end
end