diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index 620d197d4..ed6aa86f3 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -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 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..47cfc9e0f 100644 --- a/spec/requests/datacite_dois/post_spec.rb +++ b/spec/requests/datacite_dois/post_spec.rb @@ -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) } @@ -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 @@ -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 @@ -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