Class: EVSSSupplementalDocumentUploadProvider

Inherits:
Object
  • Object
show all
Includes:
SupplementalDocumentUploadProvider
Defined in:
lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb

Constant Summary collapse

STATSD_PROVIDER_METRIC =
'evss_supplemental_document_upload_provider'

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

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) ⇒ EVSSSupplementalDocumentUploadProvider

the document attachment itself.

Parameters:

  • form526_submission (Form526Submission)
  • va_document_type (String)

    VA document code; see LighthouseDocument::DOCUMENT_TYPES

  • statsd_metric_prefix (String)

    prefix, e.g. ‘worker.evss.submit_form526_bdd_instructions’ from including job

  • supporting_evidence_attachment (SupportingEvidenceAttachment) (defaults to: nil)

    (optional) for Veteran-uploaded documents,



15
16
17
18
19
20
21
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 15

def initialize(form526_submission, va_document_type, statsd_metric_prefix, supporting_evidence_attachment = nil)
  @form526_submission = form526_submission
  @va_document_type = va_document_type
  @statsd_metric_prefix = statsd_metric_prefix
  # Unused for EVSS uploads:
  @supporting_evidence_attachment = supporting_evidence_attachment
end

Instance Method Details

#base_logging_infoObject (private)



92
93
94
95
96
97
98
99
100
101
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 92

def base_logging_info
  {
    class: 'EVSSSupplementalDocumentUploadProvider',
    submitted_claim_id: @form526_submission.,
    submission_id: @form526_submission.id,
    user_uuid: @form526_submission.user_uuid,
    va_document_type_code: @va_document_type,
    primary_form: 'Form526'
  }
end

#generate_upload_document(file_name) ⇒ EVSSClaimDocument

Uploads to EVSS via the EVSS::DocumentsService require both the file body and an instance of EVSSClaimDocument, so we have to generate and validate that first. Note the EVSSClaimDocument class name is a misnomer; it is more accurately described as an assembly of file-related EVSS metadata, not the actual uploaded file itself

Parameters:

  • file_name (String)

    The name of the file we want to appear in EVSS

Returns:



30
31
32
33
34
35
36
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 30

def generate_upload_document(file_name)
  EVSSClaimDocument.new(
    evss_claim_id: @form526_submission.,
    document_type: @va_document_type,
    file_name:
  )
end

#log_upload_attemptObject (private)



103
104
105
106
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 103

def log_upload_attempt
  Rails.logger.info('EVSSSupplementalDocumentUploadProvider upload attempted', base_logging_info)
  StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_ATTEMPT_METRIC}")
end

#log_upload_failureObject (private)



113
114
115
116
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 113

def log_upload_failure
  Rails.logger.error('EVSSSupplementalDocumentUploadProvider upload failed', base_logging_info)
  StatsD.increment("#{@statsd_metric_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_FAILED_METRIC}")
end

#log_upload_successObject (private)



108
109
110
111
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 108

def log_upload_success
  Rails.logger.info('EVSSSupplementalDocumentUploadProvider upload successful', base_logging_info)
  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 This is meant to log an upload attempt that was retried and eventually given up on, so we can investigate the failure in Datadog

(e.g. UploadBDDInstructions)

Parameters:

  • uploading_job_class (String)

    the job where we are uploading the EVSSClaimDocument

  • error_class (String)

    the Error class of the exception that exhausted the upload job

  • error_message (String)

    the message in the exception that exhausted the upload job



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 76

def log_uploading_job_failure(uploading_job_class, error_class, error_message)
  Rails.logger.error(
    "#{uploading_job_class} EVSSSupplementalDocumentUploadProvider 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

#submit_upload_document(evss_claim_document, file_body) ⇒ Faraday::Response

Initializes and uploads via our EVSS Document Service API wrapper

Parameters:

  • evss_claim_document
  • file_body (String)

Returns:

  • (Faraday::Response)

    The EVSS::DocumentsService API calls are implemented with Faraday



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 53

def submit_upload_document(evss_claim_document, file_body)
  log_upload_attempt

  client = EVSS::DocumentsService.new(@form526_submission.auth_headers)
  client.upload(file_body, evss_claim_document)

  # EVSS::DocumentsService uploads throw a EVSS::ErrorMiddleware::EVSSError if they fail
  # If no exception is raised, log a success response
  log_upload_success
rescue EVSS::ErrorMiddleware::EVSSError => e
  # If exception is raised, log and re-raise the error
  log_upload_failure
  raise e
end

#validate_upload_document(evss_claim_document) ⇒ Object

Takes the necessary validation steps to ensure the document metadata is sufficient for submission to EVSS

Parameters:



43
44
45
# File 'lib/disability_compensation/providers/document_upload/evss_supplemental_document_upload_provider.rb', line 43

def validate_upload_document(evss_claim_document)
  evss_claim_document.valid?
end