-
Notifications
You must be signed in to change notification settings - Fork 4
Add batch export feature for ProQuest JSON #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| class ProquestExportJob < ActiveJob::Base | ||
| queue_as :default | ||
|
|
||
| def perform(partial_harvest, full_harvest) | ||
| export = ProquestExportBatch.new | ||
|
|
||
| # update_all is an option here if performance is poor, but we would need a workaround to update paper_trail | ||
| # versions as update_all does not trigger callbacks. | ||
| if partial_harvest.present? | ||
| partial_harvest.each do |thesis| | ||
| thesis.update(proquest_exported: 'Partial harvest', proquest_export_batch: export) | ||
| end | ||
| end | ||
| if full_harvest.present? | ||
| full_harvest.each { |thesis| thesis.update(proquest_exported: 'Full harvest', proquest_export_batch: export) } | ||
| end | ||
|
|
||
| all_to_export = partial_harvest + full_harvest | ||
| attach_and_send(export, all_to_export) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def attach_and_send(export, all_to_export) | ||
| export_json = export.build_json(all_to_export) | ||
| export.proquest_export.attach(io: StringIO.new(export_json), | ||
| filename: "proquest_export_#{Date.today.strftime('%Y%m%d_%s')}.json", | ||
| content_type: 'application/json') | ||
| export.save | ||
| BatchMailer.proquest_export_email(export.proquest_export.blob, all_to_export.count).deliver_later | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| class ProquestExportBatch < ApplicationRecord | ||
| has_many :theses | ||
|
|
||
| has_one_attached :proquest_export | ||
| has_one_attached :budget_report | ||
|
|
||
| def build_json(theses) | ||
| thesis_records = theses.map { |thesis| record(thesis) } | ||
| { records: thesis_records }.to_json | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def record(thesis) | ||
| { | ||
| dspace_handle: thesis.dspace_handle, | ||
| full_harvest: evaluate_export_type(thesis) | ||
| } | ||
| end | ||
|
|
||
| def evaluate_export_type(thesis) | ||
| thesis.proquest_exported == 'Full harvest' | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <p>Hello,</p> | ||
|
|
||
| <p>Attached is a ProQuest export of <%= @thesis_count %> theses generated on | ||
| <%= Date.current.strftime('%A, %B %d, %Y') %> at <%= Time.now.strftime('%r %Z') %>. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <tr> | ||
| <td><%= link_to title_helper(proquest_status_thesis), edit_admin_thesis_path(proquest_status_thesis.id) %></td> | ||
| <td> | ||
| <% proquest_status_thesis.authors.each do |author| %> | ||
| <%= link_to author.user.display_name, edit_admin_author_path(author.id) %><br> | ||
| <% end %> | ||
| </td> | ||
| <td><%= proquest_status_thesis.dspace_handle %></td> | ||
| <td><%= render_proquest_status(proquest_status_thesis) %></td> | ||
| <td><%= proquest_status_thesis.proquest_exported %></td> | ||
| </tr> |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <tr> | ||
| <td colspan="5">No theses match these criteria.</td> | ||
| </tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <tr> | ||
|
JPrevost marked this conversation as resolved.
|
||
| <td><%= link_to title_helper(proquest_export_thesis), edit_admin_thesis_path(proquest_export_thesis.id) %></td> | ||
| <td> | ||
| <% proquest_export_thesis.authors.each do |author| %> | ||
| <%= link_to author.user.display_name, edit_admin_author_path(author.id) %><br> | ||
| <% end %> | ||
| </td> | ||
| <td><%= proquest_export_thesis.grad_date %></td> | ||
| <td><%= proquest_export_thesis.dspace_handle %></td> | ||
| <td><%= render_proquest_status(proquest_export_thesis) %></td> | ||
| </tr> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <%= content_for(:title, "Thesis Processing | MIT Libraries") %> | ||
|
|
||
| <% content_for :additional_js do %> | ||
| <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script> | ||
| <% end %> | ||
|
|
||
| <link href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css" rel="stylesheet"> | ||
|
|
||
| <h3 class="title title-page">Export theses for ProQuest</h3> | ||
|
|
||
| <%= render 'shared/you_are' %> | ||
|
|
||
| <div class="gridband" id="export-action" aria-live="polite" role="region"> | ||
| <div class="inline-action well warning"> | ||
| <% if @theses.count < 1 %> | ||
| <p>No theses are available to export.</p> | ||
| <% else %> | ||
| <div class="message"> | ||
| <h4 class="title">Ready to export <%= @theses.count %> theses?</h4> | ||
| <p>If the set of thesis records below is correct, click the button at right to export their handles. Use the | ||
| <%= link_to "ProQuest Status Report", report_proquest_status_path %> to review ProQuest opt-in statuses.</p> | ||
| </div> | ||
| <div class="actions"> | ||
| <%= link_to "Export theses to send to ProQuest", thesis_proquest_export_path, class: 'button button-primary' %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
|
|
||
| <table class="table" id="proquestPreview" summary="This table presents a list of theses with their ProQuest opt-in status." | ||
| title="ProQuest opt-in status"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">Title</th> | ||
| <th scope="col">Author(s)</th> | ||
| <th scope="col">Term</th> | ||
| <th scope="col">DSpace handle</th> | ||
| <th scope="col">Opted in to ProQuest?</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <%= render(partial: 'proquest_export_thesis', collection: @theses) || render('shared/proquest_thesis_empty') %> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| <script type="text/javascript"> | ||
| $(document).ready(function () { | ||
| $('#proquestPreview').DataTable({ | ||
| pageLength: -1, | ||
| lengthMenu: [ | ||
| [10, 25, 50, -1], | ||
| [10, 25, 50, 'All'], | ||
| ], | ||
| }); | ||
| }); | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddProquestExportedToThesis < ActiveRecord::Migration[6.1] | ||
| def change | ||
| add_column :theses, :proquest_exported, :integer, null: false, default: 0 | ||
| end | ||
| end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20221209161518_create_proquest_export_batches.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class CreateProquestExportBatches < ActiveRecord::Migration[6.1] | ||
| def change | ||
| create_table :proquest_export_batches do |t| | ||
|
|
||
| t.timestamps | ||
| end | ||
|
|
||
| add_reference :theses, :proquest_export_batch, null: true, index: true | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.