Skip to content

Commit

Permalink
Merge branch 'master' into 76083-vpg-appointment-slots
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-mccurdy authored Mar 25, 2024
2 parents 5540135 + 02ff64f commit 893533c
Show file tree
Hide file tree
Showing 53 changed files with 1,080 additions and 459 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ end

group :test do
gem 'apivore', git: 'https://github.com/department-of-veterans-affairs/apivore', tag: 'v2.0.0.vsp'
gem 'mock_redis'
gem 'fakeredis'
gem 'pdf-inspector'
gem 'rspec_junit_formatter'
gem 'rspec-retry'
Expand Down Expand Up @@ -215,7 +215,7 @@ group :development, :test do
gem 'rubocop-rails'
gem 'rubocop-rspec'
gem 'rubocop-thread_safety'
gem 'sidekiq', '~> 7.2.0'
gem 'sidekiq', '>= 6.4.0'
gem 'timecop'
gem 'webmock'
gem 'yard'
Expand Down
40 changes: 18 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,12 @@ PATH
GEM
remote: https://enterprise.contribsys.com/
specs:
sidekiq-ent (7.2.2)
einhorn (~> 1.0)
gserver
sidekiq (>= 7.2.0, < 8)
sidekiq-pro (>= 7.2.0, < 8)
sidekiq-pro (7.2.0)
sidekiq (>= 7.2.0, < 8)
sidekiq-ent (2.5.3)
einhorn (>= 0.7.4)
sidekiq (>= 6.5.0, < 7)
sidekiq-pro (>= 5.5.0, < 6)
sidekiq-pro (5.5.8)
sidekiq (~> 6.0, >= 6.5.6)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -283,7 +282,7 @@ GEM
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
carrierwave (3.0.6)
carrierwave (3.0.7)
activemodel (>= 6.0.0)
activesupport (>= 6.0.0)
addressable (~> 2.6)
Expand Down Expand Up @@ -418,6 +417,8 @@ GEM
railties (>= 5.0.0)
faker (3.2.3)
i18n (>= 1.8.11, < 2)
fakeredis (0.9.2)
redis (~> 4.8)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-follow_redirects (0.3.0)
Expand Down Expand Up @@ -602,7 +603,7 @@ GEM
ffi (~> 1.0)
libddwaf (1.14.0.0.0-x86_64-linux)
ffi (~> 1.0)
liquid (5.4.0)
liquid (5.5.0)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -633,7 +634,6 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.3)
mock_redis (0.44.0)
msgpack (1.7.2)
msgpack (1.7.2-java)
multi_json (1.15.0)
Expand Down Expand Up @@ -689,7 +689,7 @@ GEM
operating_hours (0.1.0)
optimist (3.1.0)
os (1.1.4)
ox (2.14.17)
ox (2.14.18)
parallel (1.24.0)
parallel_tests (4.5.2)
parallel
Expand Down Expand Up @@ -812,10 +812,7 @@ GEM
rchardet (1.8.0)
rdoc (6.6.2)
psych (>= 4.0.0)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-client (0.20.0)
connection_pool
redis (4.8.1)
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.0)
Expand Down Expand Up @@ -957,11 +954,10 @@ GEM
shrine (3.5.0)
content_disposition (~> 1.0)
down (~> 5.1)
sidekiq (7.2.2)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.19.0)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
sidekiq_alive (2.4.0)
gserver (~> 0.0.1)
sidekiq (>= 5, < 8)
Expand Down Expand Up @@ -1126,6 +1122,7 @@ DEPENDENCIES
facilities_api!
factory_bot_rails
faker
fakeredis
faraday (~> 2.9)
faraday-follow_redirects
faraday-httpclient
Expand Down Expand Up @@ -1173,7 +1170,6 @@ DEPENDENCIES
mimemagic
mini_magick
mobile!
mock_redis
mocked_authentication!
my_health!
net-sftp
Expand Down Expand Up @@ -1238,7 +1234,7 @@ DEPENDENCIES
sentry-ruby
shoulda-matchers
shrine
sidekiq (~> 7.2.0)
sidekiq (>= 6.4.0)
sidekiq-ent!
sidekiq-pro!
sidekiq_alive
Expand Down
4 changes: 4 additions & 0 deletions app/models/saved_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def update_form(key, value)
self.form = JSON.generate(application)
end

