-
Notifications
You must be signed in to change notification settings - Fork 66
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
#90355 [10-10 Health Apps] Improve code quality for shared code #20022
base: master
Are you sure you want to change the base?
Changes from 7 commits
eceeff9
7fe7ebf
1c48fca
fd68cdd
92a5f1f
993d293
874539a
03066c6
6f18f95
efb5141
f2a6d59
49c107b
ae3a419
9347b9b
35b9cfb
7d05fde
afe1337
35a5789
8fff4f5
4683176
827217d
19b426f
9efcd0a
761d5f2
d1599d5
ec715c9
c891ec6
daf3fe7
fa9eb40
37e125d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
require 'hca/configuration' | ||
require 'hca/ezr_postfill' | ||
require 'va1010_forms/utils' | ||
require 'va1010_forms/enrollment_system/service' | ||
|
||
module Form1010Ezr | ||
class Service < Common::Client::Base | ||
|
@@ -37,7 +38,13 @@ def submit_async(parsed_form) | |
|
||
def submit_sync(parsed_form) | ||
res = with_monitoring do | ||
es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) | ||
if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) | ||
VA1010Forms::EnrollmentSystem::Service.new( | ||
HealthCareApplication.get_user_identifier(@user) | ||
).submit(parsed_form, FORM_ID) | ||
else | ||
es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) | ||
end | ||
end | ||
|
||
# Log the 'formSubmissionId' for successful submissions | ||
|
@@ -106,11 +113,8 @@ def validate_form(parsed_form) | |
) | ||
end | ||
|
||
log_validation_errors(parsed_form) | ||
log_validation_errors(validation_errors, parsed_form) | ||
|
||
Rails.logger.error( | ||
"10-10EZR form validation failed. Form does not match schema. Error list: #{validation_errors}" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logger was moved into the |
||
raise Common::Exceptions::SchemaValidationErrors, validation_errors | ||
end | ||
end | ||
|
@@ -155,7 +159,7 @@ def configure_and_validate_form(parsed_form) | |
post_fill_fields(parsed_form) | ||
validate_form(parsed_form) | ||
# Due to overriding the JSON form schema, we need to do so after the form has been validated | ||
override_parsed_form(parsed_form) | ||
HCA::OverridesParser.new(parsed_form).override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seemed a bit more logical than calling a method that calls this line of code. |
||
add_financial_flag(parsed_form) | ||
end | ||
|
||
|
@@ -167,9 +171,14 @@ def add_financial_flag(parsed_form) | |
end | ||
end | ||
|
||
def log_validation_errors(parsed_form) | ||
# @param [Hash] errors | ||
def log_validation_errors(errors, parsed_form) | ||
StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.validation_error") | ||
|
||
Rails.logger.error( | ||
"10-10EZR form validation failed. Form does not match schema. Error list: #{errors}" | ||
) | ||
|
||
PersonalInformationLog.create( | ||
data: parsed_form, | ||
error_class: 'Form1010Ezr ValidationError' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -865,18 +865,18 @@ def add_attachment(file, id, is_dd214) | |
end | ||
|
||
# @param [Hash] veteran data in JSON format | ||
# @param [Account] current_user | ||
# @param [Hash] user_identifier | ||
# @param [String] form_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def veteran_to_save_submit_form( | ||
veteran, | ||
current_user, | ||
user_identifier, | ||
form_id | ||
) | ||
return {} if veteran.blank? | ||
|
||
copy_spouse_address!(veteran) | ||
|
||
request = build_form_for_user(current_user, form_id) | ||
request = build_form_for_user(user_identifier, form_id) | ||
|
||
veteran['attachments']&.each_with_index do |attachment, i| | ||
guid = attachment['confirmationCode'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'benchmark' | ||
require 'common/client/base' | ||
require 'hca/configuration' | ||
require 'hca/overrides_parser' | ||
|
||
module VA1010Forms | ||
module EnrollmentSystem | ||
class Service < Common::Client::Base | ||
include ActionView::Helpers::NumberHelper | ||
|
||
configuration HCA::Configuration | ||
|
||
# @param [Hash] user_identifier | ||
# @example { 'icn' => user.icn, 'edipi' => user.edipi } | ||
def initialize(user_identifier = nil) | ||
super() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint was complaining about not having |
||
@user_identifier = user_identifier | ||
end | ||
|
||
def submit(parsed_form, form_id) | ||
formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form( | ||
parsed_form, | ||
@user_identifier, | ||
form_id | ||
) | ||
submission_body = submission_body(formatted) | ||
response = perform(:post, '', submission_body) | ||
|
||
root = response.body.locate('S:Envelope/S:Body/submitFormResponse').first | ||
form_submission_id = root.locate('formSubmissionId').first.text.to_i | ||
|
||
{ | ||
success: true, | ||
formSubmissionId: form_submission_id, | ||
timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s | ||
} | ||
rescue => e | ||
raise e | ||
end | ||
|
||
private | ||
|
||
def soap | ||
# Savon *seems* like it should be setting these things correctly | ||
# from what the docs say. Our WSDL file is weird, maybe? | ||
Savon.client( | ||
wsdl: HCA::Configuration::WSDL, | ||
env_namespace: :soap, | ||
element_form_default: :qualified, | ||
namespaces: { | ||
'xmlns:tns': 'http://va.gov/service/esr/voa/v1' | ||
}, | ||
namespace: 'http://va.gov/schema/esr/voa/v1' | ||
) | ||
end | ||
|
||
def log_payload_info(formatted_form, submission_body) | ||
form_name = formatted_form.dig('va:form', 'va:formIdentifier', 'va:value') | ||
attachments = formatted_form.dig('va:form', 'va:attachments') | ||
attachment_count = attachments&.length || 0 | ||
# Log the attachment sizes in descending order | ||
if attachment_count.positive? | ||
# Convert the attachments into xml format so they resemble what will be sent to VES | ||
attachment_sizes = | ||
attachments.map { |a| a.to_xml.size }.sort.reverse!.map { |size| number_to_human_size(size) }.join(', ') | ||
|
||
Rails.logger.info("Attachment sizes in descending order: #{attachment_sizes}") | ||
end | ||
|
||
Rails.logger.info( | ||
"Payload for submitted #{form_name}: Body size of #{number_to_human_size(submission_body.bytesize)} " \ | ||
"with #{attachment_count} attachment(s)" | ||
) | ||
end | ||
|
||
def submission_body(formatted_form) | ||
content = Gyoku.xml(formatted_form) | ||
submission_body = soap.build_request(:save_submit_form, message: content).body | ||
log_payload_info(formatted_form, submission_body) | ||
|
||
submission_body | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed a bit more logical than calling a method that calls this line of code.