Skip to content

Commit

Permalink
clean up metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
SamStuckey committed Apr 24, 2024
1 parent a6a72a9 commit 044e608
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/sidekiq/central_mail/submit_form4142_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job
LIGHTHOUSE_STATSD_KEY_PREFIX = 'worker.lighthouse.submit_form4142'

class BenefitsIntake4142Error < StandardError; end
class VeteranCountryNotDefined < StandardError; end

sidekiq_retries_exhausted do |msg, _ex|
job_id = msg['jid']
Expand Down Expand Up @@ -124,16 +125,45 @@ def upload_to_central_mail

def upload_to_lighthouse
@lighthouse_service = BenefitsIntakeService::Service.new(with_upload_location: true)

payload = {
upload_url: @lighthouse_service.location,
file: { file: @pdf_path, file_name: @pdf_path.split('/').last },
metadata: generate_metadata.to_json,
attachments: [] # wipn8923 is this better than nil?
attachments: [] # [ wipn8923 ] TODO: is this better than nil?
}

@lighthouse_service.upload_doc(**payload)
end

def generate_metadata
vet_name = submission.full_name
filenumber = submission.auth_headers['va_eauth_birlsfilenumber']

metadata = {
'veteranFirstName' => vet_name[:first],
'veteranLastName' => vet_name[:last],
'zipCode' => determine_zip,
'source' => "Form526Submission va.gov",

Check failure on line 147 in app/sidekiq/central_mail/submit_form4142_job.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
'docType' => '4142',
'businessLine' => '',
'fileNumber' => filenumber # wipn8923 TODO: validate that this is correct
}

SimpleFormsApiSubmission::MetadataValidator
.validate(metadata, zip_code_is_us_based: usa_based?)
end

def usa_based?
country = (

Check failure on line 158 in app/sidekiq/central_mail/submit_form4142_job.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/RedundantParentheses: Don't use parentheses around a logical expression.
subission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress', 'country') ||
subission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'country')
)
raise VeteranCountryNotDefined if country.blank?

%w[USA US].include?(country.upcase)
end

# 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
Expand Down

0 comments on commit 044e608

Please sign in to comment.