Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPCOARスキーマ2.0の出力を追加 #1862

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions app/controllers/oai_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
class OaiController < ApplicationController
skip_after_action :verify_authorized

class OaiController < ActionController::API
def index
provider = OaiProvider.new
response = provider.process_request(oai_params.to_h)

# ruby-oaiではフォーマット名を含んだメソッド(e.g. to_jpcoar)が呼ばれるが、
# メソッド名にはドットを含められないため、リクエストを受け取ったときに変換
# している
case params['metadataPrefix']
when 'jpcoar_2.0'
request_hash = oai_params.to_h.merge({'metadataPrefix': 'jpcoar_20'})
else
request_hash = oai_params.to_h
end

response = provider.process_request(request_hash)
render body: response, content_type: 'text/xml'
end

Expand Down
5 changes: 5 additions & 0 deletions app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ def self.new_agents(agents_params)

agents
end

def to_jpcoar
xml = ::Builder::XmlMarkup.new
xml.tag! 'jpcoar:creatorName', full_name
end
end

# == Schema Information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# OAI-PMHでJPCOARスキーマ2.0を扱うためのモジュール
module EnjuOai
class Jpcoar < OAI::Provider::Metadata::Format

class Jpcoar20 < OAI::Provider::Metadata::Format
def initialize
@prefix = 'jpcoar'
@schema = 'https://github.com/JPCOAR/schema/blob/master/1.0/jpcoar_scm.xsd'
@namespace = 'https://github.com/JPCOAR/schema/blob/master/1.0/'
@prefix = 'jpcoar_20'
@schema = 'https://github.com/JPCOAR/schema/blob/master/2.0/jpcoar_scm.xsd'
@namespace = 'https://github.com/JPCOAR/schema/blob/master/2.0/'
@element_namespace = 'dc'
@fields = [ :title, :creator, :subject, :description, :publisher,
:contributor, :date, :type, :format, :identifier,
Expand All @@ -13,14 +13,13 @@ def initialize

def header_specification
{
'xmlns:jpcoar' => "https://github.com/JPCOAR/schema/blob/master/1.0/",
'xmlns:jpcoar' => "https://github.com/JPCOAR/schema/blob/master/2.0/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xsi:schemaLocation' =>
%{https://github.com/JPCOAR/schema/blob/master/1.0/
%{https://github.com/JPCOAR/schema/blob/master/2.0/
jpcoar_scm.xsd}.gsub(/\s+/, ' ')
}
end

end
end
26 changes: 26 additions & 0 deletions app/models/concerns/enju_oai/jpcoar20dummy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OAI-PMHでJPCOARスキーマ2.0を扱うためのダミーモジュール
# ruby-oaiでメソッド名にドットが含められないため、ダミーのprefixを設定している
module EnjuOai
class Jpcoar20dummy < Jpcoar20
def initialize
@prefix = 'jpcoar_2.0'
@schema = 'https://github.com/JPCOAR/schema/blob/master/2.0/jpcoar_scm.xsd'
@namespace = 'https://github.com/JPCOAR/schema/blob/master/2.0/'
@element_namespace = 'dc'
@fields = [ :title, :creator, :subject, :description, :publisher,
:contributor, :date, :type, :format, :identifier,
:source, :language, :relation, :coverage, :rights]
end

def header_specification
{
'xmlns:jpcoar' => "https://github.com/JPCOAR/schema/blob/master/2.0/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xsi:schemaLocation' =>
%{https://github.com/JPCOAR/schema/blob/master/2.0/
jpcoar_scm.xsd}.gsub(/\s+/, ' ')
}
end
end
end
93 changes: 80 additions & 13 deletions app/models/concerns/enju_oai/oai_model.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module EnjuOai
module OaiModel
extend ActiveSupport::Concern
OAI::Provider::Base.register_format(EnjuOai::Jpcoar.instance)
OAI::Provider::Base.register_format(EnjuOai::Jpcoar20.instance)
OAI::Provider::Base.register_format(EnjuOai::Jpcoar20dummy.instance)
OAI::Provider::Base.register_format(EnjuOai::Dcndl.instance)

def to_oai_dc
Expand All @@ -26,34 +27,96 @@ def to_oai_dc
xml.target!
end

def to_jpcoar
# jpcoar_2.0フォーマットでの出力
def to_jpcoar_20
xml = Builder::XmlMarkup.new
xml.tag!('jpcoar:jpcoar', "xsi:schemaLocation" => "https://github.com/JPCOAR/schema/blob/master/1.0/jpcoar_scm.xsd",
xml.tag!(
'jpcoar:jpcoar', "xsi:schemaLocation" => "https://github.com/JPCOAR/schema/blob/master/2.0/jpcoar_scm.xsd",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xmlns:rioxxterms" => "http://www.rioxx.net/schema/v2.0/rioxxterms/",
"xmlns:datacite" => "https://schema.datacite.org/meta/kernel-4/",
"xmlns:oaire" => "http://namespace.openaire.eu/schema/oaire/",
"xmlns:dcndl" => "http://ndl.go.jp/dcndl/terms/",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
"xmlns:jpcoar" => "https://github.com/JPCOAR/schema/blob/master/1.0/") do
"xmlns:dcterms" => "http://purl.org/dc/terms/",
"xmlns:jpcoar" => "https://github.com/JPCOAR/schema/blob/master/2.0/"
) do
# タイトル
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/1
xml.tag! 'dc:title', original_title
xml.tag! 'dc:language', language.iso_639_2
xml.tag! 'jpcoar:creators' do
creators.readable_by(nil).each do |creator|
xml.tag! 'jpcoar:creatorName', creator.full_name

# 作成者
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/3
creators.readable_by(nil).each do |creator|
xml.tag! 'jpcoar:creator' do
xml.target! << creator.to_jpcoar
end
end

# 寄与者
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/4
contributors.readable_by(nil).each do |contributor|
xml.tag! 'jpcoar:contributor' do
xml.target! << contributor.to_jpcoar
end
end

# アクセス権
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/5
# TBD

# 権利情報
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/6
# TBD

# 主題
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/8
subjects.each do |subject|
xml.tag! 'jpcoar:subject', subject.term
xml.tag! 'jpcoar:subject', subject.term, subjectScheme: 'Other'
end

if attachment.attached?
xml.tag! 'jpcoar:file' do
xml.tag! 'jpcoar:URI', Rails.application.routes.url_helpers.rails_storage_proxy_url(fileset.attachment, host: ENV['ENJU_LEAF_BASE_URL'])
end
# 出版者
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/10
if publishers.first
xml.tag! 'dc:publisher', publishers.first.full_name
end

# 日付
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/12
xml.tag! 'datacite:date', date_of_publication&.iso8601, dateType: 'Issued' if date_of_publication
xml.tag! 'datacite:date', updated_at.to_date.iso8601, dateType: 'Updated'
xml.tag! 'dcterms:date', pub_date if pub_date

# 資源タイプ
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/15
# TBD

# 出版タイプ
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/17
# TBD

# 識別子
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/18
xml.tag! 'jpcoar:identifier', Rails.application.routes.url_helpers.manifestation_url(self, host: ENV['ENJU_LEAF_BASE_URL']), identifierType: 'URI'

# 関連情報
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/20
# TBD

# 収録物識別子
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/24
# 収録物名
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/25
# TBD

# 会議記述
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/35
# TBD

# ファイル情報
# https://schema.irdb.nii.ac.jp/ja/schema/2.0/43
# TBD
end

xml.target!
Expand Down Expand Up @@ -262,10 +325,14 @@ def to_dcndl
xml.target!
end

# OAI-PMHのbaseURLを取得する
# @return [String]
def self.repository_url
URI.join(ENV['ENJU_LEAF_BASE_URL'], '/oai')
end

# OAI-PMHのレコードプレフィックスを取得する
# @return [String]
def self.record_prefix
"oai:#{URI.parse(ENV['ENJU_LEAF_BASE_URL']).host}:manifestations"
end
Expand Down
20 changes: 2 additions & 18 deletions spec/requests/oai_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
end
end

describe 'jpcoar' do
describe 'jpcoar_2.0' do
before(:each) do
@metadata_format = 'jpcoar'
@metadata_format = 'jpcoar_2.0'
end

it "should get ListRecords" do
Expand Down Expand Up @@ -64,21 +64,5 @@
expect(response).to be_successful
end
end

describe 'junii2' do
before(:each) do
@metadata_format = 'junii2'
end

it "should get ListRecords" do
get oai_path(verb: 'ListRecords', metadataPrefix: @metadata_format)
expect(response).to be_successful
end

it "should get GetRecord" do
get oai_path(verb: 'GetRecord', identifier: "oai:localhost:manifestations:#{@manifestation.id}", metadataPrefix: @metadata_format)
expect(response).to be_successful
end
end
end
end
Loading