From 1c8575fc08e2d10c91d31647377a0b0bde123508 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Fri, 10 Jul 2020 12:13:27 +0200 Subject: [PATCH 1/5] test: add test --- spec/fixtures/datacite_kernel_3.json | 122 +++++++++++++++++++++++++++ spec/writers/bibtex_writer_spec.rb | 12 +++ 2 files changed, 134 insertions(+) create mode 100644 spec/fixtures/datacite_kernel_3.json diff --git a/spec/fixtures/datacite_kernel_3.json b/spec/fixtures/datacite_kernel_3.json new file mode 100644 index 00000000..5defe47b --- /dev/null +++ b/spec/fixtures/datacite_kernel_3.json @@ -0,0 +1,122 @@ +{ + "id": "https://doi.org/10.17169/refubium-26807", + "doi": "10.17169/REFUBIUM-26807", + "url": "https://refubium.fu-berlin.de/handle/fub188/27046", + "types": { + "ris": "RPRT", + "bibtex": "article", + "citeproc": "article-journal", + "schemaOrg": "ScholarlyArticle", + "resourceType": "Bachelorarbeit", + "resourceTypeGeneral": "Text" + }, + "creators": [ + { + "name": "Zoschke, Marius Robert", + "nameType": "Personal", + "givenName": "Marius Robert", + "familyName": "Zoschke", + "affiliation": [], + "nameIdentifiers": [] + } + ], + "titles": [ + { + "title": "Spielbare Erlebniswelten" + }, + { + "title": "Involvierungsstrategien in immersiven Performance-Installationen", + "titleType": "Subtitle" + } + ], + "publisher": "Freie Universität Berlin", + "container": {}, + "subjects": [ + { + "subject": "Immersion" + }, + { + "subject": "Theater" + }, + { + "subject": "Interaktion" + }, + { + "subject": "Performance" + }, + { + "subject": "Partizipation" + }, + { + "subject": "Affekt" + }, + { + "subject": "Game" + }, + { + "subject": "Affektivität" + }, + { + "subject": "Involvierung" + }, + { + "subject": "Narration" + }, + { + "subject": "700 Künste und Unterhaltung::700 Künste::700 Künste, Bildende und angewandte Kunst", + "subjectScheme": "ddc" + }, + { + "subject": "700 Künste und Unterhaltung::790 Sport, Spiele, Unterhaltung::792 Bühnenkunst", + "subjectScheme": "ddc" + } + ], + "contributors": [ + { + "name": "Universitätsbibliothek Der FU Berlin", + "affiliation": [], + "contributorType": "DataManager", + "nameIdentifiers": [] + }, + { + "name": "Universitätsbibliothek Der FU Berlin", + "affiliation": [], + "contributorType": "HostingInstitution", + "nameIdentifiers": [] + } + ], + "dates": [ + { + "date": "2020-04-01", + "dateType": "Accepted" + }, + { + "date": "2020-04-01", + "dateType": "Available" + }, + { + "date": "2019", + "dateType": "Issued" + } + ], + "publicationYear": 2019, + "identifiers": [], + "sizes": [ + "31 Seiten" + ], + "formats": [], + "rightsList": [ + { + "rightsUri": "http://www.fu-berlin.de/sites/refubium/rechtliches/Nutzungsbedingungen" + } + ], + "descriptions": [], + "geoLocations": [], + "fundingReferences": [], + "relatedIdentifiers": [], + "schemaVersion": "http://datacite.org/schema/kernel-3", + "providerId": "tib", + "clientId": "tib.fuub", + "agency": "datacite", + "state": "findable" +} \ No newline at end of file diff --git a/spec/writers/bibtex_writer_spec.rb b/spec/writers/bibtex_writer_spec.rb index ec2c1c6d..ef7a7836 100644 --- a/spec/writers/bibtex_writer_spec.rb +++ b/spec/writers/bibtex_writer_spec.rb @@ -19,6 +19,18 @@ expect(bibtex[:copyright]).to eq("Creative Commons Attribution 3.0 Unported") end + it "with schema_3" do + input = "10.17169/refubium-26807" + input = fixture_path + "datacite_kernel_3.json" + subject = Bolognese::Metadata.new(input: input, from: "datacite_json") + + bibtex = BibTeX.parse(subject.bibtex).to_a(quotes: '').first + expect(bibtex[:bibtex_type].to_s).to eq("article") + expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.17169/refubium-26807") + expect(bibtex[:doi]).to eq("10.17169/REFUBIUM-26807") + expect(bibtex[:year]).to eq("2019") + end + it "with pages" do input = "https://doi.org/10.1155/2012/291294" subject = Bolognese::Metadata.new(input: input, from: "crossref") From 30cb747b842e86aca9a9e6d7fe3ba94c06a4bf0f Mon Sep 17 00:00:00 2001 From: kjgarza Date: Fri, 10 Jul 2020 12:13:44 +0200 Subject: [PATCH 2/5] fix: deal with xml version 3 --- lib/bolognese/datacite_utils.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bolognese/datacite_utils.rb b/lib/bolognese/datacite_utils.rb index 0cdd0ab9..a5ae5f5e 100644 --- a/lib/bolognese/datacite_utils.rb +++ b/lib/bolognese/datacite_utils.rb @@ -11,7 +11,13 @@ def datacite_xml end def datacite_errors(xml: nil, schema_version: nil) - schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4" + if xml.present? + namespaces = Nokogiri::XML(xml, nil, 'UTF-8').root.namespaces + schema_version = namespaces.fetch('xmlns',nil).presence || namespaces.fetch('xmlns:ns0',nil).presence + else + schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4" + end + kernel = schema_version.to_s.split("/").last filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__) schema = Nokogiri::XML::Schema(open(filepath)) From 783fe53c0d4bcc3612fb73858b3885c1992dd8e2 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Fri, 10 Jul 2020 15:44:43 +0200 Subject: [PATCH 3/5] feedback: update fixture --- spec/fixtures/datacite_kernel_3.json | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/spec/fixtures/datacite_kernel_3.json b/spec/fixtures/datacite_kernel_3.json index 5defe47b..cc56606e 100644 --- a/spec/fixtures/datacite_kernel_3.json +++ b/spec/fixtures/datacite_kernel_3.json @@ -30,7 +30,6 @@ } ], "publisher": "Freie Universität Berlin", - "container": {}, "subjects": [ { "subject": "Immersion" @@ -71,20 +70,6 @@ "subjectScheme": "ddc" } ], - "contributors": [ - { - "name": "Universitätsbibliothek Der FU Berlin", - "affiliation": [], - "contributorType": "DataManager", - "nameIdentifiers": [] - }, - { - "name": "Universitätsbibliothek Der FU Berlin", - "affiliation": [], - "contributorType": "HostingInstitution", - "nameIdentifiers": [] - } - ], "dates": [ { "date": "2020-04-01", @@ -100,20 +85,9 @@ } ], "publicationYear": 2019, - "identifiers": [], "sizes": [ "31 Seiten" ], - "formats": [], - "rightsList": [ - { - "rightsUri": "http://www.fu-berlin.de/sites/refubium/rechtliches/Nutzungsbedingungen" - } - ], - "descriptions": [], - "geoLocations": [], - "fundingReferences": [], - "relatedIdentifiers": [], "schemaVersion": "http://datacite.org/schema/kernel-3", "providerId": "tib", "clientId": "tib.fuub", From 3262d578ca3e963501a0d7db516eabf689e45d7f Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 14 Jul 2020 12:52:57 +0200 Subject: [PATCH 4/5] feedback: change test to use schema in xml --- spec/writers/bibtex_writer_spec.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/writers/bibtex_writer_spec.rb b/spec/writers/bibtex_writer_spec.rb index ef7a7836..af3f1681 100644 --- a/spec/writers/bibtex_writer_spec.rb +++ b/spec/writers/bibtex_writer_spec.rb @@ -20,15 +20,14 @@ end it "with schema_3" do - input = "10.17169/refubium-26807" - input = fixture_path + "datacite_kernel_3.json" - subject = Bolognese::Metadata.new(input: input, from: "datacite_json") - + # input = fixture_path + "datacite_kernel_3.json" + input = fixture_path + "datacite_schema_3.xml" + subject = Bolognese::Metadata.new(input: input, from: "datacite") bibtex = BibTeX.parse(subject.bibtex).to_a(quotes: '').first - expect(bibtex[:bibtex_type].to_s).to eq("article") - expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.17169/refubium-26807") - expect(bibtex[:doi]).to eq("10.17169/REFUBIUM-26807") - expect(bibtex[:year]).to eq("2019") + expect(bibtex[:bibtex_type].to_s).to eq("misc") + expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5061/dryad.8515") + expect(bibtex[:doi]).to eq("10.5061/dryad.8515") + expect(bibtex[:year]).to eq("2011") end it "with pages" do From e322866a0717f5bf272ee122ef8502a140e81145 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 14 Jul 2020 15:54:33 +0200 Subject: [PATCH 5/5] remove unused file and convert to json and the bibtex --- spec/fixtures/datacite_kernel_3.json | 96 ---------------------------- spec/writers/bibtex_writer_spec.rb | 3 +- 2 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 spec/fixtures/datacite_kernel_3.json diff --git a/spec/fixtures/datacite_kernel_3.json b/spec/fixtures/datacite_kernel_3.json deleted file mode 100644 index cc56606e..00000000 --- a/spec/fixtures/datacite_kernel_3.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "id": "https://doi.org/10.17169/refubium-26807", - "doi": "10.17169/REFUBIUM-26807", - "url": "https://refubium.fu-berlin.de/handle/fub188/27046", - "types": { - "ris": "RPRT", - "bibtex": "article", - "citeproc": "article-journal", - "schemaOrg": "ScholarlyArticle", - "resourceType": "Bachelorarbeit", - "resourceTypeGeneral": "Text" - }, - "creators": [ - { - "name": "Zoschke, Marius Robert", - "nameType": "Personal", - "givenName": "Marius Robert", - "familyName": "Zoschke", - "affiliation": [], - "nameIdentifiers": [] - } - ], - "titles": [ - { - "title": "Spielbare Erlebniswelten" - }, - { - "title": "Involvierungsstrategien in immersiven Performance-Installationen", - "titleType": "Subtitle" - } - ], - "publisher": "Freie Universität Berlin", - "subjects": [ - { - "subject": "Immersion" - }, - { - "subject": "Theater" - }, - { - "subject": "Interaktion" - }, - { - "subject": "Performance" - }, - { - "subject": "Partizipation" - }, - { - "subject": "Affekt" - }, - { - "subject": "Game" - }, - { - "subject": "Affektivität" - }, - { - "subject": "Involvierung" - }, - { - "subject": "Narration" - }, - { - "subject": "700 Künste und Unterhaltung::700 Künste::700 Künste, Bildende und angewandte Kunst", - "subjectScheme": "ddc" - }, - { - "subject": "700 Künste und Unterhaltung::790 Sport, Spiele, Unterhaltung::792 Bühnenkunst", - "subjectScheme": "ddc" - } - ], - "dates": [ - { - "date": "2020-04-01", - "dateType": "Accepted" - }, - { - "date": "2020-04-01", - "dateType": "Available" - }, - { - "date": "2019", - "dateType": "Issued" - } - ], - "publicationYear": 2019, - "sizes": [ - "31 Seiten" - ], - "schemaVersion": "http://datacite.org/schema/kernel-3", - "providerId": "tib", - "clientId": "tib.fuub", - "agency": "datacite", - "state": "findable" -} \ No newline at end of file diff --git a/spec/writers/bibtex_writer_spec.rb b/spec/writers/bibtex_writer_spec.rb index af3f1681..ab5e3b33 100644 --- a/spec/writers/bibtex_writer_spec.rb +++ b/spec/writers/bibtex_writer_spec.rb @@ -22,7 +22,8 @@ it "with schema_3" do # input = fixture_path + "datacite_kernel_3.json" input = fixture_path + "datacite_schema_3.xml" - subject = Bolognese::Metadata.new(input: input, from: "datacite") + json = Bolognese::Metadata.new(input: input, from: "datacite") + subject = Bolognese::Metadata.new(input: json.meta.to_json, from: "datacite_json") bibtex = BibTeX.parse(subject.bibtex).to_a(quotes: '').first expect(bibtex[:bibtex_type].to_s).to eq("misc") expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5061/dryad.8515")