Skip to content

Commit

Permalink
Save and display ingest confirmation result
Browse files Browse the repository at this point in the history
  • Loading branch information
fcd1 committed Nov 22, 2024
1 parent 7d9c716 commit 60b6795
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/controllers/sword_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def deposit
@endpoint.deposit_title.truncate_words(20).truncate(200, omission: '')
@deposit.item_in_hyacinth = @endpoint.adapter_item_identifier
@deposit.asset_pids = @endpoint.asset_pids
@deposit.ingest_confirmed = @endpoint.ingest_confirmed
@deposit.save
# @depositor.deposits << @deposit
# @collection.deposits << @deposit
Expand Down
5 changes: 5 additions & 0 deletions app/views/deposits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<%= @deposit.asset_pids %>
</p>

<p>
<strong>Ingest Confirmed?</strong>
<%= @deposit.ingest_confirmed %>
</p>

<p>
<strong>Depositor User ID:</strong>
<%= @deposit.depositor_user_id %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241122163611_add_ingest_confirmed_to_deposits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIngestConfirmedToDeposits < ActiveRecord::Migration[7.2]
def change
add_column :deposits, :ingest_confirmed, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_11_21_213246) do
ActiveRecord::Schema[7.2].define(version: 2024_11_22_163611) do
create_table "collections", force: :cascade do |t|
t.string "name", null: false
t.string "atom_title", null: false
Expand Down Expand Up @@ -59,6 +59,7 @@
t.string "depositor_user_id"
t.string "collection_slug"
t.text "asset_pids"
t.boolean "ingest_confirmed"
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"
Expand Down
8 changes: 5 additions & 3 deletions lib/sword/adapters/hyacinth_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ def expected_and_retrieved_asset_pids_match?
Net::HTTP.start(uri.hostname,
uri.port,
use_ssl: HYACINTH_CONFIG[:use_ssl]) { |http| http.request(get_req) }
unless server_response.nil?
retrieved_pids =
JSON.parse(server_response.body)['ordered_child_digital_objects'].each.map { |pid_hash| pid_hash['pid'] }
unless server_response.is_a? Net::HTTPSuccess
Rails.logger.warn("Item GET failure (Item PID: #{@item_pid}, HTTP code: #{server_response.code})")
return false
end
retrieved_pids =
JSON.parse(server_response.body)['ordered_child_digital_objects'].each.map { |pid_hash| pid_hash['pid'] }
pids_match = Set.new(@asset_pids) == Set.new(retrieved_pids)
unless pids_match
Rails.logger.warn("Asset pids mismatch (expected: #{@asset_pids}, retrieved from Hyacinth Item: #{retrieved_pids}")
Expand Down
10 changes: 6 additions & 4 deletions lib/sword/endpoints/mets_to_hyacinth_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@ def ingest_into_hyacinth
ingest_documents_into_hyacinth
ingest_mets_xml_file_into_hyacinth
@asset_pids = @hyacinth_adapter.asset_pids
validate_asset_pids
confirm_ingest
else
Rails.logger.warn "Bypassing ingest into Hyacinth, set bogus PID"
# bogus item identifier. Instead, could use string 'NotApplicable'
@adapter_item_identifier = 'na:xxxxxxxxxxx'
end
end

def validate_asset_pids
def confirm_ingest
if @hyacinth_adapter.expected_and_retrieved_asset_pids_match?
Rails.logger.warn("MetsToHyacinthEndpoint: Asset pids match")
Rails.logger.warn("MetsToHyacinthEndpoint: Ingest confirmed")
true
else
Rails.logger.warn("MetsToHyacinthEndpoint: ASSET PIDS DO NOT MATCH!!!")
Rails.logger.warn("MetsToHyacinthEndpoint: INGEST NOT CONFIRMED!!!")
false
end
end

Expand Down

0 comments on commit 60b6795

Please sign in to comment.