Skip to content

Commit

Permalink
Merge branch 'master' into API-38963-VnpPtcpntAddrsService
Browse files Browse the repository at this point in the history
  • Loading branch information
acovrig committed Aug 27, 2024
2 parents d3632b7 + 91b7592 commit a25882a
Show file tree
Hide file tree
Showing 98 changed files with 1,384 additions and 732 deletions.
8 changes: 5 additions & 3 deletions app/controllers/sign_in/client_configs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def destroy
private

def client_config_params
params.require(:client_config).permit(:client_id, :authentication, :anti_csrf, :redirect_uri, :description,
:access_token_duration, :access_token_audience, :refresh_token_duration,
:logout_redirect_uri, :pkce, :refresh_token_path, certificates: [])
params.require(:client_config).permit(:client_id, :authentication, :redirect_uri, :refresh_token_duration,
:access_token_duration, :access_token_audience, :logout_redirect_uri,
:pkce, :terms_of_use_url, :enforced_terms, :shared_sessions, :anti_csrf,
:description, certificates: [], access_token_attributes: [],
service_levels: [], credential_service_providers: [])
end

def set_client_config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

# NOTE: This table was renamed and then dropped in the migration `DropAccreditedRepresentativePortalPilotRepresentatives`
class CreateAccreditedRepresentativePortalVerifiedRepresentatives < ActiveRecord::Migration[7.1]
def change
create_table :accredited_representative_portal_verified_representatives do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NOTE: This table was dropped in the migration `DropAccreditedRepresentativePortalPilotRepresentatives`
class CreateAccreditedRepresentativePortalPilotRepresentatives < ActiveRecord::Migration[7.1]
def change
create_table :accredited_representative_portal_pilot_representatives do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DropAccreditedRepresentativePortalPilotRepresentatives < ActiveRecord::Migration[6.0]
def up
drop_table :accredited_representative_portal_pilot_representatives, if_exists: true
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
9 changes: 0 additions & 9 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/admin/redis_health_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def self.redis_up
def self.app_data_redis_up
Thread.current[:app_data_redis_up] ||= begin
# Test 1: Check attribute that uses redis key
bank_name = BankName.find_or_build('fake routing number')
bank_name.update(bank_name: 'fake bank name')
BankName.delete('fake routing number')
bank_name.present?
session = Session.find_or_build('fake token')
session.update(uuid: '1234')
Session.delete('fake token')
session.present?
rescue => e
Rails.logger.error(
{ message: "ARGO CD UPGRADE - REDIS TEST: Failed to access app data Redis. Error: #{e.message}" }
Expand Down
4 changes: 2 additions & 2 deletions lib/disability_compensation/factories/api_provider_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def generate_pdf_service_provider
def supplemental_document_upload_service_provider
case api_provider
when API_PROVIDER[:evss]
EVSSSupplementalDocumentUploadProvider.new(@options[:form526_submission], @options[:file_body])
EVSSSupplementalDocumentUploadProvider.new(@options[:form526_submission])
when API_PROVIDER[:lighthouse]
LighthouseSupplementalDocumentUploadProvider.new(@options[:form526_submission], @options[:file_body])
LighthouseSupplementalDocumentUploadProvider.new(@options[:form526_submission])
else
raise NotImplementedError, 'No known Supplemental Document Upload Api Provider type provided'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class EVSSSupplementalDocumentUploadProvider
STATSD_PROVIDER_METRIC = 'evss_supplemental_document_upload_provider'

# @param form526_submission [Form526Submission]
# @param file_body [String]
def initialize(form526_submission, file_body)
def initialize(form526_submission)
@form526_submission = form526_submission
@file_body = file_body
end

# Uploads to EVSS via the EVSS::DocumentsService require both the file body and an instance
Expand Down Expand Up @@ -45,29 +43,27 @@ def validate_upload_document(evss_claim_document)
# Initializes and uploads via our EVSS Document Service API wrapper
#
# @param evss_claim_document
# @param file_body [String]
#
# @return [Faraday::Response] The EVSS::DocumentsService API calls are implemented with Faraday
def submit_upload_document(evss_claim_document)
def submit_upload_document(evss_claim_document, file_body)
client = EVSS::DocumentsService.new(@form526_submission.auth_headers)
client.upload(@file_body, evss_claim_document)
client.upload(file_body, evss_claim_document)
end

def log_upload_success(uploading_class_prefix)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_SUCCESS_METRIC}")
end

def log_upload_error_retry(uploading_class_prefix)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_RETRIED_METRIC}")
end

def log_upload_failure(uploading_class_prefix, error)
def log_upload_failure(uploading_class_prefix, error_class, error_message)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_FAILED_METRIC}")

