Class: BenefitsIntakeService::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- BenefitsIntakeService::Service
- Defined in:
- lib/benefits_intake_service/service.rb
Overview
Proxy Service for the Lighthouse Claims Intake API Service. We are using it here to submit claims that cannot be auto-established, via paper submission (electronic PDF submissiont to CMP)
Direct Known Subclasses
Constant Summary collapse
- REQUIRED_CREATE_HEADERS =
%w[X-VA-First-Name X-VA-Last-Name X-VA-SSN X-VA-Birth-Date].freeze
Instance Attribute Summary collapse
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #generate_metadata(metadata) ⇒ Object
- #generate_tmp_metadata_file(metadata) ⇒ Object
- #get_bulk_status_of_uploads(ids) ⇒ Object
- #get_file_path_from_objs(file) ⇒ Object
-
#get_location_and_uuid ⇒ Object
Instantiates a new location and uuid via lighthouse.
-
#get_upload_docs(file_with_full_path:, metadata:, attachments: []) ⇒ Object
Combines instantiating a new location/uuid and returning the important bits.
- #get_upload_location ⇒ Object
-
#initialize(with_upload_location: false) ⇒ Service
constructor
TODO: Remove param and clean up Form526BackupSubmissionProcess::Processor to use instance vars.
-
#permanent_file?(_file) ⇒ Boolean
Overload in other services to define files not meant to be deleted.
- #upload_deletion_logic(file_with_full_path:, attachments:) ⇒ Object
- #upload_doc(upload_url:, file:, metadata:, attachments: []) ⇒ Object
- #upload_form(main_document:, attachments:, form_metadata:) ⇒ Object
-
#validate_document(doc_path:) ⇒ Object
Validate a file satisfies Benefits Intake specifications.
Methods included from Common::Client::Concerns::Monitoring
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Constructor Details
#initialize(with_upload_location: false) ⇒ Service
TODO: Remove param and clean up Form526BackupSubmissionProcess::Processor to use instance vars
37 38 39 40 41 42 43 44 |
# File 'lib/benefits_intake_service/service.rb', line 37 def initialize(with_upload_location: false) super() if with_upload_location upload_return = get_location_and_uuid @uuid = upload_return[:uuid] @location = upload_return[:location] end end |
Instance Attribute Details
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
23 24 25 |
# File 'lib/benefits_intake_service/service.rb', line 23 def uuid @uuid end |
Instance Method Details
#generate_metadata(metadata) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/benefits_intake_service/service.rb', line 91 def () { veteranFirstName: [:veteran_first_name], veteranLastName: [:veteran_last_name], fileNumber: [:file_number], zipCode: [:zip], source: 'va.gov backup submission', docType: [:doc_type], businessLine: 'CMP', claimDate: [:claim_date] } end |
#generate_tmp_metadata_file(metadata) ⇒ Object
104 105 106 |
# File 'lib/benefits_intake_service/service.rb', line 104 def () Common::FileHelpers.generate_temp_file(.to_s, "#{SecureRandom.hex}.benefits_intake.metadata.json") end |
#get_bulk_status_of_uploads(ids) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/benefits_intake_service/service.rb', line 64 def get_bulk_status_of_uploads(ids) body = { ids: }.to_json response = perform( :post, 'uploads/report', body, { 'Content-Type' => 'application/json', 'accept' => 'application/json' } ) raise response.body unless response.success? response end |
#get_file_path_from_objs(file) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/benefits_intake_service/service.rb', line 78 def get_file_path_from_objs(file) case file when EVSS::DisabilityCompensationForm::Form8940Document file.pdf_path when CarrierWave::SanitizedFile file.file when Hash get_file_path_from_objs(file[:file]) else file end end |
#get_location_and_uuid ⇒ Object
Instantiates a new location and uuid via lighthouse
109 110 111 112 113 114 115 |
# File 'lib/benefits_intake_service/service.rb', line 109 def get_location_and_uuid upload_return = get_upload_location { uuid: upload_return.body.dig('data', 'id'), location: upload_return.body.dig('data', 'attributes', 'location') } end |
#get_upload_docs(file_with_full_path:, metadata:, attachments: []) ⇒ Object
Combines instantiating a new location/uuid and returning the important bits
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/benefits_intake_service/service.rb', line 118 def get_upload_docs(file_with_full_path:, metadata:, attachments: []) json_tmpfile = () file_name = File.basename(file_with_full_path) params = { metadata: Faraday::UploadIO.new(json_tmpfile, Mime[:json].to_s, 'metadata.json'), content: Faraday::UploadIO.new(file_with_full_path, Mime[:pdf].to_s, file_name) } .each.with_index do |, i| file_path = get_file_path_from_objs([:file]) file_name = [:file_name] || ['name'] params["attachment#{i + 1}".to_sym] = Faraday::UploadIO.new(file_path, Mime[:pdf].to_s, file_name) end [params, json_tmpfile] end |
#get_upload_location ⇒ Object
58 59 60 61 62 |
# File 'lib/benefits_intake_service/service.rb', line 58 def get_upload_location headers = {} request_body = {} perform :post, 'uploads', request_body, headers end |
#permanent_file?(_file) ⇒ Boolean
Overload in other services to define files not meant to be deleted
162 163 164 |
# File 'lib/benefits_intake_service/service.rb', line 162 def permanent_file?(_file) false end |
#upload_deletion_logic(file_with_full_path:, attachments:) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/benefits_intake_service/service.rb', line 144 def upload_deletion_logic(file_with_full_path:, attachments:) if Rails.env.production? Common::FileHelpers.delete_file_if_exists(file_with_full_path) unless permanent_file?(file_with_full_path) .each do |evidence_file| to_del = get_file_path_from_objs(evidence_file) # dont delete the instructions pdf we keep on the fs and send along for bdd claims Common::FileHelpers.delete_file_if_exists(to_del) unless permanent_file?(to_del) end else Rails.logger.info("Would have deleted file #{file_with_full_path} if in production env.") .each do |evidence_file| to_del = get_file_path_from_objs(evidence_file) Rails.logger.info("Would have deleted file #{to_del} if in production env.") unless permanent_file?(to_del) end end end |
#upload_doc(upload_url:, file:, metadata:, attachments: []) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/benefits_intake_service/service.rb', line 131 def upload_doc(upload_url:, file:, metadata:, attachments: []) file_with_full_path = get_file_path_from_objs(file) params, _json_tmpfile = get_upload_docs(file_with_full_path:, metadata:, attachments:) response = perform :put, upload_url, params, { 'Content-Type' => 'multipart/form-data' } raise response.body unless response.success? upload_deletion_logic(file_with_full_path:, attachments:) response end |
#upload_form(main_document:, attachments:, form_metadata:) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/benefits_intake_service/service.rb', line 46 def upload_form(main_document:, attachments:, form_metadata:) raise 'Ran Method without Instance Variables' if @location.blank? = () upload_doc( upload_url: @location, file: main_document, metadata: .to_json, attachments: ) end |
#validate_document(doc_path:) ⇒ Object
Validate a file satisfies Benefits Intake specifications. File must be a PDF.
29 30 31 32 33 34 |
# File 'lib/benefits_intake_service/service.rb', line 29 def validate_document(doc_path:) # TODO: allow headers: to be passed to function if/when other file types are allowed headers = { 'Content-Type': 'application/pdf' } request_body = File.read(doc_path, mode: 'rb') perform :post, 'uploads/validate_document', request_body, headers end |