Skip to content

Commit

Permalink
Merge pull request #1271 from datacite/schema-3-dep
Browse files Browse the repository at this point in the history
Lupo Schema 3 Deprecation Tasks
  • Loading branch information
svogt0511 authored Jan 8, 2025
2 parents 7c251e5 + 7244544 commit d575faa
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 167 deletions.
10 changes: 8 additions & 2 deletions app/validators/xml_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ def validate_each(record, _attribute, value)
kernel = get_valid_kernel(record.schema_version)
return false if kernel.blank?

invalid_schemas = %w[http://datacite.org/schema/kernel-2.1 http://datacite.org/schema/kernel-2.2]
invalid_schemas = %w[
http://datacite.org/schema/kernel-2.1
http://datacite.org/schema/kernel-2.2
http://datacite.org/schema/kernel-3.0
http://datacite.org/schema/kernel-3.1
http://datacite.org/schema/kernel-3
]

if record.new_record? && invalid_schemas.include?(record.schema_version)
if invalid_schemas.include?(record.schema_version)
record.errors.add(:xml, "DOI #{record.uid}: Schema #{record.schema_version} is no longer supported")
return false
end
Expand Down
39 changes: 39 additions & 0 deletions spec/fixtures/files/ns3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<ns0:resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns0="http://datacite.org/schema/kernel-3"
xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd">
<ns0:identifier identifierType="DOI">10.4231/D38G8FK8B</ns0:identifier>
<ns0:creators>
<ns0:creator>
<ns0:creatorName>Patiño, Carlos</ns0:creatorName>
</ns0:creator>
<ns0:creator>
<ns0:creatorName>Alzate-Vargas, Lorena</ns0:creatorName>
</ns0:creator>
<ns0:creator>
<ns0:creatorName>Li, Chunyu</ns0:creatorName>
</ns0:creator>
<ns0:creator>
<ns0:creatorName>Haley, Benjamin</ns0:creatorName>
</ns0:creator>
<ns0:creator>
<ns0:creatorName>Strachan, Alejandro</ns0:creatorName>
</ns0:creator>
</ns0:creators>
<ns0:titles>
<ns0:title>LAMMPS Data-File Generator</ns0:title>
</ns0:titles>
<ns0:publisher>nanoHUB</ns0:publisher>
<ns0:publicationYear>2018</ns0:publicationYear>
<ns0:dates>
<ns0:date dateType="Valid">2018-07-18</ns0:date>
<ns0:date dateType="Accepted">2018-07-18</ns0:date>
</ns0:dates>
<ns0:language>en</ns0:language>
<ns0:resourceType resourceTypeGeneral="Software">Simulation Tool</ns0:resourceType>
<ns0:version>1.5.2</ns0:version>
<ns0:descriptions>
<ns0:description descriptionType="Other">This tool generates all necessary input files for
LAMMPS simulations of molecular systems starting with an atomistic structure.</ns0:description>
</ns0:descriptions>
</ns0:resource>
2 changes: 2 additions & 0 deletions spec/fixtures/files/ns30.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ns0:resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://datacite.org/schema/kernel-3.0" xsi:schemaLocation="http://datacite.org/schema/kernel-3.0 http://schema.datacite.org/meta/kernel-3.0/metadata.xsd"><ns0:identifier identifierType="DOI">10.4231/D38G8FK8B</ns0:identifier><ns0:creators><ns0:creator> <ns0:creatorName>Patiño, Carlos</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Alzate-Vargas, Lorena</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Li, Chunyu</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Haley, Benjamin</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Strachan, Alejandro</ns0:creatorName></ns0:creator></ns0:creators><ns0:titles> <ns0:title>LAMMPS Data-File Generator</ns0:title></ns0:titles><ns0:publisher>nanoHUB</ns0:publisher><ns0:publicationYear>2018</ns0:publicationYear><ns0:dates> <ns0:date dateType="Valid">2018-07-18</ns0:date> <ns0:date dateType="Accepted">2018-07-18</ns0:date></ns0:dates><ns0:language>en</ns0:language><ns0:resourceType resourceTypeGeneral="Software">Simulation Tool</ns0:resourceType><ns0:version>1.5.2</ns0:version><ns0:descriptions> <ns0:description descriptionType="Other">This tool generates all necessary input files for LAMMPS simulations of molecular systems starting with an atomistic structure.</ns0:description></ns0:descriptions></ns0:resource>
2 changes: 2 additions & 0 deletions spec/fixtures/files/ns31.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ns0:resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://datacite.org/schema/kernel-3.1" xsi:schemaLocation="http://datacite.org/schema/kernel-3.1 http://schema.datacite.org/meta/kernel-3.1/metadata.xsd"><ns0:identifier identifierType="DOI">10.4231/D38G8FK8B</ns0:identifier><ns0:creators><ns0:creator> <ns0:creatorName>Patiño, Carlos</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Alzate-Vargas, Lorena</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Li, Chunyu</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Haley, Benjamin</ns0:creatorName></ns0:creator><ns0:creator> <ns0:creatorName>Strachan, Alejandro</ns0:creatorName></ns0:creator></ns0:creators><ns0:titles> <ns0:title>LAMMPS Data-File Generator</ns0:title></ns0:titles><ns0:publisher>nanoHUB</ns0:publisher><ns0:publicationYear>2018</ns0:publicationYear><ns0:dates> <ns0:date dateType="Valid">2018-07-18</ns0:date> <ns0:date dateType="Accepted">2018-07-18</ns0:date></ns0:dates><ns0:language>en</ns0:language><ns0:resourceType resourceTypeGeneral="Software">Simulation Tool</ns0:resourceType><ns0:version>1.5.2</ns0:version><ns0:descriptions> <ns0:description descriptionType="Other">This tool generates all necessary input files for LAMMPS simulations of molecular systems starting with an atomistic structure.</ns0:description></ns0:descriptions></ns0:resource>
237 changes: 72 additions & 165 deletions spec/requests/datacite_dois/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -888,62 +888,6 @@
end
end

context "when the request uses schema 3" do
let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"source" => "test",
"event" => "publish",
},
},
}
end

