Skip to content

Commit

Permalink
Merge pull request #81 from datacite/add_import_one
Browse files Browse the repository at this point in the history
Add name_identifier import_one task
  • Loading branch information
richardhallett authored Feb 17, 2021
2 parents 4c1cc9f + 3db3d3b commit 9733bee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/models/name_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -82,7 +95,7 @@ def self.push_item(item)
"subj" => subj,
"obj" => obj }
end

ssum
end

Expand All @@ -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" => {
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/name_identifier.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9733bee

Please sign in to comment.