diff --git a/app/controllers/deposits_controller.rb b/app/controllers/deposits_controller.rb index 9c7850d..d07f99c 100644 --- a/app/controllers/deposits_controller.rb +++ b/app/controllers/deposits_controller.rb @@ -63,6 +63,61 @@ def destroy end end + def get_endpoint(collection_slug, + depositor_user_id) + case COLLECTIONS[:slug][collection_slug][:parser] + when "academic-commons" + Sword::Endpoints::AcademicCommonsEndpoint.new(collection_slug, depositor_user_id) + when "proquest" + Sword::Endpoints::ProquestEndpoint.new(collection_slug, depositor_user_id) + when "eprints" + Sword::Endpoints::EprintsEndpoint.new(collection_slug, depositor_user_id) + else + # raise an exception here + end + end + + def resubmit + original_deposit = Deposit.find(params[:id]) + endpoint = get_endpoint(original_deposit.collection_slug, + original_deposit.depositor_user_id) + + path_to_deposit_contents = original_deposit.content_path + + # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. + Rails.logger.warn("About to resubmit deposit for deposit id: #{original_deposit.id}:" \ + "Collection slug: #{original_deposit.collection_slug}, " \ + "Username: #{original_deposit.depositor_user_id}, " \ + "Path to contents: #{path_to_deposit_contents}" + ) + + endpoint.handle_deposit(path_to_deposit_contents) + + # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. + Rails.logger.warn("Following is a re-deposit:" \ + "Title: #{endpoint.deposit_title.truncate_words(10)}, " \ + "Files: #{endpoint.documents_to_deposit}, " \ + "Hyacinth item pid: #{endpoint.adapter_item_identifier}, " \ + "Hyacinth asset pids: #{endpoint.asset_pids}, " \ + "Path to SWORD contents: #{path_to_deposit_contents}" + ) + + # create Deposit instance to store deposit info in database + resubmit_deposit = Deposit.new + resubmit_deposit.depositor_user_id = @depositor_user_id + resubmit_deposit.collection_slug = @collection_slug + resubmit_deposit.deposit_files = endpoint.documents_to_deposit + resubmit_deposit.title = "(RE-DEPOSIT) " + original_deposit.title + resubmit_deposit.item_in_hyacinth = endpoint.adapter_item_identifier + resubmit_deposit.asset_pids = endpoint.asset_pids + resubmit_deposit.ingest_confirmed = endpoint.confirm_ingest + resubmit_deposit.content_path = path_to_deposit_contents + resubmit_deposit.save + response.status = 201 + render json: { item_pid: endpoint.adapter_item_identifier, + ingest_into_hyacinth: !(HYACINTH_CONFIG[:bypass_ingest] or COLLECTIONS[:slug][endpoint.collection_slug][:bypass_hyacinth_ingest])} + end + private # Use callbacks to share common setup or constraints between actions. def set_deposit diff --git a/app/controllers/sword_controller.rb b/app/controllers/sword_controller.rb index cce2673..00fdc2e 100644 --- a/app/controllers/sword_controller.rb +++ b/app/controllers/sword_controller.rb @@ -59,47 +59,6 @@ def deposit ingest_into_hyacinth: !(HYACINTH_CONFIG[:bypass_ingest] or COLLECTIONS[:slug][@endpoint.collection_slug][:bypass_hyacinth_ingest])} end - def resubmit_deposit(deposit) - - @endpoint = get_endpoint(deposit.collection_slug, - deposit.depositor_user_id) - - @path_to_deposit_contents = deposit.content_path - - # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. - Rails.logger.warn("About to resubmit deposit for deposit id: #{deposit.id}:" \ - "Collection slug: #{deposit.collection_slug}, " \ - "Username: #{deposit.depositor_user_id}, " \ - "Path to contents: #{@path_to_deposit_contents}" - ) - - @endpoint.handle_deposit(@path_to_deposit_contents) - - # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. - Rails.logger.warn("Following is a re-deposit:" \ - "Title: #{@endpoint.deposit_title.truncate_words(10)}, " \ - "Files: #{@endpoint.documents_to_deposit}, " \ - "Hyacinth item pid: #{@endpoint.adapter_item_identifier}, " \ - "Hyacinth asset pids: #{@endpoint.asset_pids}, " \ - "Path to SWORD contents: #{@path_to_deposit_contents}" - ) - - # create Deposit instance to store deposit info in database - @deposit = Deposit.new - @deposit.depositor_user_id = @depositor_user_id - @deposit.collection_slug = @collection_slug - @deposit.deposit_files = @endpoint.documents_to_deposit - @deposit.title = "(RE-DEPOSIT) " + deposit.title - @deposit.item_in_hyacinth = @endpoint.adapter_item_identifier - @deposit.asset_pids = @endpoint.asset_pids - @deposit.ingest_confirmed = @endpoint.confirm_ingest - @deposit.content_path = @path_to_deposit_contents - @deposit.save - response.status = 201 - render json: { item_pid: @endpoint.adapter_item_identifier, - ingest_into_hyacinth: !(HYACINTH_CONFIG[:bypass_ingest] or COLLECTIONS[:slug][@endpoint.collection_slug][:bypass_hyacinth_ingest])} - end - def service_document # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. Rails.logger.warn("Received Service Document request. Username: #{@depositor_user_id}") diff --git a/app/views/deposits/show.html.erb b/app/views/deposits/show.html.erb index 24bbdf6..41e52fb 100644 --- a/app/views/deposits/show.html.erb +++ b/app/views/deposits/show.html.erb @@ -49,3 +49,4 @@

<%= link_to 'Delete', @deposit, method: :delete, data: { confirm: 'Are you sure?' } %> +<%= link_to 'Resubmit', resubmit_deposit_path %> diff --git a/config/routes.rb b/config/routes.rb index 60957d6..ab6de28 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,10 @@ post 'add_permission', action: 'add_permission', as: 'add_permission' end end - resources :deposits + resources :deposits do + get 'resubmit', on: :member + end + resources :packages # Example resource route with options: