Skip to content

Commit

Permalink
import isbn to IsbnRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed May 3, 2020
1 parent 774684d commit f457845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions app/models/concerns/enju_ndl/enju_manifestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.import_from_ndl_search(options)

def self.import_record(doc)
iss_itemno = URI.parse(doc.at('//dcndl:BibAdminResource[@rdf:about]').values.first).path.split('/').last
identifier_type = IdentifierType.where(name: 'iss_itemno').first_or_create!
identifier_type = IdentifierType.find_or_create_by!(name: 'iss_itemno')
identifier = Identifier.find_by(body: iss_itemno, identifier_type_id: identifier_type.id)
return identifier.manifestation if identifier

Expand Down Expand Up @@ -152,9 +152,17 @@ def self.import_record(doc)
)
manifestation.serial = true if is_serial
identifier = {}
if isbn
identifier[:isbn] = Identifier.new(body: isbn)
identifier[:isbn].identifier_type = IdentifierType.where(name: 'isbn').first || IdnetifierType.create!(name: 'isbn')
if isbn.present?
IsbnRecordAndManifestation.create(
isbn_record: IsbnRecord.find_or_create_by(body: isbn),
manifestation: manifestation
)
end
if issn.present?
IssnRecordAndManifestation.create(
issn_record: IssnRecord.find_or_create_by(body: issn),
manifestation: manifestation
)
end
if iss_itemno
identifier[:iss_itemno] = Identifier.new(body: iss_itemno)
Expand All @@ -164,10 +172,6 @@ def self.import_record(doc)
identifier[:jpno] = Identifier.new(body: jpno)
identifier[:jpno].identifier_type = IdentifierType.where(name: 'jpno').first || IdentifierType.create!(name: 'jpno')
end
if issn
identifier[:issn] = Identifier.new(body: issn)
identifier[:issn].identifier_type = IdentifierType.where(name: 'issn').first || IdentifierType.create!(name: 'issn')
end
if issn_l
identifier[:issn_l] = Identifier.new(body: issn_l)
identifier[:issn_l].identifier_type = IdentifierType.where(name: 'issn_l').first || IdentifierType.create!(name: 'issn_l')
Expand Down
2 changes: 1 addition & 1 deletion spec/models/ndl_book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
it "should import bibliographic record", vcr: true do
manifestation = NdlBook.import_from_sru_response('R100000002-I000010980901-00')
manifestation.manifestation_identifier.should eq 'http://iss.ndl.go.jp/books/R100000002-I000010980901-00'
manifestation.identifier_contents(:isbn).should eq ['9784839931995']
expect(manifestation.isbn_records.pluck(:body)).to eq ['9784839931995']
manifestation.classifications.pluck(:category).should eq ["007.64"]
manifestation.identifier_contents(:iss_itemno).should eq ["R100000002-I000010980901-00"]
manifestation.identifier_contents(:jpno).should eq ["21816393"]
Expand Down

0 comments on commit f457845

Please sign in to comment.