Class: EVSS::DocumentUpload

Inherits:
Object
  • Object
show all
Extended by:
Logging::ThirdPartyTransaction::MethodWrapper, SentryLogging
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/evss/document_upload.rb

Constant Summary collapse

FILENAME_EXTENSION_MATCHER =
/\.\w*$/
OBFUSCATED_CHARACTER_MATCHER =
/[a-zA-Z\d]/
DD_ZSF_TAGS =
['service:claim-status', 'function: evidence upload to EVSS'].freeze
NOTIFY_SETTINGS =
Settings.vanotify.services.benefits_management_tools
MAILER_TEMPLATE_ID =
NOTIFY_SETTINGS.template_id.evidence_submission_failure_email

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SentryLogging

log_exception_to_sentry, log_message_to_sentry, non_nil_hash?, normalize_level, rails_logger, set_sentry_metadata

Methods included from Logging::ThirdPartyTransaction::MethodWrapper

wrap_with_logging

Instance Attribute Details

#auth_headersObject

Returns the value of attribute auth_headers.



20
21
22
# File 'app/sidekiq/evss/document_upload.rb', line 20

def auth_headers
  @auth_headers
end

#document_hashObject

Returns the value of attribute document_hash.



20
21
22
# File 'app/sidekiq/evss/document_upload.rb', line 20

def document_hash
  @document_hash
end

#user_uuidObject

Returns the value of attribute user_uuid.



20
21
22
# File 'app/sidekiq/evss/document_upload.rb', line 20

def user_uuid
  @user_uuid
end

Class Method Details

.format_issue_instant_for_mailers(issue_instant) ⇒ Object



96
97
98
99
100
101
102
# File 'app/sidekiq/evss/document_upload.rb', line 96

def self.format_issue_instant_for_mailers(issue_instant)
  # We want to return all times in EDT
  timestamp = Time.at(issue_instant).in_time_zone('America/New_York')

  # We display dates in mailers in the format "May 1, 2024 3:01 p.m. EDT"
  timestamp.strftime('%B %-d, %Y %-l:%M %P %Z').sub(/([ap])m/, '\1.m.')
end

.notify_clientObject



104
105
106
# File 'app/sidekiq/evss/document_upload.rb', line 104

def self.notify_client
  VaNotify::Service.new(NOTIFY_SETTINGS.api_key)
end

.obscured_filename(original_filename) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/sidekiq/evss/document_upload.rb', line 81

def self.obscured_filename(original_filename)
  extension = original_filename[FILENAME_EXTENSION_MATCHER]
  filename_without_extension = original_filename.gsub(FILENAME_EXTENSION_MATCHER, '')

  if filename_without_extension.length > 5
    # Obfuscate with the letter 'X'; we cannot obfuscate with special characters such as an asterisk,
    # as these filenames appear in VA Notify Mailers and their templating engine uses markdown.
    # Therefore, special characters can be interpreted as markdown and introduce formatting issues in the mailer
    obfuscated_portion = filename_without_extension[3..-3].gsub(OBFUSCATED_CHARACTER_MATCHER, 'X')
    filename_without_extension[0..2] + obfuscated_portion + filename_without_extension[-2..] + extension
  else
    original_filename
  end
end

Instance Method Details

#clean_up!Object (private)



124
125
126
# File 'app/sidekiq/evss/document_upload.rb', line 124

def clean_up!
  uploader.remove!
end

#clientObject (private)



140
141
142
# File 'app/sidekiq/evss/document_upload.rb', line 140

def client
  @client ||= EVSS::DocumentsService.new(auth_headers)
end

#documentObject (private)



136
137
138
# File 'app/sidekiq/evss/document_upload.rb', line 136

def document
  @document ||= EVSSClaimDocument.new(document_hash)
end

#file_bodyObject (private)



144
145
146
# File 'app/sidekiq/evss/document_upload.rb', line 144

def file_body
  @file_body ||= perform_initial_file_read
end

#perform(auth_headers, user_uuid, document_hash) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'app/sidekiq/evss/document_upload.rb', line 70

def perform(auth_headers, user_uuid, document_hash)
  @auth_headers = auth_headers
  @user_uuid = user_uuid
  @document_hash = document_hash

  validate_document!
  pull_file_from_cloud!
  perform_document_upload_to_evss
  clean_up!
end

#perform_document_upload_to_evssObject (private)



119
120
121
122
# File 'app/sidekiq/evss/document_upload.rb', line 119

def perform_document_upload_to_evss
  Rails.logger.info('Begining document upload file to EVSS', filesize: file_body.try(:size))
  client.upload(file_body, document)
end

#perform_initial_file_readObject (private)



128
129
130
# File 'app/sidekiq/evss/document_upload.rb', line 128

def perform_initial_file_read
  uploader.read_for_upload
end

#pull_file_from_cloud!Object (private)



115
116
117
# File 'app/sidekiq/evss/document_upload.rb', line 115

def pull_file_from_cloud!
  uploader.retrieve_from_store!(document.file_name)
end

#uploaderObject (private)



132
133
134
# File 'app/sidekiq/evss/document_upload.rb', line 132

def uploader
  @uploader ||= EVSSClaimDocumentUploader.new(user_uuid, document.uploader_ids)
end

#validate_document!Object (private)



110
111
112
113
# File 'app/sidekiq/evss/document_upload.rb', line 110

def validate_document!
  Sentry.set_tags(source: 'claims-status')
  raise Common::Exceptions::ValidationErrors unless document.valid?
end