Skip to content

Commit

Permalink
Merge pull request #5037 from sul-dlss/report-model-switch#5003
Browse files Browse the repository at this point in the history
Switch subset of reports to new repository models
  • Loading branch information
justinlittman authored May 22, 2024
2 parents ebf845e + fdc5085 commit f925cb5
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/reports/invalid_edtf_dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/invalid_form_source_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/invalid_iso8601_dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/invalid_subject_non_source_uris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/property_contains_property_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
14 changes: 8 additions & 6 deletions app/reports/property_contains_property_dros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
Expand Down
18 changes: 10 additions & 8 deletions app/reports/property_events_with_display_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(';')

[
Expand Down
12 changes: 7 additions & 5 deletions app/reports/property_existence_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/property_nesting_level_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/reports/property_nesting_level_dros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit f925cb5

Please sign in to comment.