Skip to content

Commit

Permalink
allow manual updates of crossref and orcid metadata stored with datac…
Browse files Browse the repository at this point in the history
…ite. #301
  • Loading branch information
Martin Fenner committed Jul 4, 2019
1 parent ce50eab commit d732568
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ GEM
latex-decode (~> 0.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bolognese (1.2)
bolognese (1.2.2)
activesupport (>= 4.2.5, < 6)
benchmark_methods (~> 0.7)
bibtex-ruby (~> 4.1)
Expand Down
21 changes: 13 additions & 8 deletions app/jobs/crossref_doi_by_id_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ class CrossrefDoiByIdJob < ActiveJob::Base

# discard_on ActiveJob::DeserializationError

def perform(id)
def perform(id, options={})
logger = Logger.new(STDOUT)

doi = doi_from_url(id)
return {} unless doi.present?

# check whether DOI has been registered with DataCite already
result = Doi.find_by_id(doi).results.first
return {} unless result.blank?
# check whether DOI has been stored with DataCite already
# unless we want to refresh the metadata
unless options[:refresh]
result = Doi.find_by_id(doi).results.first
return {} unless result.blank?
end

# otherwise store Crossref metadata with DataCite
# using client crossref.citations and DataCite XML
Expand Down Expand Up @@ -42,14 +45,16 @@ def perform(id)
url = "http://localhost/dois/#{doi}"
response = Maremma.put(url, accept: 'application/vnd.api+json',
content_type: 'application/vnd.api+json',
data: data.to_json,
data: data.to_json,
username: ENV["ADMIN_USERNAME"],
password: ENV["ADMIN_PASSWORD"])

if [200, 201].include?(response.status)
logger.info "DOI #{doi} created."
if response.status == 201
logger.info "DOI #{doi} record created."
elsif response.status == 200
logger.info "DOI #{doi} record updated."
else
logger.warn "[Error for DOI #{doi}]: " + response.body["errors"].inspect
logger.error "[Error parsing Crossref DOI #{doi}]: " + response.body["errors"].inspect
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/jobs/crossref_doi_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CrossrefDoiJob < ActiveJob::Base
queue_as :lupo_background

def perform(ids)
ids.each { |id| CrossrefDoiByIdJob.perform_later(id) }
def perform(ids, options={})
ids.each { |id| CrossrefDoiByIdJob.perform_later(id, options) }
end
end
11 changes: 7 additions & 4 deletions app/jobs/orcid_auto_update_by_id_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ class OrcidAutoUpdateByIdJob < ActiveJob::Base

# discard_on ActiveJob::DeserializationError

def perform(id)
def perform(id, options={})
logger = Logger.new(STDOUT)

orcid = orcid_from_url(id)
return {} unless orcid.present?

# check whether ORCID ID has been registered with DataCite already
result = Researcher.find_by_id(orcid).results.first
return {} unless result.blank?
# check whether ORCID ID has been stored with DataCite already
# unless we want to refresh the metadata
unless options[:refresh]
result = Researcher.find_by_id(orcid).results.first
return {} unless result.blank?
end

# otherwise fetch basic ORCID metadata and store with DataCite
url = "https://pub.orcid.org/v2.1/#{orcid}/person"
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/orcid_auto_update_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class OrcidAutoUpdateJob < ActiveJob::Base
queue_as :lupo_background

def perform(ids)
ids.each { |id| OrcidAutoUpdateByIdJob.perform_later(id) }
def perform(ids, options={})
ids.each { |id| OrcidAutoUpdateByIdJob.perform_later(id, options) }
end
end
4 changes: 2 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def self.update_datacite_crossref(options={})
cursor = response.results.to_a.last[:sort].first.to_i

dois = response.results.results.map(&:obj_id).uniq
CrossrefDoiJob.perform_later(dois)
CrossrefDoiJob.perform_later(dois, options)
end
end

Expand All @@ -350,7 +350,7 @@ def self.update_datacite_orcid_auto_update(options={})
cursor = response.results.to_a.last[:sort].first.to_i

ids = response.results.results.map(&:obj_id).uniq
OrcidAutoUpdateJob.perform_later(ids)
OrcidAutoUpdateJob.perform_later(ids, options)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/event.rake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace :datacite_crossref do
task :import_doi => :environment do
cursor = (ENV['CURSOR'] || Event.minimum(:id)).to_i

Event.update_datacite_crossref(cursor: cursor)
Event.update_datacite_crossref(cursor: cursor, refresh: ENV['REFRESH'], size: ENV['SIZE'])
end
end

Expand All @@ -46,6 +46,6 @@ namespace :datacite_orcid_auto_update do
task :import_orcid => :environment do
cursor = (ENV['CURSOR'] || Event.minimum(:id)).to_i

Event.update_datacite_orcid_auto_update(cursor: cursor)
Event.update_datacite_orcid_auto_update(cursor: cursor, refresh: ENV['REFRESH'], size: ENV['SIZE'])
end
end

0 comments on commit d732568

Please sign in to comment.