enju_biblio 0.3.8 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/content_types_controller.rb +1 -1
- data/app/controllers/item_custom_properties_controller.rb +69 -0
- data/app/controllers/items_controller.rb +2 -3
- data/app/controllers/manifestation_custom_properties_controller.rb +69 -0
- data/app/controllers/manifestations_controller.rb +12 -15
- data/app/controllers/resource_import_results_controller.rb +6 -2
- data/app/models/agent.rb +6 -6
- data/app/models/agent_import_file.rb +7 -7
- data/app/models/agent_type.rb +0 -1
- data/app/models/carrier_type.rb +0 -1
- data/app/models/content_type.rb +0 -1
- data/app/models/form_of_work.rb +1 -2
- data/app/models/frequency.rb +0 -1
- data/app/models/identifier_type.rb +0 -1
- data/app/models/item.rb +15 -16
- data/app/models/item_custom_property.rb +18 -0
- data/app/models/item_custom_value.rb +17 -0
- data/app/models/license.rb +0 -1
- data/app/models/manifestation.rb +54 -22
- data/app/models/manifestation_custom_property.rb +18 -0
- data/app/models/manifestation_custom_value.rb +17 -0
- data/app/models/medium_of_performance.rb +1 -2
- data/app/models/picture_file.rb +0 -2
- data/app/models/resource_export_file.rb +4 -2
- data/app/models/resource_import_file.rb +157 -67
- data/app/policies/item_custom_property_policy.rb +21 -0
- data/app/policies/manifestation_custom_property_policy.rb +21 -0
- data/app/views/agent_import_results/index.txt.ruby +5 -0
- data/app/views/agent_relationship_types/_form.html.erb +1 -1
- data/app/views/agent_types/_form.html.erb +1 -1
- data/app/views/carrier_types/_form.html.erb +1 -1
- data/app/views/create_types/_form.html.erb +1 -1
- data/app/views/form_of_works/_form.html.erb +1 -1
- data/app/views/frequencies/_form.html.erb +1 -1
- data/app/views/item_custom_properties/_form.html.erb +32 -0
- data/app/views/item_custom_properties/edit.html.erb +13 -0
- data/app/views/item_custom_properties/index.html.erb +43 -0
- data/app/views/item_custom_properties/new.html.erb +12 -0
- data/app/views/item_custom_properties/show.html.erb +28 -0
- data/app/views/items/_form.html.erb +13 -10
- data/app/views/items/show.html.erb +3 -4
- data/app/views/licenses/_form.html.erb +1 -1
- data/app/views/manifestation_custom_properties/_form.html.erb +32 -0
- data/app/views/manifestation_custom_properties/edit.html.erb +13 -0
- data/app/views/manifestation_custom_properties/index.html.erb +43 -0
- data/app/views/manifestation_custom_properties/new.html.erb +12 -0
- data/app/views/manifestation_custom_properties/show.html.erb +28 -0
- data/app/views/manifestation_relationship_types/_form.html.erb +1 -1
- data/app/views/manifestations/_export_detail.html.erb +1 -0
- data/app/views/manifestations/_export_list.html.erb +1 -0
- data/app/views/manifestations/_form.html.erb +18 -10
- data/app/views/manifestations/_show_detail_librarian.html.erb +9 -3
- data/app/views/manifestations/_show_detail_user.html.erb +8 -0
- data/app/views/manifestations/show.json.jbuilder +2 -0
- data/app/views/medium_of_performances/_form.html.erb +1 -1
- data/app/views/picture_files/edit.html.erb +4 -0
- data/app/views/produce_types/_form.html.erb +1 -1
- data/app/views/realize_types/_form.html.erb +1 -1
- data/app/views/resource_import_results/index.txt.ruby +5 -0
- data/app/views/series_statement_merges/_form.html.erb +1 -1
- data/config/locales/translation_en.yml +22 -8
- data/config/locales/translation_ja.yml +22 -8
- data/config/routes.rb +2 -0
- data/db/migrate/20081027150907_create_picture_files.rb +0 -2
- data/db/migrate/20200425072340_create_manifestation_custom_properties.rb +12 -0
- data/db/migrate/20200425072349_create_item_custom_properties.rb +12 -0
- data/db/migrate/20200425074758_create_manifestation_custom_values.rb +12 -0
- data/db/migrate/20200425074822_create_item_custom_values.rb +12 -0
- data/lib/enju_biblio/version.rb +1 -1
- data/spec/cassette_library/ResourceImportFile/when_its_mode_is_create_/when_it_is_written_in_utf-8/should_import_custom_values.yml +121 -0
- data/spec/cassette_library/resource_import_results/index_txt_ruby/renders_a_list_of_resource_import_results.yml +121 -0
- data/spec/controllers/content_types_controller_spec.rb +1 -1
- data/spec/controllers/item_custom_properties_controller_spec.rb +449 -0
- data/spec/controllers/items_controller_spec.rb +22 -25
- data/spec/controllers/manifestation_custom_properties_controller_spec.rb +449 -0
- data/spec/controllers/manifestations_controller_spec.rb +20 -23
- data/spec/dummy/db/schema.rb +43 -12
- data/spec/factories/item_custom_property.rb +6 -0
- data/spec/factories/item_custom_value.rb +6 -0
- data/spec/factories/manifestation_custom_property.rb +6 -0
- data/spec/factories/manifestation_custom_value.rb +6 -0
- data/spec/fixtures/creates.yml +2 -0
- data/spec/fixtures/item_custom_properties.yml +24 -0
- data/spec/fixtures/library_groups.yml +29 -15
- data/spec/fixtures/manifestation_custom_properties.yml +24 -0
- data/spec/fixtures/picture_files.yml +0 -2
- data/spec/fixtures/produces.yml +2 -0
- data/spec/fixtures/realizes.yml +2 -0
- data/spec/fixtures/resource_import_results.yml +2 -2
- data/spec/models/item_custom_property_spec.rb +18 -0
- data/spec/models/item_custom_value_spec.rb +17 -0
- data/spec/models/manifestation_custom_property_spec.rb +18 -0
- data/spec/models/manifestation_custom_value_spec.rb +17 -0
- data/spec/models/manifestation_spec.rb +11 -21
- data/spec/models/picture_file_spec.rb +0 -2
- data/spec/models/resource_export_file_spec.rb +61 -8
- data/spec/models/resource_import_file_spec.rb +43 -13
- data/spec/requests/item_custom_properties_spec.rb +129 -0
- data/spec/requests/manifestation_custom_properties_spec.rb +129 -0
- data/spec/routing/item_custom_properties_routing_spec.rb +38 -0
- data/spec/routing/manifestation_custom_properties_routing_spec.rb +38 -0
- data/spec/system/items_spec.rb +12 -0
- data/spec/system/manifestations_spec.rb +12 -0
- data/spec/views/agent_import_results/index.html.erb_spec.rb +29 -0
- data/spec/views/agent_import_results/index.txt.ruby_spec.rb +20 -0
- data/spec/views/agent_import_results/show.html.erb_spec.rb +24 -0
- data/spec/views/item_custom_properties/edit.html.erb_spec.rb +21 -0
- data/spec/views/item_custom_properties/index.html.erb_spec.rb +25 -0
- data/spec/views/item_custom_properties/new.html.erb_spec.rb +21 -0
- data/spec/views/item_custom_properties/show.html.erb_spec.rb +16 -0
- data/spec/views/manifestation_custom_properties/edit.html.erb_spec.rb +21 -0
- data/spec/views/manifestation_custom_properties/index.html.erb_spec.rb +25 -0
- data/spec/views/manifestation_custom_properties/new.html.erb_spec.rb +21 -0
- data/spec/views/manifestation_custom_properties/show.html.erb_spec.rb +16 -0
- data/spec/views/manifestations/show.json.jbuilder_spec.rb +16 -0
- data/spec/views/manifestations/show.txt.ruby_spec.rb +1 -1
- data/spec/views/resource_import_results/index.txt.ruby_spec.rb +22 -0
- data/spec/views/resource_import_results/show.html.erb_spec.rb +1 -1
- metadata +118 -37
- data/app/models/custom_property.rb +0 -17
- data/app/views/agent_import_results/index.txt.erb +0 -3
- data/app/views/items/_custom_property_fields.html.erb +0 -7
- data/app/views/manifestations/_custom_property_fields.html.erb +0 -7
- data/app/views/resource_import_results/index.txt.erb +0 -3
- data/db/migrate/20191219122214_create_custom_properties.rb +0 -12
- data/spec/factories/custom_property.rb +0 -18
- data/spec/models/custom_property_spec.rb +0 -18
- data/spec/system/custom_properties_spec.rb +0 -84
@@ -0,0 +1,18 @@
|
|
1
|
+
class ItemCustomProperty < ApplicationRecord
|
2
|
+
include MasterModel
|
3
|
+
validates :name, presence: true, uniqueness: true
|
4
|
+
acts_as_list
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: item_custom_properties
|
10
|
+
#
|
11
|
+
# id :integer not null, primary key
|
12
|
+
# name :string not null
|
13
|
+
# display_name :text not null
|
14
|
+
# note :text
|
15
|
+
# position :integer default(1), not null
|
16
|
+
# created_at :datetime not null
|
17
|
+
# updated_at :datetime not null
|
18
|
+
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ItemCustomValue < ApplicationRecord
|
2
|
+
belongs_to :item_custom_property
|
3
|
+
belongs_to :item, required: false
|
4
|
+
validates :item_custom_property, uniqueness: {scope: :item_id}
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: item_custom_values
|
10
|
+
#
|
11
|
+
# id :integer not null, primary key
|
12
|
+
# item_custom_property_id :integer not null
|
13
|
+
# item_id :integer not null
|
14
|
+
# value :text
|
15
|
+
# created_at :datetime not null
|
16
|
+
# updated_at :datetime not null
|
17
|
+
#
|
data/app/models/license.rb
CHANGED
data/app/models/manifestation.rb
CHANGED
@@ -25,13 +25,13 @@ class Manifestation < ApplicationRecord
|
|
25
25
|
belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
|
26
26
|
has_one :resource_import_result
|
27
27
|
has_many :identifiers, dependent: :destroy
|
28
|
-
has_many :
|
28
|
+
has_many :manifestation_custom_values, -> { joins(:manifestation_custom_property).order(:position) }
|
29
29
|
accepts_nested_attributes_for :creators, allow_destroy: true, reject_if: :all_blank
|
30
30
|
accepts_nested_attributes_for :contributors, allow_destroy: true, reject_if: :all_blank
|
31
31
|
accepts_nested_attributes_for :publishers, allow_destroy: true, reject_if: :all_blank
|
32
32
|
accepts_nested_attributes_for :series_statements, allow_destroy: true, reject_if: :all_blank
|
33
33
|
accepts_nested_attributes_for :identifiers, allow_destroy: true, reject_if: :all_blank
|
34
|
-
accepts_nested_attributes_for :
|
34
|
+
accepts_nested_attributes_for :manifestation_custom_values, reject_if: :all_blank
|
35
35
|
|
36
36
|
searchable do
|
37
37
|
text :title, default_boost: 2 do
|
@@ -96,7 +96,7 @@ class Manifestation < ApplicationRecord
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
string :language do
|
99
|
-
language
|
99
|
+
language&.name
|
100
100
|
end
|
101
101
|
string :item_identifier, multiple: true do
|
102
102
|
if series_master?
|
@@ -120,7 +120,7 @@ class Manifestation < ApplicationRecord
|
|
120
120
|
end
|
121
121
|
time :date_of_publication
|
122
122
|
integer :pub_year do
|
123
|
-
date_of_publication
|
123
|
+
date_of_publication&.year
|
124
124
|
end
|
125
125
|
integer :creator_ids, multiple: true
|
126
126
|
integer :contributor_ids, multiple: true
|
@@ -357,7 +357,7 @@ class Manifestation < ApplicationRecord
|
|
357
357
|
# TODO: よりよい推薦方法
|
358
358
|
def self.pickup(keyword = nil, current_user = nil)
|
359
359
|
return nil if self.cached_numdocs < 5
|
360
|
-
if current_user
|
360
|
+
if current_user&.role
|
361
361
|
current_role_id = current_user.role.id
|
362
362
|
else
|
363
363
|
current_role_id = 1
|
@@ -433,7 +433,7 @@ class Manifestation < ApplicationRecord
|
|
433
433
|
end
|
434
434
|
|
435
435
|
def index_series_statement
|
436
|
-
series_statements.map{|s| s.index; s.root_manifestation
|
436
|
+
series_statements.map{|s| s.index; s.root_manifestation&.index}
|
437
437
|
end
|
438
438
|
|
439
439
|
def acquired_at
|
@@ -541,16 +541,34 @@ class Manifestation < ApplicationRecord
|
|
541
541
|
def to_hash(role: 'Guest')
|
542
542
|
record = {
|
543
543
|
manifestation_id: id,
|
544
|
-
|
544
|
+
original_title: original_title,
|
545
545
|
title_alternative: title_alternative,
|
546
546
|
title_transcription: title_transcription,
|
547
547
|
statement_of_responsibility: statement_of_responsibility,
|
548
548
|
serial: serial,
|
549
549
|
manifestation_identifier: manifestation_identifier,
|
550
|
-
creator:
|
551
|
-
|
552
|
-
|
553
|
-
|
550
|
+
creator: creates.map{|create|
|
551
|
+
if create.create_type
|
552
|
+
"#{create.agent.full_name}||#{create.create_type.name}"
|
553
|
+
else
|
554
|
+
"#{create.agent.full_name}"
|
555
|
+
end
|
556
|
+
}.join('//'),
|
557
|
+
contributor: realizes.map{|realize|
|
558
|
+
if realize.realize_type
|
559
|
+
"#{realize.agent.full_name}||#{realize.realize_type.name}"
|
560
|
+
else
|
561
|
+
"#{realize.agent.full_name}"
|
562
|
+
end
|
563
|
+
}.join('//'),
|
564
|
+
publisher: produces.map{|produce|
|
565
|
+
if produce.produce_type
|
566
|
+
"#{produce.agent.full_name}||#{produce.produce_type.name}"
|
567
|
+
else
|
568
|
+
"#{produce.agent.full_name}"
|
569
|
+
end
|
570
|
+
}.join('//'),
|
571
|
+
pub_date: date_of_publication,
|
554
572
|
year_of_publication: year_of_publication,
|
555
573
|
publication_place: publication_place,
|
556
574
|
manifestation_created_at: created_at,
|
@@ -577,13 +595,13 @@ class Manifestation < ApplicationRecord
|
|
577
595
|
depth: depth,
|
578
596
|
price: price,
|
579
597
|
access_address: access_address,
|
580
|
-
|
598
|
+
manifestation_required_role: required_role.name,
|
581
599
|
description: description,
|
582
600
|
note: note
|
583
601
|
}
|
584
602
|
|
585
603
|
IdentifierType.find_each do |type|
|
586
|
-
record[type.name.to_sym] = identifiers.where(identifier_type: type).pluck(:body).join('//')
|
604
|
+
record[:"identifier:#{type.name.to_sym}"] = identifiers.where(identifier_type: type).pluck(:body).join('//')
|
587
605
|
end
|
588
606
|
|
589
607
|
series = series_statements.order(:position)
|
@@ -608,15 +626,9 @@ class Manifestation < ApplicationRecord
|
|
608
626
|
record.merge!({
|
609
627
|
memo: memo
|
610
628
|
})
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
property = custom_properties[i]
|
615
|
-
if property
|
616
|
-
record[:"manifestation_custom_property_#{i + 1}"] = "#{property.label}: #{property.value}"
|
617
|
-
else
|
618
|
-
record[:"manifestation_custom_property_#{i + 1}"] = nil
|
619
|
-
end
|
629
|
+
ManifestationCustomProperty.order(:position).each do |custom_property|
|
630
|
+
custom_value = manifestation_custom_values.find_by(manifestation_custom_property: custom_property)
|
631
|
+
record[:"manifestation:#{custom_property.name}"] = custom_value&.value
|
620
632
|
end
|
621
633
|
end
|
622
634
|
|
@@ -629,6 +641,14 @@ class Manifestation < ApplicationRecord
|
|
629
641
|
end
|
630
642
|
end
|
631
643
|
|
644
|
+
if defined?(EnjuNdl)
|
645
|
+
record["jpno"] = identifier_contents(:jpno).first
|
646
|
+
end
|
647
|
+
|
648
|
+
if defined?(EnjuNii)
|
649
|
+
record["ncid"] = identifier_contents(:ncid).first
|
650
|
+
end
|
651
|
+
|
632
652
|
record
|
633
653
|
end
|
634
654
|
|
@@ -671,6 +691,18 @@ class Manifestation < ApplicationRecord
|
|
671
691
|
]
|
672
692
|
}.flatten
|
673
693
|
end
|
694
|
+
|
695
|
+
def set_custom_property(row)
|
696
|
+
ManifestationCustomProperty.all.each do |property|
|
697
|
+
if row[property]
|
698
|
+
custom_value = ManifestationCustomValue.new(
|
699
|
+
manifestation: self,
|
700
|
+
manifestation_custom_property: property,
|
701
|
+
value: row[property]
|
702
|
+
)
|
703
|
+
end
|
704
|
+
end
|
705
|
+
end
|
674
706
|
end
|
675
707
|
|
676
708
|
# == Schema Information
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ManifestationCustomProperty < ApplicationRecord
|
2
|
+
include MasterModel
|
3
|
+
validates :name, presence: true, uniqueness: true
|
4
|
+
acts_as_list
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: manifestation_custom_properties
|
10
|
+
#
|
11
|
+
# id :integer not null, primary key
|
12
|
+
# name :string not null
|
13
|
+
# display_name :text not null
|
14
|
+
# note :text
|
15
|
+
# position :integer default(1), not null
|
16
|
+
# created_at :datetime not null
|
17
|
+
# updated_at :datetime not null
|
18
|
+
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ManifestationCustomValue < ApplicationRecord
|
2
|
+
belongs_to :manifestation_custom_property
|
3
|
+
belongs_to :manifestation, required: false
|
4
|
+
validates :manifestation_custom_property, uniqueness: {scope: :manifestation_id}
|
5
|
+
end
|
6
|
+
|
7
|
+
# == Schema Information
|
8
|
+
#
|
9
|
+
# Table name: manifestation_custom_values
|
10
|
+
#
|
11
|
+
# id :integer not null, primary key
|
12
|
+
# manifestation_custom_property_id :integer not null
|
13
|
+
# manifestation_id :integer not null
|
14
|
+
# value :text
|
15
|
+
# created_at :datetime not null
|
16
|
+
# updated_at :datetime not null
|
17
|
+
#
|
data/app/models/picture_file.rb
CHANGED
@@ -31,8 +31,10 @@ class ResourceExportFile < ApplicationRecord
|
|
31
31
|
transition_to!(:started)
|
32
32
|
role_name = user.try(:role).try(:name)
|
33
33
|
tsv = Manifestation.export(role: role_name)
|
34
|
-
|
35
|
-
|
34
|
+
file = StringIO.new(tsv)
|
35
|
+
file.class.class_eval { attr_accessor :original_filename, :content_type }
|
36
|
+
file.original_filename = 'resource_export.txt'
|
37
|
+
self.resource_export = file
|
36
38
|
save!
|
37
39
|
transition_to!(:completed)
|
38
40
|
mailer = ResourceExportMailer.completed(self)
|
@@ -76,12 +76,13 @@ class ResourceImportFile < ApplicationRecord
|
|
76
76
|
#end
|
77
77
|
row_num = 1
|
78
78
|
|
79
|
-
ResourceImportResult.create!(resource_import_file_id: id, body: rows.headers.join("\t"))
|
79
|
+
ResourceImportResult.create!(resource_import_file_id: id, body: (%w( imported_manifestation_id imported_item_id ) + rows.headers).join("\t"))
|
80
80
|
rows.each do |row|
|
81
81
|
row_num += 1
|
82
|
-
import_result = ResourceImportResult.
|
82
|
+
import_result = ResourceImportResult.new(resource_import_file_id: id)
|
83
83
|
if row['dummy'].to_s.strip.present?
|
84
84
|
import_result.error_message = "line #{row_num}: #{I18n.t('import.dummy')}"
|
85
|
+
import_result.body = ([nil, nil] + row.fields).join("\t")
|
85
86
|
import_result.save!
|
86
87
|
next
|
87
88
|
end
|
@@ -92,6 +93,7 @@ class ResourceImportFile < ApplicationRecord
|
|
92
93
|
import_result.item = item
|
93
94
|
import_result.manifestation = item.manifestation
|
94
95
|
import_result.error_message = "line #{row_num}: #{I18n.t('import.item_found')}"
|
96
|
+
import_result.body = ([item.manifestation.id, item.id] + row.fields).join("\t")
|
95
97
|
import_result.save!
|
96
98
|
num[:item_found] += 1
|
97
99
|
next
|
@@ -187,8 +189,13 @@ class ResourceImportFile < ApplicationRecord
|
|
187
189
|
import_result.manifestation = manifestation
|
188
190
|
|
189
191
|
if manifestation
|
192
|
+
ResourceImportFile.import_manifestation_custom_value(row, manifestation).each do |value|
|
193
|
+
value.update!(manifestation: manifestation)
|
194
|
+
end
|
195
|
+
|
196
|
+
item = nil
|
190
197
|
if item_identifier.present? || row['shelf'].present? || row['call_number'].present?
|
191
|
-
|
198
|
+
item = create_item(row, manifestation)
|
192
199
|
else
|
193
200
|
if manifestation.fulltext_content?
|
194
201
|
item = create_item(row, manifestation)
|
@@ -200,17 +207,21 @@ class ResourceImportFile < ApplicationRecord
|
|
200
207
|
end
|
201
208
|
num[:failed] += 1
|
202
209
|
end
|
210
|
+
|
211
|
+
if item
|
212
|
+
ResourceImportFile.import_item_custom_value(row, item).each do |value|
|
213
|
+
value.update!(item: item)
|
214
|
+
end
|
215
|
+
|
216
|
+
import_result.item = item
|
217
|
+
end
|
203
218
|
else
|
204
219
|
num[:failed] += 1
|
205
220
|
end
|
206
221
|
|
222
|
+
import_result.body = ([manifestation.try(:id), item.try(:id)] + row.fields).join("\t")
|
207
223
|
import_result.save!
|
208
|
-
num[:item_imported] +=1 if import_result.item
|
209
|
-
|
210
|
-
if row_num % 50 == 0
|
211
|
-
Sunspot.commit
|
212
|
-
GC.start
|
213
|
-
end
|
224
|
+
num[:item_imported] += 1 if import_result.item
|
214
225
|
end
|
215
226
|
|
216
227
|
Sunspot.commit
|
@@ -311,56 +322,24 @@ class ResourceImportFile < ApplicationRecord
|
|
311
322
|
rows.each do |row|
|
312
323
|
row_num += 1
|
313
324
|
import_result = ResourceImportResult.create!(resource_import_file_id: id, body: row.fields.join("\t"))
|
314
|
-
|
315
|
-
item
|
325
|
+
item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
|
326
|
+
unless item
|
327
|
+
item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
|
328
|
+
end
|
329
|
+
|
316
330
|
if item
|
317
331
|
if item.manifestation
|
318
332
|
fetch(row, edit_mode: 'update')
|
333
|
+
item = update_item(item, row)
|
319
334
|
end
|
320
335
|
|
321
|
-
|
322
|
-
|
323
|
-
checkout_type = CheckoutType.find_by(name: row['checkout_type'])
|
324
|
-
use_restriction = UseRestriction.find_by(name: row['use_restriction'].to_s.strip)
|
336
|
+
ResourceImportFile.import_item_custom_value(row, item).each do |value|
|
337
|
+
value.update!(item: item)
|
325
338
|
end
|
326
|
-
|
327
|
-
|
328
|
-
bookstore = Bookstore.find_by(name: row['bookstore'])
|
329
|
-
required_role = Role.find_by(name: row['required_role'])
|
330
|
-
|
331
|
-
item.shelf = shelf if shelf
|
332
|
-
item.circulation_status = circulation_status if circulation_status
|
333
|
-
item.checkout_type = checkout_type if checkout_type
|
334
|
-
item.bookstore = bookstore if bookstore
|
335
|
-
item.required_role = required_role if required_role
|
336
|
-
item.use_restriction = use_restriction if use_restriction
|
337
|
-
|
338
|
-
acquired_at = Time.zone.parse(row['acquired_at']) rescue nil
|
339
|
-
binded_at = Time.zone.parse(row['binded_at']) rescue nil
|
340
|
-
item.acquired_at = acquired_at if acquired_at
|
341
|
-
item.binded_at = binded_at if binded_at
|
342
|
-
|
343
|
-
item_columns = %w(
|
344
|
-
call_number
|
345
|
-
binding_item_identifier binding_call_number binded_at
|
346
|
-
)
|
347
|
-
item_columns.each do |column|
|
348
|
-
if row[column].present?
|
349
|
-
item.assign_attributes(:"#{column}" => row[column])
|
350
|
-
end
|
339
|
+
ResourceImportFile.import_manifestation_custom_value(row, item.manifestation).each do |value|
|
340
|
+
value.update!(manifestation: item.manifestation)
|
351
341
|
end
|
352
342
|
|
353
|
-
item.price = row['item_price'] if row['item_price'].present?
|
354
|
-
item.note = row['item_note'].try(:gsub, /\\n/, "\n") if row['item_note'].present?
|
355
|
-
item.url = row['item_url'] if row['item_url'].present?
|
356
|
-
|
357
|
-
if row['include_supplements']
|
358
|
-
if %w(t true).include?(row['include_supplements'].downcase.strip)
|
359
|
-
item.include_supplements = true
|
360
|
-
else
|
361
|
-
item.include_supplements = false if item.include_supplements
|
362
|
-
end
|
363
|
-
end
|
364
343
|
item.manifestation.reload
|
365
344
|
item.save!
|
366
345
|
import_result.item = item
|
@@ -372,6 +351,9 @@ class ResourceImportFile < ApplicationRecord
|
|
372
351
|
end
|
373
352
|
if manifestation
|
374
353
|
fetch(row, edit_mode: 'update')
|
354
|
+
ResourceImportFile.import_manifestation_custom_value(row, manifestation).each do |value|
|
355
|
+
value.update!(manifestation: manifestation)
|
356
|
+
end
|
375
357
|
import_result.manifestation = manifestation
|
376
358
|
end
|
377
359
|
end
|
@@ -397,8 +379,11 @@ class ResourceImportFile < ApplicationRecord
|
|
397
379
|
|
398
380
|
rows.each do |row|
|
399
381
|
row_num += 1
|
400
|
-
|
401
|
-
item
|
382
|
+
item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
|
383
|
+
unless item
|
384
|
+
item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
|
385
|
+
end
|
386
|
+
|
402
387
|
if item
|
403
388
|
item.destroy if item.removable?
|
404
389
|
end
|
@@ -422,10 +407,9 @@ class ResourceImportFile < ApplicationRecord
|
|
422
407
|
row_num = 1
|
423
408
|
|
424
409
|
rows.each do |row|
|
425
|
-
|
426
|
-
item = Item.find_by(item_identifier: item_identifier)
|
410
|
+
item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip) if row['item_identifier'].to_s.strip.present?
|
427
411
|
unless item
|
428
|
-
item = Item.find_by(id: row['item_id'].to_s.strip)
|
412
|
+
item = Item.find_by(id: row['item_id'].to_s.strip) if row['item_id'].to_s.strip.present?
|
429
413
|
end
|
430
414
|
|
431
415
|
manifestation_identifier = row['manifestation_identifier'].to_s.strip
|
@@ -482,6 +466,9 @@ class ResourceImportFile < ApplicationRecord
|
|
482
466
|
use_restriction include_supplements item_note item_url
|
483
467
|
dummy
|
484
468
|
)
|
469
|
+
header_columns += ManifestationCustomProperty.order(:position).pluck(:name).map{|c| "manifestation:#{c}"}
|
470
|
+
header_columns += ItemCustomProperty.order(:position).pluck(:name).map{|c| "item:#{c}"}
|
471
|
+
|
485
472
|
if defined?(EnjuSubject)
|
486
473
|
header_columns += ClassificationType.order(:position).pluck(:name).map{|c| "classification:#{c}"}
|
487
474
|
header_columns += SubjectHeadingType.order(:position).pluck(:name).map{|s| "subject:#{s}"}
|
@@ -578,12 +565,68 @@ class ResourceImportFile < ApplicationRecord
|
|
578
565
|
item
|
579
566
|
end
|
580
567
|
|
568
|
+
def update_item(item, row)
|
569
|
+
shelf = Shelf.find_by(name: row['shelf'].to_s.strip)
|
570
|
+
bookstore = Bookstore.find_by(name: row['bookstore'])
|
571
|
+
required_role = Role.find_by(name: row['required_role'])
|
572
|
+
|
573
|
+
item.shelf = shelf if shelf
|
574
|
+
item.bookstore = bookstore if bookstore
|
575
|
+
item.required_role = required_role if required_role
|
576
|
+
|
577
|
+
acquired_at = Time.zone.parse(row['acquired_at']) rescue nil
|
578
|
+
binded_at = Time.zone.parse(row['binded_at']) rescue nil
|
579
|
+
item.acquired_at = acquired_at if acquired_at
|
580
|
+
item.binded_at = binded_at if binded_at
|
581
|
+
|
582
|
+
if defined?(EnjuCirculation)
|
583
|
+
circulation_status = CirculationStatus.find_by(name: row['circulation_status'])
|
584
|
+
checkout_type = CheckoutType.find_by(name: row['checkout_type'])
|
585
|
+
use_restriction = UseRestriction.find_by(name: row['use_restriction'].to_s.strip)
|
586
|
+
item.circulation_status = circulation_status if circulation_status
|
587
|
+
item.checkout_type = checkout_type if checkout_type
|
588
|
+
item.use_restriction = use_restriction if use_restriction
|
589
|
+
end
|
590
|
+
|
591
|
+
item_columns = %w(
|
592
|
+
call_number
|
593
|
+
binding_item_identifier binding_call_number binded_at
|
594
|
+
)
|
595
|
+
item_columns.each do |column|
|
596
|
+
if row[column].present?
|
597
|
+
item.assign_attributes(:"#{column}" => row[column])
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
item.price = row['item_price'] if row['item_price'].present?
|
602
|
+
item.note = row['item_note'].try(:gsub, /\\n/, "\n") if row['item_note'].present?
|
603
|
+
item.url = row['item_url'] if row['item_url'].present?
|
604
|
+
|
605
|
+
if row['include_supplements']
|
606
|
+
if %w(t true).include?(row['include_supplements'].downcase.strip)
|
607
|
+
item.include_supplements = true
|
608
|
+
else
|
609
|
+
item.include_supplements = false if item.include_supplements
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
item
|
614
|
+
end
|
615
|
+
|
581
616
|
def fetch(row, options = {edit_mode: 'create'})
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
617
|
+
manifestation = nil
|
618
|
+
item = nil
|
619
|
+
|
620
|
+
if options[:edit_mode] == 'update'
|
621
|
+
if row['item_identifier'].to_s.strip.present?
|
622
|
+
item = Item.find_by(item_identifier: row['item_identifier'].to_s.strip)
|
623
|
+
end
|
624
|
+
if row['item_id'].to_s.strip.present?
|
625
|
+
item = Item.find_by(id: row['item_id'].to_s.strip)
|
626
|
+
end
|
627
|
+
|
628
|
+
manifestation = item.manifestation if item
|
629
|
+
|
587
630
|
unless manifestation
|
588
631
|
manifestation_identifier = row['manifestation_identifier'].to_s.strip
|
589
632
|
manifestation = Manifestation.find_by(manifestation_identifier: manifestation_identifier) if manifestation_identifier
|
@@ -608,13 +651,13 @@ class ResourceImportFile < ApplicationRecord
|
|
608
651
|
end
|
609
652
|
|
610
653
|
# TODO: 小数点以下の表現
|
611
|
-
language = Language.
|
612
|
-
language = Language.
|
613
|
-
language = Language.
|
654
|
+
language = Language.find_by(name: row['language'].to_s.strip.camelize)
|
655
|
+
language = Language.find_by(iso_639_2: row['language'].to_s.strip.downcase) unless language
|
656
|
+
language = Language.find_by(iso_639_1: row['language'].to_s.strip.downcase) unless language
|
614
657
|
|
615
|
-
carrier_type = CarrierType.
|
616
|
-
content_type = ContentType.
|
617
|
-
frequency = Frequency.
|
658
|
+
carrier_type = CarrierType.find_by(name: row['carrier_type'].to_s.strip)
|
659
|
+
content_type = ContentType.find_by(name: row['content_type'].to_s.strip)
|
660
|
+
frequency = Frequency.find_by(name: row['frequency'].to_s.strip)
|
618
661
|
|
619
662
|
fulltext_content = serial = nil
|
620
663
|
if %w(t true).include?(row['fulltext_content'].to_s.downcase.strip)
|
@@ -764,6 +807,7 @@ class ResourceImportFile < ApplicationRecord
|
|
764
807
|
manifestation.set_agent_role_type(publishers_list, scope: :publisher)
|
765
808
|
end
|
766
809
|
end
|
810
|
+
|
767
811
|
manifestation
|
768
812
|
end
|
769
813
|
|
@@ -790,6 +834,52 @@ class ResourceImportFile < ApplicationRecord
|
|
790
834
|
end
|
791
835
|
identifiers
|
792
836
|
end
|
837
|
+
|
838
|
+
def self.import_manifestation_custom_value(row, manifestation)
|
839
|
+
values = []
|
840
|
+
ManifestationCustomProperty.order(:position).pluck(:name).map{|c| "manifestation:#{c}"}.each do |column_name|
|
841
|
+
value = nil
|
842
|
+
property = column_name.split(':').last
|
843
|
+
next if row[column_name].blank?
|
844
|
+
if manifestation
|
845
|
+
value = manifestation.manifestation_custom_values.find_by(manifestation_custom_property: property)
|
846
|
+
end
|
847
|
+
|
848
|
+
if value
|
849
|
+
value.value = row[column_name]
|
850
|
+
else
|
851
|
+
value = ManifestationCustomValue.new(
|
852
|
+
manifestation_custom_property: ManifestationCustomProperty.find_by(name: property),
|
853
|
+
value: row[column_name]
|
854
|
+
)
|
855
|
+
end
|
856
|
+
values << value
|
857
|
+
end
|
858
|
+
values
|
859
|
+
end
|
860
|
+
|
861
|
+
def self.import_item_custom_value(row, item)
|
862
|
+
values = []
|
863
|
+
ItemCustomProperty.order(:position).pluck(:name).map{|c| "item:#{c}"}.each do |column_name|
|
864
|
+
value = nil
|
865
|
+
property = column_name.split(':').last
|
866
|
+
next if row[column_name].blank?
|
867
|
+
if item
|
868
|
+
value = item.item_custom_values.find_by(item_custom_property: property)
|
869
|
+
end
|
870
|
+
|
871
|
+
if value
|
872
|
+
value.value = row[column_name]
|
873
|
+
else
|
874
|
+
value = ItemCustomValue.new(
|
875
|
+
item_custom_property: ItemCustomProperty.find_by(name: property),
|
876
|
+
value: row[column_name]
|
877
|
+
)
|
878
|
+
end
|
879
|
+
values << value
|
880
|
+
end
|
881
|
+
values
|
882
|
+
end
|
793
883
|
end
|
794
884
|
|
795
885
|
# == Schema Information
|