Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ gem 'net-ldap'
# temporarily hold back bulkrax version to 0.1.0
gem 'bulkrax', git: 'https://github.com/samvera-labs/bulkrax.git', ref: '5299b81' # branch: 'main'

# EZID client from Duke
gem 'ezid-client'
# custom datacite client
gem 'datacite', git: 'https://github.com/IUBLibTech/datacite-ruby', branch: 'datacore'

# Use jquery as the JavaScript library
gem 'jquery-rails'
Expand Down
15 changes: 11 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: https://github.com/IUBLibTech/datacite-ruby
revision: 95c7061f1cd95e8d8134b6e03738f871037e9b60
branch: datacore
specs:
datacite (0.6.0)
dry-monads (~> 1.3)
faraday (~> 0.17.6)
zeitwerk (~> 2.4)

GIT
remote: https://github.com/notch8/willow_sword.git
revision: 0a669d78617c6003e4aa1a46a10447be92be27d5
Expand Down Expand Up @@ -340,9 +350,6 @@ GEM
ethon (0.16.0)
ffi (>= 1.15.0)
execjs (2.10.0)
ezid-client (1.11.0)
hashie (~> 3.4, >= 3.4.3)
nokogiri
factory_bot (6.4.5)
activesupport (>= 5.0.0)
faraday (0.17.6)
Expand Down Expand Up @@ -1094,12 +1101,12 @@ DEPENDENCIES
config
coveralls_reborn
database_cleaner
datacite!
devise
devise-guests (~> 0.6)
dotenv-rails
down (~> 4.4)
edtf
ezid-client
factory_bot
fcrepo_wrapper
flipflop (= 2.6.0)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def self.modified_field
}
end

# FIXME: review DOI searching
config.add_search_field('doi') do |field|
field.label = "Doi"
solr_name = solr_name("doi_label", :stored_searchable)
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/concerns/datacore/doi_controller_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module Datacore
module DoiControllerBehavior

def doi_minting_enabled?
::Datacore::DoiMintingService.enabled?
end

def doi
doi_mint!

respond_to do |wants|
wants.html { redirect_to [main_app, curation_concern] }
wants.json do
render :show,
status: :ok,
location: polymorphic_path([main_app, curation_concern])
end
end
end

private

def doi_mint!
if !doi_minting_enabled?
flash[:alert] = MsgHelper.t('data_set.doi_minting_disabled')
elsif curation_concern.doi_pending?
flash[:notice] = MsgHelper.t('data_set.doi_is_being_minted')
elsif curation_concern.doi_minted?
flash[:alert] = MsgHelper.t('data_set.doi_already_exists')
elsif !curation_concern.doi_minimum_files?
flash[:alert] = MsgHelper.t('data_set.doi_requires_work_with_files')
elsif !curation_concern.valid?
flash[:alert] = MsgHelper.t('data_set.doi_requires_valid_work')
elsif (curation_concern.depositor != current_user.email) && !current_ability.admin?
flash[:alert] = MsgHelper.t('data_set.doi_user_without_access')
elsif curation_concern.doi_mint(current_user: current_user, event_note: 'DataSetsController')
flash[:notice] = MsgHelper.t('data_set.doi_minting_started')
else
flash[:error] = MsgHelper.t('data_set.doi_minting_error')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Deepblue

module WorksControllerBehavior
extend ActiveSupport::Concern
#in umrdr
#include Hyrax::Controller

include Hyrax::WorksControllerBehavior
include Deepblue::ControllerWorkflowEventBehavior

Expand Down
43 changes: 2 additions & 41 deletions app/controllers/hyrax/data_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class DataSetsController < DeepblueController
PARAMS_KEY = 'data_set'

include Deepblue::WorksControllerBehavior
include Datacore::DoiControllerBehavior

self.curation_concern_type = ::DataSet
self.show_presenter = Hyrax::DataSetPresenter
delegate :show_presenter, to: :class

before_action :assign_date_coverage, only: %i[create update]
before_action :assign_admin_set, only: %i[create update]
Expand Down Expand Up @@ -94,47 +96,6 @@ def assign_admin_set

# end date_coverage

## DOI

def doi
doi_mint
respond_to do |wants|
wants.html { redirect_to [main_app, curation_concern] }
wants.json do
render :show,
status: :ok,
location: polymorphic_path([main_app, curation_concern])
end
end
end