it "creates a Doi" do
post "/dois", valid_attributes, headers

expect(last_response.status).to eq(201)
expect(json.dig("data", "attributes", "url")).to eq("http://www.bl.uk/pdf/patspec.pdf")
expect(json.dig("data", "attributes", "doi")).to eq("10.14454/10703")
expect(json.dig("data", "attributes", "titles")).to eq([{ "title" => "Data from: A new malaria agent in African hominids." }])
expect(json.dig("data", "attributes", "source")).to eq("test")
expect(json.dig("data", "attributes", "schemaVersion")).to eq("http://datacite.org/schema/kernel-3")
expect(json.dig("data", "attributes", "state")).to eq("findable")
end
end

context "when the request creates schema 3 with funder contributor type" do
let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"contributors" => [{ "contributorType" => "Funder", "name" => "Wellcome Trust", "nameType" => "Organizational" }],
"source" => "test",
"event" => "publish",
},
},
}
end

it "creates a Doi" do
post "/dois", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "DOI 10.14454/10703: No matching global declaration available for the validation root. at line 2, column 0", "uid" => "10.14454/10703" }])
end
end

context "when the request has wrong object in nameIdentifiers" do
let(:valid_attributes) { JSON.parse(file_fixture("datacite_wrong_nameIdentifiers.json").read) }

Expand Down Expand Up @@ -1024,6 +968,78 @@
end
end

context "when the xml request uses unsupported metadata version - kernel-3" do
let(:xml) { Base64.strict_encode64(file_fixture("ns3.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"event" => "publish",
},
},
}
end

it "returns an error that schema is no longer supported" do
post "/dois", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "DOI 10.14454/10703: Schema http://datacite.org/schema/kernel-3 is no longer supported", "uid" => "10.14454/10703" }])
end
end

context "when the xml request uses unsupported metadata version - kernel-3.0" do
let(:xml) { Base64.strict_encode64(file_fixture("ns30.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"event" => "publish",
},
},
}
end

