enju_nii 0.1.0.pre11 → 0.1.0.pre12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +36 -1
- data/app/controllers/cinii_books_controller.rb +3 -3
- data/app/controllers/nii_types_controller.rb +7 -2
- data/app/helpers/cinii_books_helper.rb +4 -1
- data/app/models/cinii_book.rb +4 -2
- data/app/models/enju_nii/ability.rb +5 -2
- data/app/models/nii_type.rb +13 -1
- data/db/migrate/20141115051741_remove_ncid_from_manifestations.rb +5 -0
- data/lib/enju_nii/cinii_book.rb +101 -26
- data/lib/enju_nii/version.rb +1 -1
- data/lib/enju_nii.rb +1 -0
- data/spec/cassette_library/CiniiBook/should_import_a_bibliographic_record.yml +302 -236
- data/spec/cassette_library/CiniiBook/should_import_a_bibliographic_record_with_dual_languages.yml +292 -0
- data/spec/cassette_library/CiniiBook/should_search_with_ncid.yml +75 -0
- data/spec/controllers/nii_types_controller_spec.rb +167 -0
- data/spec/dummy/app/models/ability.rb +4 -1
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/boot.rb +4 -9
- data/spec/dummy/config/database.yml +23 -18
- data/spec/dummy/config/environment.rb +3 -3
- data/spec/dummy/config/environments/development.rb +25 -14
- data/spec/dummy/config/environments/production.rb +50 -31
- data/spec/dummy/config/environments/test.rb +20 -17
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/db/migrate/005_create_manifestations.rb +0 -1
- data/spec/dummy/db/migrate/20140519170214_create_resource_import_file_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140519171220_create_import_request_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140524020735_create_agent_import_file_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140614141500_create_resource_export_file_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +5 -1
- data/spec/dummy/db/migrate/20140821151023_create_colors.rb +14 -0
- data/spec/dummy/db/migrate/20140822114527_add_error_message_to_resource_import_result.rb +5 -0
- data/spec/dummy/db/migrate/20140823083524_add_extent_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20140823094847_add_dimensions_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20140823095740_rename_manifestation_periodical_to_serial.rb +9 -0
- data/spec/dummy/db/migrate/20141003181336_add_full_name_transcription_to_profile.rb +5 -0
- data/spec/dummy/db/migrate/20141003182825_add_date_of_birth_to_profile.rb +5 -0
- data/spec/dummy/db/schema.rb +91 -78
- data/spec/fixtures/agent_types.yml +7 -7
- data/spec/fixtures/carrier_types.yml +19 -31
- data/spec/fixtures/content_types.yml +73 -7
- data/spec/fixtures/manifestations.yml +119 -119
- data/spec/fixtures/nii_types.yml +98 -0
- data/spec/fixtures/subject_types.yml +4 -4
- data/spec/fixtures/users.yml +1 -1
- data/spec/models/cinii_book_spec.rb +40 -1
- data/spec/spec_helper.rb +2 -0
- metadata +84 -19
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/factories/nii_type.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b039e1f74ef637be9af2190fc44d5701a1ca9cd
|
4
|
+
data.tar.gz: 56effeda641726a5cfbe45404113f37baef4f2b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 519d4ad886c3aea5037bf3d1bb7c598e9125de79dd7b28136eebec17dc289890ebb5b22d3cd098b4394b5a1b1d76b3ba1b1d7641cde6fb38027347e197ca6617
|
7
|
+
data.tar.gz: e2fe019f0bf282aa4c9720ddac6ac900329b8615019feaf027323049316023c27cf10d14b521293a39e728bdd6cf94a09dd86ba0118cfd5c98a74dee78ebfa86
|
data/README.rdoc
CHANGED
@@ -1,3 +1,38 @@
|
|
1
1
|
= EnjuNii
|
2
|
+
{<img src="https://secure.travis-ci.org/next-l/enju_nii.png?branch=1.1" alt="Build Status" />}[http://travis-ci.org/next-l/enju_nii]
|
3
|
+
{<img src="https://coveralls.io/repos/next-l/enju_nii/badge.png?branch=1.1" alt="Coverage Status" />}[https://coveralls.io/r/next-l/enju_nii?branch=1.1]
|
4
|
+
{<img src="https://hakiri.io/github/next-l/enju_nii/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_nii/1.1]
|
2
5
|
|
3
|
-
|
6
|
+
CiNii Booksから書誌をインポートするための Enju プラグインです。
|
7
|
+
|
8
|
+
== インストール方法 / How to Install
|
9
|
+
|
10
|
+
お使いのenju_leafのGemfile に以下の行を追加してください。
|
11
|
+
|
12
|
+
gem 'enju_nii', github: "next-l/enju_nii", branch: '1.1'
|
13
|
+
|
14
|
+
gemをインストールします。
|
15
|
+
|
16
|
+
$ bundle update
|
17
|
+
|
18
|
+
インストールが完了したら、以下のコマンドでセットアップを行います。
|
19
|
+
|
20
|
+
$ rake enju_nii_engine:install:migrations
|
21
|
+
$ rake enju_nii:setup
|
22
|
+
|
23
|
+
データベースを更新します。
|
24
|
+
|
25
|
+
$ rake db:migrate
|
26
|
+
|
27
|
+
その後、Enjuを再起動してください。
|
28
|
+
|
29
|
+
\http://(Enjuのホスト)/cinii_books/ にアクセスすると、
|
30
|
+
CiNii Books検索によるインポート機能が利用できます。
|
31
|
+
|
32
|
+
== ライセンス / License
|
33
|
+
|
34
|
+
This project rocks and uses MIT-LICENSE.
|
35
|
+
|
36
|
+
== 製作者・貢献者 (Authors and contributors)
|
37
|
+
* {TANABE, Kosuke}[https://github.com/nabeta] ({@nabeta}[https://twitter.com/nabeta])
|
38
|
+
* {Project Next-L}[http://www.next-l.jp] ({@ProjectNextL}[https://twitter.com/ProjectNextL])
|
@@ -25,10 +25,10 @@ class CiniiBooksController < ApplicationController
|
|
25
25
|
respond_to do |format|
|
26
26
|
if @manifestation.try(:save)
|
27
27
|
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
|
28
|
-
format.html { redirect_to
|
28
|
+
format.html { redirect_to manifestation_url(@manifestation) }
|
29
29
|
else
|
30
|
-
flash[:notice] = t('
|
31
|
-
format.html { redirect_to
|
30
|
+
flash[:notice] = t('enju_nii.record_not_found')
|
31
|
+
format.html { redirect_to cinii_books_url }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -38,7 +38,7 @@ class NiiTypesController < ApplicationController
|
|
38
38
|
# POST /nii_types
|
39
39
|
# POST /nii_types.json
|
40
40
|
def create
|
41
|
-
@nii_type = NiiType.new(
|
41
|
+
@nii_type = NiiType.new(nii_type_params)
|
42
42
|
|
43
43
|
respond_to do |format|
|
44
44
|
if @nii_type.save
|
@@ -60,7 +60,7 @@ class NiiTypesController < ApplicationController
|
|
60
60
|
end
|
61
61
|
|
62
62
|
respond_to do |format|
|
63
|
-
if @nii_type.update_attributes(
|
63
|
+
if @nii_type.update_attributes(nii_type_params)
|
64
64
|
format.html { redirect_to @nii_type, notice: t('controller.successfully_updated', model: t('activerecord.models.nii_type')) }
|
65
65
|
format.json { head :no_content }
|
66
66
|
else
|
@@ -80,4 +80,9 @@ class NiiTypesController < ApplicationController
|
|
80
80
|
format.json { head :no_content }
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def nii_type_params
|
86
|
+
params.require(:nii_type).permit(:name, :display_name, :note)
|
87
|
+
end
|
83
88
|
end
|
@@ -4,7 +4,10 @@ module CiniiBooksHelper
|
|
4
4
|
if ncid.blank?
|
5
5
|
t('enju_nii.not_available')
|
6
6
|
else
|
7
|
-
|
7
|
+
identifier_type = IdentifierType.where(:name => 'ncid').first
|
8
|
+
if identifier_type
|
9
|
+
manifestation = Identifier.where(:body => ncid, :identifier_type_id => identifier_type.id).first.try(:manifestation)
|
10
|
+
end
|
8
11
|
unless manifestation
|
9
12
|
link_to t('enju_nii.add'), cinii_books_path(:book => {:ncid => ncid}), :method => :post
|
10
13
|
else
|
data/app/models/cinii_book.rb
CHANGED
@@ -52,8 +52,10 @@ class CiniiBook
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.import_ncid(ncid)
|
55
|
-
|
56
|
-
|
55
|
+
identifier_type = IdentifierType.where(name: 'ncid').first
|
56
|
+
identifier_type = IdentifierType.create!(name: 'ncid') unless identifier_type
|
57
|
+
identifier = Identifier.where(body: ncid, identifier_type_id: identifier_type.id).first
|
58
|
+
return if identifier
|
57
59
|
url = "http://ci.nii.ac.jp/ncid/#{ncid}.rdf"
|
58
60
|
doc = Nokogiri::XML(Faraday.get(url).body)
|
59
61
|
Manifestation.import_record_from_cinii_books(doc)
|
@@ -2,10 +2,13 @@ module EnjuNii
|
|
2
2
|
class Ability
|
3
3
|
include CanCan::Ability
|
4
4
|
|
5
|
-
def initialize(user, ip_address =
|
5
|
+
def initialize(user, ip_address = '0.0.0.0')
|
6
6
|
case user.try(:role).try(:name)
|
7
7
|
when 'Administrator'
|
8
|
-
can [:read, :update], NiiType
|
8
|
+
can [:read, :create, :update], NiiType
|
9
|
+
can [:destroy, :delete], NiiType do |nii_type|
|
10
|
+
true unless nii_type.manifestations.exists?
|
11
|
+
end if LibraryGroup.site_config.network_access_allowed?(ip_address)
|
9
12
|
else
|
10
13
|
can :read, NiiType
|
11
14
|
end
|
data/app/models/nii_type.rb
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
class NiiType < ActiveRecord::Base
|
2
|
-
attr_accessible :name, :display_name, :note
|
3
2
|
include MasterModel
|
4
3
|
default_scope { order('nii_types.position') }
|
5
4
|
has_many :manifestations
|
6
5
|
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: nii_types
|
10
|
+
#
|
11
|
+
# id :integer not null, primary key
|
12
|
+
# name :string(255) not null
|
13
|
+
# display_name :text
|
14
|
+
# note :text
|
15
|
+
# position :integer
|
16
|
+
# created_at :datetime
|
17
|
+
# updated_at :datetime
|
18
|
+
#
|
data/lib/enju_nii/cinii_book.rb
CHANGED
@@ -22,18 +22,20 @@ module EnjuNii
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def import_record_from_cinii_books(doc)
|
25
|
-
# http://ci.nii.ac.jp/info/ja/
|
26
|
-
return nil
|
25
|
+
# http://ci.nii.ac.jp/info/ja/api/api_outline.html#cib_od
|
26
|
+
#return nil
|
27
27
|
|
28
28
|
ncid = doc.at('//cinii:ncid').try(:content)
|
29
|
-
|
30
|
-
|
29
|
+
identifier_type = IdentifierType.where(name: 'ncid').first
|
30
|
+
identifier_type = IdentifierType.create!(name: 'ncid') unless identifier_type
|
31
|
+
identifier = Identifier.where(body: ncid, identifier_type_id: identifier_type.id).first
|
32
|
+
return identifier.manifestation if identifier
|
31
33
|
|
32
|
-
creators =
|
33
|
-
publishers =
|
34
|
+
creators = get_cinii_creator(doc)
|
35
|
+
publishers = get_cinii_publisher(doc)
|
34
36
|
|
35
37
|
# title
|
36
|
-
title =
|
38
|
+
title = get_cinii_title(doc)
|
37
39
|
manifestation = Manifestation.new(title)
|
38
40
|
|
39
41
|
# date of publication
|
@@ -48,33 +50,68 @@ module EnjuNii
|
|
48
50
|
end
|
49
51
|
manifestation.pub_date = pub_date
|
50
52
|
|
51
|
-
|
53
|
+
manifestation.statement_of_responsibility = doc.at('//dc:creator').try(:content)
|
54
|
+
|
55
|
+
language = Language.where(:iso_639_3 => get_cinii_language(doc)).first
|
52
56
|
if language
|
53
57
|
manifestation.language_id = language.id
|
54
58
|
else
|
55
59
|
manifestation.language_id = 1
|
56
60
|
end
|
57
61
|
|
58
|
-
|
59
|
-
|
62
|
+
urn = doc.at("//dcterms:hasPart[@rdf:resource]")
|
63
|
+
if urn
|
64
|
+
urn = urn.attributes["resource"].value
|
60
65
|
if urn =~ /^urn:isbn/
|
61
|
-
|
66
|
+
isbn = Lisbn.new(urn.gsub(/^urn:isbn:/, "")).isbn
|
62
67
|
end
|
63
|
-
rescue NoMethodError
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
identifier = {}
|
71
|
+
if ncid
|
72
|
+
identifier[:ncid] = Identifier.new(body: ncid)
|
73
|
+
identifier_type_ncid = IdentifierType.where(name: 'ncid').first
|
74
|
+
identifier_type_ncid = IdentifierType.where(name: 'ncid').create! unless identifier_type_ncid
|
75
|
+
identifier[:ncid].identifier_type = identifier_type_ncid
|
76
|
+
end
|
77
|
+
if isbn
|
78
|
+
identifier[:isbn] = Identifier.new(body: isbn)
|
79
|
+
identifier_type_isbn = IdentifierType.where(name: 'isbn').first
|
80
|
+
identifier_type_isbn = IdentifierType.where(name: 'isbn').create! unless identifier_type_isbn
|
81
|
+
identifier[:isbn].identifier_type = identifier_type_isbn
|
82
|
+
end
|
83
|
+
identifier.each do |k, v|
|
84
|
+
manifestation.identifiers << v
|
85
|
+
end
|
86
|
+
|
87
|
+
manifestation.carrier_type = CarrierType.where(name: 'volume').first
|
88
|
+
manifestation.manifestation_content_type = ContentType.where(name: 'text').first
|
69
89
|
|
70
90
|
if manifestation.valid?
|
71
|
-
|
91
|
+
Agent.transaction do
|
72
92
|
manifestation.save!
|
73
|
-
|
74
|
-
|
93
|
+
create_cinii_series_statements(doc, manifestation)
|
94
|
+
publisher_patrons = Agent.import_agents(publishers)
|
95
|
+
creator_patrons = Agent.import_agents(creators)
|
75
96
|
manifestation.publishers = publisher_patrons
|
76
97
|
manifestation.creators = creator_patrons
|
77
|
-
|
98
|
+
if defined?(EnjuSubject)
|
99
|
+
subjects = get_cinii_subjects(doc)
|
100
|
+
subject_heading_type = SubjectHeadingType.where(name: 'bsh').first
|
101
|
+
subject_heading_type = SubjectHeadingType.create!(name: 'bsh') unless subject_heading_type
|
102
|
+
subjects.each do |term|
|
103
|
+
subject = Subject.where(:term => term[:term]).first
|
104
|
+
unless subject
|
105
|
+
subject = Subject.new(term)
|
106
|
+
subject.subject_heading_type = subject_heading_type
|
107
|
+
subject_type = SubjectType.where(name: 'concept').first
|
108
|
+
subject_type = SubjectType.create(name: 'concept') unless subject_type
|
109
|
+
subject.subject_type = subject_type
|
110
|
+
end
|
111
|
+
manifestation.subjects << subject
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
78
115
|
end
|
79
116
|
|
80
117
|
manifestation
|
@@ -101,7 +138,7 @@ module EnjuNii
|
|
101
138
|
def return_rdf(isbn)
|
102
139
|
rss = self.search_cinii_by_isbn(isbn)
|
103
140
|
if rss.channel.totalResults.to_i == 0
|
104
|
-
rss = self.search_cinii_by_isbn(
|
141
|
+
rss = self.search_cinii_by_isbn(cinii_normalize_isbn(isbn))
|
105
142
|
end
|
106
143
|
if rss.items.first
|
107
144
|
Nokogiri::XML(Faraday.get("#{rss.items.first.link}.rdf").body)
|
@@ -116,7 +153,7 @@ module EnjuNii
|
|
116
153
|
end
|
117
154
|
|
118
155
|
private
|
119
|
-
def
|
156
|
+
def cinii_normalize_isbn(isbn)
|
120
157
|
if isbn.length == 10
|
121
158
|
Lisbn.new(isbn).isbn13
|
122
159
|
else
|
@@ -124,7 +161,7 @@ module EnjuNii
|
|
124
161
|
end
|
125
162
|
end
|
126
163
|
|
127
|
-
def
|
164
|
+
def get_cinii_creator(doc)
|
128
165
|
doc.xpath("//foaf:maker/foaf:Person").map{|e|
|
129
166
|
{
|
130
167
|
:full_name => e.at("./foaf:name").content,
|
@@ -134,11 +171,11 @@ module EnjuNii
|
|
134
171
|
}
|
135
172
|
end
|
136
173
|
|
137
|
-
def
|
174
|
+
def get_cinii_publisher(doc)
|
138
175
|
doc.xpath("//dc:publisher").map{|e| {:full_name => e.content}}
|
139
176
|
end
|
140
177
|
|
141
|
-
def
|
178
|
+
def get_cinii_title(doc)
|
142
179
|
{
|
143
180
|
:original_title => doc.at("//dc:title[not(@xml:lang)]").content,
|
144
181
|
:title_transcription => doc.xpath("//dc:title[@xml:lang]").map{|e| e.try(:content)}.join("\n"),
|
@@ -146,8 +183,46 @@ module EnjuNii
|
|
146
183
|
}
|
147
184
|
end
|
148
185
|
|
149
|
-
def
|
150
|
-
doc.at("//dc:language").try(:content)
|
186
|
+
def get_cinii_language(doc)
|
187
|
+
language = doc.at("//dc:language").try(:content)
|
188
|
+
if language.size > 3
|
189
|
+
language[0..2]
|
190
|
+
else
|
191
|
+
language
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def get_cinii_subjects(doc)
|
196
|
+
subjects = []
|
197
|
+
doc.xpath('//foaf:topic').each do |s|
|
198
|
+
subjects << { :term => s["dc:title"] }
|
199
|
+
end
|
200
|
+
subjects
|
201
|
+
end
|
202
|
+
|
203
|
+
def create_cinii_series_statements(doc, manifestation)
|
204
|
+
series = doc.at("//dcterms:isPartOf")
|
205
|
+
if series and parent_url = series["rdf:resource"]
|
206
|
+
ptbl = series["dc:title"]
|
207
|
+
parent_url = parent_url.gsub(/\#\w+\Z/, "")
|
208
|
+
parent_doc = Nokogiri::XML(Faraday.get(parent_url+".rdf").body)
|
209
|
+
parent_titles = get_cinii_title(parent_doc)
|
210
|
+
series_statement = SeriesStatement.new(parent_titles)
|
211
|
+
series_statement.series_statement_identifier = parent_url
|
212
|
+
manifestation.series_statements << series_statement
|
213
|
+
if parts = ptbl.split(/ \. /)
|
214
|
+
parts[1..-1].each do |part|
|
215
|
+
title, volume_number, = part.split(/ ; /)
|
216
|
+
original_title, title_transcription, = title.split(/\|\|/)
|
217
|
+
series_statement = SeriesStatement.new(
|
218
|
+
:original_title => original_title,
|
219
|
+
:title_transcription => title_transcription,
|
220
|
+
:volume_number_string => volume_number,
|
221
|
+
)
|
222
|
+
manifestation.series_statements << series_statement
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
151
226
|
end
|
152
227
|
end
|
153
228
|
|
data/lib/enju_nii/version.rb
CHANGED