Skip to content

Commit

Permalink
Notify processors to create new Archivematica accessions
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

If a processor adds an Archivematica Accession for a thesis that
is otherwise ready for publication, they will need to update that
thesis before its publication status switches over to 'Publication
review'. This could become substantially time consuming when
working with large batches of theses.

Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/ETD-596

How this addresses that need:

This creates new Degree Period records during the Registrar Data
Import job, using a similar pattern to how we create new Degree
and Department records. It also adds new Degree Period records
to the mailer, so that processors can proactively create
Archivematica Accession records for them.

Side effects of this change:

* One of the registrar data fixtures has been updated so that more than
one degree date will be created in the relevant test.
* Rubocop identified and fixed a couple of issues unrelated to this
change.
  • Loading branch information
jazairi committed Oct 4, 2023
1 parent 031f501 commit 5b529d5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/jobs/registrar_import_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RegistrarImportJob < ActiveJob::Base

def perform(registrar)
results = { read: 0, processed: 0, new_users: 0, new_theses: 0, updated_theses: 0, new_degrees: [], new_depts: [],
errors: [] }
new_degree_periods: [], errors: [] }

CSV.new(registrar.graduation_list.download, headers: true).each.with_index(1) do |row, i|
Rails.logger.info("Parsing row #{i}")
Expand Down Expand Up @@ -33,6 +33,8 @@ def perform(registrar)
results[:new_depts] << department if department.id_previously_changed?
grad_date = reformat_grad_date(row['Degree Award Date'])
logger.info("Grad date is #{grad_date.inspect}")
degree_period = DegreePeriod.from_grad_date(grad_date)
results[:new_degree_periods] << degree_period if degree_period.id_previously_changed?
begin
# Set whodunnit for thesis transaction
PaperTrail.request.whodunnit = 'registrar'
Expand Down
16 changes: 16 additions & 0 deletions app/models/degree_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ class DegreePeriod < ApplicationRecord

VALID_GRAD_MONTHS = %w[May June September February].freeze
validates_inclusion_of :grad_month, in: VALID_GRAD_MONTHS

# Given a grad date from a registrar data import CSV (or elsewhere, look up a Degree Period and create one if it does
# not exist.
def self.from_grad_date(grad_date)
new_grad_month = grad_date.strftime('%B')
new_grad_year = grad_date.strftime('%Y')
degree_period = DegreePeriod.find_by(grad_month: new_grad_month, grad_year: new_grad_year)
if degree_period.blank?
new_degree_period = DegreePeriod.create!(grad_month: new_grad_month, grad_year: new_grad_year)
Rails.logger.warn("New department created, requires Processor attention: \
#{new_degree_period.grad_month} #{new_degree_period.grad_year}")
new_degree_period
else
degree_period
end
end
end
13 changes: 13 additions & 0 deletions app/views/report_mailer/registrar_import_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<li>New authors: <%= @results[:new_users] %></li>
<li>New degrees: <%= @results[:new_degrees].count %></li>
<li>New DLCs: <%= @results[:new_depts].count %></li>
<li>New degree periods: <%= @results[:new_degree_periods].count %></li>
</ul>

<% if @results[:errors].any? %>
Expand Down Expand Up @@ -45,3 +46,15 @@
<% end %>
</ul>
<% end %>
<% if @results[:new_degree_periods].any? %>
<p>The following new degree periods must be assigned Archivematica accession numbers to enable publication for
associated theses:</p>

