Skip to content

Commit

Permalink
check doi registration agency of each prefix. #703
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 11, 2021
1 parent 07ac6af commit 30f79ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/models/prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Prefix < ApplicationRecord
# include helper module for Elasticsearch
include Indexable

# include helper module for Prefix registration
include Identifiable

include Elasticsearch::Model

validates_presence_of :uid
Expand Down Expand Up @@ -102,6 +105,31 @@ def self.find_by_id(id)
)
end

def self.get_registration_agency
headers = [
"Prefix",
"RA",
]

rows = Prefix.all.pluck(:uid).reduce([]) do |sum, prefix|
ra = get_doi_ra(prefix).to_s.downcase

if ra != "datacite"
row = {
prefix: prefix,
ra: ra,
}.values

sum << CSV.generate_line(row)
end

sum
end

csv = [CSV.generate_line(headers)] + rows
csv.join("")
end

def client_ids
clients.pluck(:symbol).map(&:downcase)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/prefix.rake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ namespace :prefix do
puts Prefix.delete_by_query(index: ENV["INDEX"], query: ENV["QUERY"])
end

desc "Get registration agency for each prefix"
task registration_agency: :environment do
puts Prefix.get_registration_agency
end

desc "Delete prefix and associated DOIs"
task delete: :environment do
# These prefixes are used by multiple prefixes and can't be deleted
Expand Down

0 comments on commit 30f79ee

Please sign in to comment.