Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved merge conflicts while merging master into feature/APPEALS-28… #21167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

class Api::Events::V1::DecisionReviewCreatedController < Api::ApplicationController
def decision_review_created
consumer_event_id = drc_params[:event_id]
claim_id = drc_params[:claim_id]
::Events::DecisionReviewCreated.create!(consumer_event_id, claim_id)
render json: { message: "DecisionReviewCreatedEvent successfully processed and backfilled" }, status: :created
rescue Caseflow::Error::RedisLockFailed => error
render json: { message: error.message }, status: :conflict
rescue StandardError => error
render json: { message: error.message }, status: :unprocessable_entity
end

def decision_review_created_error
event_id = drc_error_params[:event_id]
errored_claim_id = drc_error_params[:errored_claim_id]
error_message = drc_error_params[:error]
::Events::DecisionReviewCreatedError.handle_service_error(event_id, errored_claim_id, error_message)
render json: { message: "Decision Review Created Error Saved in Caseflow" }, status: :created
rescue Caseflow::Error::RedisLockFailed => error
render json: { message: error.message }, status: :conflict
rescue StandardError => error
render json: { message: error.message }, status: :unprocessable_entity
end

private

def drc_error_params
params.permit(:event_id, :errored_claim_id, :error)
end

def drc_params
params.permit(:event_id, :claim_id)
end
end
14 changes: 7 additions & 7 deletions app/controllers/api/v3/issues/ama/veterans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class Api::V3::Issues::Ama::VeteransController < Api::V3::BaseController
end

def show
veteran = find_veteran
page = init_page
per_page = init_per
if veteran
MetricsService.record("Retrieving AMA Request Issues for Veteran: #{veteran.participant_id}",
service: "AMA Request Issue endpoint",
name: "VeteransController.show") do
MetricsService.record("Retrieving AMA Request Issues for Veteran with participant ID: #{params[:participant_id]}",
service: "AMA Request Issue endpoint",
name: "VeteransController.show") do
veteran = find_veteran
page = init_page
per_page = init_per
if veteran
render_request_issues(Api::V3::Issues::Ama::VbmsAmaDtoBuilder.new(veteran, page, per_page).hash_response)
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/api/v3/issues/vacols/veterans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def file_number
end

def show
page = ActiveRecord::Base.sanitize_sql(params[:page].to_i) if params[:page]
# per_page uses the default value defined in the DtoBuilder unless a param is given,
# but it cannot exceed the upper bound
per_page = [params[:per_page].to_i, DEFAULT_UPPER_BOUND_PER_PAGE].min if params[:per_page]&.to_i&.positive?
# Disallow page(0) since page(0) == page(1) in kaminari. This is to avoid confusion.
(page.nil? || page <= 0) ? page = 1 : page ||= 1

MetricsService.record("VACOLS: Get VACOLS Issues information for Veteran",
name: "Api::V3::Issues::Vacols::VeteransController.show") do
name: "Api::V3::Issues::Vacols::VeteransController.show") do
page = ActiveRecord::Base.sanitize_sql(params[:page].to_i) if params[:page]
# per_page uses the default value defined in the DtoBuilder unless a param is given,
# but it cannot exceed the upper bound
per_page = [params[:per_page].to_i, DEFAULT_UPPER_BOUND_PER_PAGE].min if params[:per_page]&.to_i&.positive?
# Disallow page(0) since page(0) == page(1) in kaminari. This is to avoid confusion.
(page.nil? || page <= 0) ? page = 1 : page ||= 1

render_vacols_issues(Api::V3::Issues::Vacols::VbmsVacolsDtoBuilder.new(@veteran, page, per_page))
end
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/claim_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ClaimReview < DecisionReview

has_many :end_product_establishments, as: :source
has_many :messages, as: :detail

has_one :event_record, as: :backfill_record
with_options if: :saving_review do
validate :validate_receipt_date
validate :validate_veteran
Expand Down Expand Up @@ -301,6 +301,11 @@ def cleared_nonrating_ep?
processed? && cleared_end_products.any?(&:nonrating?)
end

def from_decision_review_created_event?
# refer back to the associated Intake to see if both objects came from DRCE
intake ? intake.from_decision_review_created_event? : false
end

private

def cleared_end_products
Expand Down
6 changes: 6 additions & 0 deletions app/models/claimant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Claimant < CaseflowRecord
has_one :unrecognized_appellant, lambda { |claimant|
where(id: UnrecognizedAppellant.order(:id).find_by(claimant: claimant)&.id)
}, dependent: :destroy
has_one :event_record, as: :backfill_record

# rubocop:disable Rails/UniqueValidationWithoutIndex
validates :participant_id,
Expand Down Expand Up @@ -86,6 +87,11 @@ def find_power_of_attorney
# no-op except on BgsRelatedClaimants
end

