diff --git a/app/models/prefix.rb b/app/models/prefix.rb index db20a647d..332d41a49 100644 --- a/app/models/prefix.rb +++ b/app/models/prefix.rb @@ -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 @@ -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 diff --git a/lib/tasks/prefix.rake b/lib/tasks/prefix.rake index 4490de8f0..aa498c157 100644 --- a/lib/tasks/prefix.rake +++ b/lib/tasks/prefix.rake @@ -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