def doi_minting_enabled?
::Deepblue::DoiBehavior::DOI_MINTING_ENABLED
end

def doi_mint
# Do not mint doi if
# one already exists
# work file_set count is 0.
if curation_concern.doi_pending?
flash[:notice] = MsgHelper.t( 'data_set.doi_is_being_minted' )
elsif curation_concern.doi_minted?
flash[:notice] = MsgHelper.t( 'data_set.doi_already_exists' )
elsif curation_concern.file_sets.count < 1
flash[:notice] = MsgHelper.t( 'data_set.doi_requires_work_with_files' )
elsif ( curation_concern.depositor != current_user.email ) && !current_ability.admin?
flash[:notice] = MsgHelper.t( 'data_set.doi_user_without_access' )
elsif curation_concern.doi_mint( current_user: current_user, event_note: 'DataSetsController' )
flash[:notice] = MsgHelper.t( 'data_set.doi_minting_started' )
end
end

# def mint_doi_enabled?
# true
# end

## end DOI

## Globus

def globus_add_email
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/hyrax/deepblue_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ def display_provenance_log_enabled?
end

def doi_minting_enabled?
false
::Datacore::DoiMintingService.enabled?
end

def globus_download_enabled?
false
end

# def mint_doi_enabled?
# false
# end

def tombstone_enabled?
false
end
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/hyrax/file_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FileSetsController < ApplicationController

PARAMS_KEY = 'file_set'
self.show_presenter = Hyrax::DsFileSetPresenter
delegate :show_presenter, to: :class

alias_method :monkey_attempt_update, :attempt_update
# alias_method :monkey_update_metadata, :update_metadata
Expand Down Expand Up @@ -103,10 +104,6 @@ def presenter
end
end

def show_presenter
Hyrax::DsFileSetPresenter
end

def search_result_document( search_params )
_, document_list = search_results( search_params )
return document_list.first unless document_list.empty?
Expand Down
2 changes: 1 addition & 1 deletion app/indexers/data_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def generate_solr_document
# solr_doc['member_of_collection_ids_ssim'] = object.member_of_collections.map(&:id)

solr_doc[Solrizer.solr_name('creator_ordered', :stored_searchable)] = object.creator_ordered
solr_doc[Solrizer.solr_name('doi', :symbol)] = object.doi
solr_doc['doi_ssi'] = object.doi # FIXME: fix tesim version getting created

value = Array( object.referenced_by ).join( " " )
solr_doc[Solrizer.solr_name('referenced_by', :stored_searchable)] = value
Expand Down
53 changes: 15 additions & 38 deletions app/jobs/doi_minting_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,30 @@ class DoiMintingJob < ::Hyrax::ApplicationJob

queue_as :doi_minting

def perform( id, current_user: nil, job_delay: 0 )
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
"current_user=#{current_user}",
"job_delay=#{job_delay}"]
if 0 < job_delay
return unless ActiveFedora::Base.find( id ).doi_pending?
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
"current_user=#{current_user}",
"sleeping #{job_delay} seconds"]
sleep job_delay
def perform(id, current_user: nil, job_delay: 0)
sleep(job_delay) if job_delay > 0
work = ActiveFedora::Base.find(id)
unless work.doi_pending? && work.valid?
Rails.logger.error "DoiMintingJob called on #{'invalid ' unless work.valid?}work (#{work.id})#{' in invalid doi state (' + work.doi.to_s + ')' unless work.doi_pending?}, aborting"
return
end
work = ActiveFedora::Base.find( id )
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
Deepblue::LoggingHelper.obj_class( "work", work ),
"work.doi=#{work.doi}",
"work.doi_pending?=#{work.doi_pending?}"]
return unless work.doi_pending?
current_user = work.depositor if current_user.blank?
user = User.find_by_user_key( current_user )
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
"user.email=#{user.email}",
"Starting..." ]
# Rails.logger.debug "DoiMintingJob work id #{id} #{user.email} starting..."
if Deepblue::DoiMintingService.mint_doi_for( work: work, current_user: current_user )
Rails.logger.debug "DoiMintingJob work id #{id} #{user.email} succeeded."
if Datacore::DoiMintingService.mint_doi_for(work: work, current_user: current_user)
Rails.logger.debug "DoiMintingJob work id #{id} #{current_user} succeeded."
# do success callback
if Hyrax.config.callback.set?( :after_doi_success )
Hyrax.config.callback.run( :after_doi_success, work, user, log.created_at )
if Hyrax.config.callback.set?(:after_doi_success)
Hyrax.config.callback.run(:after_doi_success, work, user, log.created_at)
end
else
Rails.logger.debug "DoiMintingJob work id #{id} #{user.email} failed."
Rails.logger.debug "DoiMintingJob work id #{id} #{current_user} failed."
# do failure callback
if Hyrax.config.callback.set?( :after_doi_failure )
Hyrax.config.callback.run( :after_doi_failure, work, user, log.created_at )
if Hyrax.config.callback.set?(:after_doi_failure)
Hyrax.config.callback.run(:after_doi_failure, work, user, log.created_at)
end
end
true
rescue Exception => e # rubocop:disable Lint/RescueException
Rails.logger.error "DoiMintingJob.perform(#{id},#{job_delay}) #{e.class}: #{e.message} at #{e.backtrace[0]}"
raise
false
end

