enju_ndl 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/ndl_books_controller.rb +2 -2
- data/app/helpers/ndl_books_helper.rb +8 -4
- data/app/models/ndl_book.rb +0 -13
- data/app/views/ndl_books/index.html.erb +1 -1
- data/config/locales/en.yml +3 -0
- data/config/locales/ja.yml +2 -0
- data/lib/enju_ndl/engine.rb +3 -0
- data/lib/enju_ndl/ndl_search.rb +65 -7
- data/lib/enju_ndl/version.rb +1 -1
- metadata +48 -14
@@ -18,12 +18,12 @@ class NdlBooksController < ApplicationController
|
|
18
18
|
def create
|
19
19
|
if params[:book]
|
20
20
|
@manifestation = NdlBook.import_from_sru_response(params[:book][:nbn])
|
21
|
-
if @manifestation.save
|
21
|
+
if @manifestation.try(:save)
|
22
22
|
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
|
23
23
|
flash[:porta_import] == true
|
24
24
|
redirect_to manifestation_items_url(@manifestation)
|
25
25
|
else
|
26
|
-
flash[:notice] = t('
|
26
|
+
flash[:notice] = t('enju_ndl.record_not_found')
|
27
27
|
redirect_to ndl_books_url
|
28
28
|
end
|
29
29
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module NdlBooksHelper
|
3
3
|
def link_to_import(nbn)
|
4
|
-
|
5
|
-
|
6
|
-
link_to '追加', ndl_books_path(:book => {:nbn => nbn}), :method => :post
|
4
|
+
if nbn.blank?
|
5
|
+
t('enju_ndl.not_available')
|
7
6
|
else
|
8
|
-
|
7
|
+
manifestation = Manifestation.where(:nbn => nbn).first
|
8
|
+
unless manifestation
|
9
|
+
link_to '追加', ndl_books_path(:book => {:nbn => nbn}), :method => :post
|
10
|
+
else
|
11
|
+
'登録済み'
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/app/models/ndl_book.rb
CHANGED
@@ -20,19 +20,6 @@ class NdlBook
|
|
20
20
|
10
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.find_by_isbn(isbn)
|
24
|
-
url = "http://iss.ndl.go.jp/api/opensearch?dpid=iss-ndl-opac&isbn=#{isbn}&cnt=1&idx=1"
|
25
|
-
Rails.logger.debug url
|
26
|
-
xml = open(url).read
|
27
|
-
doc = Nokogiri::XML(xml).at('//channel/item')
|
28
|
-
{
|
29
|
-
:title => doc.at('./title').content,
|
30
|
-
:publisher => doc.xpath('./dc:publisher').collect(&:content).join(' '),
|
31
|
-
:creator => doc.xpath('./dc:creator[@xsi:type="dcndl:NDLNH"]').collect(&:content).join(' '),
|
32
|
-
:isbn => doc.at('./dc:identifier[@xsi:type="dcndl:ISBN"]').try(:content).to_s
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
23
|
def self.import_from_sru_response(jpno)
|
37
24
|
manifestation = Manifestation.where(:nbn => jpno).first
|
38
25
|
return if manifestation
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
<%= form_for :books, :url => ndl_books_path, :html => {:method => 'get'} do -%>
|
7
7
|
<p>
|
8
|
-
<%=
|
8
|
+
<%= search_field_tag 'query', h(@query), {:id => 'search_form_top', :class => 'search_form'} -%>
|
9
9
|
<%= submit_tag '検索' -%>
|
10
10
|
</p>
|
11
11
|
<%- end -%>
|
data/config/locales/en.yml
CHANGED
data/config/locales/ja.yml
CHANGED
data/lib/enju_ndl/engine.rb
CHANGED
data/lib/enju_ndl/ndl_search.rb
CHANGED
@@ -20,8 +20,6 @@ module EnjuNdl
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def import_record(doc)
|
23
|
-
pub_date, langugage, nbn, ndc, isbn = nil, nil, nil, nil, nil
|
24
|
-
|
25
23
|
nbn = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').try(:content)
|
26
24
|
manifestation = Manifestation.where(:nbn => nbn).first if nbn
|
27
25
|
return manifestation if manifestation
|
@@ -32,7 +30,7 @@ module EnjuNdl
|
|
32
30
|
title = get_title(doc)
|
33
31
|
|
34
32
|
# date of publication
|
35
|
-
pub_date = doc.at('//dcterms:date').content.to_s.gsub(/\./, '-')
|
33
|
+
pub_date = doc.at('//dcterms:date').try(:content).to_s.gsub(/\./, '-')
|
36
34
|
unless pub_date =~ /^\d+(-\d{0,2}){0,2}$/
|
37
35
|
pub_date = nil
|
38
36
|
end
|
@@ -44,18 +42,34 @@ module EnjuNdl
|
|
44
42
|
language_id = 1
|
45
43
|
end
|
46
44
|
|
47
|
-
isbn = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content)
|
45
|
+
isbn = ISBN_Tools.cleanup(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content))
|
46
|
+
issn_l = ISBN_Tools.cleanup(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSNL"]').try(:content))
|
48
47
|
classification_urls = doc.xpath('//dcterms:subject[@rdf:resource]').map{|subject| subject.attributes['resource'].value}
|
49
48
|
if classification_urls
|
50
|
-
ndc9_url = classification_urls.map{|url| URI.parse(url)}.select{|u| u.path.split('/').reverse[1] == 'ndc9'}.first
|
49
|
+
ndc9_url = classification_urls.map{|url| URI.parse(URI.escape(url))}.select{|u| u.path.split('/').reverse[1] == 'ndc9'}.first
|
51
50
|
if ndc9_url
|
52
51
|
ndc = ndc9_url.path.split('/').last
|
53
52
|
end
|
54
53
|
end
|
54
|
+
|
55
|
+
carrier_type = content_type = nil
|
56
|
+
doc.xpath('//dcndl:materialType[@rdf:resource]').each do |d|
|
57
|
+
case d.attributes['resource'].try(:content)
|
58
|
+
when 'http://ndl.go.jp/ndltype/Book'
|
59
|
+
carrier_type = CarrierType.where(:name => 'print').first
|
60
|
+
content_type = ContentType.where(:name => 'text').first
|
61
|
+
when 'http://purl.org/dc/dcmitype/Sound'
|
62
|
+
content_type = ContentType.where(:name => 'audio').first
|
63
|
+
when 'http://purl.org/dc/dcmitype/MovingImage'
|
64
|
+
content_type = ContentType.where(:name => 'video').first
|
65
|
+
when 'http://ndl.go.jp/ndltype/ElectronicResource'
|
66
|
+
carrier_type = CarrierType.where(:name => 'file').first
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
55
70
|
description = doc.at('//dcterms:abstract').try(:content)
|
56
71
|
price = doc.at('//dcndl:price').try(:content)
|
57
72
|
volume_number_string = doc.at('//dcndl:volume/rdf:Description/rdf:value').try(:content)
|
58
|
-
|
59
73
|
manifestation = nil
|
60
74
|
Patron.transaction do
|
61
75
|
publisher_patrons = Patron.import_patrons(publishers)
|
@@ -76,10 +90,14 @@ module EnjuNdl
|
|
76
90
|
:nbn => nbn,
|
77
91
|
:ndc => ndc
|
78
92
|
)
|
93
|
+
manifestation.carrier_type = carrier_type if carrier_type
|
94
|
+
manifestation.content_type = content_type if content_type
|
79
95
|
manifestation.publishers << publisher_patrons
|
80
96
|
create_frbr_instance(doc, manifestation)
|
81
97
|
end
|
82
98
|
|
99
|
+
create_series_statement(doc, manifestation)
|
100
|
+
|
83
101
|
#manifestation.send_later(:create_frbr_instance, doc.to_s)
|
84
102
|
return manifestation
|
85
103
|
end
|
@@ -178,7 +196,7 @@ module EnjuNdl
|
|
178
196
|
|
179
197
|
def get_language(doc)
|
180
198
|
# TODO: 言語が複数ある場合
|
181
|
-
language = doc.at('//dcterms:language[@rdf:datatype="http://purl.org/dc/terms/ISO639-2"]').content
|
199
|
+
language = doc.at('//dcterms:language[@rdf:datatype="http://purl.org/dc/terms/ISO639-2"]').try(:content)
|
182
200
|
if language
|
183
201
|
language.downcase
|
184
202
|
end
|
@@ -191,6 +209,46 @@ module EnjuNdl
|
|
191
209
|
end
|
192
210
|
return publishers
|
193
211
|
end
|
212
|
+
|
213
|
+
def create_series_statement(doc, manifestation)
|
214
|
+
series = series_title = {}
|
215
|
+
series[:title] = doc.at('//dcndl:seriesTitle/rdf:Description/rdf:value').try(:content)
|
216
|
+
series[:title_transcription] = doc.at('//dcndl:seriesTitle/rdf:Description/dcndl:seriesTitleTranscription').try(:content)
|
217
|
+
if series[:title]
|
218
|
+
series_title[:title] = series[:title].split(';')[0].strip
|
219
|
+
series_title[:title_transcription] = series[:title_transcription]
|
220
|
+
end
|
221
|
+
|
222
|
+
publication_periodicity = doc.at('//dcndl:publicationPeriodicity').try(:content)
|
223
|
+
|
224
|
+
if series_title[:title]
|
225
|
+
series_statement = SeriesStatement.where(:original_title => series_title[:title]).first
|
226
|
+
unless series_statement
|
227
|
+
series_statement = SeriesStatement.new(
|
228
|
+
:original_title => series_title[:title],
|
229
|
+
:title_transcription => series_title[:title_transcription],
|
230
|
+
:periodical => false
|
231
|
+
)
|
232
|
+
end
|
233
|
+
elsif publication_periodicity
|
234
|
+
issn = ISBN_Tools.cleanup(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSN"]').try(:content))
|
235
|
+
series_statement = SeriesStatement.where(:issn => issn).first
|
236
|
+
unless series_statement
|
237
|
+
series_statement = SeriesStatement.new(
|
238
|
+
:original_title => manifestation.original_title,
|
239
|
+
:title_transcription => manifestation.title_transcription,
|
240
|
+
:issn => issn,
|
241
|
+
:periodical => true
|
242
|
+
)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
if series_statement
|
247
|
+
manifestation.series_statement = series_statement
|
248
|
+
manifestation.save
|
249
|
+
end
|
250
|
+
manifestation
|
251
|
+
end
|
194
252
|
end
|
195
253
|
|
196
254
|
class AlreadyImported < StandardError
|
data/lib/enju_ndl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enju_ndl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70163314227080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70163314227080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: devise
|
27
|
-
requirement: &
|
27
|
+
requirement: &70163314226520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70163314226520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &70163314225900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70163314225900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: will_paginate
|
49
|
-
requirement: &
|
49
|
+
requirement: &70163314225200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,43 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70163314225200
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: acts_as_list
|
60
|
+
requirement: &70163314224780 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70163314224780
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: attribute_normalizer
|
71
|
+
requirement: &70163314224200 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70163314224200
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: library_stdnums
|
82
|
+
requirement: &70163314223780 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70163314223780
|
58
91
|
- !ruby/object:Gem::Dependency
|
59
92
|
name: sqlite3
|
60
|
-
requirement: &
|
93
|
+
requirement: &70163314223360 !ruby/object:Gem::Requirement
|
61
94
|
none: false
|
62
95
|
requirements:
|
63
96
|
- - ! '>='
|
@@ -65,10 +98,10 @@ dependencies:
|
|
65
98
|
version: '0'
|
66
99
|
type: :development
|
67
100
|
prerelease: false
|
68
|
-
version_requirements: *
|
101
|
+
version_requirements: *70163314223360
|
69
102
|
- !ruby/object:Gem::Dependency
|
70
103
|
name: rspec-rails
|
71
|
-
requirement: &
|
104
|
+
requirement: &70163314222940 !ruby/object:Gem::Requirement
|
72
105
|
none: false
|
73
106
|
requirements:
|
74
107
|
- - ! '>='
|
@@ -76,7 +109,7 @@ dependencies:
|
|
76
109
|
version: '0'
|
77
110
|
type: :development
|
78
111
|
prerelease: false
|
79
|
-
version_requirements: *
|
112
|
+
version_requirements: *70163314222940
|
80
113
|
description: NDL WebAPI wrapper for Next-L Enju
|
81
114
|
email:
|
82
115
|
- tanabe@mwr.mediacom.keio.ac.jp
|
@@ -130,3 +163,4 @@ summary: enju_ndl plugin
|
|
130
163
|
test_files:
|
131
164
|
- test/enju_ndl_test.rb
|
132
165
|
- test/test_helper.rb
|
166
|
+
has_rdoc:
|