@@ -19,7 +19,7 @@ class User
1919 Email = Struct . new ( :preferred , :email_address , :email_types )
2020 Phone = Struct . new ( :preferred , :preferred_sms , :phone_number , :phone_types )
2121
22- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
22+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
2323 def initialize ( id )
2424 @id = id
2525 logger . info "#{ id } - Processing record..."
@@ -51,13 +51,33 @@ def initialize(id)
5151 @jobs = Jobs . new ( id )
5252
5353 #----------------------------------------------------------------#
54- # NO ELIGIBLE JOB - NO REASON TO PROCEED!
54+ # NO ELIGIBLE JOB
55+ # AP-345: Changed this logic
56+ # If we could not find an "eligible" job we'd just skip this user
57+ # and move on. Now what we need to do is update the user's expiration
58+ # date to the current date so that they will get purged from Alma.
59+ # We'll either use the first job found (which is the users most recent job)
60+ # or we'll create a dummy job with the expected_end_date set to today.
5561 unless @jobs . eligible_job?
56- @user = nil
57- @jobs = nil
58- @rec = nil
59- @ucpath_rec = nil
60- logger . info "#{ id } - No eligible job, skipping LDAP search"
62+ if @jobs . first_job
63+ logger . info "#{ id } - No eligible job found, using first job"
64+ @jobs . job = @jobs . first_job
65+
66+ @jobs . job . expected_end_date = Date . today . to_s
67+ else
68+ logger . info "#{ id } - No job found, using a dummy job"
69+ @jobs . job = Jobs . dummy_job
70+ end
71+ end
72+
73+ #----------------------------------------------------------------#
74+ # If we have a termination date that is before the last Alma
75+ # purge date, then we can skip this user
76+ term_date = @jobs . job . termination_date
77+
78+ if term_date && term_date != '' && Date . iso8601 ( term_date ) < Date . parse ( Config . setting ( 'last_alma_purge' ) )
79+ logger . info "#{ id } - Ineligible: Termination date before #{ Config . setting ( 'last_alma_purge' ) } "
80+ @eligible = false
6181 return
6282 end
6383
@@ -91,7 +111,7 @@ def initialize(id)
91111
92112 logger . info "#{ id } - Eligible: #{ eligible? } "
93113 end
94- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
114+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
95115
96116 def eligible?
97117 eligible
@@ -107,7 +127,7 @@ def create_user_record
107127 if ldap &.berkeleyeduaffiliations
108128 ldap . berkeleyeduaffiliations . each do |affiliation |
109129 if Config . student_affiated? affiliation
110- logger . info "#{ id } - Ineligible - ldap student affiliation: #{ affiliation } "
130+ logger . info "#{ id } - Ineligible: ldap student affiliation: #{ affiliation } "
111131 return nil
112132 end
113133 end
0 commit comments