Skip to content

Commit

Permalink
Merge branch 'master' into vi-471
Browse files Browse the repository at this point in the history
  • Loading branch information
bramleyjl authored Sep 24, 2024
2 parents f4485b3 + 504cebc commit efb0daf
Show file tree
Hide file tree
Showing 19 changed files with 688 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ lib/benefits_intake_service @department-of-veterans-affairs/benefits-dependents-
lib/bgs @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/bid @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/bip_claims @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/burials @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/carma @department-of-veterans-affairs/vfs-10-10 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/caseflow @department-of-veterans-affairs/lighthouse-banana-peels @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/central_mail @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -1384,6 +1385,7 @@ spec/lib/bgs @department-of-veterans-affairs/benefits-dependents-management @dep
spec/lib/bid @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/bip_claims @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/breakers @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/burials @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/carma @department-of-veterans-affairs/vfs-10-10 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/caseflow @department-of-veterans-affairs/lighthouse-banana-peels @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/central_mail @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down
91 changes: 64 additions & 27 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
# frozen_string_literal: true

require 'pension_burial/tag_sentry'
require 'burials/monitor'

module V0
class BurialClaimsController < ClaimsBaseController
service_tag 'burial-application'

def show
submission_attempt = determine_submission_attempt
claim = claim_class.find_by!(guid: params[:id])
form_submission = claim&.form_submissions&.last
submission_attempt = form_submission&.form_submission_attempts&.last
if submission_attempt
state = submission_attempt.aasm_state == 'failure' ? 'failure' : 'success'
render(json: { data: { attributes: { state: } } })
elsif central_mail_submission
render json: CentralMailSubmissionSerializer.new(central_mail_submission)
else
Rails.logger.error("ActiveRecord::RecordNotFound: Claim submission not found for claim_id: #{params[:id]}")
render(json: { data: { attributes: { state: 'not found' } } }, status: :not_found)
end
rescue ActiveRecord::RecordNotFound => e
monitor.track_show404(params[:id], current_user, e)
render(json: { data: { attributes: { state: 'not found' } } }, status: :not_found)
rescue => e
Rails.logger.error(e.to_s)
monitor.track_show_error(params[:id], current_user, e)
render(json: { data: { attributes: { state: 'error processing request' } } }, status: :unprocessable_entity)
end

def create
PensionBurial::TagSentry.tag_sentry

claim = if Flipper.enabled?(:va_burial_v2)
# cannot parse a nil form, to pass unit tests do a check for form presence
form = filtered_params[:form]
claim_class.new(form:, formV2: form.present? ? JSON.parse(form)['formV2'] : nil)
else
claim_class.new(form: filtered_params[:form])
end

unless claim.save
StatsD.increment("#{stats_key}.failure")
Sentry.set_tags(team: 'benefits-memorial-1') # tag sentry logs with team name
Rails.logger.error('Burial claim was not saved', { error_messages: claim.errors,
user_uuid: current_user&.uuid,
in_progress_form_id: in_progress_form&.id })
raise Common::Exceptions::ValidationErrors, claim
end
claim = create_claim
monitor.track_create_attempt(claim, current_user)

track_claim_save_failure(claim) unless claim.save

# this method also calls claim.process_attachments!
claim.submit_to_structured_data_services!

Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.form_id}"

in_progress_form = current_user ? InProgressForm.form_for_user(claim.form_id, current_user) : nil
claim.form_start_date = in_progress_form.created_at if in_progress_form
monitor.track_create_success(in_progress_form, claim, current_user)

clear_saved_form(claim.form_id)
render json: SavedClaimSerializer.new(claim)
rescue => e
monitor.track_create_error(in_progress_form, claim, current_user, e)
raise e
end

def create_claim
if Flipper.enabled?(:va_burial_v2)
form = filtered_params[:form]
claim_class.new(form:, formV2: form.present? ? JSON.parse(form)['formV2'] : nil)
else
claim_class.new(form: filtered_params[:form])
end
end

def short_name
Expand All @@ -59,18 +68,46 @@ def claim_class

private

def determine_submission_attempt
claim = claim_class.find_by(guid: params[:id])
form_submission = claim&.form_submissions&.last
form_submission&.form_submission_attempts&.last
end

def central_mail_submission
CentralMailSubmission.joins(:central_mail_claim).find_by(saved_claims: { guid: params[:id] })
end

def in_progress_form
current_user ? InProgressForm.form_for_user(claim.form_id, current_user) : nil
end

def track_claim_save_failure(claim)
StatsD.increment("#{stats_key}.failure")
Sentry.set_tags(team: 'benefits-memorial-1') # tag sentry logs with team name
Rails.logger.error('Burial claim was not saved', { error_messages: claim.errors,
user_uuid: current_user&.uuid,
in_progress_form_id: in_progress_form&.id })
log_validation_error_to_metadata(in_progress_form, claim)
raise Common::Exceptions::ValidationErrors, claim
end

##
# include validation error on in_progress_form metadata.
# `noop` if in_progress_form is `blank?`
#
# @param in_progress_form [InProgressForm]
# @param claim [Pensions::SavedClaim]
#
def log_validation_error_to_metadata(in_progress_form, claim)
return if in_progress_form.blank?

metadata = in_progress_form.metadata
metadata['submission']['error_message'] = claim&.errors&.errors&.to_s
in_progress_form.update(metadata:)
end

