From c76f950a54528fd56b352b0c31ad532591573709 Mon Sep 17 00:00:00 2001 From: Fred Duby Date: Thu, 21 Nov 2024 17:45:34 -0500 Subject: [PATCH] Save and display asset PIDs --- app/controllers/sword_controller.rb | 1 + app/models/deposit.rb | 1 + app/views/deposits/show.html.erb | 5 +++++ db/migrate/20241121213246_add_asset_pids_to_deposits.rb | 5 +++++ db/schema.rb | 3 ++- lib/sword/adapters/hyacinth_adapter.rb | 5 ++++- lib/sword/endpoints/mets_to_hyacinth_endpoint.rb | 2 ++ 7 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20241121213246_add_asset_pids_to_deposits.rb diff --git a/app/controllers/sword_controller.rb b/app/controllers/sword_controller.rb index 9ba0efc..2a2e065 100644 --- a/app/controllers/sword_controller.rb +++ b/app/controllers/sword_controller.rb @@ -47,6 +47,7 @@ def deposit @deposit.title = @endpoint.deposit_title.truncate_words(20).truncate(200, omission: '') @deposit.item_in_hyacinth = @endpoint.adapter_item_identifier + @deposit.asset_pids = @endpoint.asset_pids @deposit.save # @depositor.deposits << @deposit # @collection.deposits << @deposit diff --git a/app/models/deposit.rb b/app/models/deposit.rb index 42a7368..4b03bfb 100644 --- a/app/models/deposit.rb +++ b/app/models/deposit.rb @@ -1,6 +1,7 @@ class Deposit < ApplicationRecord # belongs_to :depositor # belongs_to :collectio + serialize :asset_pids, type: Array serialize :deposit_errors, type: Array serialize :deposit_files, type: Array end diff --git a/app/views/deposits/show.html.erb b/app/views/deposits/show.html.erb index ad6fe89..48e455e 100644 --- a/app/views/deposits/show.html.erb +++ b/app/views/deposits/show.html.erb @@ -18,6 +18,11 @@ target: '_blank') %>

+

+ Asset PIDs: + <%= @deposit.asset_pids %> +

+

Depositor User ID: <%= @deposit.depositor_user_id %> diff --git a/db/migrate/20241121213246_add_asset_pids_to_deposits.rb b/db/migrate/20241121213246_add_asset_pids_to_deposits.rb new file mode 100644 index 0000000..936ee37 --- /dev/null +++ b/db/migrate/20241121213246_add_asset_pids_to_deposits.rb @@ -0,0 +1,5 @@ +class AddAssetPidsToDeposits < ActiveRecord::Migration[7.2] + def change + add_column :deposits, :asset_pids, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 644a6ca..61e74d8 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[7.1].define(version: 2024_10_30_175752) do +ActiveRecord::Schema[7.2].define(version: 2024_11_21_213246) do create_table "collections", force: :cascade do |t| t.string "name", null: false t.string "atom_title", null: false @@ -58,6 +58,7 @@ t.datetime "updated_at", precision: nil, null: false t.string "depositor_user_id" t.string "collection_slug" + t.text "asset_pids" t.index ["collection_id"], name: "index_deposits_on_collection_id" t.index ["collection_slug"], name: "index_deposits_on_collection_slug" t.index ["depositor_id"], name: "index_deposits_on_depositor_id" diff --git a/lib/sword/adapters/hyacinth_adapter.rb b/lib/sword/adapters/hyacinth_adapter.rb index 4ff2ab5..d7fbc80 100644 --- a/lib/sword/adapters/hyacinth_adapter.rb +++ b/lib/sword/adapters/hyacinth_adapter.rb @@ -3,7 +3,8 @@ module Sword module Adapters class HyacinthAdapter - attr_reader :digital_object_data, + attr_reader :asset_pids, + :digital_object_data, :dynamic_field_data, :hyacinth_server_response, :item_pid @@ -37,6 +38,7 @@ class HyacinthAdapter :use_and_reproduction_uri def initialize + @asset_pids = [] @corporate_names = [] @dynamic_field_data = {} @notes = [] @@ -133,6 +135,7 @@ def ingest_asset(parent_pid, Rails.logger.warn("ingest_asset: Completed ingest request to Hyacinth") if HYACINTH_CONFIG[:log_ingest] end # puts @hyacinth_response.inspect + @asset_pids << pid_last_ingest @hyacinth_server_response end diff --git a/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb b/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb index 14c277c..379f628 100644 --- a/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb +++ b/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb @@ -9,6 +9,7 @@ class MetsToHyacinthEndpoint < Endpoint # Some of these can be removed if no need for external access, # though in that case specs may need to be updated to access # instance var directly instead of through attr_reader + attr_reader :asset_pids attr_reader :content_dir attr_reader :mets_xml_file attr_reader :mets_parser @@ -66,6 +67,7 @@ def ingest_into_hyacinth @adapter_item_identifier = ingest_item_into_hyacinth ingest_documents_into_hyacinth ingest_mets_xml_file_into_hyacinth + @asset_pids = @hyacinth_adapter.asset_pids else Rails.logger.warn "Bypassing ingest into Hyacinth, set bogus PID" # bogus item identifier. Instead, could use string 'NotApplicable'