end
72 changes: 30 additions & 42 deletions app/models/concerns/deepblue/doi_behavior.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
# frozen_string_literal: true

module Deepblue

class DoiError < RuntimeError
end

module DoiBehavior

DOI_MINTING_ENABLED = true
DOI_PENDING = 'doi_pending'
DOI_MINIMUM_FILE_COUNT = 1

def doi_minted?
!doi.nil?
rescue
nil
doi.present? && !doi_pending?
end

def doi_minting_enabled?
::Deepblue::DoiBehavior::DOI_MINTING_ENABLED
::Datacore::DoiMintingService.enabled?
end

def doi_pending?
doi == DOI_PENDING
end

def doi_mint( current_user: nil, event_note: '', enforce_minimum_file_count: true, job_delay: 0 )
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
"doi=#{doi}",
"current_user=#{current_user}",
"event_note=#{event_note}",
"enforce_minimum_file_count=#{enforce_minimum_file_count}",
"job_delay=#{job_delay}" ]
return false if doi_pending?
# Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
# Deepblue::LoggingHelper.called_from,
# "work.id=#{id}",
# "past doi_pending?" ]
return false if doi_minted?
# Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
# Deepblue::LoggingHelper.called_from,
# "work.id=#{id}",
# "past doi_minted?" ]
return false if enforce_minimum_file_count && file_sets.count < DOI_MINIMUM_FILE_COUNT
self.doi = DOI_PENDING
self.save
self.reload
current_user = current_user.email if current_user.respond_to? :email
Deepblue::LoggingHelper.bold_debug [ Deepblue::LoggingHelper.here,
Deepblue::LoggingHelper.called_from,
"work.id=#{id}",
"doi=#{doi}",
"about to call DoiMintingJob" ]
::DoiMintingJob.perform_later( id, current_user: current_user, job_delay: job_delay )
return true
def doi_minimum_files?
file_sets.count >= DOI_MINIMUM_FILE_COUNT
end

def doi_mint(current_user: nil, event_note: '', enforce_minimum_file_count: true, job_delay: 0 )
if !doi_minting_enabled?
Rails.logger.warn "DoiBehavior.doi_mint called for curation_concern.id #{id} with minting disabled"
return false
elsif invalid?
Rails.logger.warn "DoiBehavior.doi_mint called for curation_concern.id #{id} with invalid metadata: #{self.errors.full_messages}"
return false
elsif doi_pending?
Rails.logger.warn "DoiBehavior.doi_mint called for curation_concern.id #{id} with pending doi"
return false
elsif doi_minted?
Rails.logger.warn "DoiBehavior.doi_mint called for curation_concern.id #{id} with minted doi (#{doi})"
return false
elsif enforce_minimum_file_count && !doi_minimum_files?
Rails.logger.warn "DoiBehavior.doi_mint called for curation_concern.id #{id} with insufficient FileSet count (#{file_sets.count})"
return false
else
self.doi = DOI_PENDING
self.save
self.reload
::DoiMintingJob.perform_later(id, current_user: current_user&.try(:email), job_delay: job_delay)
Rails.logger.info "DoiBehavior.doi_mint called DoiMintingJob for curation_concern.id #{id}"
return true
end
rescue Exception => e # rubocop:disable Lint/RescueException
Rails.logger.error "DoiBehavior.doi_mint for curation_concern.id #{id} -- #{e.class}: #{e.message} at #{e.backtrace[0]}"
end

end

end
Loading