enju_ndl 0.1.0.pre19 → 0.1.0.pre20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/ndl_book.rb +2 -2
- data/lib/enju_ndl/ndl_search.rb +36 -26
- data/lib/enju_ndl/version.rb +1 -1
- data/spec/cassette_library/ImportRequest/should_import_isbn.yml +504 -0
- data/spec/cassette_library/Manifestation/should_imporrt_a_bibliographic_record.yml +1168 -0
- data/spec/cassette_library/Manifestation/should_import_isbn.yml +504 -0
- data/spec/controllers/ndl_books_controller_spec.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/005_create_manifestations.rb +0 -12
- data/spec/dummy/db/migrate/20130506175303_create_identifier_types.rb +12 -0
- data/spec/dummy/db/migrate/20130506175834_create_identifiers.rb +14 -0
- data/spec/dummy/db/schema.rb +22 -13
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/fixtures/identifier_types.yml +29 -0
- data/spec/fixtures/subject_heading_types.yml +39 -0
- data/spec/fixtures/subject_types.yml +18 -4
- data/spec/models/import_request_spec.rb +10 -0
- data/spec/models/manifestation_spec.rb +7 -5
- data/spec/models/ndl_book_spec.rb +4 -4
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae2aa3ca95edd0d99542de23296cff581d1a3200
|
4
|
+
data.tar.gz: b6be5ee4f709e1552c650bfb134a6c5e617e2fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f727978dc92a297600878a0b7ce55e1c9f7a70c0a3068a85701567e868bea978ebfdb784692311d9406f760f8b045c4d11cb097dcf88c3c440027f3b58a4320b
|
7
|
+
data.tar.gz: e75f87e0759fa1f76dc75a51238167262c79a9d244b761d2b60287a917c09f90bd19b0c720c4f69a552ce19c7557a61b45941751dffb487f5db1df2bd9ea5a42
|
data/app/models/ndl_book.rb
CHANGED
@@ -62,8 +62,8 @@ class NdlBook
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.import_from_sru_response(jpno)
|
65
|
-
|
66
|
-
return if
|
65
|
+
identifier = Identifier.where(:body => jpno, :identifier_type_id => IdentifierType.where(:name => 'nbn').first_or_create.id).first
|
66
|
+
return if identifier
|
67
67
|
url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&recordSchema=dcndl&&maximumRecords=1&&query=%28jpno=#{jpno}%29&onlyBib=true"
|
68
68
|
xml = open(url).read
|
69
69
|
response = Nokogiri::XML(xml).at('//xmlns:recordData')
|
data/lib/enju_ndl/ndl_search.rb
CHANGED
@@ -6,6 +6,11 @@ module EnjuNdl
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
+
def import_isbn(isbn)
|
10
|
+
manifestation = Manifestation.import_from_ndl_search(:isbn => isbn)
|
11
|
+
manifestation
|
12
|
+
end
|
13
|
+
|
9
14
|
def import_from_ndl_search(options)
|
10
15
|
#if options[:isbn]
|
11
16
|
lisbn = Lisbn.new(options[:isbn])
|
@@ -13,7 +18,7 @@ module EnjuNdl
|
|
13
18
|
#end
|
14
19
|
|
15
20
|
manifestation = Manifestation.find_by_isbn(lisbn.isbn)
|
16
|
-
return manifestation if manifestation
|
21
|
+
return manifestation.first if manifestation.present?
|
17
22
|
|
18
23
|
doc = return_xml(lisbn.isbn)
|
19
24
|
raise EnjuNdl::RecordNotFound unless doc
|
@@ -23,8 +28,8 @@ module EnjuNdl
|
|
23
28
|
|
24
29
|
def import_record(doc)
|
25
30
|
nbn = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').try(:content)
|
26
|
-
|
27
|
-
return manifestation if
|
31
|
+
identifier = Identifier.where(:body => nbn, :identifier_type_id => IdentifierType.where(:name => 'nbn').first_or_create.id).first
|
32
|
+
return identifier.manifestation if identifier
|
28
33
|
|
29
34
|
publishers = get_publishers(doc)
|
30
35
|
|
@@ -53,6 +58,7 @@ module EnjuNdl
|
|
53
58
|
end
|
54
59
|
|
55
60
|
isbn = Lisbn.new(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content).to_s).try(:isbn)
|
61
|
+
issn = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSN"]').try(:content))
|
56
62
|
issn_l = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSNL"]').try(:content))
|
57
63
|
|
58
64
|
carrier_type = content_type = nil
|
@@ -75,6 +81,7 @@ module EnjuNdl
|
|
75
81
|
price = doc.at('//dcndl:price').try(:content)
|
76
82
|
volume_number_string = doc.at('//dcndl:volume/rdf:Description/rdf:value').try(:content)
|
77
83
|
extent = get_extent(doc)
|
84
|
+
publication_periodicity = doc.at('//dcndl:publicationPeriodicity').try(:content)
|
78
85
|
|
79
86
|
manifestation = nil
|
80
87
|
Patron.transaction do
|
@@ -89,19 +96,38 @@ module EnjuNdl
|
|
89
96
|
# TODO: NDLサーチに入っている図書以外の資料を調べる
|
90
97
|
#:carrier_type_id => CarrierType.where(:name => 'print').first.id,
|
91
98
|
:language_id => language_id,
|
92
|
-
:isbn => isbn,
|
93
99
|
:pub_date => date,
|
94
100
|
:description => description,
|
95
101
|
:volume_number_string => volume_number_string,
|
96
102
|
:price => price,
|
97
|
-
:nbn => nbn,
|
98
103
|
:start_page => extent[:start_page],
|
99
104
|
:end_page => extent[:end_page],
|
100
105
|
:height => extent[:height]
|
101
106
|
)
|
107
|
+
identifier = {}
|
108
|
+
if isbn
|
109
|
+
identifier[:isbn] = Identifier.new(:body => isbn)
|
110
|
+
identifier[:isbn].identifier_type = IdentifierType.where(:name => 'isbn').first_or_create
|
111
|
+
end
|
112
|
+
if nbn
|
113
|
+
identifier[:nbn] = Identifier.new(:body => nbn)
|
114
|
+
identifier[:nbn].identifier_type = IdentifierType.where(:name => 'nbn').first_or_create
|
115
|
+
end
|
116
|
+
if issn
|
117
|
+
identifier[:issn] = Identifier.new(:body => issn)
|
118
|
+
identifier[:issn].identifier_type = IdentifierType.where(:name => 'issn').first_or_create
|
119
|
+
end
|
120
|
+
if issn_l
|
121
|
+
identifier[:issn] = Identifier.new(:body => issn_l)
|
122
|
+
identifier[:issn].identifier_type = IdentifierType.where(:name => 'issn_l').first_or_create
|
123
|
+
end
|
102
124
|
manifestation.carrier_type = carrier_type if carrier_type
|
103
125
|
manifestation.manifestation_content_type = content_type if content_type
|
126
|
+
manifestation.periodical = true if publication_periodicity
|
104
127
|
if manifestation.save
|
128
|
+
identifier.each do |k, v|
|
129
|
+
manifestation.identifiers << v
|
130
|
+
end
|
105
131
|
manifestation.publishers << publisher_patrons
|
106
132
|
create_additional_attributes(doc, manifestation)
|
107
133
|
create_series_statement(doc, manifestation)
|
@@ -127,21 +153,18 @@ module EnjuNdl
|
|
127
153
|
manifestation.creators << creator_patrons
|
128
154
|
|
129
155
|
if defined?(EnjuSubject)
|
130
|
-
subject_heading_type = SubjectHeadingType.where(:name => 'ndlsh').
|
131
|
-
unless subject_heading_type
|
132
|
-
subject_heading_type = SubjectHeadingType.create!(:name => 'ndlsh')
|
133
|
-
end
|
156
|
+
subject_heading_type = SubjectHeadingType.where(:name => 'ndlsh').first_or_create
|
134
157
|
subjects.each do |term|
|
135
158
|
subject = Subject.where(:term => term[:term]).first
|
136
159
|
unless subject
|
137
160
|
subject = Subject.new(term)
|
138
161
|
subject.subject_heading_type = subject_heading_type
|
139
|
-
subject.subject_type = SubjectType.
|
162
|
+
subject.subject_type = SubjectType.where(:name => 'concept').first_or_create
|
140
163
|
end
|
141
|
-
if subject.valid?
|
164
|
+
#if subject.valid?
|
142
165
|
manifestation.subjects << subject
|
143
|
-
end
|
144
|
-
subject.save!
|
166
|
+
#end
|
167
|
+
#subject.save!
|
145
168
|
end
|
146
169
|
if classification_urls
|
147
170
|
ndc9_url = classification_urls.map{|url| URI.parse(URI.escape(url))}.select{|u| u.path.split('/').reverse[1] == 'ndc9'}.first
|
@@ -287,8 +310,6 @@ module EnjuNdl
|
|
287
310
|
series_title[:title_transcription] = series[:title_transcription]
|
288
311
|
end
|
289
312
|
|
290
|
-
publication_periodicity = doc.at('//dcndl:publicationPeriodicity').try(:content)
|
291
|
-
|
292
313
|
if series_title[:title]
|
293
314
|
series_statement = SeriesStatement.where(:original_title => series_title[:title]).first
|
294
315
|
unless series_statement
|
@@ -297,17 +318,6 @@ module EnjuNdl
|
|
297
318
|
:title_transcription => series_title[:title_transcription]
|
298
319
|
)
|
299
320
|
end
|
300
|
-
elsif publication_periodicity
|
301
|
-
issn = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSN"]').try(:content))
|
302
|
-
series_statement = SeriesStatement.where(:issn => issn).first
|
303
|
-
unless series_statement
|
304
|
-
series_statement = SeriesStatement.new(
|
305
|
-
:original_title => manifestation.original_title,
|
306
|
-
:title_transcription => manifestation.title_transcription,
|
307
|
-
:issn => issn,
|
308
|
-
:periodical => true
|
309
|
-
)
|
310
|
-
end
|
311
321
|
end
|
312
322
|
|
313
323
|
if series_statement.try(:save)
|
data/lib/enju_ndl/version.rb
CHANGED