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

CH 31 Form Send to RES #16363

Merged
merged 31 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6666219
RES Library file copied from VRE and updated
tfink419 Apr 16, 2024
1f6d312
Update to use proper api access
tfink419 Apr 17, 2024
5fa497d
Update key names
tfink419 Apr 24, 2024
84ae59d
Update codeowners, slight fixes, empty spec
tfink419 Apr 24, 2024
233a030
Codeowners change
tfink419 Apr 25, 2024
3f68448
Split regional office
tfink419 May 9, 2024
d8e6acf
Actually use new service
tfink419 May 14, 2024
c48ad0e
Merge branch 'master' into ch31-submission-to-res-65386
tfink419 May 15, 2024
a84e190
Final fixes
tfink419 May 15, 2024
7eb270e
Ignore spec for now
tfink419 May 15, 2024
353a19e
Fix rubocop lint
tfink419 May 15, 2024
c5adb8f
More failed tests
tfink419 May 17, 2024
19abff9
Merge branch 'master' into ch31-submission-to-res-65386
tfink419 May 17, 2024
b46fbd6
Fix lint
tfink419 May 17, 2024
5ab6c1a
Fix specs
tfink419 May 17, 2024
1eb487c
Fix lints
tfink419 May 17, 2024
bd705d5
move params
tfink419 May 20, 2024
2ad49a6
remove process attachments
tfink419 May 22, 2024
879551c
Update receivedDate value and stationId field
tfink419 May 28, 2024
a84a697
Use flipper for res v vre submission
tfink419 May 28, 2024
cac7108
Merge branch 'master' into ch31-submission-to-res-65386
tfink419 May 29, 2024
86b7baa
Update code and add specs for flipper
tfink419 May 29, 2024
f35d6d8
lint
tfink419 May 29, 2024
6208e37
Remove sentry logging, readd lighthouse submission
tfink419 May 29, 2024
86c6d49
Rename central mail method to refer lighthouse
tfink419 May 29, 2024
b3086a1
Fix message
tfink419 May 29, 2024
ccb9d8f
Remove checks for sentry logging
tfink419 May 29, 2024
bc33b02
Fix spec
tfink419 May 29, 2024
d52ea75
change logger method syntax, rename boolean
tfink419 May 30, 2024
5474e8e
Reupdate logger message
tfink419 May 30, 2024
5b142cf
other logger messages
tfink419 May 30, 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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ lib/vetext @department-of-veterans-affairs/mobile-api-team
lib/vic @department-of-veterans-affairs/octo-identity
lib/virtual_regional_office @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/vre @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/res @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/webhooks @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
modules/accredited_representatives @department-of-veterans-affairs/accredited-representation-management
modules/appeals_api @department-of-veterans-affairs/lighthouse-banana-peels @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -1437,6 +1438,7 @@ spec/lib/vbs @department-of-veterans-affairs/vsa-debt-resolution @department-of-
spec/lib/vetext @department-of-veterans-affairs/mobile-api-team
spec/lib/virtual_regional_office @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/vre/ch31_form_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/res/ch31_form_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/webhooks/utilities_spec.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/mailers/ch31_submissions_report_mailer_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/mailers/create_daily_spool_files_mailer_spec.rb @department-of-veterans-affairs/my-education-benefits @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down
108 changes: 70 additions & 38 deletions app/models/saved_claim/veteran_readiness_employment_claim.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'sentry_logging'
require 'res/ch31_form'
require 'vre/ch31_form'

class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim
Expand Down Expand Up @@ -74,7 +75,7 @@ class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim
}.freeze

def initialize(args)
@sent_to_cmp = false
@sent_to_lighthouse = false
super
end

Expand Down Expand Up @@ -107,34 +108,31 @@ def add_office_location(updated_form)
@office_location = regional_office[0]
office_name = regional_office[1]

updated_form['veteranInformation']&.merge!({ 'regionalOffice' => "#{@office_location} - #{office_name}" })
updated_form['veteranInformation']&.merge!({
'regionalOffice' => "#{@office_location} - #{office_name}",
'regionalOfficeName' => office_name,
'stationId' => @office_location
})
end

def send_to_vre(user)
add_claimant_info(user)

