Class: DecisionReview::SubmitUpload

Inherits:
Object
  • Object
show all
Includes:
DecisionReviewV1::Appeals::LoggingUtils, Sidekiq::Job
Defined in:
app/sidekiq/decision_review/submit_upload.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'worker.decision_review.submit_upload'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DecisionReviewV1::Appeals::LoggingUtils

#benchmark?, #benchmark_to_log_data_hash, #extract_uuid_from_central_mail_message, #log_formatted, #parse_form412_response_to_log_msg, #parse_lighthouse_response_to_log_msg, #run_and_benchmark_if_enabled

Class Method Details

.record_email_send_failure(upload, submission, e) ⇒ Object (private)



199
200
201
202
203
204
205
206
207
# File 'app/sidekiq/decision_review/submit_upload.rb', line 199

def self.record_email_send_failure(upload, submission, e)
  appeal_type = submission.type_of_appeal
  params = { submitted_appeal_uuid: submission.,
             appeal_submission_upload_id: upload.id,
             appeal_type:,
             message: e.message }
  Rails.logger.error('DecisionReview::SubmitUpload retries exhausted email error', params)
  StatsD.increment("#{STATSD_KEY_PREFIX}.retries_exhausted.email_error", tags: ["appeal_type:#{appeal_type}"])
end

.record_email_send_successful(upload, submission, notification_id) ⇒ Object (private)



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'app/sidekiq/decision_review/submit_upload.rb', line 184

def self.record_email_send_successful(upload, submission, notification_id)
  appeal_type = submission.type_of_appeal
  params = { submitted_appeal_uuid: submission.,
             appeal_submission_upload_id: upload.id,
             appeal_type:,
             notification_id: }
  Rails.logger.info('DecisionReview::SubmitUpload retries exhausted email queued', params)
  StatsD.increment("#{STATSD_KEY_PREFIX}.retries_exhausted.email_queued")

  tags = ["service:#{DecisionReviewV1::APPEAL_TYPE_TO_SERVICE_MAP[appeal_type]}",
          'function: evidence submission to Lighthouse']
  StatsD.increment('silent_failure_avoided_no_confirmation', tags:)
end

.send_notification_email(upload, submission) ⇒ Object (private)



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/sidekiq/decision_review/submit_upload.rb', line 167

def self.send_notification_email(upload, submission)
  appeal_type = submission.type_of_appeal
  reference = "#{appeal_type}-evidence-#{upload.lighthouse_upload_id}"

  email_address = submission.current_email_address
  template_id = DecisionReviewV1::EVIDENCE_TEMPLATE_IDS[appeal_type]
  personalisation = {
    first_name: submission.get_mpi_profile.given_names[0],
    filename: upload.masked_attachment_filename,
    date_submitted: upload.created_at.strftime('%B %d, %Y')
  }

  service = ::VaNotify::Service.new(Settings.vanotify.services.benefits_decision_review.api_key)
  service.send_email({ email_address:, template_id:, personalisation:, reference: })
end

Instance Method Details

#get_dr_svcObject (private)



111
112
113
# File 'app/sidekiq/decision_review/submit_upload.rb', line 111

def get_dr_svc
  DecisionReviewV1::Service.new
end

#get_sanitized_file!(form_attachment:) ⇒ CarrierWave::SanitizedFile (private)

Get the sanitized file from S3

Parameters:

Returns:

  • (CarrierWave::SanitizedFile)

    The sanitized file from S3



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/sidekiq/decision_review/submit_upload.rb', line 74

def get_sanitized_file!(form_attachment:)
  appeal_submission_upload = form_attachment.appeal_submission_upload
  appeal_submission = appeal_submission_upload.appeal_submission
  # For now, I'm limiting our new `log_formatted` style of logging to the NOD form. In the near future, we will
  # expand this style of logging to every Decision Review form.
  form_id = appeal_submission.type_of_appeal == 'NOD' ? '10182' : '995'
  log_params = sanitized_file_log_params(appeal_submission, appeal_submission_upload, form_attachment, form_id)

  begin
    sanitized_file = form_attachment.get_file
    log_formatted(**log_params.merge(is_success: true))
    sanitized_file
  rescue => e
    log_formatted(**log_params.merge(is_success: false, response_error: e))
    raise e
  end
end

#handle_notice_of_disagreement(appeal_submission_upload, file_number_or_ssn, sanitized_file) ⇒ Faraday::Env (private)

Handle notice of disagreement appeal type. Make a request to Lighthouse to get the URL where we can upload the file, then get the file from S3 and send it to Lighthouse

Parameters:

  • appeal_submission_upload (AppealSubmissionUpload)
  • file_number_or_ssn (String)

    Veteran’s SSN or File #

  • sanitized_file (CarrierWave::SanitizedFile)

    The sanitized file from S3

