From 5b529d55f1ee4ed6315dbec2a7173fd69b36ccf4 Mon Sep 17 00:00:00 2001 From: jazairi <16103405+jazairi@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:40:23 -0400 Subject: [PATCH] Notify processors to create new Archivematica accessions 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. --- app/jobs/registrar_import_job.rb | 4 +++- app/models/degree_period.rb | 16 +++++++++++++++ .../registrar_import_email.html.erb | 13 ++++++++++++ .../files/registrar_data_full_anonymized.csv | 4 ++-- test/jobs/registrar_import_job_test.rb | 4 +++- test/mailers/report_mailer_test.rb | 2 +- test/models/degree_period_test.rb | 20 +++++++++++++++++-- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/app/jobs/registrar_import_job.rb b/app/jobs/registrar_import_job.rb index 1fc91506..c68e135d 100644 --- a/app/jobs/registrar_import_job.rb +++ b/app/jobs/registrar_import_job.rb @@ -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}") @@ -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' diff --git a/app/models/degree_period.rb b/app/models/degree_period.rb index ba3fc6c8..aa72922d 100644 --- a/app/models/degree_period.rb +++ b/app/models/degree_period.rb @@ -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 diff --git a/app/views/report_mailer/registrar_import_email.html.erb b/app/views/report_mailer/registrar_import_email.html.erb index a256f2e5..17180bb7 100644 --- a/app/views/report_mailer/registrar_import_email.html.erb +++ b/app/views/report_mailer/registrar_import_email.html.erb @@ -14,6 +14,7 @@
  • New authors: <%= @results[:new_users] %>
  • New degrees: <%= @results[:new_degrees].count %>
  • New DLCs: <%= @results[:new_depts].count %>
  • +
  • New degree periods: <%= @results[:new_degree_periods].count %>
  • <% if @results[:errors].any? %> @@ -45,3 +46,15 @@ <% end %> <% end %> + +<% if @results[:new_degree_periods].any? %> +

    The following new degree periods must be assigned Archivematica accession numbers to enable publication for + associated theses:

    + + +<% end %> diff --git a/test/fixtures/files/registrar_data_full_anonymized.csv b/test/fixtures/files/registrar_data_full_anonymized.csv index a8f307c7..355c2a81 100644 --- a/test/fixtures/files/registrar_data_full_anonymized.csv +++ b/test/fixtures/files/registrar_data_full_anonymized.csv @@ -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,,finleyjessica@example.com -"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,,pattersondavid@example.com -"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,dianebishop@example.com +"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,,pattersondavid@example.com +"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,dianebishop@example.com "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,tony71@example.com "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,jeffrey83@example.com "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,carrieenglish@example.com diff --git a/test/jobs/registrar_import_job_test.rb b/test/jobs/registrar_import_job_test.rb index 73220a9e..66250d26 100644 --- a/test/jobs/registrar_import_job_test.rb +++ b/test/jobs/registrar_import_job_test.rb @@ -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') @@ -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' @@ -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 diff --git a/test/mailers/report_mailer_test.rb b/test/mailers/report_mailer_test.rb index 5a080539..11a4e9a8 100644 --- a/test/mailers/report_mailer_test.rb +++ b/test/mailers/report_mailer_test.rb @@ -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 diff --git a/test/models/degree_period_test.rb b/test/models/degree_period_test.rb index 958394db..6fdcd0e5 100644 --- a/test/models/degree_period_test.rb +++ b/test/models/degree_period_test.rb @@ -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 @@ -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 @@ -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