diff --git a/app/forms/usage_statistics_reports_form.rb b/app/forms/usage_statistics_reports_form.rb index 6d79ce2ce..dc89a121d 100644 --- a/app/forms/usage_statistics_reports_form.rb +++ b/app/forms/usage_statistics_reports_form.rb @@ -12,6 +12,7 @@ class UsageStatisticsReportsForm < FormObject 'Resource Type' => SolrDocument.field_semantics[:resource_type], 'Organization' => SolrDocument.field_semantics[:organization], 'Department' => SolrDocument.field_semantics[:department], + 'Degree Level' => SolrDocument.field_semantics[:degree_level], 'Series' => SolrDocument.field_semantics[:columbia_series], 'Non CU Series' => SolrDocument.field_semantics[:non_columbia_series], 'CUL DOI' => SolrDocument.field_semantics[:id] diff --git a/db/schema.rb b/db/schema.rb index 9f62e6afb..6c0e4cc23 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_05_18_134528) do +ActiveRecord::Schema.define(version: 2022_12_08_202313) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false diff --git a/spec/academic_commons/metrics/usage_statistics_spec.rb b/spec/academic_commons/metrics/usage_statistics_spec.rb index b65ce8e8d..4c6cae049 100644 --- a/spec/academic_commons/metrics/usage_statistics_spec.rb +++ b/spec/academic_commons/metrics/usage_statistics_spec.rb @@ -2,6 +2,7 @@ RSpec.describe AcademicCommons::Metrics::UsageStatistics do let(:uni) { 'abc123' } + let(:degree_level) { 'Doctoral' } let(:item_identifier) { '10.7916/ALICE' } let(:item_fedora_pid) { 'actest:1' } let(:other_item_identifier) { '10.7916/TESTDOC5' } @@ -102,12 +103,33 @@ ) end + let(:item_by_degree_level_params) do + { + rows: 100_000, sort: 'title_sort asc', q: nil, page: 1, + fq: ["degree_level_name_ssim:\"#{degree_level}\"", 'has_model_ssim:"info:fedora/ldpd:ContentAggregator"'], + fl: 'title_ssi,id,cul_doi_ssi,fedora3_pid_ssi,publisher_doi_ssi,genre_ssim,record_creation_dtsi,object_state_ssi,free_to_read_start_date_ssi' + } + end + let(:item_by_degree_level_response) do + wrap_solr_response_data( + 'response' => { + 'docs' => [ + { 'id' => item_identifier, 'title_ssi' => 'First Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z', + 'cul_doi_ssi' => item_identifier, 'fedora3_pid_ssi' => item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' }, + { 'id' => other_item_identifier, 'title_ssi' => 'Second Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z', + 'cul_doi_ssi' => other_item_identifier, 'fedora3_pid_ssi' => other_item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' } + ] + } + ) + end + before do allow(Blacklight.default_index).to receive(:search).with(any_by_author_params).and_return(any_by_author_response) allow(Blacklight.default_index).to receive(:search).with(item_by_author_params).and_return(item_by_author_response) allow(Blacklight.default_index).to receive(:search).with(assets_for_item_params).and_return(assets_for_item_response) allow(Blacklight.default_index).to receive(:search).with(assets_for_other_item_params).and_return(assets_for_other_item_response) allow(Blacklight.default_index).to receive(:search).with(list_items_params).and_return(list_items_response) + allow(Blacklight.default_index).to receive(:search).with(item_by_degree_level_params).and_return(item_by_degree_level_response) end describe '.new' do @@ -226,6 +248,19 @@ expect(usage_stats.total_for(Statistic::DOWNLOAD, :lifetime)).to be 1 end end + + context 'when requesting stats for degree level' do + subject(:usage_stats) do + described_class.new( + solr_params: item_by_degree_level_params, + include_streaming: true + ).calculate_lifetime + end + + it 'returns correct results' do + expect(subject.map(&:document).map(&:to_h)).to eq item_by_degree_level_response.documents.map(&:to_h) + end + end end end diff --git a/spec/api/v1/record_spec.rb b/spec/api/v1/record_spec.rb index c3467c301..3f8227c23 100644 --- a/spec/api/v1/record_spec.rb +++ b/spec/api/v1/record_spec.rb @@ -11,10 +11,10 @@ 'columbia_series' => [], 'created_at' => '2017-09-14T16:31:33Z', 'date' => '1865', - 'degree_discipline' => nil, - 'degree_grantor' => nil, - 'degree_level' => nil, - 'degree_name' => nil, + 'degree_discipline' => 'Disciplinary Studies', + 'degree_grantor' => 'The Grantonator', + 'degree_level' => 'Doctoral', + 'degree_name' => 'Ph.D.', 'department' => ['Bucolic Literary Society.'], 'embargo_end' => nil, 'id' => '10.7916/ALICE', diff --git a/spec/fixtures/desc_metadata/to_solr.json b/spec/fixtures/desc_metadata/to_solr.json index 1f3ae79df..0cd02d47b 100644 --- a/spec/fixtures/desc_metadata/to_solr.json +++ b/spec/fixtures/desc_metadata/to_solr.json @@ -61,6 +61,21 @@ "start_page_ssi": "1", "end_page_ssi": "69", "date_ssi": "June 2008", + "degree_discipline_ssim": [ + "Disciplinary Studies" + ], + "degree_grantor_ssim": [ + "The Grantonator" + ], + "degree_level_name_ssim": [ + "Doctoral" + ], + "degree_level_ssim": [ + "2" + ], + "degree_name_ssim": [ + "Ph.D." + ], "book_journal_title_ssi": "Project Gutenberg", "book_journal_title_q": [ "Project Gutenberg" diff --git a/spec/fixtures/fedora_objs/mods.xml b/spec/fixtures/fedora_objs/mods.xml index dcf0e1773..4909c2f05 100644 --- a/spec/fixtures/fedora_objs/mods.xml +++ b/spec/fixtures/fedora_objs/mods.xml @@ -27,6 +27,15 @@ 1865 + + + Ph.D. + The Grantonator + Disciplinary Studies + 2 + + + English diff --git a/spec/fixtures/oai_xml/list_records_response.xml b/spec/fixtures/oai_xml/list_records_response.xml index 6373c8a5c..a57b000e9 100644 --- a/spec/fixtures/oai_xml/list_records_response.xml +++ b/spec/fixtures/oai_xml/list_records_response.xml @@ -8,6 +8,7 @@
oai:academiccommons.columbia.edu:10.7916/ALICE 2017-09-14T16:31:33Z + degree_level:Doctoral
diff --git a/yarn.lock b/yarn.lock index 6c894d51c..617aad5b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1905,9 +1905,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001280: - version "1.0.30001280" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001280.tgz#066a506046ba4be34cde5f74a08db7a396718fb7" - integrity sha512-kFXwYvHe5rix25uwueBxC569o53J6TpnGu0BEEn+6Lhl2vsnAumRFWEBhDft1fwyo6m1r4i+RqA4+163FpeFcA== + version "1.0.30001574" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001574.tgz" + integrity sha512-BtYEK4r/iHt/txm81KBudCUcTy7t+s9emrIaHqjYurQ10x71zJ5VQ9x1dYPcz/b+pKSp4y/v1xSI67A+LzpNyg== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0"