Class: ImportDataset

Inherits:
ApplicationRecord show all
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

DarwinCore

Defined Under Namespace

Classes: DarwinCore

Instance Attribute Summary collapse

Instance Method Summary collapse

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

transaction_with_retry

Instance Attribute Details

#descriptionString

Returns user-supplied description of the dataset.

Returns:

  • (String)

    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 }

  validates_attachment :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

#metadataHash

Returns data about the dataset. No particular structure is enforced, any subclass may store metadata (typically to aid the import process).

Returns:

  • (Hash)

    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 }

  validates_attachment :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_typeString

Returns the content type (mime).

Returns:

  • (String)

    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 }

  validates_attachment :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_nameString

the name of the file as uploaded by the user.

Returns:

  • (String)


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 }

  validates_attachment :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_sizeInteger

Returns size of the document in K.

Returns:

  • (Integer)

    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 }

  validates_attachment :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_atTimestamp

Returns last time this document was updated.

Returns:

  • (Timestamp)

    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 }

  validates_attachment :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

#statusString

Returns current import status (e.g. Pending, Completed, Closed).

Returns:

  • (String)

    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 }

  validates_attachment :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_relationshipsObject (private)



61
62
63
# File 'app/models/import_dataset.rb', line 61

def delete_origin_relationships
  OriginRelationship.where(old_object: self).delete_all
end

#stageObject

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