##
# retreive a monitor for tracking
#
# @return [Burials::Monitor]
#
def monitor
@monitor ||= Burials::Monitor.new
end
end
end
89 changes: 89 additions & 0 deletions lib/burials/monitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# frozen_string_literal: true

module Burials
##
# Monitor functions for Rails logging and StatsD
#
class Monitor
CLAIM_STATS_KEY = 'api.burial_claim'

##
# log GET 404 from controller
# @see BurialClaimsController
#
# @param confirmation_number [UUID] saved_claim guid
# @param current_user [User]
# @param e [ActiveRecord::RecordNotFound]
#
def track_show404(confirmation_number, current_user, e)
Rails.logger.error('21P-530EZ submission not found',
{ confirmation_number:, user_uuid: current_user&.uuid, message: e&.message })
end

##
# log GET 500 from controller
# @see BurialClaimsController
#
# @param confirmation_number [UUID] saved_claim guid
# @param current_user [User]
# @param e [Error]
#
def track_show_error(confirmation_number, current_user, e)
Rails.logger.error('21P-530EZ fetching submission failed',
{ confirmation_number:, user_uuid: current_user&.uuid, message: e&.message })
end

##
# log POST processing started
# @see BurialClaimsController
#
# @param claim [Pension::SavedClaim]
# @param current_user [User]
#
def track_create_attempt(claim, current_user)
StatsD.increment("#{CLAIM_STATS_KEY}.attempt")
Rails.logger.info('21P-530EZ submission to Sidekiq begun',
{ confirmation_number: claim&.confirmation_number, user_uuid: current_user&.uuid })
end

##
# log POST processing failure
# @see BurialClaimsController
#
# @param in_progress_form [InProgressForm]
# @param claim [SavedClaim::Burial]
# @param current_user [User]
# @param e [Error]
#
def track_create_error(in_progress_form, claim, current_user, e = nil)
StatsD.increment("#{CLAIM_STATS_KEY}.failure")
Rails.logger.error('21P-530EZ submission to Sidekiq failed',
{ confirmation_number: claim&.confirmation_number, user_uuid: current_user&.uuid,
in_progress_form_id: in_progress_form&.id, errors: claim&.errors&.errors,
message: e&.message })
end

##
# log POST processing success
# @see BurialClaimsController
#
# @param in_progress_form [InProgressForm]
# @param claim [SavedClaim::Burial]
# @param current_user [User]
#
def track_create_success(in_progress_form, claim, current_user)
StatsD.increment("#{CLAIM_STATS_KEY}.success")
if claim.form_start_date
claim_duration = claim.created_at - claim.form_start_date
tags = ["form_id:#{claim.form_id}"]
StatsD.measure('saved_claim.time-to-file', claim_duration, tags:)
end
context = {
confirmation_number: claim&.confirmation_number,
user_uuid: current_user&.uuid,
in_progress_form_id: in_progress_form&.id
}
Rails.logger.info('21P-530EZ submission to Sidekiq success', context)
end
end
end
4 changes: 4 additions & 0 deletions modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ def jrn

private

def builder_to_xml(builder)
builder.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
end

def transform_keys(hash_or_array)
transformer = lambda do |object|
case object
Expand Down
30 changes: 24 additions & 6 deletions modules/claims_api/lib/bgs_service/person_web_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,33 @@ def bean_name
end

def find_dependents_by_ptcpnt_id(id)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
<ptcpntId />
EOXML

{ ptcpntId: id }.each do |k, v|
body.xpath("./*[local-name()='#{k}']").first.content = v
builder = Nokogiri::XML::Builder.new do
ptcpntId id
end

body = builder_to_xml(builder)

make_request(endpoint: bean_name, action: 'findDependentsByPtcpntId', body:, key: 'DependentDTO')
end

# ptcpntIdA is the veteranʼs or dependentʼs participant id
# ptcpntIdB is the poaʼs participant id
def manage_ptcpnt_rlnshp_poa(options = {})
builder = Nokogiri::XML::Builder.new do
PtcpntRlnshpDTO do
authznChangeClmantAddrsInd 'Y' if options[:authzn_change_clmant_addrs_ind].present?
authznPoaAccessInd 'Y' if options[:authzn_poa_access_ind].present?
compId do
ptcpntIdA options[:ptcpnt_id_a]
ptcpntIdB options[:ptcpnt_id_b]
end
statusTypeCd options[:status_type_cd] || 'CURR'
end
end

body = builder_to_xml(builder)

make_request(endpoint: bean_name, action: 'managePtcpntRlnshpPoa', body:, key: 'PtcpntRlnshpDTO')
end
end
end
11 changes: 11 additions & 0 deletions modules/claims_api/lib/claims_api/error/soap_error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def get_exception
raise ::Common::Exceptions::UnprocessableEntity.new(
detail: 'Please try again after checking your input values.'
)
elsif participant_has_open_claims?
raise ::Common::Exceptions::ServiceError.new(
detail: 'PtcpntIdA has open claims.'
)
else
soap_logging('500')
raise ::Common::Exceptions::ServiceError.new(detail: 'An external server is experiencing difficulty.')
Expand Down Expand Up @@ -64,6 +68,13 @@ def unprocessable?
has_errors
end

def participant_has_open_claims?
has_error = @fault_string.include?('PtcpntIdA has open claims')
soap_logging('422') if has_error

has_error
end

def soap_logging(status_code)
ClaimsApi::Logger.log('soap_error_handler',
detail: "Returning #{status_code} via local_bgs & soap_error_handler, " \
Expand Down
Loading

0 comments on commit efb0daf

Please sign in to comment.