-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* RES Library file copied from VRE and updated * Update to use proper api access * Update key names * Update codeowners, slight fixes, empty spec * Codeowners change * Split regional office * Actually use new service * Final fixes * Ignore spec for now * Fix rubocop lint * More failed tests * Fix lint * Fix specs * Fix lints * move params * remove process attachments * Update receivedDate value and stationId field * Use flipper for res v vre submission * Update code and add specs for flipper * lint * Remove sentry logging, readd lighthouse submission * Rename central mail method to refer lighthouse * Fix message * Remove checks for sentry logging * Fix spec * change logger method syntax, rename boolean * Reupdate logger message * other logger messages
- Loading branch information
Showing
13 changed files
with
400 additions
and
112 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -74,7 +75,7 @@ class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim | |
}.freeze | ||
|
||
def initialize(args) | ||
@sent_to_cmp = false | ||
@sent_to_lighthouse = false | ||
super | ||
end | ||
|
||
|
@@ -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( | ||
|
@@ -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 | ||
|
@@ -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( | ||
|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.