From 8f011488a2f5baa93bff0f8278d5174d3a0e8955 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Tue, 27 Feb 2024 16:24:51 -0500 Subject: [PATCH 01/17] initial commit --- app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb | 72 +++++++ lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 199 ++++++++++++++++++ .../ptcpnt_persn_id_depnt_org_fix_job_spec.rb | 81 +++++++ .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 159 ++++++++++++++ 4 files changed, 511 insertions(+) create mode 100644 app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb create mode 100644 lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb create mode 100644 spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb create mode 100644 spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb diff --git a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb new file mode 100644 index 00000000000..316c088c4ed --- /dev/null +++ b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require_relative "../../lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb" +require_relative "../../lib/helpers/master_scheduler_interface.rb" +class PtcpntPersnIdDepntOrgFixJob < CaseflowJob + include MasterSchedulerInterface + + ASSOCIATIONS = [ + BgsPowerOfAttorney, + BgsAttorney, + CavcRemandsAppellantSubstitution, + Claimant, + DecisionIssue, + EndProductEstablishment, + Notification, + Organization, + Person, + RequestIssue, + VbmsDistribution, + Veteran + ].freeze + + def initialize + @stuck_job_report_service = StuckJobReportService.new + @start_time = nil + @end_time = nil + super + end + + def error_text + "participantPersonId does not match a dependent or an organization" + end + + def perform + start_time + + loop_through_and_call_process_records + + end_time + log_processing_time + end + + def loop_through_and_call_process_records + process_records + end + + def process_records + fix_instance.start_processing_records + end + + def records_with_errors + fix_instance.error_records + end + + def log_processing_time + (@end_time && @start_time) ? @end_time - @start_time : 0 + end + + def start_time + @start_time ||= Time.zone.now + end + + def end_time + @end_time ||= Time.zone.now + end + + private + + def fix_instance + @fix_instance ||= PtcpntPersnIdDepntOrgFix.new(@stuck_job_report_service) + end +end diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb new file mode 100644 index 00000000000..37c7d875081 --- /dev/null +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -0,0 +1,199 @@ +# frozen_string_literal: true + +class PtcpntPersnIdDepntOrgFix < CaseflowJob + ERROR_TEXT = "participantPersonId does not match a dependent or an organization" + + ASSOCIATIONS = [ + BgsPowerOfAttorney, + BgsAttorney, + CavcRemandsAppellantSubstitution, + Claimant, + DecisionIssue, + EndProductEstablishment, + Notification, + Organization, + Person, + RequestIssue, + VbmsDistribution, + Veteran + ].freeze + + def initialize(stuck_job_report_service) + @stuck_job_report_service = stuck_job_report_service + end + + def start_processing_records + return if error_records.blank? + + # count of records with errors before fix + @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) + + error_records.each do |sc| + incorrect_pid = sc.claimant.participant_id + # check that claimant type is VeteranClaimant + next unless sc.claimant.type == "VeteranClaimant" + + veteran_file_number = sc.veteran.file_number + correct_pid = retrieve_correct_pid(veteran_file_number) + + handle_person_and_claimant_records(correct_pid, sc) + retrieve_records_to_fix(correct_pid, incorrect_pid) + + #Re-run job after fixing broken records + re_run_job(sc) + end + # record count with errors after fix + @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) + end + + def handle_person_and_claimant_records(correct_pid, sc) + correct_person_record = Person.find_by(participant_id: correct_pid) + incorrect_person_record = sc.claimant.person + binding.pry + ActiveRecord::Base.transaction do + if correct_person_record.present? + claimants_array_to_be_moved_to = correct_person_record.claimants + claimants_array_to_remove_claimants_from = incorrect_person_record.claimants + + claimants_array_to_be_moved_to << claimants_array_to_remove_claimants_from + + #Reset the Incorrect Person's Claimant's array before destroying Incorrect Person record + claimants_array_to_remove_claimants_from = [] + incorrect_person_record.destroy! + else + incorrect_person_record.update(participant_id: correct_pid) + end + + if sc.claimant.payee_code != "00" + sc.claimant.update(payee_code: "00") + end + + rescue StandardError => error + log_error(error) + @stuck_job_report_service.append_error(record.class.name, record.id, error) + end + end + + def retrieve_correct_pid(veteran_file_number) + begin + hash = BGSService.new.fetch_veteran_info(veteran_file_number) + hash[:ptcpnt_id] + rescue StandardError => error + message = "Error retrieving participant ID for veteran file number #{veteran_file_number}: #{error}" + @stuck_job_report_service.logs.push(message) + log_error(error) + end + end + + def retrieve_records_to_fix(correct_pid, incorrect_pid) + incorrectly_associated_records = [] + # binding.pry + # correct_person_record = Person.find_by(participant_id: correct_pid) + # incorrect_person_record = Person.find_by(participant_id: incorrect_pid) + + iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + + incorrectly_associated_records.each do |record| + fix_record(record, correct_pid) + end + end + + def re_run_job(sc) + begin + DecisionReviewProcessJob.perform_now(sc) + rescue StandardError => error + @stuck_job_report_service.append_error(sc.class.name, sc.id, error) + log_error(error) + end + end + + def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + ASSOCIATIONS.each do |ass| + if ass.attribute_names.include?("participant_id") + records = ass.where(participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + elsif ass.attribute_names.include?("claimant_participant_id") + records = ass.where(claimant_participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + elsif ass.attribute_names.include?("veteran_participant_id") + records = ass.where(veteran_participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + end + end + end + + def fix_record(record, correct_pid) + if record.attribute_names.include?("participant_id") + process_participant_id_record(record, correct_pid) + elsif record.attribute_names.include?("claimant_participant_id") + process_claimant_participant_id_record(record, correct_pid) + elsif record.attribute_names.include?("veteran_participant_id") + process_veteran_participant_id_record(record, correct_pid) + end + end + + # def discern_record(record, correct_person_record, correct_pid, incorrect_person_record) + # case record.class.name + # when "VeteranClaimant" + # process_veteran_claimant_record(record, correct_pid) + # when "Person" + # update_person_record(record, correct_person_record, correct_pid, incorrect_person_record) + # else + # process_participant_id_record(record, correct_person_record) + # end + # end + + # def process_veteran_claimant_record(record, correct_pid) + # ActiveRecord::Base.transaction do + # record.update(participant_id: correct_pid, payee_code: "00") + # rescue StandardError => error + # log_error(error) + # @stuck_job_report_service.append_error(record.class.name, record.id, error) + # end + # end + + # def update_person_record(record, correct_person_record, correct_pid, incorrect_person_record) + # ActiveRecord::Base.transaction do + # if correct_person_record.present? + # binding.pry + # incorrect_person_record.destroy! + # else + # # incorrect_person_record.update(partipcipant_id: correct_pid) + # end + # rescue StandardError => error + # log_error(error) + # @stuck_job_report_service.append_error(record.class.name, record.id, error) + # end + # end + + def process_participant_id_record(record, correct_pid) + ActiveRecord::Base.transaction do + record.update(particpant_id: correct_pid) + rescue StandardError => error + log_error(error) + @stuck_job_report_service.append_error(record.class.name, record.id, error) + end + end + + def process_claimant_participant_id_record(record, correct_pid) + ActiveRecord::Base.transaction do + record.update(claimant_participant_id: correct_pid) + rescue StandardError => error + log_error(error) + @stuck_job_report_service.append_error(record.class.name, record.id, error) + end + end + + def process_veteran_participant_id_record(record, correct_pid) + ActiveRecord::Base.transaction do + record.update(veteran_participant_id: correct_pid) + rescue StandardError => error + log_error(error) + @stuck_job_report_service.append_error(record.class.name, record.id, error) + end + end + + def error_records + SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + end +end diff --git a/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb b/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb new file mode 100644 index 00000000000..a3c96cc2156 --- /dev/null +++ b/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +describe PtcpntPersnIdDepntOrgFixJob, :postgres do + let(:error_text) { "participantPersonId does not match a dependent or an organization" } + let(:veteran_file_number) {"123456789"} + let(:correct_pid) {"654321"} + let(:end_product_establishment) { create(:end_product_establishment, claimant_participant_id: "incorrect_pid") } + let(:claimant) { create(:claimant, participant_id: "incorrect_pid", type: "VeteranClaimant", payee_code: "00") } + let!(:supplemental_claim) do + create( + :supplemental_claim, + establishment_error: error_text, + claimants: [ + claimant + ], + end_product_establishments: [ + end_product_establishment + ] + ) + end + + it_behaves_like "a Master Scheduler serializable object", PtcpntPersnIdDepntOrgFixJob + + subject { described_class.new } + + + # context "BGS Service fails" do + # before do + # # Stub BGSService to simulate an error response + # allow_any_instance_of(BGSService).to receive(:fetch_veteran_info).with(veteran_file_number) do + # raise StandardError, "Simulated BGS error" + # end + # end + # it "handles errors from BGSService and logs errors appropriately" do + # # Ensure that log_error is being called + # expect(subject).to receive(:log_error).with("Error retrieving participant ID for veteran file number #{veteran_file_number}: Simulated BGS error").at_least(:once) + # end + + # it "logs to the stuck_job_report_service" do + # expect { subject.retrieve_correct_pid(veteran_file_number) }.to change { subject.instance_variable_get(:@stuck_job_report_service).logs.count }.by(1) + # end + # end + + # context "BGS Service succeeds" do + # before do + # # Stub BGSService to simulate an error response + # allow_any_instance_of(BGSService).to receive(:fetch_veteran_info) do + # { ptcpnt_id: correct_pid } + # end + # end + # it "sends back the correct_pid" do + # subject.perform + # end + + # end + + # describe "association processing" do + # # Use factories or create test data as needed for each association + # let!(:bgs_power_of_attorney) { create(:bgs_power_of_attorney, claimant_participant_id: "incorrect_pid") } + # # Add more associations as needed + + # it "correctly identifies and processes records with incorrect participant_id for BgsPowerOfAttorney" do + # # expect(subject).to receive(:process_records).with(correct_pid, "incorrect_pid").once + # binding.pry + # subject.perform + # # binding.pry + # expect(bgs_power_of_attorney.reload.claimant_participant_id).to eq(correct_pid) + # end + + # it "correctly identifies and processes records with incorrect participant_id for Claimant" do + # expect(subject).to receive(:process_records).with(correct_pid, "incorrect_pid").once + # subject.perform + # expect(claimant.reload.participant_id).to eq(correct_pid) + # end + + # # Add more examples for other associations + # end + +end + + diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb new file mode 100644 index 00000000000..00259f08fd4 --- /dev/null +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -0,0 +1,159 @@ + +require "helpers/ptcpnt_persn_id_depnt_org_fix" + +describe PtcpntPersnIdDepntOrgFix, :postgres do + let(:error_text) { "participantPersonId does not match a dependent or an organization" } + let(:veteran_file_number) { "123456789" } + let(:correct_pid) { "654321" } + let(:incorrect_pid) { "incorrect_pid" } + let(:end_product_establishment) { create(:end_product_establishment, claimant_participant_id: incorrect_pid) } + let(:claimant) do + create( + :claimant, + participant_id: incorrect_pid, + type: "VeteranClaimant", payee_code: "00" + ) + end + # let!(:incorrect_person_record) do + # create( + # participant_id: "incorrect_pid", + # claimants: [ + # claimant + # ] + # ) + # end + # let(:incorrect_person) { create(:person, participant_id: "incorrect_pid") } + let!(:correct_person) { create(:person, participant_id: correct_pid, ssn: veteran_file_number) } + let!(:supplemental_claim) do + create( + :supplemental_claim, + establishment_error: error_text, + claimants: [ + claimant + ], + end_product_establishments: [ + end_product_establishment + ] + ) + end + let!(:stuck_job_report_service) { StuckJobReportService.new } + + subject { described_class.new(stuck_job_report_service) } + + describe "BGS Service Call" do + context "BGS Service fails" do + before do + # Stub BGSService to simulate an error response + allow_any_instance_of(BGSService).to receive(:fetch_veteran_info).with(veteran_file_number) do + fail StandardError, "Simulated BGS error" + end + end + it "handles errors from BGSService and logs errors appropriately" do + # Ensure that log_error is being called + expect(subject).to receive(:log_error).with(StandardError).at_least(:once) + subject.retrieve_correct_pid(veteran_file_number) + end + + it "logs to the stuck_job_report_service" do + expect(subject.instance_variable_get(:@stuck_job_report_service).logs).to receive(:push).with(/Error retrieving participant ID for veteran file number #{veteran_file_number}: Simulated BGS error/).at_least(:once) + subject.retrieve_correct_pid(veteran_file_number) + end + end + + context "BGS Service succeeds" do + before do + # Stub BGSService to simulate an error response + allow_any_instance_of(BGSService).to receive(:fetch_veteran_info) do + { ptcpnt_id: correct_pid } + end + end + it "sends back the correct_pid" do + subject.start_processing_records + end + end + end + + describe "Association Processing" do + before do + # Stub BGSService to simulate an error response + allow_any_instance_of(BGSService).to receive(:fetch_veteran_info) do + { ptcpnt_id: correct_pid } + end + end + + context "BgsPowerOfAttorney record" do + let!(:bgs_power_of_attorney) { create(:bgs_power_of_attorney, claimant_participant_id: "incorrect_pid") } + + it "correctly identifies and processes records with incorrect participant_id for BgsPowerOfAttorney" do + subject.start_processing_records + expect(bgs_power_of_attorney.reload.claimant_participant_id).to eq(correct_pid) + end + end + + describe '#handle_person_and_claimant_records' do + it 'handles person and claimant records' do + incorrect_person_record = supplemental_claim.claimant.person + # binding.pry + # Mocking the claimants array for incorrect_person_record + allow(incorrect_person_record).to receive(:claimants).and_return([]) + + expect { + subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + }.to change { Person.count }.by(-1) # Expect one person to be destroyed + + # binding.pry + # You can add more expectations based on your specific logic + # expect(sc.claimant.payee_code).to eq("00") + end + + context "handles person and claimant records when correct person not found" do + it 'handles person and claimant records when correct person not found' do + incorrect_person_record = supplemental_claim.claimant.person + correct_person = nil + # correct_person.reload + +binding.pry + subject.start_processing_records +binding.pry + + # expect { + # subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + # }.not_to change { Person.count } # Expect no person to be destroyed + + # You can add more expectations based on your specific logic + # expect(sc.claimant.payee_code).to eq("00") + end + + end + end + + # context "Claimant record" do + # context "On PID and payee_code" do + # it "correctly updates participant ID" do + # binding.pry + # subject.start_processing_records + # binding.pry + # expect(claimant.reload.participant_id).to eq(correct_pid) + # end + + # it "correctly updates payee_code" do + # claimant.update(payee_code: nil) + # subject.start_processing_records + # expect(claimant.reload.payee_code).to eq("00") + # end + # end + # end + + # context "Person record" do + # context "Correct Person exists" do + # it "detroys the incorrect Person record" do + # # binding.pry + # subject.start_processing_records + # # expect { incorrect_person_record.destroy! }.to change { Person.count }.by(-1) + # end + # end + # end + + # Add more examples for other associations + end +end From 550191deaa1ebd310f625df47606fd902996201f Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Wed, 28 Feb 2024 13:13:50 -0500 Subject: [PATCH 02/17] spec commit --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 17 +++-- .../ptcpnt_persn_id_depnt_org_fix_job_spec.rb | 76 ------------------- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 46 +++++------ 3 files changed, 33 insertions(+), 106 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 37c7d875081..0ae8fdc8d84 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -47,9 +47,9 @@ def start_processing_records end def handle_person_and_claimant_records(correct_pid, sc) - correct_person_record = Person.find_by(participant_id: correct_pid) + correct_person_record = get_correct_person(correct_pid) incorrect_person_record = sc.claimant.person - binding.pry + ActiveRecord::Base.transaction do if correct_person_record.present? claimants_array_to_be_moved_to = correct_person_record.claimants @@ -61,19 +61,27 @@ def handle_person_and_claimant_records(correct_pid, sc) claimants_array_to_remove_claimants_from = [] incorrect_person_record.destroy! else + # binding.pry incorrect_person_record.update(participant_id: correct_pid) + puts "Validation errors: #{incorrect_person_record.errors.full_messages}" end + # binding.pry if sc.claimant.payee_code != "00" sc.claimant.update(payee_code: "00") end + # binding.pry rescue StandardError => error log_error(error) - @stuck_job_report_service.append_error(record.class.name, record.id, error) + @stuck_job_report_service.append_error(sc.class.name, sc.id, error) end end + def get_correct_person(correct_pid) + Person.find_by(participant_id: correct_pid) + end + def retrieve_correct_pid(veteran_file_number) begin hash = BGSService.new.fetch_veteran_info(veteran_file_number) @@ -87,7 +95,6 @@ def retrieve_correct_pid(veteran_file_number) def retrieve_records_to_fix(correct_pid, incorrect_pid) incorrectly_associated_records = [] - # binding.pry # correct_person_record = Person.find_by(participant_id: correct_pid) # incorrect_person_record = Person.find_by(participant_id: incorrect_pid) @@ -155,7 +162,7 @@ def fix_record(record, correct_pid) # def update_person_record(record, correct_person_record, correct_pid, incorrect_person_record) # ActiveRecord::Base.transaction do # if correct_person_record.present? - # binding.pry + # incorrect_person_record.destroy! # else # # incorrect_person_record.update(partipcipant_id: correct_pid) diff --git a/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb b/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb index a3c96cc2156..aa2396413c9 100644 --- a/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb +++ b/spec/jobs/ptcpnt_persn_id_depnt_org_fix_job_spec.rb @@ -1,81 +1,5 @@ # frozen_string_literal: true describe PtcpntPersnIdDepntOrgFixJob, :postgres do - let(:error_text) { "participantPersonId does not match a dependent or an organization" } - let(:veteran_file_number) {"123456789"} - let(:correct_pid) {"654321"} - let(:end_product_establishment) { create(:end_product_establishment, claimant_participant_id: "incorrect_pid") } - let(:claimant) { create(:claimant, participant_id: "incorrect_pid", type: "VeteranClaimant", payee_code: "00") } - let!(:supplemental_claim) do - create( - :supplemental_claim, - establishment_error: error_text, - claimants: [ - claimant - ], - end_product_establishments: [ - end_product_establishment - ] - ) - end - it_behaves_like "a Master Scheduler serializable object", PtcpntPersnIdDepntOrgFixJob - - subject { described_class.new } - - - # context "BGS Service fails" do - # before do - # # Stub BGSService to simulate an error response - # allow_any_instance_of(BGSService).to receive(:fetch_veteran_info).with(veteran_file_number) do - # raise StandardError, "Simulated BGS error" - # end - # end - # it "handles errors from BGSService and logs errors appropriately" do - # # Ensure that log_error is being called - # expect(subject).to receive(:log_error).with("Error retrieving participant ID for veteran file number #{veteran_file_number}: Simulated BGS error").at_least(:once) - # end - - # it "logs to the stuck_job_report_service" do - # expect { subject.retrieve_correct_pid(veteran_file_number) }.to change { subject.instance_variable_get(:@stuck_job_report_service).logs.count }.by(1) - # end - # end - - # context "BGS Service succeeds" do - # before do - # # Stub BGSService to simulate an error response - # allow_any_instance_of(BGSService).to receive(:fetch_veteran_info) do - # { ptcpnt_id: correct_pid } - # end - # end - # it "sends back the correct_pid" do - # subject.perform - # end - - # end - - # describe "association processing" do - # # Use factories or create test data as needed for each association - # let!(:bgs_power_of_attorney) { create(:bgs_power_of_attorney, claimant_participant_id: "incorrect_pid") } - # # Add more associations as needed - - # it "correctly identifies and processes records with incorrect participant_id for BgsPowerOfAttorney" do - # # expect(subject).to receive(:process_records).with(correct_pid, "incorrect_pid").once - # binding.pry - # subject.perform - # # binding.pry - # expect(bgs_power_of_attorney.reload.claimant_participant_id).to eq(correct_pid) - # end - - # it "correctly identifies and processes records with incorrect participant_id for Claimant" do - # expect(subject).to receive(:process_records).with(correct_pid, "incorrect_pid").once - # subject.perform - # expect(claimant.reload.participant_id).to eq(correct_pid) - # end - - # # Add more examples for other associations - # end - end - - diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index 00259f08fd4..1769c5043f4 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -23,7 +23,7 @@ # ) # end # let(:incorrect_person) { create(:person, participant_id: "incorrect_pid") } - let!(:correct_person) { create(:person, participant_id: correct_pid, ssn: veteran_file_number) } + let(:correct_person) { create(:person, participant_id: correct_pid, ssn: veteran_file_number) } let!(:supplemental_claim) do create( :supplemental_claim, @@ -91,40 +91,36 @@ end describe '#handle_person_and_claimant_records' do - it 'handles person and claimant records' do - incorrect_person_record = supplemental_claim.claimant.person - # binding.pry - # Mocking the claimants array for incorrect_person_record - allow(incorrect_person_record).to receive(:claimants).and_return([]) - + it 'handles person records' do + correct_person expect { subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) }.to change { Person.count }.by(-1) # Expect one person to be destroyed + end - # binding.pry - # You can add more expectations based on your specific logic - # expect(sc.claimant.payee_code).to eq("00") + it 'updates supplemental_claim to the correct claimant' do + correct_person + subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + supplemental_claim.reload + expect(supplemental_claim.claimant.participant_id).to eq(correct_pid) end - context "handles person and claimant records when correct person not found" do - it 'handles person and claimant records when correct person not found' do - incorrect_person_record = supplemental_claim.claimant.person - correct_person = nil - # correct_person.reload + it 'updates supplemental_claim to the correct person' do + correct_person + subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + supplemental_claim.reload + expect(supplemental_claim.claimant.person.participant_id).to eq(correct_pid) + end -binding.pry - subject.start_processing_records -binding.pry + it 'handles person and claimant records when correct person not found' do + allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + expect { + subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + }.not_to change { Person.count } # Expect no person to be destroyed + end - # expect { - # subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - # }.not_to change { Person.count } # Expect no person to be destroyed - # You can add more expectations based on your specific logic - # expect(sc.claimant.payee_code).to eq("00") - end - end end # context "Claimant record" do From 83d2afd92218e4c41ffefdd26ad9da7e6c6b687c Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Wed, 28 Feb 2024 13:45:49 -0500 Subject: [PATCH 03/17] added specs --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 40 +-------------- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 50 ++++++++----------- 2 files changed, 21 insertions(+), 69 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 0ae8fdc8d84..265999117eb 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -61,16 +61,12 @@ def handle_person_and_claimant_records(correct_pid, sc) claimants_array_to_remove_claimants_from = [] incorrect_person_record.destroy! else - # binding.pry incorrect_person_record.update(participant_id: correct_pid) - puts "Validation errors: #{incorrect_person_record.errors.full_messages}" end - # binding.pry if sc.claimant.payee_code != "00" sc.claimant.update(payee_code: "00") end - # binding.pry rescue StandardError => error log_error(error) @@ -139,43 +135,9 @@ def fix_record(record, correct_pid) end end - # def discern_record(record, correct_person_record, correct_pid, incorrect_person_record) - # case record.class.name - # when "VeteranClaimant" - # process_veteran_claimant_record(record, correct_pid) - # when "Person" - # update_person_record(record, correct_person_record, correct_pid, incorrect_person_record) - # else - # process_participant_id_record(record, correct_person_record) - # end - # end - - # def process_veteran_claimant_record(record, correct_pid) - # ActiveRecord::Base.transaction do - # record.update(participant_id: correct_pid, payee_code: "00") - # rescue StandardError => error - # log_error(error) - # @stuck_job_report_service.append_error(record.class.name, record.id, error) - # end - # end - - # def update_person_record(record, correct_person_record, correct_pid, incorrect_person_record) - # ActiveRecord::Base.transaction do - # if correct_person_record.present? - - # incorrect_person_record.destroy! - # else - # # incorrect_person_record.update(partipcipant_id: correct_pid) - # end - # rescue StandardError => error - # log_error(error) - # @stuck_job_report_service.append_error(record.class.name, record.id, error) - # end - # end - def process_participant_id_record(record, correct_pid) ActiveRecord::Base.transaction do - record.update(particpant_id: correct_pid) + record.update(participant_id: correct_pid) rescue StandardError => error log_error(error) @stuck_job_report_service.append_error(record.class.name, record.id, error) diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index 1769c5043f4..43cddf9a264 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -73,6 +73,14 @@ end end + describe "Claimant is not VeteranClaimant" do + it "does NOT remediate the record" do + supplemental_claim.claimant.update(type: "DependentClaimant") + subject.start_processing_records + expect(supplemental_claim.reload.establishment_error).to eq(error_text) + end + end + describe "Association Processing" do before do # Stub BGSService to simulate an error response @@ -90,6 +98,7 @@ end end + describe '#handle_person_and_claimant_records' do it 'handles person records' do correct_person @@ -119,37 +128,18 @@ }.not_to change { Person.count } # Expect no person to be destroyed end + it 'updates incorrect person when correct person not found' do + allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + subject.start_processing_records + expect(supplemental_claim.claimant.person.reload.participant_id).to eq(correct_pid) + end - + it 'updates payee_code if not 00' do + allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + supplemental_claim.claimant.payee_code = nil + subject.start_processing_records + expect(supplemental_claim.claimant.payee_code).to eq("00") + end end - - # context "Claimant record" do - # context "On PID and payee_code" do - # it "correctly updates participant ID" do - # binding.pry - # subject.start_processing_records - # binding.pry - # expect(claimant.reload.participant_id).to eq(correct_pid) - # end - - # it "correctly updates payee_code" do - # claimant.update(payee_code: nil) - # subject.start_processing_records - # expect(claimant.reload.payee_code).to eq("00") - # end - # end - # end - - # context "Person record" do - # context "Correct Person exists" do - # it "detroys the incorrect Person record" do - # # binding.pry - # subject.start_processing_records - # # expect { incorrect_person_record.destroy! }.to change { Person.count }.by(-1) - # end - # end - # end - - # Add more examples for other associations end end From d122b5e29b615a87da22c162442df0a960acb941 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Wed, 28 Feb 2024 15:17:07 -0500 Subject: [PATCH 04/17] added more specs --- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index 43cddf9a264..dad9acdbe25 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -98,6 +98,52 @@ end end + context "EndProductEstablishment record" do + let!(:epe) { create( + :end_product_establishment, + claimant_participant_id: "incorrect_pid", + source_id: supplemental_claim.id, + source_type: "SupplementalClaim" + ) } + + it "correctly identifies and processes records with incorrect participant_id for EndProductEstablishment" do + subject.start_processing_records + expect(epe.reload.claimant_participant_id).to eq(correct_pid) + end + end + + context "EndProductEstablishment record" do + let!(:epe) { create( + :end_product_establishment, + claimant_participant_id: "incorrect_pid", + source_id: supplemental_claim.id, + source_type: "SupplementalClaim" + ) } + + it "correctly identifies and processes records with incorrect participant_id for EndProductEstablishment" do + subject.start_processing_records + expect(epe.reload.claimant_participant_id).to eq(correct_pid) + end + end + + context "Organization record" do + let!(:organization) { create(:organization, participant_id: incorrect_pid) } + + it "correctly identifies and processes records with incorrect participant_id for Organization" do + subject.start_processing_records + expect(organization.reload.participant_id).to eq(correct_pid) + end + end + + context "RequestIssue record" do + let!(:request_issue) { create(:request_issue, veteran_participant_id: incorrect_pid) } + + it "correctly identifies and processes records with incorrect participant_id for RequestIssue" do + subject.start_processing_records + expect(request_issue.reload.veteran_participant_id).to eq(correct_pid) + end + end + describe '#handle_person_and_claimant_records' do it 'handles person records' do From 1b2583118ad8f98ff713dc091a3b79d6093e3abb Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Wed, 28 Feb 2024 15:43:57 -0500 Subject: [PATCH 05/17] rubocopped --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 38 +++++----- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 71 ++++++++++--------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 265999117eb..c3929863cf1 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -28,27 +28,27 @@ def start_processing_records # count of records with errors before fix @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) - error_records.each do |sc| - incorrect_pid = sc.claimant.participant_id + error_records.each do |supp_claim| + incorrect_pid = supp_claim.claimant.participant_id # check that claimant type is VeteranClaimant - next unless sc.claimant.type == "VeteranClaimant" + next unless supp_claim.claimant.type == "VeteranClaimant" - veteran_file_number = sc.veteran.file_number + veteran_file_number = supp_claim.veteran.file_number correct_pid = retrieve_correct_pid(veteran_file_number) - handle_person_and_claimant_records(correct_pid, sc) + handle_person_and_claimant_records(correct_pid, supp_claim) retrieve_records_to_fix(correct_pid, incorrect_pid) - #Re-run job after fixing broken records - re_run_job(sc) + # Re-run job after fixing broken records + re_run_job(supp_claim) end # record count with errors after fix @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) end - def handle_person_and_claimant_records(correct_pid, sc) + def handle_person_and_claimant_records(correct_pid, supp_claim) correct_person_record = get_correct_person(correct_pid) - incorrect_person_record = sc.claimant.person + incorrect_person_record = supp_claim.claimant.person ActiveRecord::Base.transaction do if correct_person_record.present? @@ -57,20 +57,22 @@ def handle_person_and_claimant_records(correct_pid, sc) claimants_array_to_be_moved_to << claimants_array_to_remove_claimants_from - #Reset the Incorrect Person's Claimant's array before destroying Incorrect Person record - claimants_array_to_remove_claimants_from = [] + # Reset the Incorrect Person's Claimant's array before destroying the Incorrect Person record + incorrect_person_record.claimants.clear + + incorrect_person_record.save! incorrect_person_record.destroy! else incorrect_person_record.update(participant_id: correct_pid) end - if sc.claimant.payee_code != "00" - sc.claimant.update(payee_code: "00") + if supp_claim.claimant.payee_code != "00" + supp_claim.claimant.update(payee_code: "00") end rescue StandardError => error log_error(error) - @stuck_job_report_service.append_error(sc.class.name, sc.id, error) + @stuck_job_report_service.append_error(supp_claim.class.name, supp_claim.id, error) end end @@ -91,8 +93,6 @@ def retrieve_correct_pid(veteran_file_number) def retrieve_records_to_fix(correct_pid, incorrect_pid) incorrectly_associated_records = [] - # correct_person_record = Person.find_by(participant_id: correct_pid) - # incorrect_person_record = Person.find_by(participant_id: incorrect_pid) iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) @@ -101,11 +101,11 @@ def retrieve_records_to_fix(correct_pid, incorrect_pid) end end - def re_run_job(sc) + def re_run_job(supp_claim) begin - DecisionReviewProcessJob.perform_now(sc) + DecisionReviewProcessJob.perform_now(supp_claim) rescue StandardError => error - @stuck_job_report_service.append_error(sc.class.name, sc.id, error) + @stuck_job_report_service.append_error(supp_claim.class.name, supp_claim.id, error) log_error(error) end end diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index dad9acdbe25..6c47a8d5cc7 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "helpers/ptcpnt_persn_id_depnt_org_fix" @@ -14,15 +15,6 @@ type: "VeteranClaimant", payee_code: "00" ) end - # let!(:incorrect_person_record) do - # create( - # participant_id: "incorrect_pid", - # claimants: [ - # claimant - # ] - # ) - # end - # let(:incorrect_person) { create(:person, participant_id: "incorrect_pid") } let(:correct_person) { create(:person, participant_id: correct_pid, ssn: veteran_file_number) } let!(:supplemental_claim) do create( @@ -55,7 +47,13 @@ end it "logs to the stuck_job_report_service" do - expect(subject.instance_variable_get(:@stuck_job_report_service).logs).to receive(:push).with(/Error retrieving participant ID for veteran file number #{veteran_file_number}: Simulated BGS error/).at_least(:once) + logs = subject.instance_variable_get(:@stuck_job_report_service).logs + message_1 = "Error retrieving participant ID for veteran file " + message_2 = "number #{veteran_file_number}: Simulated BGS error" + error_message = message_1 + message_2 + + expect(logs).to receive(:push).with(error_message).at_least(:once) + subject.retrieve_correct_pid(veteran_file_number) end end @@ -99,12 +97,14 @@ end context "EndProductEstablishment record" do - let!(:epe) { create( - :end_product_establishment, - claimant_participant_id: "incorrect_pid", - source_id: supplemental_claim.id, - source_type: "SupplementalClaim" - ) } + let!(:epe) do + create( + :end_product_establishment, + claimant_participant_id: "incorrect_pid", + source_id: supplemental_claim.id, + source_type: "SupplementalClaim" + ) + end it "correctly identifies and processes records with incorrect participant_id for EndProductEstablishment" do subject.start_processing_records @@ -113,12 +113,14 @@ end context "EndProductEstablishment record" do - let!(:epe) { create( - :end_product_establishment, - claimant_participant_id: "incorrect_pid", - source_id: supplemental_claim.id, - source_type: "SupplementalClaim" - ) } + let!(:epe) do + create( + :end_product_establishment, + claimant_participant_id: "incorrect_pid", + source_id: supplemental_claim.id, + source_type: "SupplementalClaim" + ) + end it "correctly identifies and processes records with incorrect participant_id for EndProductEstablishment" do subject.start_processing_records @@ -144,43 +146,42 @@ end end - - describe '#handle_person_and_claimant_records' do - it 'handles person records' do + describe "#handle_person_and_claimant_records" do + it "handles person records" do correct_person - expect { + expect do subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - }.to change { Person.count }.by(-1) # Expect one person to be destroyed + end.to change { Person.count }.by(-1) # Expect one person to be destroyed end - it 'updates supplemental_claim to the correct claimant' do + it "updates supplemental_claim to the correct claimant" do correct_person subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) supplemental_claim.reload expect(supplemental_claim.claimant.participant_id).to eq(correct_pid) end - it 'updates supplemental_claim to the correct person' do + it "updates supplemental_claim to the correct person" do correct_person subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) supplemental_claim.reload expect(supplemental_claim.claimant.person.participant_id).to eq(correct_pid) end - it 'handles person and claimant records when correct person not found' do + it "handles person and claimant records when correct person not found" do allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) - expect { - subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - }.not_to change { Person.count } # Expect no person to be destroyed + expect do + subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) + end.not_to(change { Person.count }) # Expect no person to be destroyed end - it 'updates incorrect person when correct person not found' do + it "updates incorrect person when correct person not found" do allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) subject.start_processing_records expect(supplemental_claim.claimant.person.reload.participant_id).to eq(correct_pid) end - it 'updates payee_code if not 00' do + it "updates payee_code if not 00" do allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) supplemental_claim.claimant.payee_code = nil subject.start_processing_records From e6450dcc5659e478b287c731b8c45c2b2daebc4a Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Thu, 29 Feb 2024 08:00:01 -0500 Subject: [PATCH 06/17] code climate --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 10 ++++++---- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 16 ---------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index c3929863cf1..599d274a81d 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -135,6 +135,12 @@ def fix_record(record, correct_pid) end end + def error_records + SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + end + + private + def process_participant_id_record(record, correct_pid) ActiveRecord::Base.transaction do record.update(participant_id: correct_pid) @@ -161,8 +167,4 @@ def process_veteran_participant_id_record(record, correct_pid) @stuck_job_report_service.append_error(record.class.name, record.id, error) end end - - def error_records - SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") - end end diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index 6c47a8d5cc7..aa1ecf4ee1f 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -112,22 +112,6 @@ end end - context "EndProductEstablishment record" do - let!(:epe) do - create( - :end_product_establishment, - claimant_participant_id: "incorrect_pid", - source_id: supplemental_claim.id, - source_type: "SupplementalClaim" - ) - end - - it "correctly identifies and processes records with incorrect participant_id for EndProductEstablishment" do - subject.start_processing_records - expect(epe.reload.claimant_participant_id).to eq(correct_pid) - end - end - context "Organization record" do let!(:organization) { create(:organization, participant_id: incorrect_pid) } From b9ab999c43e23a9038faac85474deca2e1b98770 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Thu, 29 Feb 2024 08:59:37 -0500 Subject: [PATCH 07/17] code climate fixes --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 56 ++++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 599d274a81d..e99697819ac 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -52,27 +52,16 @@ def handle_person_and_claimant_records(correct_pid, supp_claim) ActiveRecord::Base.transaction do if correct_person_record.present? - claimants_array_to_be_moved_to = correct_person_record.claimants - claimants_array_to_remove_claimants_from = incorrect_person_record.claimants - - claimants_array_to_be_moved_to << claimants_array_to_remove_claimants_from - - # Reset the Incorrect Person's Claimant's array before destroying the Incorrect Person record - incorrect_person_record.claimants.clear - - incorrect_person_record.save! - incorrect_person_record.destroy! + move_claimants_to_correct_person(correct_person_record, incorrect_person_record) + destroy_incorrect_person_record(incorrect_person_record) + # binding.pry else - incorrect_person_record.update(participant_id: correct_pid) - end - - if supp_claim.claimant.payee_code != "00" - supp_claim.claimant.update(payee_code: "00") + update_incorrect_person_record_participant_id(incorrect_person_record, correct_pid) end + update_claimant_payee_code(supp_claim.claimant, "00") rescue StandardError => error - log_error(error) - @stuck_job_report_service.append_error(supp_claim.class.name, supp_claim.id, error) + handle_error(error, supp_claim) end end @@ -115,6 +104,7 @@ def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associa if ass.attribute_names.include?("participant_id") records = ass.where(participant_id: incorrect_pid) incorrectly_associated_records.push(*records) + elsif ass.attribute_names.include?("claimant_participant_id") records = ass.where(claimant_participant_id: incorrect_pid) incorrectly_associated_records.push(*records) @@ -141,12 +131,34 @@ def error_records private + def move_claimants_to_correct_person(correct_person, incorrect_person) + correct_person.claimants << incorrect_person.claimants + incorrect_person.claimants.clear + incorrect_person.save! + end + + def destroy_incorrect_person_record(incorrect_person) + incorrect_person.destroy! + end + + def update_incorrect_person_record_participant_id(incorrect_person, new_participant_id) + incorrect_person.update(participant_id: new_participant_id) + end + + def update_claimant_payee_code(claimant, new_payee_code) + claimant.update(payee_code: new_payee_code) if claimant.payee_code != new_payee_code + end + + def handle_error(error, record) + log_error(error) + @stuck_job_report_service.append_error(record.class.name, record.id, error) + end + def process_participant_id_record(record, correct_pid) ActiveRecord::Base.transaction do record.update(participant_id: correct_pid) rescue StandardError => error - log_error(error) - @stuck_job_report_service.append_error(record.class.name, record.id, error) + handle_error(error, record) end end @@ -154,8 +166,7 @@ def process_claimant_participant_id_record(record, correct_pid) ActiveRecord::Base.transaction do record.update(claimant_participant_id: correct_pid) rescue StandardError => error - log_error(error) - @stuck_job_report_service.append_error(record.class.name, record.id, error) + handle_error(error, record) end end @@ -163,8 +174,7 @@ def process_veteran_participant_id_record(record, correct_pid) ActiveRecord::Base.transaction do record.update(veteran_participant_id: correct_pid) rescue StandardError => error - log_error(error) - @stuck_job_report_service.append_error(record.class.name, record.id, error) + handle_error(error, record) end end end From 27ff9a1e6802fe143eba43f63bec7c777dd5249e Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Thu, 29 Feb 2024 10:28:09 -0500 Subject: [PATCH 08/17] uitlity function fix --- app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb | 2 +- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb index 316c088c4ed..9f52292df15 100644 --- a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb +++ b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb @@ -49,7 +49,7 @@ def process_records end def records_with_errors - fix_instance.error_records + fix_instance.class.error_records end def log_processing_time diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index e99697819ac..7117eff9962 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -125,7 +125,7 @@ def fix_record(record, correct_pid) end end - def error_records + def self.error_records SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") end From 8bd61b37f46b054ada8a15b450e29032bb6dcf0e Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Thu, 29 Feb 2024 11:10:06 -0500 Subject: [PATCH 09/17] more code climates fixes --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 33 +++++++++++-------- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 6 ++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 7117eff9962..1cbfc9ae5a2 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -22,13 +22,17 @@ def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service end + def class_self + PtcpntPersnIdDepntOrgFix + end + def start_processing_records - return if error_records.blank? + return if class_self.error_records.blank? # count of records with errors before fix - @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) + @stuck_job_report_service.append_record_count(class_self.error_records.count, ERROR_TEXT) - error_records.each do |supp_claim| + class_self.error_records.each do |supp_claim| incorrect_pid = supp_claim.claimant.participant_id # check that claimant type is VeteranClaimant next unless supp_claim.claimant.type == "VeteranClaimant" @@ -43,11 +47,12 @@ def start_processing_records re_run_job(supp_claim) end # record count with errors after fix - @stuck_job_report_service.append_record_count(error_records.count, ERROR_TEXT) + @stuck_job_report_service.append_record_count(class_self.error_records.count, ERROR_TEXT) end def handle_person_and_claimant_records(correct_pid, supp_claim) - correct_person_record = get_correct_person(correct_pid) + correct_person_record = class_self.get_correct_person(correct_pid) + incorrect_person_record = supp_claim.claimant.person ActiveRecord::Base.transaction do @@ -65,7 +70,7 @@ def handle_person_and_claimant_records(correct_pid, supp_claim) end end - def get_correct_person(correct_pid) + def self.get_correct_person(correct_pid) Person.find_by(participant_id: correct_pid) end @@ -83,7 +88,7 @@ def retrieve_correct_pid(veteran_file_number) def retrieve_records_to_fix(correct_pid, incorrect_pid) incorrectly_associated_records = [] - iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + class_self.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) incorrectly_associated_records.each do |record| fix_record(record, correct_pid) @@ -99,7 +104,7 @@ def re_run_job(supp_claim) end end - def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + def self.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) ASSOCIATIONS.each do |ass| if ass.attribute_names.include?("participant_id") records = ass.where(participant_id: incorrect_pid) @@ -115,6 +120,12 @@ def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associa end end + def self.error_records + SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + end + + private + def fix_record(record, correct_pid) if record.attribute_names.include?("participant_id") process_participant_id_record(record, correct_pid) @@ -125,12 +136,6 @@ def fix_record(record, correct_pid) end end - def self.error_records - SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") - end - - private - def move_claimants_to_correct_person(correct_person, incorrect_person) correct_person.claimants << incorrect_person.claimants incorrect_person.claimants.clear diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index aa1ecf4ee1f..d52f463c031 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -153,20 +153,20 @@ end it "handles person and claimant records when correct person not found" do - allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) expect do subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) end.not_to(change { Person.count }) # Expect no person to be destroyed end it "updates incorrect person when correct person not found" do - allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) subject.start_processing_records expect(supplemental_claim.claimant.person.reload.participant_id).to eq(correct_pid) end it "updates payee_code if not 00" do - allow(subject).to receive(:get_correct_person).with(correct_pid).and_return(nil) + allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) supplemental_claim.claimant.payee_code = nil subject.start_processing_records expect(supplemental_claim.claimant.payee_code).to eq("00") From 381b8725a01e7ac41a56b7f3ce17b021a9ee285a Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Thu, 29 Feb 2024 11:39:35 -0500 Subject: [PATCH 10/17] refactor and code climate --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 35 ++++++-------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 1cbfc9ae5a2..0d29b0131ce 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -120,22 +120,17 @@ def self.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_as end end + def fix_record(record, correct_pid) + attribute_name = determine_attribute_name(record) + process_record(record, attribute_name, correct_pid) + end + def self.error_records SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") end private - def fix_record(record, correct_pid) - if record.attribute_names.include?("participant_id") - process_participant_id_record(record, correct_pid) - elsif record.attribute_names.include?("claimant_participant_id") - process_claimant_participant_id_record(record, correct_pid) - elsif record.attribute_names.include?("veteran_participant_id") - process_veteran_participant_id_record(record, correct_pid) - end - end - def move_claimants_to_correct_person(correct_person, incorrect_person) correct_person.claimants << incorrect_person.claimants incorrect_person.claimants.clear @@ -159,25 +154,15 @@ def handle_error(error, record) @stuck_job_report_service.append_error(record.class.name, record.id, error) end - def process_participant_id_record(record, correct_pid) - ActiveRecord::Base.transaction do - record.update(participant_id: correct_pid) - rescue StandardError => error - handle_error(error, record) - end - end - - def process_claimant_participant_id_record(record, correct_pid) - ActiveRecord::Base.transaction do - record.update(claimant_participant_id: correct_pid) - rescue StandardError => error - handle_error(error, record) + def determine_attribute_name(record) + record.attribute_names.find do |attribute_name| + %w[participant_id claimant_participant_id veteran_participant_id].include?(attribute_name) end end - def process_veteran_participant_id_record(record, correct_pid) + def process_record(record, attribute_name, correct_pid) ActiveRecord::Base.transaction do - record.update(veteran_participant_id: correct_pid) + record.update(attribute_name => correct_pid) rescue StandardError => error handle_error(error, record) end From 731e2b7679507d14ff05a6659d7669dda9c3b391 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Fri, 1 Mar 2024 10:52:55 -0500 Subject: [PATCH 11/17] spec updates and copped --- app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb | 2 - lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 106 +++++++++--------- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 67 ++++++----- 3 files changed, 91 insertions(+), 84 deletions(-) diff --git a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb index 9f52292df15..f43930895ab 100644 --- a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb +++ b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb @@ -22,8 +22,6 @@ class PtcpntPersnIdDepntOrgFixJob < CaseflowJob def initialize @stuck_job_report_service = StuckJobReportService.new - @start_time = nil - @end_time = nil super end diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 0d29b0131ce..ccce33729e5 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -22,46 +22,72 @@ def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service end - def class_self - PtcpntPersnIdDepntOrgFix - end - def start_processing_records - return if class_self.error_records.blank? + return if self.class.error_records.blank? # count of records with errors before fix - @stuck_job_report_service.append_record_count(class_self.error_records.count, ERROR_TEXT) + @stuck_job_report_service.append_record_count(self.class.error_records.count, ERROR_TEXT) - class_self.error_records.each do |supp_claim| + self.class.error_records.each do |supp_claim| incorrect_pid = supp_claim.claimant.participant_id # check that claimant type is VeteranClaimant next unless supp_claim.claimant.type == "VeteranClaimant" veteran_file_number = supp_claim.veteran.file_number - correct_pid = retrieve_correct_pid(veteran_file_number) + @correct_pid = retrieve_correct_pid(veteran_file_number) - handle_person_and_claimant_records(correct_pid, supp_claim) - retrieve_records_to_fix(correct_pid, incorrect_pid) + handle_person_and_claimant_records(supp_claim) + retrieve_records_to_fix(incorrect_pid) + @stuck_job_report_service.append_single_record(supp_claim.class.name, supp_claim.id) # Re-run job after fixing broken records re_run_job(supp_claim) end # record count with errors after fix - @stuck_job_report_service.append_record_count(class_self.error_records.count, ERROR_TEXT) - end + @stuck_job_report_service.append_record_count(self.class.error_records.count, ERROR_TEXT) + end + + class << self + # def get_correct_person(correct_pid) + # Person.find_by(participant_id: correct_pid) + # end + + def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + ASSOCIATIONS.each do |ass| + if ass.attribute_names.include?("participant_id") + records = ass.where(participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + + elsif ass.attribute_names.include?("claimant_participant_id") + records = ass.where(claimant_participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + elsif ass.attribute_names.include?("veteran_participant_id") + records = ass.where(veteran_participant_id: incorrect_pid) + incorrectly_associated_records.push(*records) + end + end + end - def handle_person_and_claimant_records(correct_pid, supp_claim) - correct_person_record = class_self.get_correct_person(correct_pid) + def error_records + SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + end +end + + private + + def correct_person + Person.find_by(participant_id: @correct_pid) + end + def handle_person_and_claimant_records(supp_claim) incorrect_person_record = supp_claim.claimant.person ActiveRecord::Base.transaction do - if correct_person_record.present? - move_claimants_to_correct_person(correct_person_record, incorrect_person_record) + if correct_person.present? + move_claimants_to_correct_person(correct_person, incorrect_person_record) destroy_incorrect_person_record(incorrect_person_record) - # binding.pry else - update_incorrect_person_record_participant_id(incorrect_person_record, correct_pid) + update_incorrect_person_record_participant_id(incorrect_person_record) end update_claimant_payee_code(supp_claim.claimant, "00") @@ -70,10 +96,6 @@ def handle_person_and_claimant_records(correct_pid, supp_claim) end end - def self.get_correct_person(correct_pid) - Person.find_by(participant_id: correct_pid) - end - def retrieve_correct_pid(veteran_file_number) begin hash = BGSService.new.fetch_veteran_info(veteran_file_number) @@ -85,13 +107,13 @@ def retrieve_correct_pid(veteran_file_number) end end - def retrieve_records_to_fix(correct_pid, incorrect_pid) + def retrieve_records_to_fix(incorrect_pid) incorrectly_associated_records = [] - class_self.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + self.class.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) incorrectly_associated_records.each do |record| - fix_record(record, correct_pid) + fix_record(record) end end @@ -104,33 +126,11 @@ def re_run_job(supp_claim) end end - def self.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) - ASSOCIATIONS.each do |ass| - if ass.attribute_names.include?("participant_id") - records = ass.where(participant_id: incorrect_pid) - incorrectly_associated_records.push(*records) - - elsif ass.attribute_names.include?("claimant_participant_id") - records = ass.where(claimant_participant_id: incorrect_pid) - incorrectly_associated_records.push(*records) - elsif ass.attribute_names.include?("veteran_participant_id") - records = ass.where(veteran_participant_id: incorrect_pid) - incorrectly_associated_records.push(*records) - end - end - end - - def fix_record(record, correct_pid) + def fix_record(record) attribute_name = determine_attribute_name(record) - process_record(record, attribute_name, correct_pid) - end - - def self.error_records - SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + process_record(record, attribute_name) end - private - def move_claimants_to_correct_person(correct_person, incorrect_person) correct_person.claimants << incorrect_person.claimants incorrect_person.claimants.clear @@ -141,8 +141,8 @@ def destroy_incorrect_person_record(incorrect_person) incorrect_person.destroy! end - def update_incorrect_person_record_participant_id(incorrect_person, new_participant_id) - incorrect_person.update(participant_id: new_participant_id) + def update_incorrect_person_record_participant_id(incorrect_person) + incorrect_person.update(participant_id: @correct_pid) end def update_claimant_payee_code(claimant, new_payee_code) @@ -160,9 +160,9 @@ def determine_attribute_name(record) end end - def process_record(record, attribute_name, correct_pid) + def process_record(record, attribute_name) ActiveRecord::Base.transaction do - record.update(attribute_name => correct_pid) + record.update(attribute_name => @correct_pid) rescue StandardError => error handle_error(error, record) end diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index d52f463c031..76570d44448 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -5,9 +5,16 @@ describe PtcpntPersnIdDepntOrgFix, :postgres do let(:error_text) { "participantPersonId does not match a dependent or an organization" } let(:veteran_file_number) { "123456789" } + let!(:veteran) { create(:veteran, file_number: veteran_file_number) } let(:correct_pid) { "654321" } let(:incorrect_pid) { "incorrect_pid" } - let(:end_product_establishment) { create(:end_product_establishment, claimant_participant_id: incorrect_pid) } + let(:end_product_establishment) do + create( + :end_product_establishment, + claimant_participant_id: incorrect_pid, + veteran_file_number: veteran_file_number + ) + end let(:claimant) do create( :claimant, @@ -19,6 +26,7 @@ let!(:supplemental_claim) do create( :supplemental_claim, + veteran_file_number: veteran_file_number, establishment_error: error_text, claimants: [ claimant @@ -41,9 +49,9 @@ end end it "handles errors from BGSService and logs errors appropriately" do - # Ensure that log_error is being called - expect(subject).to receive(:log_error).with(StandardError).at_least(:once) - subject.retrieve_correct_pid(veteran_file_number) + expect(subject).to receive(:log_error).with(instance_of(StandardError)).at_least(:once) + + subject.send(:retrieve_correct_pid, veteran_file_number) end it "logs to the stuck_job_report_service" do @@ -52,9 +60,8 @@ message_2 = "number #{veteran_file_number}: Simulated BGS error" error_message = message_1 + message_2 - expect(logs).to receive(:push).with(error_message).at_least(:once) - - subject.retrieve_correct_pid(veteran_file_number) + subject.start_processing_records + expect(logs).to include(match(/#{error_message}/)) end end @@ -134,42 +141,44 @@ it "handles person records" do correct_person expect do - subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - end.to change { Person.count }.by(-1) # Expect one person to be destroyed + subject.start_processing_records.to + end + change { Person.count }.by(-1) end it "updates supplemental_claim to the correct claimant" do correct_person - subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - supplemental_claim.reload + subject.start_processing_records expect(supplemental_claim.claimant.participant_id).to eq(correct_pid) end it "updates supplemental_claim to the correct person" do correct_person - subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - supplemental_claim.reload + subject.start_processing_records expect(supplemental_claim.claimant.person.participant_id).to eq(correct_pid) end - it "handles person and claimant records when correct person not found" do - allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) - expect do - subject.handle_person_and_claimant_records(correct_pid, supplemental_claim) - end.not_to(change { Person.count }) # Expect no person to be destroyed - end + context "No Person found with correct PID" do + it "handles person and claimant records when correct person not found" do + expect do + subject.start_processing_records + end.not_to(change { Person.count }) - it "updates incorrect person when correct person not found" do - allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) - subject.start_processing_records - expect(supplemental_claim.claimant.person.reload.participant_id).to eq(correct_pid) - end + # expect do + # subject.handle_person_and_claimant_records(supplemental_claim) + # end.not_to(change { Person.count }) # Expect no person to be destroyed + end - it "updates payee_code if not 00" do - allow(PtcpntPersnIdDepntOrgFix).to receive(:get_correct_person).with(correct_pid).and_return(nil) - supplemental_claim.claimant.payee_code = nil - subject.start_processing_records - expect(supplemental_claim.claimant.payee_code).to eq("00") + it "updates incorrect person when correct person not found" do + subject.start_processing_records + expect(supplemental_claim.claimant.person.reload.participant_id).to eq(correct_pid) + end + + it "updates payee_code if not 00" do + supplemental_claim.claimant.payee_code = nil + subject.start_processing_records + expect(supplemental_claim.claimant.payee_code).to eq("00") + end end end end From 223ce82c49bde9f551cc3fe35c2f30fe90f89102 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Mon, 4 Mar 2024 10:45:17 -0500 Subject: [PATCH 12/17] addressed comments and code climate --- app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb | 17 ++--------------- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 13 +++++-------- .../ptcpnt_persn_id_depnt_org_fix_spec.rb | 4 ---- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb index f43930895ab..926696ff828 100644 --- a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb +++ b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb @@ -5,23 +5,10 @@ class PtcpntPersnIdDepntOrgFixJob < CaseflowJob include MasterSchedulerInterface - ASSOCIATIONS = [ - BgsPowerOfAttorney, - BgsAttorney, - CavcRemandsAppellantSubstitution, - Claimant, - DecisionIssue, - EndProductEstablishment, - Notification, - Organization, - Person, - RequestIssue, - VbmsDistribution, - Veteran - ].freeze - def initialize @stuck_job_report_service = StuckJobReportService.new + @start_time = nil + @end_time = nil super end diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index ccce33729e5..30fbec8d0bb 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -20,6 +20,7 @@ class PtcpntPersnIdDepntOrgFix < CaseflowJob def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service + @correct_pid = nil end def start_processing_records @@ -48,10 +49,6 @@ def start_processing_records end class << self - # def get_correct_person(correct_pid) - # Person.find_by(participant_id: correct_pid) - # end - def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) ASSOCIATIONS.each do |ass| if ass.attribute_names.include?("participant_id") @@ -66,10 +63,12 @@ def iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associa incorrectly_associated_records.push(*records) end end + # Return the updated array + incorrectly_associated_records end def error_records - SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%") + SupplementalClaim.where("establishment_error ILIKE ?", "%#{ERROR_TEXT}%").where(establishment_canceled_at: nil) end end @@ -108,9 +107,7 @@ def retrieve_correct_pid(veteran_file_number) end def retrieve_records_to_fix(incorrect_pid) - incorrectly_associated_records = [] - - self.class.iterate_through_associations_with_bad_pid(incorrect_pid, incorrectly_associated_records) + incorrectly_associated_records = self.class.iterate_through_associations_with_bad_pid(incorrect_pid, []) incorrectly_associated_records.each do |record| fix_record(record) diff --git a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb index 76570d44448..34bf8254b87 100644 --- a/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb +++ b/spec/lib/helpers/ptcpnt_persn_id_depnt_org_fix_spec.rb @@ -163,10 +163,6 @@ expect do subject.start_processing_records end.not_to(change { Person.count }) - - # expect do - # subject.handle_person_and_claimant_records(supplemental_claim) - # end.not_to(change { Person.count }) # Expect no person to be destroyed end it "updates incorrect person when correct person not found" do From 1f6957d4ecf4a37ab968d15fc4fd36a80f02daf6 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Mon, 4 Mar 2024 11:02:22 -0500 Subject: [PATCH 13/17] code climate issues --- app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb | 4 +--- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb index 926696ff828..a444566d455 100644 --- a/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb +++ b/app/jobs/ptcpnt_persn_id_depnt_org_fix_job.rb @@ -7,8 +7,6 @@ class PtcpntPersnIdDepntOrgFixJob < CaseflowJob def initialize @stuck_job_report_service = StuckJobReportService.new - @start_time = nil - @end_time = nil super end @@ -38,7 +36,7 @@ def records_with_errors end def log_processing_time - (@end_time && @start_time) ? @end_time - @start_time : 0 + (end_time && start_time) ? end_time - start_time : 0 end def start_time diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 30fbec8d0bb..56879b47149 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -20,7 +20,6 @@ class PtcpntPersnIdDepntOrgFix < CaseflowJob def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service - @correct_pid = nil end def start_processing_records @@ -35,7 +34,7 @@ def start_processing_records next unless supp_claim.claimant.type == "VeteranClaimant" veteran_file_number = supp_claim.veteran.file_number - @correct_pid = retrieve_correct_pid(veteran_file_number) + @correct_pid ||= retrieve_correct_pid(veteran_file_number) handle_person_and_claimant_records(supp_claim) retrieve_records_to_fix(incorrect_pid) From 03950e4abbeef4c4f8178b601f0be4f37d0aacf5 Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Mon, 4 Mar 2024 11:03:03 -0500 Subject: [PATCH 14/17] cc update --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 56879b47149..b1f8497c646 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -34,7 +34,7 @@ def start_processing_records next unless supp_claim.claimant.type == "VeteranClaimant" veteran_file_number = supp_claim.veteran.file_number - @correct_pid ||= retrieve_correct_pid(veteran_file_number) + @correct_pid = retrieve_correct_pid(veteran_file_number) handle_person_and_claimant_records(supp_claim) retrieve_records_to_fix(incorrect_pid) From 7fcc901df194d86c357507dc418202516576b70b Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Mon, 4 Mar 2024 11:21:21 -0500 Subject: [PATCH 15/17] code climate reek --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index b1f8497c646..a1ca264c75d 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -22,6 +22,7 @@ def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service end + # :reek:InstanceVariableAssumption def start_processing_records return if self.class.error_records.blank? From aaeaf0798466d5228bdb83fb8990437a493aed2b Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Mon, 4 Mar 2024 11:45:03 -0500 Subject: [PATCH 16/17] reek change --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index a1ca264c75d..7ed212399b7 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# :reek:InstanceVariableAssumption class PtcpntPersnIdDepntOrgFix < CaseflowJob ERROR_TEXT = "participantPersonId does not match a dependent or an organization" @@ -22,7 +23,6 @@ def initialize(stuck_job_report_service) @stuck_job_report_service = stuck_job_report_service end - # :reek:InstanceVariableAssumption def start_processing_records return if self.class.error_records.blank? From e44491847008c430e7f19f7e7b844fa0f1fa089c Mon Sep 17 00:00:00 2001 From: AdamShawBAH Date: Tue, 5 Mar 2024 09:44:50 -0500 Subject: [PATCH 17/17] write to logs --- lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb index 7ed212399b7..e690d932f92 100644 --- a/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb +++ b/lib/helpers/ptcpnt_persn_id_depnt_org_fix.rb @@ -46,6 +46,7 @@ def start_processing_records end # record count with errors after fix @stuck_job_report_service.append_record_count(self.class.error_records.count, ERROR_TEXT) + @stuck_job_report_service.write_log_report(ERROR_TEXT) end class << self