if user&.participant_id
begin
upload_to_vbms
send_vbms_confirmation_email(user)
rescue
log_message_to_sentry('Error uploading VRE claim to VBMS. Now attempting to upload claim to central mail...',
:warn, { uuid: user.uuid })
begin
send_to_central_mail!(user)
rescue => e
log_message_to_sentry('Error uploading VRE claim to central mail after failure uploading claim to vbms',
:error, { uuid: user.uuid })
log_exception_to_sentry(e, { uuid: user.uuid })
end
end
upload_to_vbms(user:)
else
log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn)
send_to_central_mail!(user)
Rails.logger.warn('Participant id is blank when submitting VRE claim')
send_to_lighthouse!(user)
end

send_vre_email_form(user)
if Flipper.enabled?(:veteran_readiness_employment_to_res)
send_to_res(user)
else
send_vre_email_form(user)
end
end

def upload_to_vbms(doc_type: '1167')
def upload_to_vbms(user:, doc_type: '1167')
form_path = PdfFill::Filler.fill_form(self, nil, { created_at: })

uploader = ClaimsApi::VBMSUploader.new(
Expand All @@ -144,43 +142,77 @@ def upload_to_vbms(doc_type: '1167')
)

log_to_statsd('vbms') do
uploader.upload!
response = uploader.upload!

if response[:vbms_document_series_ref_id].present?
updated_form = parsed_form
updated_form['documentId'] = response[:vbms_document_series_ref_id]
update!(form: updated_form.to_json)
end
end

send_vbms_confirmation_email(user)
rescue
Rails.logger.error('Error uploading VRE claim to VBMS.', { user_uuid: user.uuid })
send_to_lighthouse!(user)
end

def to_pdf(file_name = nil)
PdfFill::Filler.fill_form(self, file_name, { created_at: })
end

def send_to_central_mail!(user)
def send_to_lighthouse!(user)
form_copy = parsed_form.clone

form_copy['veteranSocialSecurityNumber'] = parsed_form.dig('veteranInformation', 'ssn')
form_copy['veteranFullName'] = parsed_form.dig('veteranInformation', 'fullName')
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!
end

send_central_mail_confirmation_email(user)
process_attachments!
@sent_to_lighthouse = true

send_lighthouse_confirmation_email(user)
rescue => e
Rails.logger.error('Error uploading VRE claim to central mail.', { user_uuid: user.uuid, e: })
end

def send_vre_email_form(user)
@office_location = check_office_location[0] if @office_location.nil?
def send_to_res(user)
email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || '[email protected]'

log_message_to_sentry("VRE claim office location: #{@office_location}",
:info, { uuid: user.uuid })
Rails.logger.info('VRE claim sending to RES service',
{
email: email_addr,
user_uuid: user.uuid,
was_sent: @sent_to_lighthouse,
user_present: user.present?
})

if user.present?
VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr,
@sent_to_lighthouse).deliver_later
end

email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || '[email protected]'
service = RES::Ch31Form.new(user:, claim: self)
service.submit
end

log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}",
:info, { uuid: user.uuid })
def send_vre_email_form(user)
email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || '[email protected]'

VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present?
Rails.logger.info('VRE claim sending to VRE service',
{
email: email_addr,
user_uuid: user.uuid,
was_sent: @sent_to_lighthouse,
user_present: user.present?
})

if user.present?
VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr,
@sent_to_lighthouse).deliver_later
end

# During Roll out our partners ask that we check vet location and if within proximity to specific offices,
# send the data to them. We always send a pdf to VBMS
Expand Down Expand Up @@ -208,7 +240,7 @@ def send_vbms_confirmation_email(user)
)
end

def send_central_mail_confirmation_email(user)
def send_lighthouse_confirmation_email(user)
return if user.va_profile_email.blank?

VANotify::EmailJob.perform_async(
Expand Down Expand Up @@ -248,7 +280,7 @@ def check_office_location
regional_office_response[:regional_office][:name]
]
rescue => e
log_message_to_sentry(e.message, :warn, {}, { team: 'vfs-ebenefits' })
Rails.logger.warn(e.message)
['000', 'Not Found']
end

Expand Down
6 changes: 3 additions & 3 deletions app/sidekiq/vre/submit1900_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Submit1900Job
def perform(claim_id, user_uuid)
claim = SavedClaim::VeteranReadinessEmploymentClaim.find claim_id
user = User.find user_uuid
claim.add_claimant_info(user)
claim.send_to_vre(user)
rescue
Rails.logger.warn('VRE::Submit1900Job failed, retrying...')
rescue => e
Rails.logger.warn("VRE::Submit1900Job failed, retrying...: #{e.message}")
tfink419 marked this conversation as resolved.
Show resolved Hide resolved
raise
end
end
end
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1495,3 +1495,7 @@ features:
toggle_vye_adress_direct_deposit_forms:
actor_type: user
description: Enable mailing address and direct deposit for VYE
veteran_readiness_employment_to_res:
actor_type: user
description: Enable RES platform for Veteran Readiness & Employment form submissions, disabled will use VRE email
enable_in_development: true
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,10 @@ vetext_push:
user: vets-api-username
pass: secret

