Class: ImportDataset
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ImportDataset
- Includes:
- Housekeeping, Shared::IsData, Shared::OriginRelationship
- Defined in:
- app/models/import_dataset.rb
Overview
A ImportDataset is uploaded file data to be imported into a project. This class shall not be instantiated, specific subclasses for each kind of dataset must be used instead.
Direct Known Subclasses
Defined Under Namespace
Classes: DarwinCore
Instance Attribute Summary collapse
-
#description ⇒ String
User-supplied description of the dataset.
-
#metadata ⇒ Hash
Data about the dataset.
-
#source_content_type ⇒ String
The content type (mime).
-
#source_file_name ⇒ String
the name of the file as uploaded by the user.
-
#source_file_size ⇒ Integer
Size of the document in K.
-
#source_updated_at ⇒ Timestamp
Last time this document was updated.
-
#status ⇒ String
Current import status (e.g. Pending, Completed, Closed).
Instance Method Summary collapse
- #delete_origin_relationships ⇒ Object private
-
#stage ⇒ Object
Stages all records from source file into DB.
Methods included from Shared::OriginRelationship
#new_objects, #old_objects, #reject_origin_relationships, #set_origin
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#description ⇒ String
Returns user-supplied description of the dataset.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#metadata ⇒ Hash
Returns data about the dataset. No particular structure is enforced, any subclass may store metadata (typically to aid the import process).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#source_content_type ⇒ String
Returns the content type (mime).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#source_file_name ⇒ String
the name of the file as uploaded by the user.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#source_file_size ⇒ Integer
Returns size of the document in K.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#source_updated_at ⇒ Timestamp
Returns last time this document was updated.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
#status ⇒ String
Returns current import status (e.g. Pending, Completed, Closed).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/import_dataset.rb', line 31 class ImportDataset < ApplicationRecord include Housekeeping include Shared::IsData include Shared::OriginRelationship attribute :status, :string, default: "Uploaded" has_many :dataset_record_fields, dependent: :delete_all # To speed up queries, normally should be get through dataset_records has_many :dataset_records, dependent: :delete_all before_destroy :delete_origin_relationships has_attached_file :source, filename_cleaner: Utilities::CleanseFilename validates :type, presence: true validates :status, presence: true validates :description, uniqueness: { scope: :project }, presence: true, length: { minimum: 2 } :source, presence: true, file_name: { matches: [/\.txt\z/, /\.csv\z/, /\.tsv\z/, /\.xlsx?\z/, /\.ods\z/, /\.zip\z/] }, size: { greater_than: 1.bytes } # Stages all records from source file into DB. Implementors must not assume it will be called only once. def stage raise "Implementation missing" end private def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end end |
Instance Method Details
#delete_origin_relationships ⇒ Object (private)
61 62 63 |
# File 'app/models/import_dataset.rb', line 61 def delete_origin_relationships OriginRelationship.where(old_object: self).delete_all end |
#stage ⇒ Object
Stages all records from source file into DB. Implementors must not assume it will be called only once.
55 56 57 |
# File 'app/models/import_dataset.rb', line 55 def stage raise "Implementation missing" end |