Class: EVSS::DisabilityCompensationForm::SubmitForm0781

Inherits:
Job
  • Object
show all
Extended by:
Logging::ThirdPartyTransaction::MethodWrapper
Defined in:
app/sidekiq/evss/disability_compensation_form/submit_form0781.rb

Constant Summary collapse

ZSF_DD_TAG_FUNCTION =
'526_form_0781_failure_email_queuing'
FORM_ID_0781 =

form id for PTSD

'21-0781'
FORM_ID_0781A =

form id for PTSD Secondary to Personal Assault

'21-0781a'
FORMS_METADATA =
{
  FORM_ID_0781 => { docType: 'L228' },
  FORM_ID_0781A => { docType: 'L229' }
}.freeze
STATSD_KEY_PREFIX =
'worker.evss.submit_form0781'
RETRY =

Sidekiq has built in exponential back-off functionality for retries A max retry attempt of 16 will result in a run time of ~48 hours This job is invoked from 526 background job

16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging::ThirdPartyTransaction::MethodWrapper

wrap_with_logging

Methods inherited from Job

#submission

Methods included from Sidekiq::Form526JobStatusTracker::JobTracker

#error_message, #job_success, #job_try, #klass, #log_error, #log_info, #metrics, #non_retryable_error_handler, #retryable_error_handler, #update_background_job_errors, #upsert_job_status, #with_tracking

Methods included from Sidekiq::Form526JobStatusTracker::BackupSubmission

#send_backup_submission_if_enabled

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Instance Attribute Details

#evss_claim_idObject (readonly)

Returns the value of attribute evss_claim_id.



16
17
18
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 16

def evss_claim_id
  @evss_claim_id
end

#submission_idObject (readonly)

Returns the value of attribute submission_id.



16
17
18
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 16

def submission_id
  @submission_id
end

#uuidObject (readonly)

Returns the value of attribute uuid.



16
17
18
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 16

def uuid
  @uuid
end

Class Method Details

.api_upload_provider(submission, form_id) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 118

def self.api_upload_provider(submission, form_id)
  user = User.find(submission.user_uuid)

  ApiProviderFactory.call(
    type: ApiProviderFactory::FACTORIES[:supplemental_document_upload],
    options: {
      form526_submission: submission,
      document_type: FORMS_METADATA[form_id][:docType],
      statsd_metric_prefix: STATSD_KEY_PREFIX
    },
    current_user: user,
    feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781
  )
end

Instance Method Details

#create_document_data(evss_claim_id, upload_data) ⇒ Object (private)



226
227
228
229
230
231
232
233
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 226

def create_document_data(evss_claim_id, upload_data)
  EVSSClaimDocument.new(
    evss_claim_id:,
    file_name: upload_data[:file_name],
    tracked_item_id: nil,
    document_type: upload_data[:doc_type]
  )
end

#generate_stamp_pdf(form_content, evss_claim_id, form_id) ⇒ Object (private)

Invokes Filler ancillary form method to generate PDF document Then calls method PDFUtilities::DatestampPdf to stamp the document. Its called twice, once to stamp with text “VA.gov YYYY-MM-DD” at the bottom of each page and second time to stamp with text “VA.gov Submission” at the top of each page



204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 204

def generate_stamp_pdf(form_content, evss_claim_id, form_id)
  submission_date = @submission&.created_at&.in_time_zone('Central Time (US & Canada)')
  form_content = form_content.merge({ 'signatureDate' => submission_date })
  pdf_path = PdfFill::Filler.fill_ancillary_form(form_content, evss_claim_id, form_id)
  stamped_path = PDFUtilities::DatestampPdf.new(pdf_path).run(text: 'VA.gov', x: 5, y: 5,
                                                              timestamp: submission_date)
  PDFUtilities::DatestampPdf.new(stamped_path).run(
    text: 'VA.gov Submission',
    x: 510,
    y: 775,
    text_only: true
  )
end

#get_docs(submission_id, uuid) ⇒ Hash

This method generates the PDF documents but does NOT send them anywhere. It just generates them to the filesystem and returns the path to them to be used by other methods.

