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.

Class Method Summary collapse

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

Class Method Details

.project_api_access_token_destroyedObject



41
42
43
44
45
# File 'app/models/download/dwc_archive/pupal_complete.rb', line 41

def self.project_api_access_token_destroyed
  # May not be necessary if the download doesn't include media extension, but
  # we're doing it anyway.
  Download::DwcArchive::PupalComplete.destroy_all
end

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