def business_line
''
end

private

def attachment_keys
Expand Down
4 changes: 4 additions & 0 deletions app/models/saved_claim/burial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ def attachment_keys
def email
parsed_form['claimantEmail']
end

def business_line
'NCA'
end
end
4 changes: 4 additions & 0 deletions app/models/saved_claim/education_career_counseling_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ def process_attachments!

CentralMail::SubmitSavedClaimJob.new.perform(id)
end

def business_line
'EDU'
end
end
23 changes: 15 additions & 8 deletions app/models/saved_claim/veteran_readiness_employment_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ def add_office_location(updated_form)
end

def send_to_vre(user)
if user&.participant_id.blank?
log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn)
send_to_central_mail!(user)
else
if user&.participant_id
begin
upload_to_vbms
send_vbms_confirmation_email(user)
Expand All @@ -129,6 +126,9 @@ def send_to_vre(user)
log_exception_to_sentry(e, { uuid: user.uuid })
end
end
else
log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn)
send_to_central_mail!(user)
end

send_vre_email_form(user)
Expand Down Expand Up @@ -156,11 +156,10 @@ def send_to_central_mail!(user)
form_copy['vaFileNumber'] = parsed_form.dig('veteranInformation', 'VAFileNumber')

update!(form: form_copy.to_json)

log_message_to_sentry(guid, :warn, { attachment_id: guid }, { team: 'vfs-ebenefits' })
@sent_to_cmp = true
log_to_statsd('cmp') do
process_attachments!
process_attachments!(user)
end

send_central_mail_confirmation_email(user)
Expand Down Expand Up @@ -218,12 +217,20 @@ def send_central_mail_confirmation_email(user)
)
end

def process_attachments!
def process_attachments!(user)
refs = attachment_keys.map { |key| Array(open_struct_form.send(key)) }.flatten
files = PersistentAttachment.where(guid: refs.map(&:confirmationCode))
files.find_each { |f| f.update(saved_claim_id: id) }

CentralMail::SubmitSavedClaimJob.new.perform(id)
if Flipper.enabled?(:central_mail_benefits_intake_submission, user)
Lighthouse::SubmitBenefitsIntakeClaim.new.perform(id)
else
CentralMail::SubmitSavedClaimJob.new.perform(id)
end
end

def business_line
'VRE'
end

private
Expand Down
128 changes: 128 additions & 0 deletions app/sidekiq/lighthouse/submit_benefits_intake_claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# frozen_string_literal: true

require 'central_mail/service'
require 'central_mail/datestamp_pdf'
require 'pension_burial/tag_sentry'
require 'benefits_intake_service/service'
require 'simple_forms_api_submission/metadata_validator'
require 'pdf_info'

module Lighthouse
class SubmitBenefitsIntakeClaim
include Sidekiq::Job
include SentryLogging
class BenefitsIntakeClaimError < StandardError; end

FOREIGN_POSTALCODE = '00000'
STATSD_KEY_PREFIX = 'worker.central_mail.submit_benefits_intake_claim'

# Sidekiq has built in exponential back-off functionality for retries
# A max retry attempt of 14 will result in a run time of ~25 hours
RETRY = 14

sidekiq_options retry: RETRY

sidekiq_retries_exhausted do |msg, _ex|
Rails.logger.send(
:error,
"Failed all retries on CentralMail::SubmitBenefitsIntakeClaim, last error: #{msg['error_message']}"
)
StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")
end

# rubocop:disable Metrics/MethodLength
def perform(saved_claim_id)
@claim = SavedClaim.find(saved_claim_id)
@pdf_path = process_record(@claim)
@attachment_paths = @claim.persistent_attachments.map do |record|
process_record(record)
end

@lighthouse_service = BenefitsIntakeService::Service.new(with_upload_location: true)
create_form_submission_attempt(@lighthouse_service.uuid)

payload = {
upload_url: @lighthouse_service.location,
file: split_file_and_path(@pdf_path),
metadata: generate_metadata.to_json,
attachments: @attachment_paths.map(&method(:split_file_and_path))
}

