Class: SampleManifestExcel::Upload::Processor::Base
  
  
  
  
  
    - Inherits:
 
    - 
      Object
      
        
          - Object
 
          
            - SampleManifestExcel::Upload::Processor::Base
 
          
        
        show all
      
     
  
  
  
  
  
  
  
      - Includes:
 
      - ActiveModel::Model, SequencescapeExcel::SubclassChecker
 
  
  
  
  
  
  
    - Defined in:
 
    - app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb
 
  
  
 
Overview
  
    
rubocop:disable Metrics/ClassLength
Uploads will be processed slightly differently based on the manifest type.
   
 
  
  
    
      Constant Summary
      collapse
    
    
      
        - MANDATORY_FIELDS =
          
        
 
        %w[country_of_origin date_of_sample_collection].freeze
 
      
    
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Constructor Details
  
    
  
  
    #initialize(upload)  ⇒ Base 
  
  
  
  
    
Returns a new instance of Base.
   
 
  
  
    
      
24
25
26 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 24
def initialize(upload)
  @upload = upload
end 
     | 
  
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #upload  ⇒ Object  
  
  
  
  
    
Returns the value of attribute upload.
   
 
  
  
    
      
17
18
19 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 17
def upload
  @upload
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #aliquots_updated?  ⇒ Boolean 
  
  
  
  
    
      
99
100
101
102 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 99
def aliquots_updated?
  downstream_aliquots_updated? || no_substitutions? ||
    log_error_and_return_false('Could not update tags in other assets.')
end
     | 
  
 
    
      
  
  
    #create_samples_if_not_present  ⇒ Object 
  
  
  
  
    
      
44
45
46 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 44
def create_samples_if_not_present
  upload.rows.each(&:sample)
end 
     | 
  
 
    
      
  
  
    #downstream_aliquots_updated?  ⇒ Boolean 
  
  
  
  
    
      
95
96
97 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 95
def downstream_aliquots_updated?
  @downstream_aliquots_updated
end 
     | 
  
 
    
      
  
  
    #processed?  ⇒ Boolean 
  
  
  
  
    
      
73
74
75 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 73
def processed?
  samples_updated? && sample_manifest_updated? && aliquots_updated?
end 
     | 
  
 
    
      
  
  
    #run(tag_group)  ⇒ Object 
  
  
  
  
    
If the processor is valid the samples and manifest are updated.
   
 
  
  
    
      
30
31
32
33
34
35
36
37
38
39
40
41
42 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 30
def run(tag_group)
  return unless valid?
    create_samples_if_not_present
    return unless samples_valid?
    update_samples_and_aliquots(tag_group)
  update_sample_manifest
end
     | 
  
 
    
      
  
  
    #sample_manifest_updated?  ⇒ Boolean 
  
  
  
  
    
      
83
84
85 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 83
def sample_manifest_updated?
  @sample_manifest_updated
end 
     | 
  
 
    
      
  
  
    #samples_updated?  ⇒ Boolean 
  
  
  
  
    
      
69
70
71 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 69
def samples_updated?
  upload.rows.all?(&:sample_skipped_or_updated?) || log_error_and_return_false('Could not update samples')
end
     | 
  
 
    
      
  
  
    #samples_valid?  ⇒ Boolean 
  
  
  
  
    
      
48
49
50
51
52
53
54
55
56
57
58
59 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 48
def samples_valid?
  all_valid = true
  upload.rows.each do |row|
    unless row.validate_sample
      upload.errors.add(:base, row.errors.full_messages.join(', ').to_s)
      all_valid = false
    end
  end
  all_valid
end
     | 
  
 
    
      
  
  
    #substitutions  ⇒ Object 
  
  
  
  
    
      
91
92
93 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 91
def substitutions
  @substitutions ||= []
end 
     | 
  
 
    
      
  
  
    #type  ⇒ Object 
  
  
  
  
    
      
87
88
89 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 87
def type
  self.class.to_s
end 
     | 
  
 
    
      
  
  
    #update_sample_manifest  ⇒ Object 
  
  
  
  
    
Override the sample manifest with the raw uploaded data.
   
 
  
  
    
      
79
80
81 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 79
def update_sample_manifest
  @sample_manifest_updated = upload.sample_manifest.update(uploaded: upload.file)
end 
     | 
  
 
    
      
  
  
    #update_samples_and_aliquots(tag_group)  ⇒ Object 
  
  
  
  
    
      
61
62
63
64
65
66
67 
     | 
    
      # File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 61
def update_samples_and_aliquots(tag_group)
  upload.rows.each do |row|
    row.update_sample(tag_group, upload.override)
    substitutions.concat(row.aliquots.filter_map(&:substitution_hash)) if row.reuploaded?
  end
  update_downstream_aliquots unless no_substitutions?
end
     |