Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/ht_downloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class HTDownloadsController < ApplicationController
"rights_code" => :ht_hathifile_rights_code_eq,
"rights_date_used" => :ht_hathifile_rights_date_used_eq,
"title" => :ht_hathifile_title_i_cont,
"pages" => :pages_eq
"pages" => :pages_eq,
"full_download" => :full_download_eq
}

# Translation table from params[:sortName] to a form Ransack can understand.
Expand All @@ -59,7 +60,8 @@ class HTDownloadsController < ApplicationController
"rights_code" => :ht_hathifile_rights_code,
"rights_date_used" => :ht_hathifile_rights_date_used,
"title" => :ht_hathifile_title,
"pages" => :pages
"pages" => :pages,
"full_download" => :full_download
}

def index
Expand Down
10 changes: 5 additions & 5 deletions app/models/ht_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class HTDownload < ApplicationRecord
scope :for_role, ->(role) { where(role: role) }

def self.ransackable_attributes(auth_object = nil)
["role", "datetime", "email", "htid", "id", "in_copyright", "inst_code", "is_partial", "sha", "yyyy", "yyyymm", "pages"]
["role", "datetime", "email", "htid", "id", "in_copyright", "inst_code", "sha", "yyyy", "yyyymm", "full_download", "pages"]
end

def self.ransackable_associations(auth_object = nil)
Expand All @@ -33,16 +33,16 @@ def hf
ht_hathifile
end

def partial?
is_partial
def full_download
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bang makes this a reliable Boolean, so I would rename to full_download?. However the bare is_partial will return 0 or 1 so I think we need

def full_download?
  !is_partial?
end

... to avoid Ruby's "zero is true" maldesign

Copy link
Collaborator

@moseshll moseshll Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing because I see a difference between k8s and Docker when I look at the is_partial method: bundle exec rails c on otis-testing gives 0/1 where in Docker I'm getting true/false. Our schema is doing the wrong thing, if you change db/schema.rb so is_partial looks like t.integer :is_partial, limit: 1 # TINYINT (and if necessary change the seeds to use [1,0].sample instead of bools) -- the display will always be "no" for the Full Download column (i.e., unless you swap in the full_download? method in the above comment).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why the t.boolean is being ignored in k8s. But I'm pretty sure the correct thing to do is make it so we always expect an integer from is_partial and a bool from is_partial?.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at this in Kubernetes. I believe this has to do with table columns being declared as tinyint(1) vs int(1) but I'm not certain. I don't think we need is_partial? at all, and I think I ran into an issue trying to use an attribute with ? in it with the table display & ransacker stuff but I'll look again. I do agree full_download? would be preferable if possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified using tinyint(1) works.

!is_partial
end

ransacker :datetime do
Arel.sql("DATE(#{table_name}.datetime)")
end

ransacker :pages do
Arel.sql("COALESCE(#{table_name}.pages, CASE WHEN #{table_name}.is_partial = '0' THEN 'all' ELSE 'unknown' END)")
ransacker :full_download do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that the logic is kind of duplicated between the ransacker and the presenter but that may just be what we need to do right now. We may want to rethink some of this later if we end up displaying the report in Tableau or something long-term (which might let us unwind some of what we're doing in the presenter)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider inverting the Boolean in the database, transition is_partial to is_full or whatever. But not now.

Copy link
Member Author

@aelkiss aelkiss Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, not now. I created an issue: https://hathitrust.atlassian.net/browse/ETT-745

Arel.sql("(CASE WHEN #{table_name}.is_partial = '0' THEN 'yes' WHEN #{table_name}.is_partial = '1' THEN 'no' END)")
end

def sha
Expand Down
13 changes: 4 additions & 9 deletions app/presenters/ht_download_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HTDownloadPresenter < ApplicationPresenter
imprint
author
rights_date_used
full_download
pages
].freeze

Expand All @@ -36,6 +37,7 @@ class HTDownloadPresenter < ApplicationPresenter
imprint: :input,
author: :input,
rights_date_used: :select,
full_download: :select,
pages: :select
}.freeze

Expand Down Expand Up @@ -118,14 +120,7 @@ def show_institution_name
link_to institution_name, ht_institution_path(inst_code)
end

def show_pages
if pages
pages
elsif !partial?
"all"
else
# partial download but no page count recorded
"unknown"
end
def show_full_download
full_download ? "yes" : "no"
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ en:
datetime: Time
digitization_agent_code: Digitization Agent
email: E-mail
full_download: Full Download
htid: HTID
imprint: Imprint
inst_code: Institution Code
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ja:
datetime: 時間
digitization_agent_code: デジタル化エージェント
email: Eメール
full_download: フルダウンロード
htid: HTID
imprint: 奥付
inst_code: 機関コード
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/otis/log_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# Both the qualifying ssdproxy records in the fixtures are partial downloads with
# 42 pages
download = HTDownload.where(role: "ssdproxy").first
expect(download.partial?).to be true
expect(download.is_partial).to be true
expect(download.pages).to eq 42
end

Expand Down
14 changes: 10 additions & 4 deletions spec/models/ht_download_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@
end
end

describe "#partial?" do
it "responds to partial?" do |download|
build(:ht_download, is_partial: 1) do |download|
expect(download.partial?).to be(true)
describe "#full_download" do
it "is false when is_partial is true" do |download|
build(:ht_download, is_partial: true) do |download|
expect(download.full_download).to be(false)
end
end

it "is true when is_partial is false" do |download|
build(:ht_download, is_partial: false) do |download|
expect(download.full_download).to be(true)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/ht_downloads_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def setup
assert_equal 10, json_body["rows"].length
end

test "export list of pages=all reports as JSON" do
test "export list of full_download=yes reports as JSON" do
sign_in!
get ht_downloads_url(format: :json, filter: "{\"pages\":\"all\"}")
get ht_downloads_url(format: :json, filter: "{\"full_download\":\"yes\"}")

json_body = JSON.parse(@response.body)
assert_kind_of Hash, json_body
Expand Down
10 changes: 10 additions & 0 deletions test/presenters/ht_download_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class HTDownloadPresenterTest < ActiveSupport::TestCase
assert_match "Resource Sharing", report.field_value(:role)
end

test "show full download - is_partial: false" do
report = HTDownloadPresenter.new(create(:ht_download, is_partial: false), action: :index)
assert_equal "yes", report.field_value(:full_download)
end

test "show full download - is_partial: true" do
report = HTDownloadPresenter.new(create(:ht_download, is_partial: true), action: :index)
assert_equal "no", report.field_value(:full_download)
end

test "show institution name" do
create(:ht_download) do |rep|
create(:ht_institution) do |inst|
Expand Down