Class: Download::DwcArchive::PupalComplete

Inherits:
Complete show all
Defined in:
app/models/download/dwc_archive/pupal_complete.rb

Overview

A complete download that doesn’t have its download file yet; when it gets it, it will replace (eat?) any existing non-pupal Complete to become the sole non-pupal Complete. Note only one is allowed at a time, per the parent validation.

Constant Summary

Constants inherited from Download

STORAGE_PATH

Instance Attribute Summary

Attributes inherited from Download

#description, #expires, #filename, #is_public, #name, #project_id, #request, #times_downloaded, #total_records, #type

Instance Method Summary collapse

Methods inherited from Complete

api_buildable?, #build, #has_eml_without_stubs, #normalized_predicate_extensions, process_complete_download_request, #sync_expires_with_preferences

Methods inherited from Download

api_buildable?, #delete_file, #dir_path, #expired?, #file, #file_path, #ready?, #set_sha2, #source_file_path=, storage_path

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 Method Details

#save_fileObject (private)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/download/dwc_archive/pupal_complete.rb', line 10

def save_file
  # Replace any older existing Complete
  complete_download = Download.where(
    type: 'Download::DwcArchive::Complete', project_id:
  ).first
  if complete_download.nil?
    if super # moved tmp file to file storage
      update_column(:type, 'Download::DwcArchive::Complete')
      return true
    end
  else
    # Replace it.
    begin
      Download.transaction do
        if super # moved tmp file to file storage
          complete_download.destroy!
          update_column(:type, 'Download::DwcArchive::Complete')
          return true
        end
      end
    rescue ActiveRecord::RecordNotDestroyed => e
      msg = "Destroy of complete download '#{complete_download.id}' failed, pupal download '#{id}' failed to eclose (should no longer exist)."
      # The older complete download remains, this one is gone: destroy of the
      # old one needs to be investigated.
      raise ActiveRecord::RecordNotDestroyed.new(msg, e.record)
    end
  end

  false
end