Class: Download::DwcArchive::PupalComplete
- Inherits:
- 
      Complete
      
        - Object
- ActiveRecord::Base
- ApplicationRecord
- Download
- Download::DwcArchive
- Complete
- Download::DwcArchive::PupalComplete
 
- 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
Instance Attribute Summary
Attributes inherited from Download
#description, #expires, #filename, #is_public, #name, #project_id, #request, #times_downloaded, #total_records, #type
Class Method Summary collapse
Instance Method Summary collapse
- #save_file ⇒ Object private
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
Class Method Details
.project_api_access_token_destroyed ⇒ Object (private)
| 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_file ⇒ Object (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 |