def from_decision_review_created_event?
# refer back to the associated Person record to see if both objects came from DRCE
person.from_decision_review_created_event?
end

private

def bgs_address_service
Expand Down
24 changes: 24 additions & 0 deletions app/models/concerns/event_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# This concern is used to identify objects associated with Appeals-Consumer Events.
module EventConcern
extend ActiveSupport::Concern

# Check if this object is associated with any Event, regardless of type
# check if this object exists in the Event Records table
def from_event?
event_record.present?
end

# Check if this object is associated with a DecisionReviewCreatedEvent
def from_decision_review_created_event?
if from_event?
# retrieve the record and the event the record is tied to
event = event_record.event

event.type == DecisionReviewCreatedEvent.name
else
false
end
end
end
6 changes: 6 additions & 0 deletions app/models/end_product_establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EndProductEstablishment < CaseflowRecord
has_many :effectuations, class_name: "BoardGrantEffectuation"
has_many :end_product_updates
has_one :priority_end_product_sync_queue
has_one :event_record, as: :backfill_record
belongs_to :vbms_ext_claim, foreign_key: "reference_id", primary_key: "claim_id", optional: true

# :block => 1 # Specify in seconds how long you want to wait for the lock to be released.
Expand Down Expand Up @@ -383,6 +384,11 @@ def status_type_code
end
end

def from_decision_review_created_event?
# refer back to the associated Intake to see if both objects came from DRCE
source.intake.from_decision_review_created_event?
end

private

def status_type
Expand Down
7 changes: 7 additions & 0 deletions app/models/events/decision_review_created_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# This class represents the DecisionReviewCreatedEvent info that is POSTed to Caseflow
# Represents a single "event" and is tied to "event records" that contain info regarding
# the different objects that Caseflow performs backfill creations for after VBMS Intake.
class DecisionReviewCreatedEvent < Event
end
19 changes: 19 additions & 0 deletions app/models/events/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# This class is the parent class for different events that Caseflow receives from appeals-consumer
class Event < CaseflowRecord
has_many :event_records
store_accessor :info, :errored_claim_id

scope :with_errored_claim_id, -> { where.not("info -> 'errored_claim_id' IS NULL") }

def completed?
completed_at?
end

def self.find_errors_by_claim_id(claim_id)
with_errored_claim_id
.where("info ->> 'errored_claim_id' = ?", claim_id)
.pluck(:error)
end
end
28 changes: 28 additions & 0 deletions app/models/events/event_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

class EventRecord < CaseflowRecord
belongs_to :event
belongs_to :backfill_record, polymorphic: true

validate :valid_backfill_record

def valid_backfill_record
unless %w[
Intake
ClaimReview
HigherLevelReview
SupplementalClaim
EndProductEstablishment
Claimant
Veteran
Person
RequestIssue
LegacyIssue
LegacyIssueOptin
User
].include?(backfill_record_type)

errors.add(:backfill_record_type, "is not a valid backfill record")
end
end
end
1 change: 1 addition & 0 deletions app/models/higher_level_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HigherLevelReview < ClaimReview
end

has_many :remand_supplemental_claims, as: :decision_review_remanded, class_name: "SupplementalClaim"
has_one :event_record, as: :backfill_record

attr_accessor :appeal_split_process

Expand Down
2 changes: 2 additions & 0 deletions app/models/intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

class Intake < CaseflowRecord
class FormTypeNotSupported < StandardError; end
include EventConcern

belongs_to :user
belongs_to :veteran
belongs_to :detail, polymorphic: true
has_one :event_record, as: :backfill_record

COMPLETION_TIMEOUT = 5.minutes
IN_PROGRESS_EXPIRES_AFTER = 1.day
Expand Down
6 changes: 6 additions & 0 deletions app/models/legacy_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
class LegacyIssue < CaseflowRecord
belongs_to :request_issue
has_one :legacy_issue_optin
has_one :event_record, as: :backfill_record

validates :request_issue, presence: true

def from_decision_review_created_event?
# refer back to the associated Intake to see if both objects came from DRCE
request_issue&.from_decision_review_created_event?
end
end
6 changes: 6 additions & 0 deletions app/models/legacy_issue_optin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class LegacyIssueOptin < CaseflowRecord
belongs_to :request_issue
belongs_to :legacy_issue
has_one :event_record, as: :backfill_record

VACOLS_DISPOSITION_CODE = "O" # oh not zero
REMAND_DISPOSITION_CODES = %w[3 L].freeze
Expand Down Expand Up @@ -109,6 +110,11 @@ def vacols_issue
AppealRepository.issues(vacols_id).find { |issue| issue.vacols_sequence_id == vacols_sequence_id }
end

def from_decision_review_created_event?
# refer back to the associated Intake to see if both objects came from DRCE
request_issue&.from_decision_review_created_event?
end

private

def revert_open_remand_issues
Expand Down
2 changes: 2 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
class Person < CaseflowRecord
include AssociatedBgsRecord
include BgsService
include EventConcern