it "returns an error that schema is no longer supported" do
post "/dois", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "DOI 10.14454/10703: Schema http://datacite.org/schema/kernel-3.0 is no longer supported", "uid" => "10.14454/10703" }])
end
end

context "when the xml request uses unsupported metadata version - kernel-3.1" do
let(:xml) { Base64.strict_encode64(file_fixture("ns31.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"event" => "publish",
},
},
}
end

it "returns an error that schema is no longer supported" do
post "/dois", valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "DOI 10.14454/10703: Schema http://datacite.org/schema/kernel-3.1 is no longer supported", "uid" => "10.14454/10703" }])
end
end

context "when the request uses schema 4.0" do
let(:xml) { Base64.strict_encode64(file_fixture("schema_4.0.xml").read) }
let(:valid_attributes) do
Expand Down Expand Up @@ -1593,30 +1609,6 @@
end
end

context "validates schema 3" do
let(:xml) { ::Base64.strict_encode64(File.read(file_fixture("datacite_schema_3.xml"))) }
let(:params) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"xml" => xml,
},
},
}
end

it "validates a Doi" do
post "/dois/validate", params, headers

expect(last_response.status).to eq(200)
expect(json.dig("data", "attributes", "doi")).to eq("10.14454/10703")
expect(json.dig("data", "attributes", "titles")).to eq([{ "title" => "Data from: A new malaria agent in African hominids." }])
expect(json.dig("data", "attributes", "dates")).to eq([{ "date" => "2011", "dateType" => "Issued" }])
end
end

context "validates schema 4.5 xml" do
let(:xml) { ::Base64.strict_encode64(File.read(file_fixture("datacite-example-full-v4.5.xml"))) }
let(:params) do
Expand Down Expand Up @@ -1878,91 +1870,6 @@
end
end

context "update individual attribute" do
let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"source" => "test",
"event" => "publish",
},
},
}
end
let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"schemaVersion" => "http://datacite.org/schema/kernel-4",
"regenerate" => true,
},
},
}
end

it "creates a Doi" do
post "/dois", valid_attributes, headers

expect(json.dig("data", "attributes", "doi")).to eq("10.14454/10703")
expect(json.dig("data", "attributes", "titles")).to eq([{ "title" => "Data from: A new malaria agent in African hominids." }])
expect(json.dig("data", "attributes", "schemaVersion")).to eq("http://datacite.org/schema/kernel-3")

doc = Nokogiri::XML(Base64.decode64(json.dig("data", "attributes", "xml")), nil, "UTF-8", &:noblanks)
expect(doc.collect_namespaces).to eq("xmlns" => "http://datacite.org/schema/kernel-3", "xmlns:dim" => "http://www.dspace.org/xmlns/dspace/dim", "xmlns:dryad" => "http://purl.org/dryad/terms/", "xmlns:dspace" => "http://www.dspace.org/xmlns/dspace/dim", "xmlns:mets" => "http://www.loc.gov/METS/", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance")
end
end

context "mds doi" do
let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"should_validate" => "true",
"source" => "mds",
"event" => "publish",
},
},
}
end

let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"should_validate" => "true",
"xml" => xml,
"source" => "mds",
"event" => "show",
},
},
}
end

it "add metadata" do
put "/dois/10.14454/10703", update_attributes, headers

expect(json.dig("data", "attributes", "doi")).to eq("10.14454/10703")
expect(json.dig("data", "attributes", "schemaVersion")).to eq("http://datacite.org/schema/kernel-3")

put "/dois/10.14454/10703", valid_attributes, headers

expect(json.dig("data", "attributes", "doi")).to eq("10.14454/10703")
expect(json.dig("data", "attributes", "schemaVersion")).to eq("http://datacite.org/schema/kernel-3")
expect(json.dig("data", "attributes", "titles")).to eq([{ "title" => "Data from: A new malaria agent in African hominids." }])
end
end

# Funder has been removed as valid contributor type in schema 4.0
context "update contributor type with funder", elasticsearch: true do
let(:update_attributes) do
Expand Down

0 comments on commit d575faa

Please sign in to comment.