enju_biblio 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/models2/agent.rb +331 -0
  3. data/app/models2/agent_import_file.rb +259 -0
  4. data/app/models2/agent_import_file_state_machine.rb +19 -0
  5. data/app/models2/agent_import_file_transition.rb +20 -0
  6. data/app/models2/agent_import_result.rb +20 -0
  7. data/app/models2/agent_merge.rb +17 -0
  8. data/app/models2/agent_merge_list.rb +27 -0
  9. data/app/models2/agent_relationship.rb +24 -0
  10. data/app/models2/agent_relationship_type.rb +20 -0
  11. data/app/models2/agent_type.rb +19 -0
  12. data/app/models2/carrier_type.rb +50 -0
  13. data/app/models2/content_type.rb +19 -0
  14. data/app/models2/country.rb +47 -0
  15. data/app/models2/create.rb +29 -0
  16. data/app/models2/create_type.rb +19 -0
  17. data/app/models2/doi_record.rb +36 -0
  18. data/app/models2/donate.rb +15 -0
  19. data/app/models2/form_of_work.rb +19 -0
  20. data/app/models2/frequency.rb +19 -0
  21. data/app/models2/identifier.rb +83 -0
  22. data/app/models2/identifier_type.rb +18 -0
  23. data/app/models2/import_request.rb +77 -0
  24. data/app/models2/import_request_state_machine.rb +9 -0
  25. data/app/models2/import_request_transition.rb +21 -0
  26. data/app/models2/isbn_record.rb +51 -0
  27. data/app/models2/isbn_record_and_manifestation.rb +18 -0
  28. data/app/models2/issn_record.rb +49 -0
  29. data/app/models2/issn_record_and_manifestation.rb +18 -0
  30. data/app/models2/item.rb +173 -0
  31. data/app/models2/item_custom_property.rb +18 -0
  32. data/app/models2/item_custom_value.rb +17 -0
  33. data/app/models2/language.rb +39 -0
  34. data/app/models2/license.rb +18 -0
  35. data/app/models2/manifestation.rb +764 -0
  36. data/app/models2/manifestation_custom_property.rb +18 -0
  37. data/app/models2/manifestation_custom_value.rb +17 -0
  38. data/app/models2/manifestation_relationship.rb +27 -0
  39. data/app/models2/manifestation_relationship_type.rb +20 -0
  40. data/app/models2/medium_of_performance.rb +19 -0
  41. data/app/models2/own.rb +29 -0
  42. data/app/models2/periodical.rb +33 -0
  43. data/app/models2/periodical_and_manifestation.rb +16 -0
  44. data/app/models2/picture_file.rb +60 -0
  45. data/app/models2/produce.rb +30 -0
  46. data/app/models2/produce_type.rb +19 -0
  47. data/app/models2/realize.rb +29 -0
  48. data/app/models2/realize_type.rb +19 -0
  49. data/app/models2/resource_export_file.rb +64 -0
  50. data/app/models2/resource_export_file_state_machine.rb +15 -0
  51. data/app/models2/resource_export_file_transition.rb +21 -0
  52. data/app/models2/resource_import_file.rb +909 -0
  53. data/app/models2/resource_import_file_state_machine.rb +19 -0
  54. data/app/models2/resource_import_file_transition.rb +21 -0
  55. data/app/models2/resource_import_result.rb +24 -0
  56. data/app/models2/series_statement.rb +72 -0
  57. data/app/models2/series_statement_merge.rb +17 -0
  58. data/app/models2/series_statement_merge_list.rb +17 -0
  59. data/app/views/manifestations/_book_jacket.html.erb +9 -5
  60. data/app/views/manifestations/_colorbox.html.erb +1 -1
  61. data/app/views/manifestations/_pickup.html.erb +1 -1
  62. data/lib/enju_biblio/version.rb +1 -1
  63. data/spec/dummy/yarn.lock +7560 -0
  64. metadata +61 -2