has_many :advance_on_docket_motions
has_many :claimants, primary_key: :participant_id, foreign_key: :participant_id
has_one :event_record, as: :backfill_record
validates :participant_id, presence: true

CACHED_BGS_ATTRIBUTES = [
Expand Down
6 changes: 6 additions & 0 deletions app/models/request_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RequestIssue < CaseflowRecord
has_many :hearing_issue_notes
has_one :legacy_issue_optin
has_many :legacy_issues
has_one :event_record, as: :backfill_record
belongs_to :correction_request_issue, class_name: "RequestIssue", foreign_key: "corrected_by_request_issue_id"
belongs_to :ineligible_due_to, class_name: "RequestIssue", foreign_key: "ineligible_due_to_id"
belongs_to :contested_decision_issue, class_name: "DecisionIssue"
Expand Down Expand Up @@ -749,6 +750,11 @@ def timely_issue?(receipt_date)
decision_date >= (receipt_date - Rating::ONE_YEAR_PLUS_DAYS)
end

def from_decision_review_created_event?
# refer back to the associated Intake to see if both objects came from DRCE
decision_review&.from_decision_review_created_event?
end

private

def create_legacy_issue!
Expand Down
1 change: 1 addition & 0 deletions app/models/supplemental_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SupplementalClaim < ClaimReview
END_PRODUCT_MODIFIERS = %w[040 041 042 043 044 045 046 047 048 049].freeze

belongs_to :decision_review_remanded, polymorphic: true
has_one :event_record, as: :backfill_record

scope :updated_since_for_appeals, lambda { |since|
select(:decision_review_remanded_id)
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class User < CaseflowRecord # rubocop:disable Metrics/ClassLength
include BgsService
include EventConcern

has_many :dispatch_tasks, class_name: "Dispatch::Task"
has_many :document_views
Expand All @@ -16,6 +17,7 @@ class User < CaseflowRecord # rubocop:disable Metrics/ClassLength
has_many :decided_membership_requests, class_name: "MembershipRequest", foreign_key: :decider_id
has_many :messages
has_many :unrecognized_appellants, foreign_key: :created_by_id
has_one :event_record, as: :backfill_record
has_one :vacols_user, class_name: "CachedUser", foreign_key: :sdomainid, primary_key: :css_id
has_one :vacols_staff, class_name: "VACOLS::Staff", foreign_key: :sdomainid, primary_key: :css_id

Expand Down
2 changes: 2 additions & 0 deletions app/models/veteran.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# rubocop:disable Metrics/ClassLength
class Veteran < CaseflowRecord
include AssociatedBgsRecord
include EventConcern

has_many :available_hearing_locations,
foreign_key: :veteran_file_number,
primary_key: :file_number, class_name: "AvailableHearingLocations"
has_one :event_record, as: :backfill_record

bgs_attr_accessor :ptcpnt_id, :sex, :address_line1, :address_line2,
:address_line3, :city, :state, :country, :zip_code,
Expand Down
9 changes: 9 additions & 0 deletions app/serializers/api/v3/issues/ama/request_issue_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class Api::V3::Issues::Ama::RequestIssueSerializer
object&.end_product_establishment&.reference_id
end

attribute :claim_errors do |object|
claim_id = object&.end_product_establishment&.reference_id
if claim_id
Event.find_errors_by_claim_id(claim_id)
else
[]
end
end

attribute :decision_issues do |object|
object.decision_issues.map do |di|
{
Expand Down
4 changes: 2 additions & 2 deletions app/services/api/v3/issues/ama/vbms_ama_dto_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def initialize(veteran, page, per_page)

def total_request_issue_count
RequestIssue.where(veteran_participant_id: @veteran_participant_id)
.where(benefit_type: %w[compensation pension fiduciary])
.where(benefit_type: %w[compensation pension])
.count
end

def serialized_request_issues(page = @page, per_page = @per_page)
serialized_data = Api::V3::Issues::Ama::RequestIssueSerializer.new(
RequestIssue.includes(:decision_issues, :decision_review)
.where(veteran_participant_id: @veteran_participant_id)
.where(benefit_type: %w[compensation pension fiduciary])
.where(benefit_type: %w[compensation pension])
.page(page).per(per_page)
).serializable_hash[:data]

Expand Down
17 changes: 17 additions & 0 deletions app/services/events/create_claimant_on_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class Events::CreateClaimantOnEvent
class << self
def process!(event:, vbms_claimant:, decision_review:)
if vbms_claimant.claim_review.veteran_is_not_claimant
claimant = Claimant.find_or_create_by!(
decision_review: decision_review,
participant_id: vbms_claimant.claimant.participant_id,
payee_code: vbms_claimant.claimant.payee_code
)
EventRecord.create!(event: event, backfill_record: claimant)
claimant
end
end
end
end
Loading
Loading