From fdc5085c6145c66f3e555b4948246865b9f6b138 Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Tue, 21 May 2024 16:43:54 -0700 Subject: [PATCH] Switch subset of reports to new repository models Fixes #5003 --- app/reports/invalid_edtf_dates.rb | 2 +- app/reports/invalid_form_source_codes.rb | 2 +- app/reports/invalid_iso8601_dates.rb | 2 +- app/reports/invalid_subject_non_source_uris.rb | 2 +- .../property_contains_property_collections.rb | 2 +- app/reports/property_contains_property_dros.rb | 14 ++++++++------ .../property_events_with_display_label.rb | 18 ++++++++++-------- app/reports/property_existence_collections.rb | 12 +++++++----- .../property_nesting_level_collections.rb | 2 +- app/reports/property_nesting_level_dros.rb | 2 +- 10 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/reports/invalid_edtf_dates.rb b/app/reports/invalid_edtf_dates.rb index 3b522eb02..a33abf051 100644 --- a/app/reports/invalid_edtf_dates.rb +++ b/app/reports/invalid_edtf_dates.rb @@ -50,7 +50,7 @@ def self.rows(sql) next if invalid_values.blank? collection_druid = rows.first['collection_id'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ id, diff --git a/app/reports/invalid_form_source_codes.rb b/app/reports/invalid_form_source_codes.rb index 9e88a9aee..c4100b59f 100644 --- a/app/reports/invalid_form_source_codes.rb +++ b/app/reports/invalid_form_source_codes.rb @@ -47,7 +47,7 @@ def self.rows(sql) .group_by { |row| row['external_identifier'] } .map do |id, rows| collection_druid = rows.first['collection_id'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ id, diff --git a/app/reports/invalid_iso8601_dates.rb b/app/reports/invalid_iso8601_dates.rb index 4d4879257..fb9dbe91e 100644 --- a/app/reports/invalid_iso8601_dates.rb +++ b/app/reports/invalid_iso8601_dates.rb @@ -47,7 +47,7 @@ def self.rows(sql) next if invalid_values.blank? collection_druid = rows.first['collection_id'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ id, diff --git a/app/reports/invalid_subject_non_source_uris.rb b/app/reports/invalid_subject_non_source_uris.rb index b74a24771..a303f3be0 100644 --- a/app/reports/invalid_subject_non_source_uris.rb +++ b/app/reports/invalid_subject_non_source_uris.rb @@ -40,7 +40,7 @@ def self.rows(sql) .group_by { |row| row['external_identifier'] } .map do |id, rows| collection_druid = rows.first['collection_id'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ id, diff --git a/app/reports/property_contains_property_collections.rb b/app/reports/property_contains_property_collections.rb index 4a3989e47..5fd4d7089 100644 --- a/app/reports/property_contains_property_collections.rb +++ b/app/reports/property_contains_property_collections.rb @@ -33,7 +33,7 @@ def self.rows(sql_query) sql_result_rows = ActiveRecord::Base.connection.execute(sql_query).to_a sql_result_rows.map do |row| - collection_name = Collection.find_by(external_identifier: row['collection_druid'])&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: row['collection_druid'])&.head_version&.label [ row['collection_druid'], diff --git a/app/reports/property_contains_property_dros.rb b/app/reports/property_contains_property_dros.rb index ed2698e18..9a306fcaf 100644 --- a/app/reports/property_contains_property_dros.rb +++ b/app/reports/property_contains_property_dros.rb @@ -18,11 +18,13 @@ class PropertyContainsPropertyDros JSON_PATH = "strict $.**.#{OUTER_PROPERTY} ? (exists(@.**{1 TO LAST}.#{INNER_PROPERTY} ? (@.size() > 0)))".freeze SQL = <<~SQL.squish.freeze - SELECT external_identifier as item_druid, - jsonb_path_query(identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') ->> 0 as catalogRecordId, - jsonb_path_query(structural, '$.isMemberOf') ->> 0 as collection_druid - FROM "dros" WHERE - jsonb_path_exists(dros.description, '#{JSON_PATH}') + SELECT ro.external_identifier as item_druid, + jsonb_path_query(rov.identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') ->> 0 as catalogRecordId, + jsonb_path_query(rov.structural, '$.isMemberOf') ->> 0 as collection_druid + FROM repository_objects AS ro, repository_object_versions AS rov + WHERE ro.head_version_id = rov.id + AND ro.object_type = 'dro' + AND jsonb_path_exists(rov.description, '#{JSON_PATH}') SQL def self.report @@ -34,7 +36,7 @@ def self.rows(sql_query) sql_result_rows = ActiveRecord::Base.connection.execute(sql_query).to_a sql_result_rows.map do |row| - collection_name = Collection.find_by(external_identifier: row['collection_druid'])&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: row['collection_druid'])&.head_version&.label [ row['item_druid'], diff --git a/app/reports/property_events_with_display_label.rb b/app/reports/property_events_with_display_label.rb index 3a43b835e..f5d31594e 100644 --- a/app/reports/property_events_with_display_label.rb +++ b/app/reports/property_events_with_display_label.rb @@ -6,13 +6,15 @@ # class PropertyEventsWithDisplayLabel SQL = <<~SQL.squish.freeze - SELECT dros.external_identifier as item_druid, - dros.label as title,#{' '} - jsonb_path_query(dros.structural, '$.isMemberOf') ->> 0 as collection_druid, - jsonb_path_query_array(dros.description, '$.event.displayLabel') as displayLabels, - jsonb_path_query_first(dros.identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') as catalogRecordId - FROM "dros" - WHERE jsonb_path_exists(dros.description, '$.event.displayLabel'); + SELECT ro.external_identifier as item_druid, + rov.label as title,#{' '} + jsonb_path_query(rov.structural, '$.isMemberOf') ->> 0 as collection_druid, + jsonb_path_query_array(rov.description, '$.event.displayLabel') as displayLabels, + jsonb_path_query_first(rov.identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') as catalogRecordId + FROM repository_objects AS ro, repository_object_versions AS rov + WHERE ro.head_version_id = rov.id + AND ro.object_type = 'dro' + AND jsonb_path_exists(rov.description, '$.event.displayLabel'); SQL def self.report @@ -25,7 +27,7 @@ def self.result_rows(sql_query) sql_result_rows = ActiveRecord::Base.connection.execute(sql_query).to_a sql_result_rows.map do |row| - collection_name = Collection.find_by(external_identifier: row['collection_druid'])&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: row['collection_druid'])&.head_version&.label display_labels = JSON.parse(row['displaylabels']).map { |label| "\"#{label}\"" }.join(';') [ diff --git a/app/reports/property_existence_collections.rb b/app/reports/property_existence_collections.rb index e336681f8..c513f8975 100644 --- a/app/reports/property_existence_collections.rb +++ b/app/reports/property_existence_collections.rb @@ -18,10 +18,12 @@ class PropertyExistenceCollections JSON_PATH = "strict $.**.#{PROPERTY} ? (@.size() > 0)".freeze # when property is array SQL = <<~SQL.squish.freeze - SELECT external_identifier as collection_druid, - jsonb_path_query(identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') ->> 0 as catalogRecordId - FROM "collections" WHERE - jsonb_path_exists(collections.description, '#{JSON_PATH}') + SELECT ro.external_identifier as collection_druid, + jsonb_path_query(rov.identification, '$.catalogLinks[*] ? (@.catalog == "folio").catalogRecordId') ->> 0 as catalogRecordId + FROM repository_objects AS ro, repository_object_versions AS rov + WHERE ro.head_version_id = rov.id + AND ro.object_type = 'collection' + AND jsonb_path_exists(rov.description, '#{JSON_PATH}') SQL def self.report @@ -34,7 +36,7 @@ def self.rows(sql_query) sql_result_rows.map do |row| collection_druid = row['collection_druid'] - collection_name = Collection.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ collection_druid, diff --git a/app/reports/property_nesting_level_collections.rb b/app/reports/property_nesting_level_collections.rb index 1b5cc6865..0b737eaf0 100644 --- a/app/reports/property_nesting_level_collections.rb +++ b/app/reports/property_nesting_level_collections.rb @@ -30,7 +30,7 @@ def self.rows(sql_query) sql_result_rows.map do |row| collection_druid = row['collection_druid'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ collection_druid, diff --git a/app/reports/property_nesting_level_dros.rb b/app/reports/property_nesting_level_dros.rb index adaac9a5c..7f381cbf7 100644 --- a/app/reports/property_nesting_level_dros.rb +++ b/app/reports/property_nesting_level_dros.rb @@ -31,7 +31,7 @@ def self.rows(sql_query) sql_result_rows.map do |row| collection_druid = row['collection_id'] - collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.label + collection_name = RepositoryObject.collections.find_by(external_identifier: collection_druid)&.head_version&.label [ row['item_druid'],