From 7e2aa4ba11c8fcffa193fd6471db3bff6eddb374 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 25 Oct 2024 16:48:13 -0400 Subject: [PATCH 1/8] Schema 3 Deprecation: Add kernel-3, etc. to the list of invalid schemas. --- app/validators/xml_schema_validator.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index 620d197d4..dce69090a 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -40,7 +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 + ] + + puts("GOT HERE!!! - CHECKING FOR INVALID SCHEMA") if record.new_record? && invalid_schemas.include?(record.schema_version) record.errors.add(:xml, "DOI #{record.uid}: Schema #{record.schema_version} is no longer supported") From bfad4f18dcdac91d992ab512c5537f932b12f9e9 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 25 Oct 2024 16:55:39 -0400 Subject: [PATCH 2/8] cleanup --- app/validators/xml_schema_validator.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index dce69090a..ee2f4efb4 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -48,8 +48,6 @@ def validate_each(record, _attribute, value) http://datacite.org/schema/kernel-3 ] - puts("GOT HERE!!! - CHECKING FOR INVALID SCHEMA") - if record.new_record? && invalid_schemas.include?(record.schema_version) record.errors.add(:xml, "DOI #{record.uid}: Schema #{record.schema_version} is no longer supported") return false From c0b4b7bdbeeafaa047b104831b359eb345af37f8 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Mon, 28 Oct 2024 15:40:12 -0400 Subject: [PATCH 3/8] Schema 3 deprecation: Add tests. --- spec/fixtures/files/ns3.xml | 39 +++++++++++++ spec/fixtures/files/ns30.xml | 2 + spec/fixtures/files/ns31.xml | 2 + spec/requests/datacite_dois/post_spec.rb | 72 ++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 spec/fixtures/files/ns3.xml create mode 100644 spec/fixtures/files/ns30.xml create mode 100644 spec/fixtures/files/ns31.xml diff --git a/spec/fixtures/files/ns3.xml b/spec/fixtures/files/ns3.xml new file mode 100644 index 000000000..8c31557b0 --- /dev/null +++ b/spec/fixtures/files/ns3.xml @@ -0,0 +1,39 @@ + + + 10.4231/D38G8FK8B + + + Patiño, Carlos + + + Alzate-Vargas, Lorena + + + Li, Chunyu + + + Haley, Benjamin + + + Strachan, Alejandro + + + + LAMMPS Data-File Generator + + nanoHUB + 2018 + + 2018-07-18 + 2018-07-18 + + en + Simulation Tool + 1.5.2 + + This tool generates all necessary input files for + LAMMPS simulations of molecular systems starting with an atomistic structure. + + \ No newline at end of file diff --git a/spec/fixtures/files/ns30.xml b/spec/fixtures/files/ns30.xml new file mode 100644 index 000000000..bec8446d5 --- /dev/null +++ b/spec/fixtures/files/ns30.xml @@ -0,0 +1,2 @@ + +10.4231/D38G8FK8B Patiño, Carlos Alzate-Vargas, Lorena Li, Chunyu Haley, Benjamin Strachan, Alejandro LAMMPS Data-File GeneratornanoHUB2018 2018-07-18 2018-07-18enSimulation Tool1.5.2 This tool generates all necessary input files for LAMMPS simulations of molecular systems starting with an atomistic structure. \ No newline at end of file diff --git a/spec/fixtures/files/ns31.xml b/spec/fixtures/files/ns31.xml new file mode 100644 index 000000000..b2132a924 --- /dev/null +++ b/spec/fixtures/files/ns31.xml @@ -0,0 +1,2 @@ + +10.4231/D38G8FK8B Patiño, Carlos Alzate-Vargas, Lorena Li, Chunyu Haley, Benjamin Strachan, Alejandro LAMMPS Data-File GeneratornanoHUB2018 2018-07-18 2018-07-18enSimulation Tool1.5.2 This tool generates all necessary input files for LAMMPS simulations of molecular systems starting with an atomistic structure. \ No newline at end of file diff --git a/spec/requests/datacite_dois/post_spec.rb b/spec/requests/datacite_dois/post_spec.rb index ffda55981..f164715b4 100644 --- a/spec/requests/datacite_dois/post_spec.rb +++ b/spec/requests/datacite_dois/post_spec.rb @@ -1024,6 +1024,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 From 93fb97de7bfc345d9b91b049db8754143cec7e32 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Tue, 29 Oct 2024 09:40:20 -0400 Subject: [PATCH 4/8] Schema 3 deprecation: remove kernel-3 tests. --- spec/requests/datacite_dois/post_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/requests/datacite_dois/post_spec.rb b/spec/requests/datacite_dois/post_spec.rb index f164715b4..6eb6f69aa 100644 --- a/spec/requests/datacite_dois/post_spec.rb +++ b/spec/requests/datacite_dois/post_spec.rb @@ -888,6 +888,8 @@ end end +# remove kernel-3 tests +=begin context "when the request uses schema 3" do let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) } let(:valid_attributes) do @@ -943,6 +945,7 @@ 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 +=end context "when the request has wrong object in nameIdentifiers" do let(:valid_attributes) { JSON.parse(file_fixture("datacite_wrong_nameIdentifiers.json").read) } @@ -1664,7 +1667,8 @@ expect(json.dig("errors")).to eq([{ "source" => "doi", "title" => "Is invalid", "uid" => "10.14454/107+03" }]) end end - +# Remove kernel-3 tests +=begin context "validates schema 3" do let(:xml) { ::Base64.strict_encode64(File.read(file_fixture("datacite_schema_3.xml"))) } let(:params) do @@ -1688,6 +1692,7 @@ expect(json.dig("data", "attributes", "dates")).to eq([{ "date" => "2011", "dateType" => "Issued" }]) end end +=end context "validates schema 4.5 xml" do let(:xml) { ::Base64.strict_encode64(File.read(file_fixture("datacite-example-full-v4.5.xml"))) } @@ -1949,7 +1954,8 @@ end end end - +# Remove kernel-3 tests. +=begin context "update individual attribute" do let(:xml) { Base64.strict_encode64(file_fixture("datacite_schema_3.xml").read) } let(:valid_attributes) do @@ -2034,6 +2040,7 @@ expect(json.dig("data", "attributes", "titles")).to eq([{ "title" => "Data from: A new malaria agent in African hominids." }]) end end +=end # Funder has been removed as valid contributor type in schema 4.0 context "update contributor type with funder", elasticsearch: true do From 99b48c3b13b80a97e00d0897b873e109b8191b1f Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Tue, 29 Oct 2024 13:15:31 -0400 Subject: [PATCH 5/8] Schema 3 deprecation: remove schema 3 tests (cannot create and update schema 3 DOI). --- spec/requests/datacite_dois/post_spec.rb | 172 ----------------------- 1 file changed, 172 deletions(-) diff --git a/spec/requests/datacite_dois/post_spec.rb b/spec/requests/datacite_dois/post_spec.rb index 6eb6f69aa..47cfc9e0f 100644 --- a/spec/requests/datacite_dois/post_spec.rb +++ b/spec/requests/datacite_dois/post_spec.rb @@ -888,65 +888,6 @@ end end -# remove kernel-3 tests -=begin - 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 -=end - context "when the request has wrong object in nameIdentifiers" do let(:valid_attributes) { JSON.parse(file_fixture("datacite_wrong_nameIdentifiers.json").read) } @@ -1667,32 +1608,6 @@ expect(json.dig("errors")).to eq([{ "source" => "doi", "title" => "Is invalid", "uid" => "10.14454/107+03" }]) end end -# Remove kernel-3 tests -=begin - 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 -=end context "validates schema 4.5 xml" do let(:xml) { ::Base64.strict_encode64(File.read(file_fixture("datacite-example-full-v4.5.xml"))) } @@ -1954,93 +1869,6 @@ end end end -# Remove kernel-3 tests. -=begin - 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 -=end # Funder has been removed as valid contributor type in schema 4.0 context "update contributor type with funder", elasticsearch: true do From 67a040afc2ca28efeb338663d8d4761a15d36eb3 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Tue, 12 Nov 2024 11:52:39 -0500 Subject: [PATCH 6/8] Schema 3 dep: appease rubocop. --- app/validators/xml_schema_validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index ee2f4efb4..258e8f7a9 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -41,7 +41,7 @@ def validate_each(record, _attribute, value) return false if kernel.blank? invalid_schemas = %w[ - http://datacite.org/schema/kernel-2.1 + 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 From 7c96f9d9d8605aac75bfb7cadc1fccac617d7376 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sun, 5 Jan 2025 16:01:17 -0500 Subject: [PATCH 7/8] Schema 3 dep: return error for schema 3 doi update. (by removing 'record.new_record? &&' from check) --- app/validators/xml_schema_validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index 258e8f7a9..ed6aa86f3 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -48,7 +48,7 @@ def validate_each(record, _attribute, value) 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 From f202bc1c927c61c8c5a129ae19be266786a3e77e Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sun, 5 Jan 2025 16:33:54 -0500 Subject: [PATCH 8/8] Y2K-type bug in test. --- spec/models/provider_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 0fc43867b..d5d326106 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -315,7 +315,7 @@ it "should show all cumulative years" do provider = create(:provider) expect(provider.cumulative_years).to eq( - [2_015, 2_016, 2_017, 2_018, 2_019, 2_020, 2_021, 2_022, 2_023, 2_024], + [2_015, 2_016, 2_017, 2_018, 2_019, 2_020, 2_021, 2_022, 2_023, 2_024, 2_025], ) end