Skip to content

Commit af2656f

Browse files
Merge branch 'AP-345-expirations' into 'master'
Allow users without eligible jobs to update and setup expiry date to current date See merge request lap/alma-user-load!49
2 parents a715c6a + 5c8238f commit af2656f

19 files changed

Lines changed: 2452 additions & 56 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ Note - to run the test suite you need to change the LDAP setting in your `.env`
136136
## Future Improvements:
137137
- Replace fixtures w/some sort of factory (VCR)
138138
- DRY things up (UCPath vs. SIS --> phone, email, address, names, etc...)
139-
- SIS - add run by user id (similar to how I setup ucpath)
139+
- SIS - add run by user id (similar to how I setup ucpath)...if possible
140140
- Move 'create_user_record' from user.rb to a separate class
141141
- Add a check to make sure all necessary config settings are set!
142-
- Fix LDAP tests to override the
143142
- Setup a rake command to run the test suite
143+
- Reduce some of the complexity in the complexity so I can remove some of the rubocop disables

config/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Settings:
55
ucpath_upload_path: "/alma/patron_employees/"
66
upload_host: "upload.lib.berkeley.edu"
77
upload_user: "ssullivan"
8+
last_alma_purge: "2023-06-30"
9+
application_version: "1.5.6"
810

911
# TODO - flesh this out
1012
# http://docopt.org/

config/ucpath_fields.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ Job:
206206
dbdef: "VARCHAR(16)"
207207
status: OPTIONAL
208208

209+
- name: termination_date
210+
jpath: "$.actions.terminationDate"
211+
dbdef: "VARCHAR(16)"
212+
status: OPTIONAL
213+
209214
EmployeeIDs:
210215
employee_rootnode: "//ar:response/emp:employees/emp:employee"
211216
total_records_xpath: "//ar:offset/ar:total"

lib/alma/xml_writer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
module Alma
55
class XMLWriter
6-
attr_reader :out
6+
attr_reader :out, :change_log_count
77

8-
def initialize(outfile)
8+
def initialize(outfile, change_log_count = nil)
99
@out = ensure_io(outfile)
10+
@change_log_count = change_log_count
1011
end
1112

1213
def write(record)
@@ -43,7 +44,8 @@ def prolog_and_opening_tag
4344
tag = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
4445
tag += "<!-- GIT_COMMIT:#{ENV['GIT_COMMIT']} -->\n"
4546
tag += "<!-- DOCKER_TAG:#{ENV['DOCKER_TAG']} -->\n"
46-
tag += "<!-- VERSION: 1.5.4 -->\n"
47+
tag += "<!-- VERSION: #{ENV['VERSION']} -->\n"
48+
tag += "<!-- CHANGE_LOG_COUNT: #{change_log_count} -->\n"
4749
tag += "<users>\n"
4850
tag
4951
end

lib/helpers/setup.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
module Helpers
77
class Setup
8+
# Set the version of the application
9+
ENV['VERSION'] = Config.setting('application_version')
10+
811
# Command Line Args:
912
attr_reader :type, :users, :start_date, :end_date, :num_days, :term_id, :outdir
1013

lib/ucpath.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def run_ucpath(setup)
1515
process_list = setup.users || UCPath::API.change_log(setup.start_date, setup.end_date)
1616

1717
if process_list
18-
writer = Alma::XMLWriter.new(setup.xml_path)
18+
writer = Alma::XMLWriter.new(setup.xml_path, process_list.count)
1919

2020
process_list.each_with_index do |id, idx|
2121
logger.info "#{idx} - #{id}"

lib/ucpath/jobs.rb

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@
77

88
module UCPath
99
class Jobs
10-
attr_accessor :job
10+
attr_accessor :job, :first_job
11+
12+
class << self
13+
# We're no longer skipping users who do not have an eligible job.
14+
# But we still need a "job record" quick and dirty to create a dummy job
15+
# and set the expiration date (expected_end_date) to today.
16+
def dummy_job
17+
OpenStruct.new(
18+
hr_status_code: 'I',
19+
expected_end_date: Date.today.to_s,
20+
org_relationship_code: nil,
21+
dept_desc: 'NO_JOB_FOUND',
22+
job_code: nil
23+
)
24+
end
25+
end
1126

1227
def initialize(id)
1328
# Fetch the raw job data
@@ -16,10 +31,10 @@ def initialize(id)
1631
return if job_data.nil?
1732

1833
# Break the jobs data into an array using jsonpath
19-
raw_jobs = JsonPath.on(job_data, '$..response[*].jobs')
20-
return unless raw_jobs.count.positive?
34+
job_list = JsonPath.on(job_data, '$..response[*].jobs')
35+
return unless job_list.count.positive?
2136

22-
@job = find_eligible_job(raw_jobs)
37+
@job = find_eligible_job(job_list)
2338
end
2439

2540
def eligible_job?
@@ -30,23 +45,20 @@ def eligible_job?
3045
private
3146

3247
# Extract the data from the raw jobs into the fields we need
48+
# config/ucpath_fields.yml contains the fields/jpath we want to extract
3349
def find_eligible_job(raw_jobs)
3450
raw_jobs.first.each do |job_hash|
35-
j = job_hash.to_json
36-
37-
job = OpenStruct.new
38-
39-
# config/ucpath_fields.yml contains the fields/jpath we need
40-
Config.ucpath_job_fields.each do |field|
41-
value = JsonPath.on(j, field['jpath']).first || ''
42-
job[field['name']] = value if value
43-
end
44-
45-
# Return this job struct if it's eligible
51+
job = OpenStruct.new(
52+
Config.ucpath_job_fields.to_h do |field|
53+
[field['name'], JsonPath.on(job_hash, field['jpath']).first || '']
54+
end
55+
)
56+
57+
# First one - save it incase we don't find any eligible jobs!
58+
@first_job ||= job
4659
return job if check_if_eligible(job)
4760
end
4861

49-
# No eligible jobs found, return nil
5062
nil
5163
end
5264

lib/ucpath/user.rb

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

spec/data/sis/expected_xml_3.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- GIT_COMMIT:LOCAL_TESTING -->
33
<!-- DOCKER_TAG:DEV -->
4-
<!-- VERSION: 1.5.4 -->
4+
<!-- VERSION: VERSIONNUMBER -->
5+
<!-- CHANGE_LOG_COUNT: -->
56
<users>
67
<user>
78
<record_type>PUBLIC</record_type>

0 commit comments

Comments
 (0)