Rails.logger.error(
'EVSSSupplementalDocumentUploadProvider upload failure',
{
class: 'EVSSSupplementalDocumentUploadProvider',
error_class: error.class,
error_message: error.message
error_class:,
error_message:
}
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ class LighthouseSupplementalDocumentUploadProvider
STATSD_PROVIDER_METRIC = 'lighthouse_supplemental_document_upload_provider'

# @param form526_submission [Form526Submission]
# @param file_body [String]
def initialize(form526_submission, file_body)
def initialize(form526_submission)
@form526_submission = form526_submission
@file_body = file_body
end

# Uploads to Lighthouse require both the file body and an instance
Expand Down Expand Up @@ -46,29 +44,27 @@ def validate_upload_document(lighthouse_document)
# Uploads the supplied file to the Lighthouse Benefits Documents API
#
# @param lighthouse_document [LighthouseDocument]
# @param file_body [String]
#
# return [Faraday::Response] BenefitsDocuments::WorkerService makes http
# calls with the Faraday gem under the hood
def submit_upload_document(lighthouse_document)
BenefitsDocuments::Form526::UploadSupplementalDocumentService.call(@file_body, lighthouse_document)
def submit_upload_document(lighthouse_document, file_body)
BenefitsDocuments::Form526::UploadSupplementalDocumentService.call(file_body, lighthouse_document)
end

def log_upload_success(uploading_class_prefix)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_SUCCESS_METRIC}")
end

def log_upload_error_retry(uploading_class_prefix)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_RETRIED_METRIC}")
end

def log_upload_failure(uploading_class_prefix, error)
def log_upload_failure(uploading_class_prefix, error_class, error_message)
StatsD.increment("#{uploading_class_prefix}.#{STATSD_PROVIDER_METRIC}.#{STATSD_FAILED_METRIC}")