but is passed along as the existing process_0781 function requires something here ‘type` (to discern between if it is a 0781 or 0781a form) and `file`, which is the generated file location

Parameters:

  • submission_id (Integer)
  • uuid (String)

    The Central Mail UUID, not actually used,

Returns:

  • (Hash)

    Returns a hash with the keys



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 142

def get_docs(submission_id, uuid)
  @submission_id = submission_id
  @uuid = uuid
  @submission = Form526Submission.find_by(id: submission_id)

  file_type_and_file_objs = []
  { 'form0781' => FORM_ID_0781, 'form0781a' => FORM_ID_0781A }.each do |form_type_key, actual_form_types|
    if parsed_forms[form_type_key].present?
      file_type_and_file_objs << {
        type: actual_form_types,
        file: process_0781(uuid, actual_form_types, parsed_forms[form_type_key],
                           upload: false)
      }
    end
  end
  file_type_and_file_objs
end

#get_evss_claim_metadata(pdf_path, form_id) ⇒ Object (private)



218
219
220
221
222
223
224
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 218

def (pdf_path, form_id)
  pdf_path_split = pdf_path.split('/')
  {
    doc_type: FORMS_METADATA[form_id][:docType],
    file_name: pdf_path_split.last
  }
end

#parsed_formsObject



160
161
162
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 160

def parsed_forms
  @parsed_forms ||= JSON.parse(submission.form_to_json(Form526Submission::FORM_0781))
end

#perform(submission_id) ⇒ Object

Performs an asynchronous job for generating and submitting 0781 + 0781A PDF documents to VBMS

Parameters:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 168

def perform(submission_id)
  @submission_id = submission_id

  Sentry.set_tags(source: '526EZ-all-claims')
  super(submission_id)

  with_tracking('Form0781 Submission', submission.saved_claim_id, submission.id) do
    # process 0781 and 0781a
    if parsed_forms['form0781'].present?
      process_0781(submission., FORM_ID_0781, parsed_forms['form0781'])
    end
    if parsed_forms['form0781a'].present?
      process_0781(submission., FORM_ID_0781A, parsed_forms['form0781a'])
    end
  end
rescue => e
  # Cannot move job straight to dead queue dynamically within an executing job
  # raising error for all the exceptions as sidekiq will then move into dead queue
  # after all retries are exhausted
  retryable_error_handler(e)
  raise e
end

#perform_client_upload(file_body, document_data, form_id) ⇒ Object (private)



249
250
251
252
253
254
255
256
257
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 249

def perform_client_upload(file_body, document_data, form_id)
  if Flipper.enabled?(:disability_compensation_use_api_provider_for_0781_uploads)
    provider = self.class.api_upload_provider(submission, form_id)
    upload_document = provider.generate_upload_document(document_data.file_name)
    provider.submit_upload_document(upload_document, file_body)
  else
    EVSS::DocumentsService.new(submission.auth_headers).upload(file_body, document_data)
  end
end

#process_0781(evss_claim_id, form_id, form_content, upload: true) ⇒ Object (private)



193
194
195
196
197
198
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 193

def process_0781(evss_claim_id, form_id, form_content, upload: true)
  @evss_claim_id = evss_claim_id
  # generate and stamp PDF file
  pdf_path0781 = generate_stamp_pdf(form_content, evss_claim_id, form_id)
  upload ? upload_to_vbms(pdf_path0781, form_id) : pdf_path0781
end

#upload_to_vbms(pdf_path, form_id) ⇒ Object (private)



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb', line 235

def upload_to_vbms(pdf_path, form_id)
  upload_data = (pdf_path, form_id)
  document_data = create_document_data(evss_claim_id, upload_data)

  raise Common::Exceptions::ValidationErrors, document_data unless document_data.valid?

  # thin wrapper to isolate upload for logging
  file_body = File.open(pdf_path).read
  perform_client_upload(file_body, document_data, form_id)
ensure
  # Delete the temporary PDF file
  File.delete(pdf_path) if pdf_path.present?
end