From 3db3d3b5c3a7b6d0743884da004326d49cfadae3 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Wed, 17 Feb 2021 12:57:00 +0100 Subject: [PATCH] Add name_identifier import_one task This is to aid in debugging when DOIs have not been added to profiles. --- app/models/name_identifier.rb | 19 ++++++++++++++++--- lib/tasks/name_identifier.rake | 10 ++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/models/name_identifier.rb b/app/models/name_identifier.rb index dbebfefa..c92a1193 100644 --- a/app/models/name_identifier.rb +++ b/app/models/name_identifier.rb @@ -21,6 +21,19 @@ def self.import(options={}) name_identifier.queue_jobs(name_identifier.unfreeze(from_date: from_date.strftime("%F"), until_date: until_date.strftime("%F"))) end + def self.import_one(options={}) + doi = options[:doi] + + if doi.blank? + message = "Error DOI #{doi}: not provided" + Rails.logger.error message + return message + end + + attributes = get_datacite_json(doi) + response = push_item({ "id" => doi, "type" => "dois", "attributes" => attributes }) + end + def source_id "datacite_orcid_auto_update" end @@ -61,7 +74,7 @@ def self.push_item(item) source_id = item.fetch("sourceId", "datacite_orcid_auto_update") relation_type_id = "is_authored_by" source_token = ENV['DATACITE_ORCID_AUTO_UPDATE_SOURCE_TOKEN'] - + push_items = Array.wrap(creators).reduce([]) do |ssum, iitem| name_identifier = Array.wrap(iitem.fetch("nameIdentifiers", nil)).find { |n| n["nameIdentifierScheme"] == "ORCID" } obj_id = normalize_orcid(name_identifier["nameIdentifier"]) if name_identifier.present? @@ -82,7 +95,7 @@ def self.push_item(item) "subj" => subj, "obj" => obj } end - + ssum end @@ -92,7 +105,7 @@ def self.push_item(item) if ENV['LAGOTTINO_TOKEN'].present? push_url = ENV['LAGOTTINO_URL'] + "/events" - data = { + data = { "data" => { "type" => "events", "attributes" => { diff --git a/lib/tasks/name_identifier.rake b/lib/tasks/name_identifier.rake index adcbf70e..0d1b07cf 100644 --- a/lib/tasks/name_identifier.rake +++ b/lib/tasks/name_identifier.rake @@ -16,4 +16,14 @@ namespace :name_identifier do response = NameIdentifier.import(from_date: from_date, until_date: until_date) puts "Queued import for #{response} DOIs created from #{from_date} - #{until_date}." end + + task :import_one => :environment do + if ENV["DOI"].nil? + puts "ENV['DOI'] is required." + exit + end + + response = NameIdentifier.import_one(doi: ENV['DOI']) + puts "Import for #{response} DOI #{ENV['DOI']}" + end end \ No newline at end of file