@@ -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 :bigint 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, optional: true
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 :bigint not null, primary key
12
+ # manifestation_custom_property_id :bigint not null
13
+ # manifestation_id :bigint not null
14
+ # value :text
15
+ # created_at :datetime not null
16
+ # updated_at :datetime not null
17
+ #
@@ -0,0 +1,27 @@
1
+ class ManifestationRelationship < ApplicationRecord
2
+ belongs_to :parent, foreign_key: 'parent_id', class_name: 'Manifestation'
3
+ belongs_to :child, foreign_key: 'child_id', class_name: 'Manifestation'
4
+ belongs_to :manifestation_relationship_type, optional: true
5
+ validate :check_parent
6
+ acts_as_list scope: :parent_id
7
+
8
+ def check_parent
9
+ if parent_id == child_id
10
+ errors.add(:parent)
11
+ errors.add(:child)
12
+ end
13
+ end
14
+ end
15
+
16
+ # == Schema Information
17
+ #
18
+ # Table name: manifestation_relationships
19
+ #
20
+ # id :integer not null, primary key
21
+ # parent_id :integer
22
+ # child_id :integer
23
+ # manifestation_relationship_type_id :integer
24
+ # created_at :datetime
25
+ # updated_at :datetime
26
+ # position :integer
27
+ #
@@ -0,0 +1,20 @@
1
+ class ManifestationRelationshipType < ApplicationRecord
2
+ include MasterModel
3
+ default_scope { order('manifestation_relationship_types.position') }
4
+ has_many :manifestation_relationships
5
+ translates :display_name
6
+ end
7
+
8
+ # == Schema Information
9
+ #
10
+ # Table name: manifestation_relationship_types
11
+ #
12
+ # id :integer not null, primary key
13
+ # name :string not null
14
+ # old_display_name :text
15
+ # note :text
16
+ # position :integer
17
+ # created_at :datetime
18
+ # updated_at :datetime
19
+ # display_name_translations :jsonb not null
20
+ #
@@ -0,0 +1,19 @@
1
+ class MediumOfPerformance < ApplicationRecord
2
+ include MasterModel
3
+ has_many :works, class_name: 'Manifestation'
4
+ translates :display_name
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: medium_of_performances
10
+ #
11
+ # id :integer not null, primary key
12
+ # name :string not null
13
+ # old_display_name :text
14
+ # note :text
15
+ # position :integer
16
+ # created_at :datetime
17
+ # updated_at :datetime
18
+ # display_name_translations :jsonb not null
19
+ #
@@ -0,0 +1,29 @@
1
+ class Own < ApplicationRecord
2
+ belongs_to :agent
3
+ belongs_to :item
4
+
5
+ validates :item_id, uniqueness: { scope: :agent_id }
6
+ after_save :reindex
7
+ after_destroy :reindex
8
+
9
+ acts_as_list scope: :item
10
+
11
+ attr_accessor :item_identifier
12
+
13
+ def reindex
14
+ agent&.index
15
+ item&.index
16
+ end
17
+ end
18
+
19
+ # == Schema Information
20
+ #
21
+ # Table name: owns
22
+ #
23
+ # id :integer not null, primary key
24
+ # agent_id :integer not null
25
+ # item_id :integer not null
26
+ # position :integer
27
+ # created_at :datetime
28
+ # updated_at :datetime
29
+ #
@@ -0,0 +1,33 @@
1
+ class Periodical < ApplicationRecord
2
+ belongs_to :frequency
3
+ has_many :periodical_and_manifestations, dependent: :destroy
4
+ has_many :manifestations, through: :periodical_and_manifestations
5
+
6
+ validates :original_title, presence: true
7
+
8
+ searchable do
9
+ string :original_title
10
+ text :original_title
11
+ text :publisher do
12
+ periodical_and_manifestations.where(periodical_master: true).each do |a|
13
+ a.manifestation.publishers.pluck(:full_name)
14
+ end
15
+ end
16
+ text :issn do
17
+ periodical_and_manifestations.where(periodical_master: true).each do |a|
18
+ a.manifestation.issn_records.pluck(:body)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # == Schema Information
25
+ #
26
+ # Table name: periodicals
27
+ #
28
+ # id :bigint not null, primary key
29
+ # original_title :text not null
30
+ # frequency_id :bigint not null
31
+ # created_at :datetime not null
32
+ # updated_at :datetime not null
33
+ #
@@ -0,0 +1,16 @@
1
+ class PeriodicalAndManifestation < ApplicationRecord
2
+ belongs_to :periodical
3
+ belongs_to :manifestation
4
+ end
5
+
6
+ # == Schema Information
7
+ #
8
+ # Table name: periodical_and_manifestations
9
+ #
10
+ # id :bigint not null, primary key
11
+ # periodical_id :bigint not null
12
+ # manifestation_id :bigint not null
13
+ # periodical_master :boolean default(FALSE), not null
14
+ # created_at :datetime not null
15
+ # updated_at :datetime not null
16
+ #
@@ -0,0 +1,60 @@
1
+ class PictureFile < ApplicationRecord
2
+ scope :attached, -> { where('picture_attachable_id IS NOT NULL') }
3
+ belongs_to :picture_attachable, polymorphic: true
4
+ before_save :extract_dimensions
5
+
6
+ if ENV['ENJU_STORAGE'] == 's3'
7
+ has_attached_file :picture, storage: :s3, styles: { medium: "600x600>", thumb: "100x100>" },
8
+ s3_credentials: {
9
+ access_key: ENV['AWS_ACCESS_KEY_ID'],
10
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
11
+ bucket: ENV['S3_BUCKET_NAME'],
12
+ s3_host_name: ENV['S3_HOST_NAME'],
13
+ s3_region: ENV['S3_REGION']
14
+ },
15
+ s3_permissions: :private
16
+ else
17
+ has_attached_file :picture, styles: { medium: "600x600>", thumb: "100x100>" },
18
+ path: ":rails_root/private/system/:class/:attachment/:id_partition/:style/:filename"
19
+ end
20
+ validates_attachment_presence :picture
21
+ validates_attachment_content_type :picture, content_type: /\Aimage\/.*\Z/
22
+
23
+ validates :picture_attachable_type, presence: true, inclusion: { in: ['Event', 'Manifestation', 'Agent', 'Shelf'] }
24
+ validates_associated :picture_attachable
25
+ default_scope { order('picture_files.position') }
26
+ # http://railsforum.com/viewtopic.php?id=11615
27
+ acts_as_list scope: 'picture_attachable_type=\'#{picture_attachable_type}\''
28
+ strip_attributes only: :picture_attachable_type
29
+
30
+ paginates_per 10
31
+
32
+ private
33
+ def extract_dimensions
34
+ return nil unless picture.queued_for_write[:original]
35
+ geometry = Paperclip::Geometry.from_file(picture.queued_for_write[:original])
36
+ self.picture_width = geometry.width.to_i
37
+ self.picture_height = geometry.height.to_i
38
+ end
39
+ end
40
+
41
+ # == Schema Information
42
+ #
43
+ # Table name: picture_files
44
+ #
45
+ # id :integer not null, primary key
46
+ # picture_attachable_id :integer
47
+ # picture_attachable_type :string
48
+ # title :text
49
+ # position :integer
50
+ # created_at :datetime
51
+ # updated_at :datetime
52
+ # picture_file_name :string
53
+ # picture_content_type :string
54
+ # picture_file_size :integer
55
+ # picture_updated_at :datetime
56
+ # picture_meta :text
57
+ # picture_fingerprint :string
58
+ # picture_width :integer
59
+ # picture_height :integer
60
+ #
@@ -0,0 +1,30 @@
1
+ class Produce < ApplicationRecord
2
+ belongs_to :agent
3
+ belongs_to :manifestation, touch: true
4
+ belongs_to :produce_type, optional: true
5
+ delegate :original_title, to: :manifestation, prefix: true
6
+
7
+ validates :manifestation_id, uniqueness: { scope: :agent_id }
8
+ after_save :reindex
9
+ after_destroy :reindex
10
+
11
+ acts_as_list scope: :manifestation
12
+
13
+ def reindex
14
+ agent&.index
15
+ manifestation&.index
16
+ end
17
+ end
18
+
19
+ # == Schema Information
20
+ #
21
+ # Table name: produces
22
+ #
23
+ # id :integer not null, primary key
24
+ # agent_id :integer not null
25
+ # manifestation_id :integer not null
26
+ # position :integer
27
+ # created_at :datetime
28
+ # updated_at :datetime
29
+ # produce_type_id :integer
30
+ #
@@ -0,0 +1,19 @@
1
+ class ProduceType < ApplicationRecord
2
+ include MasterModel
3
+ default_scope { order('produce_types.position') }
4
+ translates :display_name
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: produce_types
10
+ #
11
+ # id :integer not null, primary key
12
+ # name :string
13
+ # old_display_name :text
14
+ # note :text
15
+ # position :integer
16
+ # created_at :datetime
17
+ # updated_at :datetime
18
+ # display_name_translations :jsonb not null
19
+ #
@@ -0,0 +1,29 @@
1
+ class Realize < ApplicationRecord
2
+ belongs_to :agent
3
+ belongs_to :expression, class_name: 'Manifestation', foreign_key: 'expression_id', touch: true
4
+ belongs_to :realize_type, optional: true
5
+
6
+ validates :expression_id, uniqueness: { scope: :agent_id }
7
+ after_save :reindex
8
+ after_destroy :reindex
9
+
10
+ acts_as_list scope: :expression
11
+
12
+ def reindex
13
+ agent&.index
14
+ expression&.index
15
+ end
16
+ end
17
+
18
+ # == Schema Information
19
+ #
20
+ # Table name: realizes
21
+ #
22
+ # id :integer not null, primary key
23
+ # agent_id :integer not null
24
+ # expression_id :integer not null
25
+ # position :integer
26
+ # created_at :datetime
27
+ # updated_at :datetime
28
+ # realize_type_id :integer
29
+ #
@@ -0,0 +1,19 @@
1
+ class RealizeType < ApplicationRecord
2
+ include MasterModel
3
+ default_scope { order('realize_types.position') }
4
+ translates :display_name
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: realize_types
10
+ #
11
+ # id :integer not null, primary key
12
+ # name :string
13
+ # old_display_name :text
14
+ # note :text
15
+ # position :integer
16
+ # created_at :datetime
17
+ # updated_at :datetime
18
+ # display_name_translations :jsonb not null
19
+ #
@@ -0,0 +1,64 @@
1
+ class ResourceExportFile < ApplicationRecord
2
+ include Statesman::Adapters::ActiveRecordQueries[
3
+ transition_class: ResourceExportFileTransition,
4
+ initial_state: :pending
5
+ ]
6
+ include ExportFile
7
+
8
+ if ENV['ENJU_STORAGE'] == 's3'
9
+ has_attached_file :resource_export, storage: :s3,
10
+ s3_credentials: {
11
+ access_key: ENV['AWS_ACCESS_KEY_ID'],
12
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
13
+ bucket: ENV['S3_BUCKET_NAME'],
14
+ s3_host_name: ENV['S3_HOST_NAME'],
15
+ s3_region: ENV['S3_REGION']
16
+ },
17
+ s3_permissions: :private
18
+ else
19
+ has_attached_file :resource_export,
20
+ path: ":rails_root/private/system/:class/:attachment/:id_partition/:style/:filename"
21
+ end
22
+ validates_attachment_content_type :resource_export, content_type: /\Atext\/plain\Z/
23
+
24
+ has_many :resource_export_file_transitions, autosave: false, dependent: :destroy
25
+
26
+ def state_machine
27
+ ResourceExportFileStateMachine.new(self, transition_class: ResourceExportFileTransition)
28
+ end
29
+
30
+ delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
31
+ to: :state_machine
32
+
33
+ def export!
34
+ transition_to!(:started)
35
+ role_name = user.try(:role).try(:name)
36
+ tsv = Manifestation.export(role: role_name)
37
+ self.resource_export = StringIO.new(tsv)
38
+ self.resource_export.instance_write(:filename, "resource_export.txt")
39
+ save!
40
+ transition_to!(:completed)
41
+ mailer = ResourceExportMailer.completed(self)
42
+ send_message(mailer)
43
+ rescue => e
44
+ transition_to!(:failed)
45
+ mailer = ResourceExportMailer.failed(self)
46
+ send_message(mailer)
47
+ raise e
48
+ end
49
+ end
50
+
51
+ # == Schema Information
52
+ #
53
+ # Table name: resource_export_files
54
+ #
55
+ # id :integer not null, primary key
56
+ # user_id :integer
57
+ # resource_export_file_name :string
58
+ # resource_export_content_type :string
59
+ # resource_export_file_size :bigint
60
+ # resource_export_updated_at :datetime
61
+ # executed_at :datetime
62
+ # created_at :datetime
63
+ # updated_at :datetime
64
+ #
@@ -0,0 +1,15 @@
1
+ class ResourceExportFileStateMachine
2
+ include Statesman::Machine
3
+
4
+ state :pending, initial: true
5
+ state :started
6
+ state :completed
7
+ state :failed
8
+
9
+ transition from: :pending, to: [:started, :failed]
10
+ transition from: :started, to: [:completed, :failed]
11
+
12
+ after_transition(from: :pending, to: :started) do |resource_export_file|
13
+ resource_export_file.update_column(:executed_at, Time.zone.now)
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ class ResourceExportFileTransition < ApplicationRecord
2
+ include Statesman::Adapters::ActiveRecordTransition
3
+
4
+
5
+ belongs_to :resource_export_file, inverse_of: :resource_export_file_transitions
6
+ #attr_accessible :to_state, :sort_key, :metadata
7
+ end
8
+
9
+ # == Schema Information
10
+ #
11
+ # Table name: resource_export_file_transitions
12
+ #
13
+ # id :integer not null, primary key
14
+ # to_state :string
15
+ # metadata :text default({})
16
+ # sort_key :integer
17
+ # resource_export_file_id :integer
18
+ # created_at :datetime
19
+ # updated_at :datetime
20
+ # most_recent :boolean not null
21
+ #