Class: CentralMail::SubmitCentralForm686cJob
- Inherits:
-
Object
- Object
- CentralMail::SubmitCentralForm686cJob
show all
- Includes:
- SentryLogging, Sidekiq::Job
- Defined in:
- app/sidekiq/central_mail/submit_central_form686c_job.rb
Defined Under Namespace
Classes: CentralMailResponseError
Constant Summary
collapse
- FOREIGN_POSTALCODE =
'00000'
- FORM_ID =
'686C-674'
Instance Attribute Summary collapse
Instance Method Summary
collapse
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Instance Attribute Details
#attachment_paths ⇒ Object
Returns the value of attribute attachment_paths.
18
19
20
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 18
def attachment_paths
@attachment_paths
end
|
#claim ⇒ Object
Returns the value of attribute claim.
18
19
20
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 18
def claim
@claim
end
|
Returns the value of attribute form_path.
18
19
20
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 18
def form_path
@form_path
end
|
Instance Method Details
#check_success(response, saved_claim_id, user_struct) ⇒ Object
rubocop:disable Metrics/MethodLength #Temporary disable until flipper removed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 85
def check_success(response, saved_claim_id, user_struct)
if Flipper.enabled?(:dependents_central_submission_lighthouse)
if response.success?
Rails.logger.info('CentralMail::SubmitCentralForm686cJob succeeded!',
{ user_uuid: user_struct['uuid'], saved_claim_id:, icn: user_struct['icn'] })
update_submission('success')
send_confirmation_email(OpenStruct.new(user_struct))
else
Rails.logger.info('CentralMail::SubmitCentralForm686cJob Unsuccessful',
{ response: response['message'].presence || response['errors'] })
raise CentralMailResponseError
end
elsif response.success?
Rails.logger.info('CentralMail::SubmitCentralForm686cJob succeeded!',
{ user_uuid: user_struct['uuid'], saved_claim_id:, icn: user_struct['icn'],
centralmail_uuid: (response) })
update_submission('success')
send_confirmation_email(OpenStruct.new(user_struct))
else
Rails.logger.info('CentralMail::SubmitCentralForm686cJob Unsuccessful',
{ response: response.body })
raise CentralMailResponseError
end
end
|
#cleanup_file_paths ⇒ Object
#create_request_body ⇒ Object
rubocop:enable Metrics/MethodLength
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 112
def create_request_body
body = {
'metadata' => generate_metadata.to_json
}
body['document'] = to_faraday_upload(form_path)
i = 0
attachment_paths.each do |file_path|
body["attachment#{i += 1}"] = to_faraday_upload(file_path)
end
body
end
|
22
23
24
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 22
def (data)
data.body[/(?<=\[).*?(?=\])/].split(': ').last if data.body.present?
end
|
189
190
191
192
193
194
195
196
197
198
199
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 189
def generate_attachment_metadata(attachment_paths)
attachment_metadata = {}
i = 0
attachment_paths.each do |file_path|
i += 1
attachment_pdf_metadata = get_hash_and_pages(file_path)
attachment_metadata["ahash#{i}"] = attachment_pdf_metadata[:hash]
attachment_metadata["numberPages#{i}"] = attachment_pdf_metadata[:pages]
end
attachment_metadata
end
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 155
def generate_metadata
form = claim.parsed_form['dependents_application']
form_pdf_metadata = get_hash_and_pages(form_path)
address = form['veteran_contact_information']['veteran_address']
receive_date = claim.created_at.in_time_zone('Central Time (US & Canada)')
metadata = {
'veteranFirstName' => form['veteran_information']['full_name']['first'],
'veteranLastName' => form['veteran_information']['full_name']['last'],
'fileNumber' => form['veteran_information']['file_number'] || form['veteran_information']['ssn'],
'receiveDt' => receive_date.strftime('%Y-%m-%d %H:%M:%S'),
'uuid' => claim.guid,
'zipCode' => address['country_name'] == 'USA' ? address['zip_code'] : FOREIGN_POSTALCODE,
'source' => 'va.gov',
'hashV' => form_pdf_metadata[:hash],
'numberAttachments' => attachment_paths.size,
'docType' => claim.form_id,
'numberPages' => form_pdf_metadata[:pages]
}
metadata.merge(generate_attachment_metadata(attachment_paths))
end
|
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 176
def generate_metadata_lh
form = claim.parsed_form['dependents_application']
address = form['veteran_contact_information']['veteran_address']
{
veteran_first_name: form['veteran_information']['full_name']['first'],
veteran_last_name: form['veteran_information']['full_name']['last'],
file_number: form['veteran_information']['file_number'] || form['veteran_information']['ssn'],
zip: address['country_name'] == 'USA' ? address['zip_code'] : FOREIGN_POSTALCODE,
doc_type: claim.form_id,
claim_date: claim.created_at
}
end
|
#get_files_from_claim ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 69
def get_files_from_claim
form_674_path = process_pdf(claim.to_pdf(form_id: '21-674')) if claim.submittable_674?
form_686c_path = process_pdf(claim.to_pdf(form_id: '686C-674')) if claim.submittable_686?
@form_path = form_686c_path || form_674_path
@attachment_paths = claim.persistent_attachments.map { |pa| process_pdf(pa.to_pdf) }
attachment_paths.insert(0, form_674_path) if form_686c_path.present? && form_674_path.present?
end
|
#get_hash_and_pages(file_path) ⇒ Object
148
149
150
151
152
153
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 148
def get_hash_and_pages(file_path)
{
hash: Digest::SHA256.file(file_path).hexdigest,
pages: PdfInfo::Metadata.read(file_path).pages
}
end
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 26
def perform(saved_claim_id, encrypted_vet_info, encrypted_user_struct)
vet_info = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_vet_info))
user_struct = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_user_struct))
Rails.logger.info('CentralMail::SubmitCentralForm686cJob running!',
{ user_uuid: user_struct['uuid'], saved_claim_id:, icn: user_struct['icn'] })
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)
claim.add_veteran_info(vet_info)
get_files_from_claim
use_lighthouse = Flipper.enabled?(:dependents_central_submission_lighthouse)
result = use_lighthouse ? upload_to_lh : CentralMail::Service.new.upload(create_request_body)
check_success(result, saved_claim_id, user_struct)
rescue => e
Rails.logger.warn('CentralMail::SubmitCentralForm686cJob failed!',
{ user_uuid: user_struct['uuid'], saved_claim_id:, icn: user_struct['icn'], error: e.message })
update_submission('failed')
DependentsApplicationFailureMailer.build(OpenStruct.new(user_struct)).deliver_now if user_struct['email'].present?
raise
ensure
cleanup_file_paths
end
|
#process_pdf(pdf_path) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 138
def process_pdf(pdf_path)
stamped_path1 = CentralMail::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5)
CentralMail::DatestampPdf.new(stamped_path1).run(
text: 'FDC Reviewed - va.gov Submission',
x: 429,
y: 770,
text_only: true
)
end
|
#send_confirmation_email(user) ⇒ Object
201
202
203
204
205
206
207
208
209
210
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 201
def send_confirmation_email(user)
return if user.va_profile_email.blank?
VANotify::ConfirmationEmail.send(
email_address: user.va_profile_email,
template_id: Settings.vanotify.services.va_gov.template_id.form686c_confirmation_email,
first_name: user&.first_name&.upcase,
user_uuid_and_form_id: "#{user.uuid}_#{FORM_ID}"
)
end
|
#to_faraday_upload(file_path) ⇒ Object
131
132
133
134
135
136
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 131
def to_faraday_upload(file_path)
Faraday::UploadIO.new(
file_path,
Mime[:pdf].to_s
)
end
|
#update_submission(state) ⇒ Object
127
128
129
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 127
def update_submission(state)
claim.central_mail_submission.update!(state:) if claim.respond_to?(:central_mail_submission)
end
|
#upload_to_lh ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/sidekiq/central_mail/submit_central_form686c_job.rb', line 52
def upload_to_lh
Rails.logger.info({ message: 'SubmitCentralForm686cJob Lighthouse Initiate Submission Attempt',
claim_id: claim.id })
lighthouse_service = BenefitsIntakeService::Service.new(with_upload_location: true)
uuid = lighthouse_service.uuid
Rails.logger.info({ message: 'SubmitCentralForm686cJob Lighthouse Submission Attempt', claim_id: claim.id,
uuid: })
response = lighthouse_service.upload_form(
main_document: split_file_and_path(form_path),
attachments: attachment_paths.map(&method(:split_file_and_path)),
form_metadata: generate_metadata_lh
)
Rails.logger.info({ message: 'SubmitCentralForm686cJob Lighthouse Submission Successful', claim_id: claim.id,
uuid: })
response
end
|