Class: Lighthouse::IncomeAndAssetsIntakeJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/lighthouse/income_and_assets_intake_job.rb

Defined Under Namespace

Classes: IncomeAndAssetsIntakeError

Constant Summary collapse

INCOME_AND_ASSETS_SOURCE =
'app/sidekiq/lighthouse/income_and_assets_intake_job.rb'

Instance Method Summary collapse

Instance Method Details

#cleanup_file_pathsObject (private)

Delete temporary stamped PDF files for this instance.



165
166
167
168
169
170
171
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 165

def cleanup_file_paths
  Common::FileHelpers.delete_file_if_exists(@form_path) if @form_path
  @attachment_paths&.each { |p| Common::FileHelpers.delete_file_if_exists(p) }
rescue => e
  @ia_monitor.track_file_cleanup_error(@claim, @intake_service, @user_account_uuid, e)
  raise IncomeAndAssetsIntakeError, e.message
end

#form_submission_pollingObject (private)

Insert submission polling entries



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 144

def form_submission_polling
  form_submission = {
    form_type: @claim.form_id,
    form_data: @claim.to_json,
    saved_claim: @claim,
    saved_claim_id: @claim.id
  }
  form_submission[:user_account] = @user_account unless @user_account_uuid.nil?

  FormSubmissionAttempt.transaction do
    @form_submission = FormSubmission.create(**form_submission)
    @form_submission_attempt = FormSubmissionAttempt.create(form_submission: @form_submission,
                                                            benefits_intake_uuid: @intake_service.uuid)
  end

  Datadog::Tracing.active_trace&.set_tag('benefits_intake_uuid', @intake_service.uuid)
end

#generate_metadataHash (private)

Generate form metadata to send in upload to Benefits Intake API



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 107

def 
  form = @claim.parsed_form

  # also validates/maniuplates the metadata
  BenefitsIntake::Metadata.generate(
    form['veteranFullName']['first'],
    form['veteranFullName']['last'],
    form['vaFileNumber'] || form['veteranSocialSecurityNumber'],
    INCOME_AND_ASSETS_SOURCE,
    @claim.form_id,
    @claim.business_line
  )
end

#init(saved_claim_id, user_account_uuid) ⇒ Object (private)

Instantiate instance variables for this job



68
69
70
71
72
73
74
75
76
77
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 68

def init(saved_claim_id, )
  @ia_monitor = IncomeAndAssets::Submissions::Monitor.new

  @user_account_uuid = 
  @user_account = UserAccount.find(@user_account_uuid) if @user_account_uuid.present?
  @claim = SavedClaim::IncomeAndAssets.find(saved_claim_id)
  raise IncomeAndAssetsIntakeError, "Unable to find SavedClaim::IncomeAndAssets #{saved_claim_id}" unless @claim

  @intake_service = BenefitsIntake::Service.new
end

#perform(saved_claim_id, user_account_uuid = nil) ⇒ UUID

Process income and assets pdfs and upload to Benefits Intake API

Parameters:

  • saved_claim_id (Integer)

    the pension claim id

  • user_account_uuid (UUID) (defaults to: nil)

    the user submitting the form

Returns:

  • (UUID)

    benefits intake upload uuid



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 37

def perform(saved_claim_id,  = nil)
  return unless Flipper.enabled?(:pension_income_and_assets_clarification)

  init(saved_claim_id, )

  # generate and validate claim pdf documents
  @form_path = process_document(@claim.to_pdf)
  @attachment_paths = @claim.persistent_attachments.map { |pa| process_document(pa.to_pdf) }
  @metadata = 

  # upload must be performed within 15 minutes of this request
  upload_document

  # TODO: no confirmation email yet. Uncomment when we have one ready.
  # @claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)
  @ia_monitor.track_submission_success(@claim, @intake_service, @user_account_uuid)

  @intake_service.uuid
rescue => e
  @ia_monitor.track_submission_retry(@claim, @intake_service, @user_account_uuid, e)
  @form_submission_attempt&.fail!
  raise e
ensure
  cleanup_file_paths
end

#process_document(file_path) ⇒ String (private)

Create a temp stamped PDF and validate the PDF satisfies Benefits Intake specification

Parameters:

  • file_path (String)

Returns:

  • (String)

    path to stamped PDF



86
87
88
89
90
91
92
93
94
95
96
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 86

def process_document(file_path)
  document = PDFUtilities::DatestampPdf.new(file_path).run(text: 'VA.GOV', x: 5, y: 5)
  document = PDFUtilities::DatestampPdf.new(document).run(
    text: 'FDC Reviewed - VA.gov Submission',
    x: 429,
    y: 770,
    text_only: true
  )

  @intake_service.valid_document?(document:)
end

#upload_documentObject (private)

Upload generated pdf to Benefits Intake API



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/sidekiq/lighthouse/income_and_assets_intake_job.rb', line 124

def upload_document
  @intake_service.request_upload
  @ia_monitor.track_submission_begun(@claim, @intake_service, @user_account_uuid)
  form_submission_polling

  payload = {
    upload_url: @intake_service.location,
    document: @form_path,
    metadata: @metadata.to_json,
    attachments: @attachment_paths
  }

  @ia_monitor.track_submission_attempted(@claim, @intake_service, @user_account_uuid, payload)
  response = @intake_service.perform_upload(**payload)
  raise IncomeAndAssetsIntakeError, response.to_s unless response.success?
end