Skip to content

Commit

Permalink
REjiggering (#11687)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesoskin authored Feb 1, 2023
1 parent 89d071c commit af5c134
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions lib/sidekiq/form526_backup_submission_process/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Sidekiq
module Form526BackupSubmissionProcess
class Processor
attr_reader :submission, :lighthouse_service, :zip, :initial_upload_location, :initial_upload_uuid,
:initial_upload, :docs_gathered
:initial_upload, :docs_gathered, :initial_upload_fetched, :ignore_expiration
attr_accessor :docs

FORM_526 = 'form526'
Expand Down Expand Up @@ -49,18 +49,18 @@ class Processor

# Takes a submission id, assembles all needed docs from its payload, then sends it to central mail via
# lighthouse benefits intake API - https://developer.va.gov/explore/benefits/docs/benefits?version=current
def initialize(submission_id, docs = [])
def initialize(submission_id, docs = [], get_upload_location_on_instantiation: true, ignore_expiration: false)
@submission = Form526Submission.find(submission_id)
@docs = docs
@docs_gathered = false
@initial_upload_fetched = false
@lighthouse_service = Form526BackupSubmission::Service.new
@ignore_expiration = ignore_expiration
# We need an initial location/uuid as other ancillary docs want a reference id to it
# (eventhough I dont think they actually use it for anything because we are just using them to
# generate the pdf and not the sending portion of those classes... but it needs something there to not error)
@initial_upload = get_upload_info
uuid_and_location = upload_location_to_location_and_uuid(initial_upload)
@initial_upload_uuid = uuid_and_location[:uuid]
@initial_upload_location = uuid_and_location[:location]
instantiate_upload_info_from_lighthouse if get_upload_location_on_instantiation

determine_zip
end

Expand Down Expand Up @@ -104,6 +104,14 @@ def upload_pdf_submission_to_s3(return_url: false, url_life_length: 1.week.to_i)

private

def instantiate_upload_info_from_lighthouse
@initial_upload = get_upload_info
uuid_and_location = upload_location_to_location_and_uuid(initial_upload)
@initial_upload_uuid = uuid_and_location[:uuid]
@initial_upload_location = uuid_and_location[:location]
@initial_upload_fetched = true
end

def evidence_526_split
is_526_or_evidence = docs.group_by do |doc|
doc[:type] == FORM_526_DOC_TYPE || doc[:type] == FORM_526_UPLOADS_DOC_TYPE
Expand Down Expand Up @@ -191,6 +199,7 @@ def get_meta_data(doc_type)
end

def send_to_central_mail_through_lighthouse_claims_intake_api!
instantiate_upload_info_from_lighthouse unless @initial_upload_fetched
initial_payload, other_payloads = evidence_526_split
if SUB_METHOD == :single
submit_as_one(initial_payload, other_payloads)
Expand Down Expand Up @@ -315,6 +324,7 @@ def get_form526_pdf
submission_create_date = submission.created_at.iso8601
form_json = JSON.parse(submission.form_json)[FORM_526]
form_json[FORM_526]['claimDate'] ||= submission_create_date
form_json[FORM_526]['applicationExpirationDate'] = 365.days.from_now.iso8601 if @ignore_expiration
resp = EVSS::DisabilityCompensationForm::Service.new(headers).get_form526(form_json.to_json)
b64_enc_body = resp.body['pdf']
content = Base64.decode64(b64_enc_body)
Expand Down
3 changes: 2 additions & 1 deletion lib/sidekiq/form526_backup_submission_process/submit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Form526BackgroundLoader
sidekiq_options retry: 0

def perform(id)
Processor.new(id).upload_pdf_submission_to_s3
Processor.new(id, get_upload_location_on_instantiation: false,
ignore_expiration: true).upload_pdf_submission_to_s3
end
end

Expand Down

0 comments on commit af5c134

Please sign in to comment.