Skip to content

Commit

Permalink
remove test prefix 10.5072. #305
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 7, 2019
1 parent e860c49 commit aa9e5c8
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 53 deletions.
20 changes: 1 addition & 19 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class Doi < ActiveRecord::Base
state :tombstoned, :registered, :findable, :flagged, :broken

event :register do
# can't register test prefix
transitions from: [:draft], to: :registered, if: [:registerable?]
end

event :publish do
# can't index test prefix
transitions from: [:draft], to: :findable, if: [:registerable?]
transitions from: :registered, to: :findable
end
Expand Down Expand Up @@ -567,12 +565,8 @@ def suffix
uid.split("/", 2).last if doi.present?
end

def is_test_prefix?
prefix == "10.5072"
end

def registerable?
prefix != "10.5072" # && url.present?
true # && url.present?
end

# def is_valid?
Expand Down Expand Up @@ -657,18 +651,6 @@ def event=(value)
self.send(value) if %w(register publish hide show).include?(value)
end

# delete all DOIs with test prefix 10.5072 not updated since from_date
# we need to use destroy_all to also delete has_many associations for metadata and media
def self.delete_test_dois(from_date: nil)
from_date ||= Time.zone.now - 1.month
collection = Doi.where("updated < ?", from_date)
collection.where("doi LIKE ?", "10.5072%").find_each do |d|
logger = Logger.new(STDOUT)
logger.info "Automatically deleted #{d.doi}, last updated #{d.updated.iso8601}."
d.destroy
end
end

# to be used after DOIs were transferred to another DOI RA
def self.delete_dois_by_prefix(prefix, options={})
logger = Logger.new(STDOUT)
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/prefix_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class PrefixSerializer

attributes :registration_agency, :created, :updated

has_many :clients, record_type: :clients, if: Proc.new { |record| record.prefix != "10.5072" }
has_many :providers, record_type: :providers, if: Proc.new { |record| record.prefix != "10.5072" }
has_many :clients, record_type: :clients
has_many :providers, record_type: :providers
end
4 changes: 2 additions & 2 deletions lib/tasks/client.rake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace :client do
end

# These prefixes are used by multiple clients
prefixes_to_keep = %w(10.5072 10.4124 10.4225 10.4226 10.4227)
prefixes_to_keep = %w(10.4124 10.4225 10.4226 10.4227)

# delete all associated prefixes and DOIs
prefixes = client.prefixes.where.not('prefix IN (?)', prefixes_to_keep).pluck(:prefix)
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace :client do
end

# These prefixes are used by multiple clients
prefixes_to_keep = %w(10.5072 10.4124 10.4225 10.4226 10.4227)
prefixes_to_keep = %w(10.4124 10.4225 10.4226 10.4227)

# delete all associated prefixes
prefixes = client.prefixes.where.not('prefix IN (?)', prefixes_to_keep).pluck(:prefix)
Expand Down
6 changes: 0 additions & 6 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ namespace :doi do
Doi.set_minted
end

desc 'Delete DOIs with test prefix older than one month'
task :delete_test_dois => :environment do
from_date = ENV['FROM_DATE'] || Time.zone.now - 1.month
Doi.delete_test_dois(from_date: from_date)
end

desc 'Migrates landing page data handling camelCase changes at same time'
task :migrate_landing_page => :environment do
Doi.migrate_landing_page
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/prefix.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace :prefix do
desc 'Delete prefix and associated DOIs'
task :delete => :environment do
# These prefixes are used by multiple clients and can't be deleted
prefixes_to_keep = %w(10.5072 10.4124 10.4225 10.4226 10.4227)
prefixes_to_keep = %w(10.4124 10.4225 10.4226 10.4227)

if ENV['PREFIX'].nil?
puts "ENV['PREFIX'] is required."
Expand Down
4 changes: 2 additions & 2 deletions spec/concerns/crosscitable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

expect(meta["string"]).to eq(string)
expect(meta["from"]).to eq("datacite")
expect(meta["doi"]).to eq("10.5072/testpub")
expect(meta["doi"]).to eq("10.14454/testpub")
expect(meta["creators"]).to eq([{"familyName"=>"Smith", "givenName"=>"John", "name"=>"Smith, John", "nameType"=>"Personal"}, {"name"=>"つまらないものですが"}])
expect(meta["titles"]).to eq([{"title"=>"Właściwości rzutowań podprzestrzeniowych"}, {"title"=>"Translation of Polish titles", "titleType"=>"TranslatedTitle"}])
expect(meta["publication_year"]).to eq("2010")
Expand Down Expand Up @@ -365,7 +365,7 @@
string = file_fixture('datacite_schema_2.2.xml').read
meta = subject.parse_xml(string)

expect(meta["doi"]).to eq("10.5072/testpub")
expect(meta["doi"]).to eq("10.14454/testpub")
expect(meta["creators"]).to eq([{"familyName"=>"Smith", "givenName"=>"John", "name"=>"Smith, John", "nameType"=>"Personal"}, {"name"=>"つまらないものですが"}])
expect(meta["titles"]).to eq([{"title"=>"Właściwości rzutowań podprzestrzeniowych"}, {"title"=>"Translation of Polish titles", "titleType"=>"TranslatedTitle"}])
expect(meta["publication_year"]).to eq("2010")
Expand Down
14 changes: 7 additions & 7 deletions spec/concerns/helpable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

context "validate_prefix" do
it 'should validate' do
str = "10.5072"
expect(subject.validate_prefix(str)).to eq("10.5072")
str = "10.14454"
expect(subject.validate_prefix(str)).to eq("10.14454")
end

it 'should validate with slash' do
str = "10.5072/"
expect(subject.validate_prefix(str)).to eq("10.5072")
str = "10.14454/"
expect(subject.validate_prefix(str)).to eq("10.14454")
end

it 'should validate with shoulder' do
str = "10.5072/FK2"
expect(subject.validate_prefix(str)).to eq("10.5072")
str = "10.14454/FK2"
expect(subject.validate_prefix(str)).to eq("10.14454")
end

it 'should not validate if not DOI prefix' do
str = "20.5072"
str = "20.14454"
expect(subject.validate_prefix(str)).to be_nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/datacite_schema_2.2.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource xmlns="http://datacite.org/schema/kernel-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd">
<identifier identifierType="DOI">10.5072/testpub</identifier>
<identifier identifierType="DOI">10.14454/testpub</identifier>
<creators>
<creator>
<creatorName>Smith, John</creatorName>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/large_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<identifier identifierType="DOI">10.5072/dans-xcy-enug</identifier>
<identifier identifierType="DOI">10.14454/dans-xcy-enug</identifier>
<creators>
<creator>
<creatorName>Chris Baars at DANS for testing</creatorName>
Expand Down
12 changes: 0 additions & 12 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,13 @@
subject.register
expect(subject).to have_state(:registered)
end

it "can't register with test prefix" do
subject = create(:doi, doi: "10.5072/x")
subject.register
expect(subject).to have_state(:draft)
end
end

describe "findable" do
it "can publish" do
subject.publish
expect(subject).to have_state(:findable)
end

it "can't publish with test prefix" do
subject = create(:doi, doi: "10.5072/x")
subject.publish
expect(subject).to have_state(:draft)
end
end

describe "flagged" do
Expand Down

0 comments on commit aa9e5c8

Please sign in to comment.