response = @lighthouse_service.upload_doc(**payload)

if response.success?
log_message_to_sentry('CentralMail::SubmitSavedClaimJob succeeded', :info, generate_sentry_details)
@claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)
else
raise BenefitsIntakeClaimError, response.body
end
rescue => e
log_message_to_sentry('CentralMail::SubmitBenefitsIntakeClaim failed, retrying...', :warn,
generate_sentry_details(e))
raise
ensure
cleanup_file_paths
end

# rubocop:enable Metrics/MethodLength
def generate_metadata
form = @claim.parsed_form
veteran_full_name = form['veteranFullName']
address = form['claimantAddress'] || form['veteranAddress']

metadata = {
'veteranFirstName' => veteran_full_name['first'],
'veteranLastName' => veteran_full_name['last'],
'fileNumber' => form['vaFileNumber'] || form['veteranSocialSecurityNumber'],
'zipCode' => address['country'] == 'USA' ? address['postalCode'] : FOREIGN_POSTALCODE,
'source' => "#{@claim.class} va.gov",
'docType' => @claim.form_id,
'businessLine' => @claim.business_line
}

SimpleFormsApiSubmission::MetadataValidator.validate(metadata)
end

def process_record(record)
pdf_path = record.to_pdf
stamped_path = CentralMail::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5)
CentralMail::DatestampPdf.new(stamped_path).run(
text: 'FDC Reviewed - va.gov Submission',
x: 429,
y: 770,
text_only: true
)
end

def split_file_and_path(path)
{ file: path, file_name: path.split('/').last }
end

private

def generate_sentry_details(e = nil)
details = {
'guid' => @claim&.guid,
'docType' => @claim&.form_id,
'savedClaimId' => @saved_claim_id
}
details['error'] = e.message if e
details
end

def create_form_submission_attempt(intake_uuid)
form_submission = FormSubmission.create(
form_type: @claim.form_id,
form_data: @claim.to_json,
benefits_intake_uuid: intake_uuid,
saved_claim: @claim
)
@form_submission_attempt = FormSubmissionAttempt.create(form_submission:)
end

def cleanup_file_paths
Common::FileHelpers.delete_file_if_exists(@pdf_path) if @pdf_path
@attachment_paths&.each { |p| Common::FileHelpers.delete_file_if_exists(p) }
end
end
end
15 changes: 7 additions & 8 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ features:
actor_type: user
description: Enables users to access the claim letters page
enable_in_development: true
cst_use_lighthouse:
actor_type: user
description: When enabled, claims status tool uses the Lighthouse API instead of EVSS
enable_in_development: true
cst_use_lighthouse_5103:
actor_type: user
description: When enabled, claims status tool uses the Lighthouse API for the 5103 endpoint
Expand All @@ -190,10 +186,6 @@ features:
actor_type: user
description: When enabled, the Download Decision Letters feature includes 5103 letters
enable_in_development: true
cst_use_new_claim_cards:
actor_type: user
description: When enabled, claims status tool uses the new claim card designs
enable_in_development: true
cst_use_claim_details_v2:
actor_type: user
description: When enabled, claims status tool uses the new claim details design
Expand Down Expand Up @@ -1128,6 +1120,10 @@ features:
actor_type: user
enable_in_development: true
description: Allows appointment cancellations to be routed to Oracle Health sites.
va_online_scheduling_enable_OH_slots_search:
actor_type: user
enable_in_development: true
description: Toggle for routing slots search requests to the VetsAPI Gateway Service(VPG) instead of vaos-service
va_online_scheduling_datadog_RUM:
actor_type: user
description: Enables datadog Real User Monitoring.
Expand Down Expand Up @@ -1318,6 +1314,9 @@ features:
pension_claim_submission_to_lighthouse:
actor_type: user
description: Pension claim submission uses Lighthouse API
central_mail_benefits_intake_submission:
actor_type: user
description: Enable central mail claims submission uses Benefits Intake API
virtual_agent_enable_param_error_detection:
actor_type: user
description: If enabled, Allows for the detection of errors in the chatbot params
Expand Down
Loading

0 comments on commit 893533c

Please sign in to comment.