Skip to content

Commit

Permalink
[API-44023] add steps to poa model and response (#20398)
Browse files Browse the repository at this point in the history
* add steps to poa model and response

* add errors to get poa response

* memoize processes

* fork serializer

* update schema and docs

* update test

* remove linebreak
  • Loading branch information
tycol7 authored Jan 24, 2025
1 parent fb3e03d commit 886680e
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def submit_form_2122 # rubocop:disable Metrics/MethodLength
end

claims_v1_logging('poa_submit', message: "poa_submit complete, poa: #{power_of_attorney&.id}")
render json: ClaimsApi::PowerOfAttorneySerializer.new(power_of_attorney)
render json: ClaimsApi::V1::PowerOfAttorneySerializer.new(power_of_attorney)
end

# PUT to upload a wet-signed 2122 form.
Expand All @@ -96,7 +96,7 @@ def upload
# If upload is successful, then the PoaUpater job is also called to update the code in BGS.
ClaimsApi::PoaVBMSUploadJob.perform_async(@power_of_attorney.id, 'put')

render json: ClaimsApi::PowerOfAttorneySerializer.new(@power_of_attorney)
render json: ClaimsApi::V1::PowerOfAttorneySerializer.new(@power_of_attorney)
end

# GET the current status of a previous POA change request.
Expand All @@ -105,7 +105,7 @@ def upload
def status
find_poa_by_id

render json: ClaimsApi::PowerOfAttorneySerializer.new(@power_of_attorney)
render json: ClaimsApi::V1::PowerOfAttorneySerializer.new(@power_of_attorney)
end

# GET current POA for a Veteran.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def status
)
end

serialized_response = ClaimsApi::PowerOfAttorneySerializer.new(poa).serializable_hash
serialized_response = ClaimsApi::V2::PowerOfAttorneySerializer.new(poa).serializable_hash
serialized_response[:data][:type] = serialized_response[:data][:type].to_s.camelize(:lower)
render json: serialized_response.deep_transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
end
Expand Down
36 changes: 36 additions & 0 deletions modules/claims_api/app/models/claims_api/power_of_attorney.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,42 @@ def set_md5
self.md5 = Digest::MD5.hexdigest form_data.merge(headers).to_json
end

def processes
@processes ||= ClaimsApi::Process.where(processable: self)
.in_order_of(:step_type, ClaimsApi::Process::VALID_POA_STEP_TYPES).to_a
end

def steps
ClaimsApi::Process::VALID_POA_STEP_TYPES.each do |step_type|
unless processes.any? { |p| p.step_type == step_type }
index = ClaimsApi::Process::VALID_POA_STEP_TYPES.index(step_type)
processes.insert(index, ClaimsApi::Process.new(step_type:, step_status: 'NOT_STARTED', processable: self))
end
end

processes.map do |p|
{
type: p.step_type,
status: p.step_status,
completed_at: p.completed_at,
next_step: p.next_step
}
end
end

def errors
processes.map do |p|
error_message = p.error_messages.last
next unless error_message

{
title: error_message['title'],
detail: error_message['detail'],
code: p.step_type
}
end.compact
end

def uploader
@uploader ||= ClaimsApi::PowerOfAttorneyUploader.new(id)
end
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module ClaimsApi
module V1
class PowerOfAttorneySerializer
include JSONAPI::Serializer

set_type :claims_api_power_of_attorneys
set_id :id
set_key_transform :underscore

attributes :date_request_accepted, :previous_poa

attribute :representative do |object|
object.representative.deep_transform_keys!(&:underscore)
end

# "Uploaded" is an internal-only status indicating that the POA PDF
# was uploaded to VBMS, but we did not make it to updating BGS.
# For external consistency, return as "Updated"
attribute :status do |object|
if object[:status] == ClaimsApi::PowerOfAttorney::UPLOADED
ClaimsApi::PowerOfAttorney::UPDATED
else
object[:status]
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module ClaimsApi
module V2
class PowerOfAttorneySerializer
include JSONAPI::Serializer

set_type :claims_api_power_of_attorneys
set_id :id
set_key_transform :underscore

attributes :created_at

attribute :representative do |object|
object.representative.deep_transform_keys!(&:underscore)
end

# "Uploaded" is an internal-only status indicating that the POA PDF
# was uploaded to VBMS, but we did not make it to updating BGS.
# For external consistency, return as "Updated"
attribute :status do |object|
if object[:status] == ClaimsApi::PowerOfAttorney::UPLOADED
ClaimsApi::PowerOfAttorney::UPDATED
else
object[:status]
end
end

attribute :errors
attribute :steps

private