Returns:

  • (Faraday::Env)

    The response from Lighthouse



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/sidekiq/decision_review/submit_upload.rb', line 122

def handle_notice_of_disagreement(appeal_submission_upload, file_number_or_ssn, sanitized_file)
  Sentry.set_tags(source: '10182-board-appeal')
  appeal_submission = appeal_submission_upload.appeal_submission
  upload_url_response = get_dr_svc.get_notice_of_disagreement_upload_url(
    nod_uuid: appeal_submission.,
    file_number: file_number_or_ssn,
    user_uuid: appeal_submission.user_uuid,
    appeal_submission_upload_id: appeal_submission_upload.id
  )
  upload_url = upload_url_response.body.dig('data', 'attributes', 'location')
  get_dr_svc.put_notice_of_disagreement_upload(upload_url:,
                                               file_upload: sanitized_file,
                                               metadata_string: appeal_submission.,
                                               user_uuid: appeal_submission.user_uuid,
                                               appeal_submission_upload_id: appeal_submission_upload.id)
  upload_url_response
end

#handle_supplemental_claim(appeal_submission_upload, file_number_or_ssn, sanitized_file) ⇒ Faraday::Env (private)

Handle supplemental claims appeal type. Make a request to Lighthouse to get the URL where we can upload the file, then get the file from S3 and send it to Lighthouse

Parameters:

  • appeal_submission_upload (AppealSubmissionUpload)
  • file_number_or_ssn (String)

    Veteran’s SSN or File #

  • sanitized_file (CarrierWave::SanitizedFile)

    The sanitized file from S3

Returns:

  • (Faraday::Env)

    The response from Lighthouse



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/sidekiq/decision_review/submit_upload.rb', line 147

def handle_supplemental_claim(appeal_submission_upload, file_number_or_ssn, sanitized_file)
  Sentry.set_tags(source: '20-0995-supplemental-claim')
  appeal_submission = appeal_submission_upload.appeal_submission
  user_uuid = appeal_submission.user_uuid
  appeal_submission_upload_id = appeal_submission_upload.id
  upload_url_response = get_dr_svc.get_supplemental_claim_upload_url(
    sc_uuid: appeal_submission.,
    file_number: file_number_or_ssn,
    user_uuid:,
    appeal_submission_upload_id:
  )
  upload_url = upload_url_response.body.dig('data', 'attributes', 'location')
  get_dr_svc.put_supplemental_claim_upload(upload_url:,
                                           file_upload: sanitized_file,
                                           metadata_string: appeal_submission.,
                                           user_uuid:,
                                           appeal_submission_upload_id:)
  upload_url_response
end

#perform(appeal_submission_upload_id) ⇒ Object

Make a request to Lighthouse to get the URL where we can upload the file, then get the file from S3 and send it to Lighthouse

Parameters:

  • appeal_submission_upload_id (String)

    UUID in response from Lighthouse upload



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/sidekiq/decision_review/submit_upload.rb', line 46

def perform(appeal_submission_upload_id)
  appeal_submission_upload = AppealSubmissionUpload.find(appeal_submission_upload_id)
  appeal_submission = appeal_submission_upload.appeal_submission
  form_attachment = appeal_submission_upload.decision_review_evidence_attachment
  sanitized_file = get_sanitized_file!(form_attachment:)
  file_number_or_ssn = JSON.parse(appeal_submission.)['fileNumber']

  lh_upload_id = case appeal_submission.type_of_appeal
                 when 'NOD'
                   handle_notice_of_disagreement(appeal_submission_upload, file_number_or_ssn, sanitized_file)
                 when 'SC'
                   handle_supplemental_claim(appeal_submission_upload, file_number_or_ssn, sanitized_file)
                 else
                   raise "Unknown appeal type (#{type})"
                 end.body.dig('data', 'id')
  appeal_submission_upload.update!(lighthouse_upload_id: lh_upload_id)
  StatsD.increment("#{STATSD_KEY_PREFIX}.success")
rescue => e
  StatsD.increment("#{STATSD_KEY_PREFIX}.error")
  raise e
end

#sanitized_file_log_params(appeal_submission, appeal_submission_upload, form_attachment, form_id) ⇒ Hash (private)

Get the sanitized file from S3

Parameters:

Returns:

  • (Hash)

    log params for get_sanitized_file! logging



98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/sidekiq/decision_review/submit_upload.rb', line 98

def sanitized_file_log_params(appeal_submission, appeal_submission_upload, form_attachment, form_id)
  {
    key: :evidence_upload_retrieval,
    form_id:,
    user_uuid: appeal_submission.user_uuid,
    upstream_system: 'AWS S3',
    params: {
      appeal_submission_upload_id: appeal_submission_upload.id,
      form_attachment_id: form_attachment.id
    }
  }
end