<ul>
<% @results[:new_degree_periods].each do |degree_period| %>
<li><%= link_to "#{degree_period.grad_month} #{degree_period.grad_year}",
new_admin_archivematica_accession_url(degree_period_id: degree_period.id) %></li>
<% end %>
</ul>
<% end %>
4 changes: 2 additions & 2 deletions test/fixtures/files/registrar_data_full_anonymized.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Full Name,Degree Status,Degree Type,Degree Desc,Degree Department,Degree Award Term,Degree Award Date,Degree Code,Dept Name In Commencement Bk,Thesis Title,Is Primary Course Of Major,Thesis Coauthor,Krb Name,Last Name,First Name,Middle Name,Email Address
"Klein, Jennifer",AW,PHD,Doctor of Philosophy,MAS,2019SU,9/18/2019 0:00,PHD,Program in Media Arts and Sciences,thesis in the field of Media Arts and Sciences: Social Inductive Biases for Reinforcement Learning,Y,,finleyjessica,Klein,Jennifer,,[email protected]
"Hawkins, Destiny",AW,PHD,Doctor of Philosophy,MAS,2019SU,9/18/2019 0:00,PHD,Program in Media Arts and Sciences,thesis in the field of Media Arts and Sciences: Laser Direct-Write Fabrication of MEMS,Y,,pattersondavid,Hawkins,Destiny,,[email protected]
"Love, Tyler Alexander",AW,PHD,Doctor of Philosophy,6,2019SU,9/18/2019 0:00,PHD,Department of Electrical Engineering and Computer Science,thesis in the field of Computer Science: Fast Spectral Primitives for Directed Graphs,Y,,dianebishop,Love,Tyler,Alexander,[email protected]
"Hawkins, Destiny",AW,PHD,Doctor of Philosophy,MAS,2019SU,5/18/2023 0:00,PHD,Program in Media Arts and Sciences,thesis in the field of Media Arts and Sciences: Laser Direct-Write Fabrication of MEMS,Y,,pattersondavid,Hawkins,Destiny,,[email protected]
"Love, Tyler Alexander",AW,PHD,Doctor of Philosophy,6,2019SU,6/18/2024 0:00,PHD,Department of Electrical Engineering and Computer Science,thesis in the field of Computer Science: Fast Spectral Primitives for Directed Graphs,Y,,dianebishop,Love,Tyler,Alexander,[email protected]
"Anderson, James John",AW,SM,Master of Science in Real Estate Development,RED,2019SU,9/18/2019 0:00,SMRED,Center for Real Estate Development,,Y,,tony71,Anderson,James,John,[email protected]
"Mcclain, Matthew Patricia",AW,SM,Master of Science in Mechanical Engineering,2,2019SU,9/18/2019 0:00,SM2,Department of Mechanical Engineering,,Y,,jeffrey83,Mcclain,Matthew,Patricia,[email protected]
"Jordan, Kimberly Jason",AW,SM,Master of Science in Real Estate Development,RED,2019SU,9/18/2019 0:00,SMRED,Center for Real Estate Development,,Y,,carrieenglish,Jordan,Kimberly,Jason,[email protected]
Expand Down
4 changes: 3 additions & 1 deletion test/jobs/registrar_import_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RegistrarImportJobTest < ActiveJob::TestCase
end

test 'job runs and returns expected results' do
skip "Slow test skipped due to env settings" if ENV.fetch("SKIP_SLOW", false)
skip 'Slow test skipped due to env settings' if ENV.fetch('SKIP_SLOW', false)
registrar = Registrar.last
registrar.graduation_list.attach(io: File.open('test/fixtures/files/registrar_data_full_anonymized.csv'),
filename: 'registrar_data_full_anonymized.csv')
Expand All @@ -30,6 +30,7 @@ class RegistrarImportJobTest < ActiveJob::TestCase
assert_equal 430, results[:new_users]
assert_equal 42, results[:new_degrees].length
assert_equal 30, results[:new_depts].length
assert_equal 3, results[:new_degree_periods].length
assert_equal 1, results[:errors].length
assert_includes results[:errors][0], 'Row #418 missing a Kerberos ID'

Expand All @@ -41,6 +42,7 @@ class RegistrarImportJobTest < ActiveJob::TestCase
assert_equal 0, results[:new_users]
assert_equal 0, results[:new_degrees].length
assert_equal 0, results[:new_depts].length
assert_equal 0, results[:new_degree_periods].length
assert_equal 1, results[:errors].length
assert_includes results[:errors][0], 'Row #418 missing a Kerberos ID'
end
Expand Down
2 changes: 1 addition & 1 deletion test/mailers/report_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ReportMailerTest < ActionMailer::TestCase
ClimateControl.modify DISABLE_ALL_EMAIL: 'false' do
registrar = registrar(:valid)
results = { read: 0, processed: 0, new_users: 0, new_theses: 1, updated_theses: 0, new_degrees: [], new_depts: [],
errors: [] }
new_degree_periods: [], errors: [] }
email = ReportMailer.registrar_import_email(registrar, results)

# Send the email, then test that it got queued
Expand Down
20 changes: 18 additions & 2 deletions test/models/degree_period_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
require 'test_helper'

class DegreePeriodTest < ActiveSupport::TestCase
test 'only grad years between 1900 and 2099 are valid' do
Expand All @@ -30,7 +30,7 @@ class DegreePeriodTest < ActiveSupport::TestCase
d.grad_year = '2155'
assert_not d.valid?
end

test 'only certain grad months are valid' do
d = degree_periods(:june_2023)
assert_equal 'June', d.grad_month
Expand Down Expand Up @@ -113,4 +113,20 @@ class DegreePeriodTest < ActiveSupport::TestCase
d.save
assert_equal versions_count + 1, d.versions.count
end

test 'finds existing degree period from reformatted grad date' do
date = Date.new(2023, 6, 1)
degree_period = DegreePeriod.from_grad_date(date)
assert_equal degree_periods(:june_2023), degree_period
end

test 'creates new degree period from reformatted grad date' do
degree_period_count = DegreePeriod.count
date = Date.new(2024, 6, 1)
assert_not DegreePeriod.find_by(grad_month: 'June', grad_year: '2024')

degree_period = DegreePeriod.from_grad_date(date)
assert_equal degree_period_count + 1, DegreePeriod.count
assert_equal degree_period, DegreePeriod.last
end
end

0 comments on commit 5b529d5

Please sign in to comment.