def created_at
object.date_request_accepted
end
end
end
end
12 changes: 6 additions & 6 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ def perform(power_of_attorney_id, rep_id = nil) # rubocop:disable Metrics/Method
if response[:return_code] == 'BMOD0001'
# Clear out the error message if there were previous failures
poa_form.vbms_error_message = nil if poa_form.vbms_error_message.present?
poa_form.save
process.update!(step_status: 'SUCCESS', error_messages: [])

ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BIRLS Success')

ClaimsApi::VANotifyAcceptedJob.perform_async(poa_form.id, rep_id) if vanotify?(poa_form.auth_headers, rep_id)

ClaimsApi::PoaVBMSUpdater.perform_async(poa_form.id)

process.update!(step_status: 'SUCCESS')
else
poa_form.status = ClaimsApi::PowerOfAttorney::ERRORED
poa_form.vbms_error_message = "BGS Error: update_birls_record failed with code #{response[:return_code]}"
poa_form.save
process.update!(step_status: 'FAILED',
error_messages: [{ title: 'BGS Error',
detail: poa_form.vbms_error_message }])
ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BIRLS Failed', error: response[:return_code])

process.update!(step_status: 'FAILED')
end

poa_form.save
end

private
Expand Down
9 changes: 6 additions & 3 deletions modules/claims_api/app/sidekiq/claims_api/poa_vbms_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ def perform(power_of_attorney_id) # rubocop:disable Metrics/MethodLength

if response[:return_code] == 'GUIE50000'
poa_form.status = ClaimsApi::PowerOfAttorney::UPDATED
process.update!(step_status: 'SUCCESS')
process.update!(step_status: 'SUCCESS', error_messages: [])
poa_form.vbms_error_message = nil if poa_form.vbms_error_message.present?
ClaimsApi::Logger.log('poa_vbms_updater', poa_id: power_of_attorney_id, detail: 'VBMS Success')
else
poa_form.status = ClaimsApi::PowerOfAttorney::ERRORED
process.update!(step_status: 'FAILED')
poa_form.vbms_error_message = 'update_poa_access failed with code ' \
"#{response[:return_code]}: #{response[:return_message]}"
process.update!(step_status: 'FAILED', error_messages: [{ title: 'BGS Error',
detail: poa_form.vbms_error_message }])
ClaimsApi::Logger.log('poa_vbms_updater',
poa_id: power_of_attorney_id,
detail: 'VBMS Failed',
Expand All @@ -44,9 +45,11 @@ def perform(power_of_attorney_id) # rubocop:disable Metrics/MethodLength
poa_form.save
rescue BGS::ShareError => e
poa_form.status = ClaimsApi::PowerOfAttorney::ERRORED
process.update!(step_status: 'FAILED')
poa_form.vbms_error_message = e.respond_to?(:message) ? e.message : 'BGS::ShareError'
poa_form.save
process.update!(step_status: 'FAILED',
error_messages: [{ title: 'BGS Error',
detail: poa_form.vbms_error_message }])
ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BGS Error', error: e)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ def perform(power_of_attorney_id, form_number, rep_id, action) # rubocop:disable
else
ClaimsApi::PoaUpdater.perform_async(power_of_attorney.id, rep_id)
end
process.update!(step_status: 'SUCCESS')
process.update!(step_status: 'SUCCESS', error_messages: [])
rescue VBMS::Unknown
rescue_vbms_error(power_of_attorney)
process.update!(step_status: 'FAILED')
rescue_vbms_error(power_of_attorney, process:)
rescue Errno::ENOENT
rescue_file_not_found(power_of_attorney)
process.update!(step_status: 'FAILED')
rescue_file_not_found(power_of_attorney, process:)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ def perform(poa_id, rep_id)
poa_code_from_form('2122a', poa)
res = send_representative_notification(poa, rep)
end
process.update!(step_status: 'SUCCESS')
process.update!(step_status: 'SUCCESS', error_messages: [])
schedule_follow_up_check(res.id) if res.present?
rescue => e
process.update!(step_status: 'FAILED')
handle_failure(poa_id, e)
handle_failure(poa_id, e, process)
end

# 2122a
Expand All @@ -38,9 +37,11 @@ def send_organization_notification(poa, org)

private

def handle_failure(poa_id, error)
def handle_failure(poa_id, error, process)
job_name = 'ClaimsApi::VANotifyAcceptedJob'
msg = "VA Notify email notification failed to send for #{poa_id} with error #{error}"
process.update!(step_status: 'FAILED', error_messages: [{ title: 'VA Notify Error',
detail: msg }])
slack_alert_on_failure(job_name, msg)

ClaimsApi::Logger.log(
Expand Down
Loading

0 comments on commit 886680e

Please sign in to comment.