res:
base_url: ~
api_key: ~

veteran_readiness_and_employment:
base_url: ~
credentials: ~
Expand Down
4 changes: 4 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ vanotify:
claim_submission_timeout_text: oh_fake_timeout_template_id
claim_submission_error_text: oh_fake_error_template_id

res:
base_url: https://fake_url.com
api_key: fake_auth

veteran_readiness_and_employment:
base_url: https://fake_url.com
credentials: fake_auth
Expand Down
135 changes: 135 additions & 0 deletions lib/res/ch31_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# frozen_string_literal: true

require_relative 'service'
require_relative 'errors/ch31_errors'
require 'sentry_logging'

module RES
class Ch31Form < RES::Service
include SentryLogging
configuration RES::Configuration
STATSD_KEY_PREFIX = 'api.res'

def initialize(user:, claim:)
super()
@user = user
@claim = claim
end

# Submits prepared data derived from VeteranReadinessEmploymentClaim#form
#
# @return [Hash] the student's address
#
def submit
if @claim.nil?
Rails.logger.error('Ch31NilClaimError. user icn:', @user.icn)
raise Ch31NilClaimError
end

response = send_to_res(payload: format_payload_for_res)
response_body = response.body

raise Ch31Error if response_body['success_message'].blank?

response_body
rescue Ch31Error => e
process_ch_31_error(e, response_body)

raise
end

private

def format_payload_for_res
form_data = claim_form_hash

res_payload = {
useEva: form_data['useEva'],
receiveElectronicCommunication: form_data['receiveElectronicCommunication'],
useTelecounseling: form_data['useTelecounseling'],
appointmentTimePreferences: form_data['appointmentTimePreferences'],
yearsOfEducation: form_data['yearsOfEducation'],
isMoving: form_data['isMoving'],
mainPhone: form_data['mainPhone'],
cellNumber: form_data['cellPhone'],
internationalNumber: form_data['internationalNumber'],
email: form_data['email'],
documentId: form_data['documentId'],
receivedDate: @claim.created_at.to_date.to_s,
veteranAddress: mapped_address_hash(form_data['veteranAddress'])
}

res_payload.merge!({ veteranInformation: adjusted_veteran_information })
res_payload.merge!(new_address) if form_data['newAddress'].present?

res_payload.to_json
end

# TODO: determine need
def veteran_address(form_data)
vet_address = mapped_address_hash(form_data['veteranAddress'])

adjusted_address = {
veteranAddress: vet_address
}

return adjusted_address if adjusted_address.dig(:veteranAddress, :isForeign) == false

# RES/CMSA expects different keys for postal and state for foreign addresses
# internationPostalCode misspelling is correct
international_address = adjusted_address[:veteranAddress]
international_address[:internationPostalCode] = international_address.delete(:zipCode)
international_address[:province] = international_address.delete(:stateCode)

adjusted_address
end

def claim_form_hash
@claim.parsed_form
end

def adjusted_veteran_information
vet_info = claim_form_hash['veteranInformation']

vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber')
vet_info['regionalOffice'] = vet_info['regionalOfficeName']
vet_info.delete(:regionalOfficeName)

vet_info
end

def new_address
new_address = mapped_address_hash(claim_form_hash['newAddress'])

adjusted_new_address = {
newAddress: new_address
}

return adjusted_new_address unless new_address[:isForeign]

# RES/CMSA expects different keys for postal and state for foreign addresses
new_address[:internationalPostalCode] = new_address.delete(:zipCode)
new_address[:province] = new_address.delete(:stateCode)

adjusted_new_address
end

def mapped_address_hash(client_hash)
{
country: client_hash['country'],
street: client_hash['street'],
city: client_hash['city'],
state: client_hash['state'],
postalCode: client_hash['postalCode']
}
end

def process_ch_31_error(e, response_body)
Rails.logger.error(e)
Rails.logger.error({
intake_id: response_body['ApplicationIntake'],
error_message: response_body['ErrorMessage']
})
end
end
end
Loading
Loading