Class: LighthouseSupplementalDocumentUploadProvider
- Inherits:
-
Object
- Object
- LighthouseSupplementalDocumentUploadProvider
- Includes:
- SupplementalDocumentUploadProvider
- Defined in:
- lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb
Constant Summary collapse
- STATSD_PROVIDER_METRIC =
'lighthouse_supplemental_document_upload_provider'
- POLLING_DOCUMENT_TYPES =
Maps VA’s internal Document Types to the correct document_type attribute for a Lighthouse526DocumentUpload polling record. We need this to create a valid polling record
{ 'L023' => Lighthouse526DocumentUpload::BDD_INSTRUCTIONS_DOCUMENT_TYPE, 'L228' => Lighthouse526DocumentUpload::FORM_0781_DOCUMENT_TYPE, 'L229' => Lighthouse526DocumentUpload::FORM_0781A_DOCUMENT_TYPE }.freeze
Constants included from SupplementalDocumentUploadProvider
SupplementalDocumentUploadProvider::STASTD_UPLOAD_JOB_FAILED_METRIC, SupplementalDocumentUploadProvider::STATSD_ATTEMPT_METRIC, SupplementalDocumentUploadProvider::STATSD_FAILED_METRIC, SupplementalDocumentUploadProvider::STATSD_SUCCESS_METRIC
Instance Method Summary collapse
- #base_logging_info ⇒ Object private
-
#create_lighthouse_polling_record(lighthouse_document_request_id) ⇒ Object
private
Creates a Lighthouse526DocumentUpload polling record.
- #form_attachment_params ⇒ Object private
-
#generate_upload_document(file_name) ⇒ LighthouseDocument
Uploads to Lighthouse require both the file body and an instance of LighthouseDocument, so we have to generate and validate that first.
-
#handle_lighthouse_response(api_response) ⇒ Object
private
Processes the response from Lighthouse and logs accordingly.
-
#initialize(form526_submission, va_document_type, statsd_metric_prefix, supporting_evidence_attachment = nil) ⇒ LighthouseSupplementalDocumentUploadProvider
constructor
the document attachment itself.
- #lighthouse_success_response?(response_body) ⇒ Boolean private
- #log_upload_attempt ⇒ Object private
- #log_upload_failure(exception) ⇒ Object private
- #log_upload_success(lighthouse_document_request_id) ⇒ Object private
-
#log_uploading_job_failure(uploading_job_class, error_class, error_message) ⇒ Object
To call in the sidekiq_retries_exhausted block of the including job for DataDog monitoring.
-
#polling_record_document_type ⇒ string from Lighthouse526DocumentUpload::VALID_DOCUMENT_TYPES
private
Lighthouse526DocumentUpload polling records are marked and logged according to the type of document uploaded (e.g. “Veteran Upload”, “BDD Instructions”).
-
#submit_upload_document(lighthouse_document, file_body) ⇒ Object
Uploads the supplied file to the Lighthouse Benefits Documents API.
-
#validate_upload_document(lighthouse_document) ⇒ boolean
Takes the necessary validation steps to ensure the document metadata is sufficient for submission to Lighthouse.
Methods included from SupplementalDocumentUploadProvider
generate_upload_document, log_upload_failure, log_upload_success, raise_not_implemented_error, submit_upload_document, validate_upload_document
Constructor Details
#initialize(form526_submission, va_document_type, statsd_metric_prefix, supporting_evidence_attachment = nil) ⇒ LighthouseSupplementalDocumentUploadProvider
the document attachment itself. Required to create the Lighthouse526DocumentUpload polling record for these uploads
24 25 26 27 28 29 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 24 def initialize(form526_submission, va_document_type, statsd_metric_prefix, = nil) @form526_submission = form526_submission @va_document_type = va_document_type @statsd_metric_prefix = statsd_metric_prefix @supporting_evidence_attachment = end |
Instance Method Details
#base_logging_info ⇒ Object (private)
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 96 def base_logging_info { class: 'LighthouseSupplementalDocumentUploadProvider', submitted_claim_id: @form526_submission.submitted_claim_id, submission_id: @form526_submission.id, user_uuid: @form526_submission.user_uuid, va_document_type_code: @va_document_type, primary_form: 'Form526' } end |
#create_lighthouse_polling_record(lighthouse_document_request_id) ⇒ Object (private)
Creates a Lighthouse526DocumentUpload polling record
in the API response for polling later
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 157 def create_lighthouse_polling_record(lighthouse_document_request_id) Lighthouse526DocumentUpload.create!( form526_submission: @form526_submission, document_type: polling_record_document_type, lighthouse_document_request_id: lighthouse_document_request_id, # The Lighthouse526DocumentUpload form_attachment association is # required for uploads of type Lighthouse526DocumentUpload::VETERAN_UPLOAD_DOCUMENT_TYPE ** ) end |
#form_attachment_params ⇒ Object (private)
168 169 170 171 172 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 168 def return {} unless @supporting_evidence_attachment { form_attachment: @supporting_evidence_attachment } end |
#generate_upload_document(file_name) ⇒ LighthouseDocument
Uploads to Lighthouse require both the file body and an instance of LighthouseDocument, so we have to generate and validate that first. Note the LighthouseDocument class name is a misnomer; it is more accurately described as an assembly of file-related Lighthouse metadata, not the actual uploaded file itself
39 40 41 42 43 44 45 46 47 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 39 def generate_upload_document(file_name) LighthouseDocument.new( claim_id: @form526_submission.submitted_claim_id, # Participant ID is persisted on the submission record participant_id: @form526_submission.auth_headers['va_eauth_pid'], document_type: @va_document_type, file_name: ) end |
#handle_lighthouse_response(api_response) ⇒ Object (private)
Processes the response from Lighthouse and logs accordingly. If the upload is successful, creates a polling record so we can check on the status of the document after Lighthouse has receieved it
140 141 142 143 144 145 146 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 140 def handle_lighthouse_response(api_response) response_body = api_response.body lighthouse_document_request_id = response_body['data']['requestId'] create_lighthouse_polling_record(lighthouse_document_request_id) log_upload_success(lighthouse_document_request_id) end |
#lighthouse_success_response?(response_body) ⇒ Boolean (private)
149 150 151 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 149 def lighthouse_success_response?(response_body) !response_body['errors'] && response_body.dig('data', 'success') && response_body.dig('data', 'requestId') end |
#log_upload_attempt ⇒ Object (private)
107 108 109 110 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 107 def log_upload_attempt Rails.logger.info('LighthouseSupplementalDocumentUploadProvider upload attempted', base_logging_info) StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_ATTEMPT_METRIC}") end |
#log_upload_failure(exception) ⇒ Object (private)
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 124 def log_upload_failure(exception) Rails.logger.error( 'LighthouseSupplementalDocumentUploadProvider upload failed', { **base_logging_info, error_info: exception.errors } ) StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_FAILED_METRIC}") end |
#log_upload_success(lighthouse_document_request_id) ⇒ Object (private)
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 112 def log_upload_success(lighthouse_document_request_id) Rails.logger.info( 'LighthouseSupplementalDocumentUploadProvider upload successful', { **base_logging_info, lighthouse_document_request_id: } ) StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_SUCCESS_METRIC}") end |
#log_uploading_job_failure(uploading_job_class, error_class, error_message) ⇒ Object
To call in the sidekiq_retries_exhausted block of the including job for DataDog monitoring
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 80 def log_uploading_job_failure(uploading_job_class, error_class, ) Rails.logger.error( "#{uploading_job_class} LighthouseSupplementalDocumentUploadProvider Failure", { **base_logging_info, uploading_job_class:, error_class:, error_message: } ) StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STASTD_UPLOAD_JOB_FAILED_METRIC}") end |
#polling_record_document_type ⇒ string from Lighthouse526DocumentUpload::VALID_DOCUMENT_TYPES (private)
Lighthouse526DocumentUpload polling records are marked and logged according to the type of document uploaded (e.g. “Veteran Upload”, “BDD Instructions”). This is separate from the internal VA document code (passed to this service as @va_document_type)
179 180 181 182 183 184 185 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 179 def polling_record_document_type # Set to Veteran Upload regardless of @va_document_type if @supporting_evidence_attachment is present # Veteran-uploaded documents can be numerous VA document types return Lighthouse526DocumentUpload::VETERAN_UPLOAD_DOCUMENT_TYPE if @supporting_evidence_attachment POLLING_DOCUMENT_TYPES[@va_document_type] end |
#submit_upload_document(lighthouse_document, file_body) ⇒ Object
Uploads the supplied file to the Lighthouse Benefits Documents API
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 62 def submit_upload_document(lighthouse_document, file_body) log_upload_attempt begin api_response = BenefitsDocuments::Form526::UploadSupplementalDocumentService.call(file_body, lighthouse_document) rescue => e log_upload_failure(e) raise e end handle_lighthouse_response(api_response) end |
#validate_upload_document(lighthouse_document) ⇒ boolean
Takes the necessary validation steps to ensure the document metadata is sufficient for submission to Lighthouse
54 55 56 |
# File 'lib/disability_compensation/providers/document_upload/lighthouse_supplemental_document_upload_provider.rb', line 54 def validate_upload_document(lighthouse_document) lighthouse_document.valid? end |