Skip to content

Commit

Permalink
Merge pull request #773 from pulibrary/i769
Browse files Browse the repository at this point in the history
[i769] Don't include retirees in list of ineligible patrons for Alma
  • Loading branch information
kevinreiss authored May 2, 2024
2 parents 77e8edd + 29e91a4 commit 9c15ff9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/models/alma_people/alma_person_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ def initialize(oit_person_feed: AlmaPeople::OitPersonFeed.new, begin_date: 1.day
@enabled_flag = enabled_flag
@ineligible_flag = 'I'
@invalid_records = []
@ineligible_count = 0
end

private

attr_reader :ineligible_count

def handle(data_set:)
data_set.report_time = Time.zone.now.midnight
oit_people = oit_person_feed.get_json(begin_date:, end_date:, enabled_flag:)
Expand All @@ -36,7 +39,7 @@ def build_xml(oit_people:, eligibility:)
builder = Nokogiri::XML::Builder.new do |xml|
xml.users do
oit_people.each do |person|
convert_person_to_xml(xml:, person:)
convert_person_to_xml(xml:, person:, eligibility:)
end
end
end
Expand All @@ -61,10 +64,11 @@ def transfer_alma_person_file(filename:)
report_uploader.run
end

def convert_person_to_xml(xml:, person:)
def convert_person_to_xml(xml:, person:, eligibility:)
alma_person = AlmaPeople::AlmaXmlPerson.new(xml:, person:)
if alma_person.valid?
if alma_person.valid? && alma_person.should_be_included?
alma_person.convert
handle_ineligible_patron_converted if eligibility == 'I'
else
@invalid_records << alma_person
end
Expand All @@ -80,7 +84,11 @@ def ineligible_user
oit_people_ineligible = oit_person_feed.get_json(begin_date:, end_date:, enabled_flag: @ineligible_flag)
full_path = build_xml(oit_people: oit_people_ineligible, eligibility: @ineligible_flag)
transfer_alma_person_file(filename: full_path)
", ineligible_people_updated: #{oit_people_ineligible.count}, file: #{File.basename(full_path)}"
", ineligible_people_updated: #{ineligible_count}, file: #{File.basename(full_path)}"
end

def handle_ineligible_patron_converted
@ineligible_count = ineligible_count + 1
end
end
end
15 changes: 15 additions & 0 deletions app/models/alma_people/alma_xml_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def convert
end
end

# #should_be_included? checks to make sure the person meets
# our business logic rules. This is different than #valid?,
# which checks to make sure the data about the person is correct
def should_be_included?
eligible? || not_a_retiree?
end

private

def create_status(status_flag:)
Expand Down Expand Up @@ -138,6 +145,14 @@ def create_address(type:, preferred:, line1:, line2:, line3:, line4:, city:, sta
end
# rubocop:enable Metrics/ParameterLists
# rubocop:enable Metrics/MethodLength

def eligible?
person["ELIGIBLE_INELIGIBLE"] == 'E'
end

def not_a_retiree?
person["VCURSTATUS"] != 'RETR'
end
end
end
# rubocop:enable Metrics/AbcSize
Expand Down
29 changes: 29 additions & 0 deletions spec/models/alma_people/alma_person_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@
data = File.read("spec/fixtures/person_feed/alma_people_#{yesterday}_#{today}_I.xml")
expect(validate_xml(data)).to be_truthy
end

context 'when the person is a retiree' do
let(:oit_ineligible_people) do
[{ "VCURAFFIL" => "EM",
"VCURGROUP" => "DF",
"VCURSTATUS" => "RETR",
"UG_CLASS_YEAR" => nil,
"VCLASS" => "N/A",
"VTITLE" => "Emeritus.",
"BEMERITUS" => "FEMER",
"VJOBFUNCTION" => "FR",
"PRF_OR_PRI_FIRST_NAM" => "Retiree",
"PATRON_EXPIRATION_DATE" => "2022-10-31",
"ELIGIBLE_INELIGIBLE" => "I",
"EMPLOYEE_TYPE" => "eme" },
{ "PRF_OR_PRI_FIRST_NAM" => "NotRetired",
"PATRON_EXPIRATION_DATE" => "2022-10-31",
"ELIGIBLE_INELIGIBLE" => "I" }]
end
it('does not include them in the list we send to alma, so they do not lose their privileges') do
expect(alma_person_feed.run).to be_truthy
data_set = DataSet.last
expect(data_set.data).to eq("people_updated: 1, file: alma_people_#{yesterday}_#{today}_E.xml, ineligible_people_updated: 1, file: alma_people_#{yesterday}_#{today}_I.xml")
data = File.read("spec/fixtures/person_feed/alma_people_#{yesterday}_#{today}_I.xml")
expect(validate_xml(data)).to be_truthy
expect(data).to include 'NotRetired'
expect(data).not_to include 'Retiree'
end
end
end
end

Expand Down
34 changes: 34 additions & 0 deletions spec/models/alma_people/alma_xml_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,39 @@
end
end
end

describe('#should_be_included?') do
end
context 'for a typical Ineligible patron' do
let(:oit_person) do
JSON.parse('{
"VCURSTATUS": "ACTV",
"ELIGIBLE_INELIGIBLE": "I",
"PATRON_EXPIRATION_DATE": "2024-01-01"
}')
end
it 'returns true' do
Nokogiri::XML::Builder.new do |xml|
alma_person = described_class.new(xml:, person: oit_person)
expect(alma_person.should_be_included?).to eq(true)
end
end
end

context 'when an otherwise Ineligible patron is a retiree and thus gets borrowing privileges' do
let(:oit_person) do
JSON.parse('{
"VCURSTATUS": "RETR",
"ELIGIBLE_INELIGIBLE": "I",
"PATRON_EXPIRATION_DATE": "2024-01-01"
}')
end
it 'returns false' do
Nokogiri::XML::Builder.new do |xml|
alma_person = described_class.new(xml:, person: oit_person)
expect(alma_person.should_be_included?).to eq(false)
end
end
end
end
end

0 comments on commit 9c15ff9

Please sign in to comment.