Rails.logger.error(
'LighthouseSupplementalDocumentUploadProvider upload failure',
{
class: 'LighthouseSupplementalDocumentUploadProvider',
error_class: error.class,
error_message: error.message
error_class:,
error_message:
}
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ def self.generate_upload_document(_file_name, _document_type)
raise_not_implemented_error
end

def self.validate_upload_document(_lighthouse_document)
def self.validate_upload_document(_document)
raise_not_implemented_error
end

def self.submit_upload_document(_lighthouse_document)
def self.submit_upload_document(_document, _file_body)
raise_not_implemented_error
end

def self.log_upload_success(_uploading_class_prefix)
raise_not_implemented_error
end

def self.log_upload_error_retry(_uploading_class_prefix)
raise_not_implemented_error
end

def self.log_upload_failure(_uploading_class_prefix, _error)
def self.log_upload_failure(_uploading_class_prefix, _error_class, _error_message)
raise_not_implemented_error
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'pdf_fill/forms/va21p527ez'
require 'pdf_fill/forms/va21p530'
require 'pdf_fill/forms/va21p530v2'
require 'pdf_fill/forms/va214142'
Expand Down
1 change: 1 addition & 0 deletions lib/lighthouse/facilities/facility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Facility < Common::Base
attribute :unique_id, String
attribute :visn, String
attribute :website, String
attribute :parent, Object

def initialize(fac)
super(fac)
Expand Down
15 changes: 6 additions & 9 deletions lib/logging/third_party_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ def wrap_with_logging(*method_names, additional_class_logs: {}, additional_insta
method_names.each do |method_name|
# define patchable method(s) with the same name inside of a proxy module.
define_method(method_name) do |*args, &block|
str_args = args.to_s
log_3pi_begin(method_name, additional_class_logs, additional_instance_logs, str_args)
log_3pi_begin(method_name, additional_class_logs, additional_instance_logs)
# delegate to the original behavior
result = super(*args, &block)
log_3pi_complete(method_name, additional_class_logs, additional_instance_logs, str_args)
log_3pi_complete(method_name, additional_class_logs, additional_instance_logs)
result
end
end
Expand All @@ -45,13 +44,12 @@ def wrap_with_logging(*method_names, additional_class_logs: {}, additional_insta
# these will be included after instance instantiation, making them available
# to the instance and retaining their scope.
module ScopedInstanceMethods
def log_3pi_begin(method_name, additional_class_logs, additional_instance_logs, args)
def log_3pi_begin(method_name, additional_class_logs, additional_instance_logs)
@start_time = Time.current

log = {
start_time: @start_time.to_s,
wrapped_method: "#{self.class}##{method_name}",
passed_args: args.to_s
wrapped_method: "#{self.class}##{method_name}"
}

log.merge!(default_logs)
Expand All @@ -63,14 +61,13 @@ def log_3pi_begin(method_name, additional_class_logs, additional_instance_logs,
Rails.logger.error(e)
end

def log_3pi_complete(method_name, additional_class_logs, additional_instance_logs, args)
def log_3pi_complete(method_name, additional_class_logs, additional_instance_logs)
now = Time.current

log = {
upload_duration: (now - @start_time).to_f,
wrapped_method: "#{self.class}##{method_name}",
end_time: now.to_s,
passed_args: args.to_s
end_time: now.to_s
}

log.merge!(default_logs)
Expand Down
77 changes: 72 additions & 5 deletions lib/pdf_fill/filler.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'pdf_fill/forms/va21p527ez'
require 'pdf_fill/forms/va21p0969'
require 'pdf_fill/forms/va21p530'
require 'pdf_fill/forms/va21p530v2'
Expand All @@ -18,14 +17,36 @@
require 'pdf_fill/forms/va5655'

module PdfFill
# Provides functionality to fill and process PDF forms.
#
# This module includes methods to register form classes, fill out PDF forms, and handle extra PDF generation.
module Filler
class PdfFillerException < StandardError; end
module_function

# A PdfForms instance for handling standard PDF forms.
PDF_FORMS = PdfForms.new(Settings.binaries.pdftk)

# A PdfForms instance for handling Unicode PDF forms with XFdf data format.
UNICODE_PDF_FORMS = PdfForms.new(Settings.binaries.pdftk, data_format: 'XFdf', utf8_fields: true)
FORM_CLASSES = {

# A hash mapping form IDs to their corresponding form classes.
# This constant is intentionally mutable.
FORM_CLASSES = {} # rubocop:disable Style/MutableConstant

##
# Registers a form class with a specific form ID.
#
# @param form_id [String] The form ID to register.
# @param form_class [Class] The class associated with the form ID.
#
def register_form(form_id, form_class)
FORM_CLASSES[form_id] = form_class
end

# Registers form classes for various form IDs.
{
'21P-0969' => PdfFill::Forms::Va21p0969,
'21P-527EZ' => PdfFill::Forms::Va21p527ez,
'21P-530' => PdfFill::Forms::Va21p530,
'21P-530V2' => PdfFill::Forms::Va21p530v2,
'21-4142' => PdfFill::Forms::Va214142,
Expand All @@ -40,8 +61,18 @@ module Filler
'21-0538' => PdfFill::Forms::Va210538,
'26-1880' => PdfFill::Forms::Va261880,
'5655' => PdfFill::Forms::Va5655
}.freeze
}.each do |form_id, form_class|
register_form(form_id, form_class)
end

##
# Combines extra pages into the main PDF if necessary.
#
# @param old_file_path [String] The path to the original PDF file.
# @param extras_generator [ExtrasGenerator] The generator for extra pages.
#
# @return [String] The path to the final combined PDF.
#
def combine_extras(old_file_path, extras_generator)
if extras_generator.text?
file_path = "#{old_file_path.gsub('.pdf', '')}_final.pdf"
Expand All @@ -58,17 +89,49 @@ def combine_extras(old_file_path, extras_generator)
end
end

##
# Fills a form based on the provided saved claim and options.
#
# @param saved_claim [SavedClaim] The saved claim containing form data.
# @param file_name_extension [String, nil] Optional file name extension.
# @param fill_options [Hash] Options for filling the form.
#
# @raise [PdfFillerException] If the form is not found.
# @return [String] The path to the filled PDF form.
#
def fill_form(saved_claim, file_name_extension = nil, fill_options = {})
form_id = saved_claim.form_id
form_class = FORM_CLASSES[form_id]

raise PdfFillerException, "Form #{form_id} was not found." unless form_class

process_form(form_id, saved_claim.parsed_form, form_class, file_name_extension || saved_claim.id, fill_options)
end

##
# Fills an ancillary form based on the provided data and form ID.
#
# @param form_data [Hash] The data to fill in the form.
# @param claim_id [String] The ID of the claim.
# @param form_id [String] The form ID.
#
# @return [String] The path to the filled PDF form.
#
def fill_ancillary_form(form_data, claim_id, form_id)
process_form(form_id, form_data, FORM_CLASSES[form_id], claim_id)
end

##
# Processes a form by filling it with data and saving it to a file.
#
# @param form_id [String] The form ID.
# @param form_data [Hash] The data to fill in the form.
# @param form_class [Class] The class associated with the form ID.
# @param file_name_extension [String] The file name extension for the output PDF.
# @param fill_options [Hash] Options for filling the form.
#
# @return [String] The path to the filled PDF form.
#
def process_form(form_id, form_data, form_class, file_name_extension, fill_options = {})
folder = 'tmp/pdfs'
FileUtils.mkdir_p(folder)
Expand All @@ -78,8 +141,12 @@ def process_form(form_id, form_data, form_class, file_name_extension, fill_optio
form_data: form_class.new(form_data).merge_fields(fill_options),
pdftk_keys: form_class::KEY
)

has_template = form_class.const_defined?(:TEMPLATE)
template_path = has_template ? form_class::TEMPLATE : "lib/pdf_fill/forms/pdfs/#{form_id}.pdf"

(form_id == SavedClaim::CaregiversAssistanceClaim::FORM ? UNICODE_PDF_FORMS : PDF_FORMS).fill_form(
"lib/pdf_fill/forms/pdfs/#{form_id}.pdf",
template_path,
file_path,
new_hash,
flatten: Rails.env.production?
Expand Down
Loading

0 comments on commit a25882a

Please sign in to comment.