Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBX-82245] implement LH getPDF for 526 backup path #16876

Merged
merged 39 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1921f39
[DBX-82245] implement LH getPDF for 526 backup path
SamStuckey May 24, 2024
b44f041
add spec
SamStuckey Jun 5, 2024
307566e
general save
SamStuckey Jun 6, 2024
0a4a6b8
add TREX debug to gitignore
SamStuckey Jun 6, 2024
87f89eb
general save
SamStuckey Jun 6, 2024
3927c2b
creating broken pdf successfully?
SamStuckey Jun 6, 2024
8f62466
general save
SamStuckey Jun 6, 2024
b4199cc
Notate for handoff
SamStuckey Jun 10, 2024
62d2d9d
removing flipper and refactoring to support both providers
tblackwe Jun 12, 2024
02a43bc
improved conditional
tblackwe Jun 12, 2024
7718ab8
remove accidental schema changes
SamStuckey Jun 12, 2024
a4441a4
cleanup
tblackwe Jun 12, 2024
bf91385
removing wip comment
tblackwe Jun 12, 2024
74d1b1f
do you want to know the worst thing about infinite loops?
tblackwe Jun 12, 2024
1cd3bca
whitespace
tblackwe Jun 12, 2024
6874803
Merge branch 'master' into dbx-82245/implement-backup-submission-lh-a…
tblackwe Jun 12, 2024
22b887c
rubocop mad
tblackwe Jun 12, 2024
3f78fc9
[DBX-82245] implement LH getPDF for 526 backup path
SamStuckey May 24, 2024
db4a642
add spec
SamStuckey Jun 5, 2024
c9a0f66
general save
SamStuckey Jun 6, 2024
44ec8c5
add TREX debug to gitignore
SamStuckey Jun 6, 2024
2bc523e
general save
SamStuckey Jun 6, 2024
1168604
creating broken pdf successfully?
SamStuckey Jun 6, 2024
ad2dcb9
general save
SamStuckey Jun 6, 2024
7eb38e7
Notate for handoff
SamStuckey Jun 10, 2024
99bc364
removing flipper and refactoring to support both providers
tblackwe Jun 12, 2024
8ff8c3a
improved conditional
tblackwe Jun 12, 2024
611c6d6
remove accidental schema changes
SamStuckey Jun 12, 2024
43d11db
cleanup
tblackwe Jun 12, 2024
ef19cc1
removing wip comment
tblackwe Jun 12, 2024
fb0c816
do you want to know the worst thing about infinite loops?
tblackwe Jun 12, 2024
cdabb04
whitespace
tblackwe Jun 12, 2024
8098340
rubocop mad
tblackwe Jun 12, 2024
ef99475
Merge branch 'dbx-82245/implement-backup-submission-lh-api-factory' o…
tblackwe Jun 12, 2024
1f15692
fixing gemlock
tblackwe Jun 12, 2024
b0eff5f
rubocop less mad
tblackwe Jun 12, 2024
da522e3
some changes from review
tblackwe Jun 13, 2024
560bc3c
fixed test
tblackwe Jun 13, 2024
a727b5c
Merge branch 'master' into dbx-82245/implement-backup-submission-lh-a…
tblackwe Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ clamav_tmp/*

# Ignore development setup (native, docker, hybrid)
.developer-setup

# ignore DBEX LH migration debug tools
lib/TREX
staging.benefits_claims.pem
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def generate_pdf_service_provider
# for instance, in the backup process
EvssGeneratePdfProvider.new(@options[:auth_headers], breakered: @options[:breakered])
when API_PROVIDER[:lighthouse]
LighthouseGeneratePdfProvider.new({})
LighthouseGeneratePdfProvider.new(@current_user[:icn])
else
raise NotImplementedError, 'No known Generate Pdf Api Provider type provided'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
require 'disability_compensation/providers/generate_pdf/generate_pdf_provider'

class LighthouseGeneratePdfProvider
include GeneratePdfProvider
def initialize(icn)
@icn = icn
end

def generate_526_pdf(form_content)
body = transform_service.transform(JSON.parse(form_content))
service.submit526(body, nil, nil, { generate_pdf: true })
end

def initialize(_auth_headers)
# TODO: Implement in Ticket#
def transform_service
@transform_service ||= EVSS::DisabilityCompensationForm::Form526ToLighthouseTransform.new
end

def generate_526_pdf(_form_content)
# TODO: Implement in Ticket#
def service
@service ||= BenefitsClaims::Service.new(@icn)
end
end
58 changes: 33 additions & 25 deletions lib/sidekiq/form526_backup_submission_process/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Processor
def initialize(submission_id, docs = [], get_upload_location_on_instantiation: true, ignore_expiration: false)
@submission_id = submission_id
@submission = Form526Submission.find(submission_id)
@user_account = UserAccount.find_by(id: submission.user_uuid) ||
Account.lookup_by_user_uuid(submission.user_uuid)
@docs = docs
@docs_gathered = false
@initial_upload_fetched = false
Expand Down Expand Up @@ -120,8 +122,6 @@ def upload_pdf_submission_to_s3(return_url: false, url_life_length: 1.week.to_i)
generate_zip_and_upload(params_docs, zipname, metadata, return_url, url_life_length)
end

private

def instantiate_upload_info_from_lighthouse
initial_upload = @lighthouse_service.get_location_and_uuid
@initial_upload_uuid = initial_upload[:uuid]
Expand Down Expand Up @@ -303,8 +303,6 @@ def submit_ancillary_payloads(docs)
end

def determine_zip
# TODO: Figure out if I need to use currentMailingAddress or changeOfAddress zip?
# TODO: I dont think it matters too much though
z = submission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress')
if z.nil? || z['country']&.downcase != 'usa'
@zip = '00000'
Expand All @@ -328,22 +326,26 @@ def write_to_tmp_file(content, ext = 'pdf')
def get_form526_pdf
headers = submission.auth_headers
submission_create_date = submission.created_at.iso8601
form_json = JSON.parse(submission.form_json)[FORM_526]
form_json = submission.form[FORM_526]
form_json[FORM_526]['claimDate'] ||= submission_create_date
form_json[FORM_526]['applicationExpirationDate'] = 365.days.from_now.iso8601 if @ignore_expiration
resp = get_form_from_external_api(headers, form_json.to_json)
b64_enc_body = resp.body['pdf']
content = Base64.decode64(b64_enc_body)

if submission.claims_api?
resp = get_form_from_external_api(headers, ApiProviderFactory::API_PROVIDER[:lighthouse], form_json.to_json)
content = resp.env.response_body
else
resp = get_form_from_external_api(headers, ApiProviderFactory::API_PROVIDER[:evss], form_json.to_json)
b64_enc_body = resp.body['pdf']
content = Base64.decode64(b64_enc_body)
end
file = write_to_tmp_file(content)
docs << {
type: FORM_526_DOC_TYPE,
file:
}
docs << { type: FORM_526_DOC_TYPE, file: }
end

def get_form_from_external_api(headers, form_json)
# 82245 - Adding provider to method. this should be removed when toxic exposure flipper is removed
def get_form_from_external_api(headers, provider, form_json)
# get the "breakered" version
service = choose_provider(headers, breakered: true)
service = choose_provider(headers, provider, breakered: true)

service.generate_526_pdf(form_json)
end
Expand Down Expand Up @@ -408,7 +410,6 @@ def convert_docs_to_pdf
'Complete 526 PDF Generating for Backup Submission',
{ submission_id:, initial_upload_uuid: }
)

result
end

Expand All @@ -428,14 +429,14 @@ def convert_doc_to_pdf(doc, klass)
end
end

def choose_provider(headers, breakered: true)
# 82245 - Adding provider to method. this should be removed when toxic exposure flipper is removed
def choose_provider(headers, provider, breakered: true)
SamStuckey marked this conversation as resolved.
Show resolved Hide resolved
ApiProviderFactory.call(
type: ApiProviderFactory::FACTORIES[:generate_pdf],
# let Flipper - the feature toggle - choose which provider
provider: nil,
provider:,
# this sends the auth headers and if we want the "breakered" or "non-breakered" version
options: { auth_headers: headers, breakered: },
current_user: OpenStruct.new({ flipper_id: submission.user_uuid }),
current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: @user_account.icn }),
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF
)
end
Expand All @@ -445,12 +446,18 @@ class NonBreakeredProcessor < Processor
def get_form526_pdf
headers = submission.auth_headers
submission_create_date = submission.created_at.iso8601
form_json = JSON.parse(submission.form_json)[FORM_526]
form_json = submission.form[FORM_526]
form_json[FORM_526]['claimDate'] ||= submission_create_date
form_json[FORM_526]['applicationExpirationDate'] = 365.days.from_now.iso8601 if @ignore_expiration
resp = get_from_non_breakered_service(headers, form_json.to_json)
b64_enc_body = resp.body['pdf']
content = Base64.decode64(b64_enc_body)
if submission.claims_api?
resp = get_from_non_breakered_service(headers, ApiProviderFactory::API_PROVIDER[:lighthouse],
form_json.to_json)
content = resp.env.response_body
else
resp = get_from_non_breakered_service(headers, ApiProviderFactory::API_PROVIDER[:evss], form_json.to_json)
b64_enc_body = resp.body['pdf']
content = Base64.decode64(b64_enc_body)
end
file = write_to_tmp_file(content)
docs << {
type: FORM_526_DOC_TYPE,
Expand All @@ -459,9 +466,10 @@ def get_form526_pdf
end
end

def get_from_non_breakered_service(headers, form_json)
# 82245 - Adding provider to method. this should be removed when toxic exposure flipper is removed
def get_from_non_breakered_service(headers, provider, form_json)
# get the "non-breakered" version
service = choose_provider(headers, breakered: false)
service = choose_provider(headers, provider, breakered: false)

service.get_form526(form_json)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,26 @@
end
end
end

describe '#choose_provider' do
let(:account) { create(:account) }
let(:submission) { create(:form526_submission, user_uuid: account.idme_uuid, submit_endpoint: 'claims_api') }

it 'delegates to the ApiProviderFactory with the correct data' do
auth_headers = {}
expect(ApiProviderFactory).to receive(:call).with(
{
type: ApiProviderFactory::FACTORIES[:generate_pdf],
provider: ApiProviderFactory::API_PROVIDER[:lighthouse],
options: { auth_headers:, breakered: true },
current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: account.icn }),
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_GENERATE_PDF
}
)

subject
.new(submission.id, get_upload_location_on_instantiation: false)
.choose_provider(auth_headers, ApiProviderFactory::API_PROVIDER[:lighthouse])
end
end
end
Loading