From 2a0a6f516cc8d59889570306ae19491644316935 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Wed, 21 Sep 2022 19:49:03 +0100 Subject: [PATCH 1/4] Re-enable related items --- app/serializers/datacite_doi_serializer.rb | 8 +- spec/factories/doi.rb | 12 +- spec/requests/datacite_dois_spec.rb | 152 ++++++++++----------- 3 files changed, 85 insertions(+), 87 deletions(-) diff --git a/app/serializers/datacite_doi_serializer.rb b/app/serializers/datacite_doi_serializer.rb index ca5addf9a..906d8d73e 100644 --- a/app/serializers/datacite_doi_serializer.rb +++ b/app/serializers/datacite_doi_serializer.rb @@ -24,7 +24,7 @@ class DataciteDoiSerializer :language, :types, :related_identifiers, - # :related_items, + :related_items, :sizes, :formats, :version, @@ -191,9 +191,9 @@ class DataciteDoiSerializer Array.wrap(object.related_identifiers) end - # attribute :related_items do |object| - # Array.wrap(object.related_items) - # end + attribute :related_items do |object| + Array.wrap(object.related_items) + end attribute :geo_locations, if: diff --git a/spec/factories/doi.rb b/spec/factories/doi.rb index ea76128ed..29a50d86b 100644 --- a/spec/factories/doi.rb +++ b/spec/factories/doi.rb @@ -160,13 +160,11 @@ "firstPage" => "249", "lastPage" => "264", "publicationYear" => "2018", - "relatedItemIdentifier" => - { "__content__" => "10.1016/j.physletb.2017.11.044", - "relatedItemIdentifierType" => "DOI" }, - "relatedItemType" => "Journal", - "relationType" => "IsPublishedIn", - "titles" => { "title" => "Physics letters / B" }, - "volume" => "776" + "relatedItemIdentifier" => { "relatedItemIdentifier" => "10.1016/j.physletb.2017.11.044", "relatedItemIdentifierType" => "DOI" }, + "relatedItemType" => "Journal", + "relationType" => "IsPublishedIn", + "titles" => [{ "title" => "Physics letters / B" }], + "volume" => "776" } ] end diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index e9d1219ad..1a46916f4 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -1972,32 +1972,32 @@ expect(json.dig("data", "attributes", "source")).to eq("test") expect(json.dig("data", "attributes", "types")).to eq("bibtex" => "article", "citeproc" => "article-journal", "resourceType" => "BlogPosting", "resourceTypeGeneral" => "Text", "ris" => "RPRT", "schemaOrg" => "ScholarlyArticle") expect(json.dig("data", "attributes", "state")).to eq("findable") - # expect(json.dig("data", "attributes", "relatedItems")).to eq(["relationType" => "IsPublishedIn", - # "relatedItemType" => "Journal", - # "publicationYear" => "2018", - # "relatedItemIdentifier" => { - # "relatedItemIdentifier" => "10.1016/j.physletb.2017.11.044", - # "relatedItemIdentifierType" => "DOI", - # "relatedMetadataScheme" => "citeproc+json", - # "schemeURI" => "https://github.com/citation-style-language/schema/raw/master/csl-data.json", - # "schemeType" => "URL" - # }, - # "contributors" => [{ "name" => "Smithson, James", - # "contributorType" => "ProjectLeader", - # "givenName" => "James", - # "familyName" => "Smithson", - # "nameType" => "Personal" - # }], - # "creators" => [{ "name" => "Smith, John", - # "nameType" => "Personal", - # "givenName" => "John", - # "familyName" => "Smith", - # }], - # "firstPage" => "249", - # "lastPage" => "264", - # "titles" => [{ "title" => "Physics letters / B" }], - # "volume" => "776" - # ]) + expect(json.dig("data", "attributes", "relatedItems")).to eq(["relationType" => "IsPublishedIn", + "relatedItemType" => "Journal", + "publicationYear" => "2018", + "relatedItemIdentifier" => { + "relatedItemIdentifier" => "10.1016/j.physletb.2017.11.044", + "relatedItemIdentifierType" => "DOI", + "relatedMetadataScheme" => "citeproc+json", + "schemeURI" => "https://github.com/citation-style-language/schema/raw/master/csl-data.json", + "schemeType" => "URL" + }, + "contributors" => [{ "name" => "Smithson, James", + "contributorType" => "ProjectLeader", + "givenName" => "James", + "familyName" => "Smithson", + "nameType" => "Personal" + }], + "creators" => [{ "name" => "Smith, John", + "nameType" => "Personal", + "givenName" => "John", + "familyName" => "Smith", + }], + "firstPage" => "249", + "lastPage" => "264", + "titles" => [{ "title" => "Physics letters / B" }], + "volume" => "776" + ]) doc = Nokogiri::XML(Base64.decode64(json.dig("data", "attributes", "xml")), nil, "UTF-8", &:noblanks) expect(doc.at_css("identifier").content).to eq("10.14454/10703") @@ -2202,56 +2202,56 @@ expect(last_response.status).to eq(201) - # expect(json.dig("data", "attributes", "relatedItems")).to eq([{ "relationType" => "IsPublishedIn", - # "relatedItemType" => "Journal", - # "relatedItemIdentifier" => { "relatedItemIdentifier" => "10.5072/john-smiths-1234", - # "relatedItemIdentifierType" => "DOI", - # "relatedMetadataScheme" => "citeproc+json", - # "schemeURI" => "https://github.com/citation-style-language/schema/raw/master/csl-data.json", - # "schemeType" => "URL" }, - # "creators" => [ - # { - # "nameType" => "Personal", - # "name" => "Smith, John", - # "givenName" => "John", - # "familyName" => "Smith" - # } - # ], - # "titles" => [ - # { "title" => "Understanding the fictional John Smith" }, - # { "titleType" => "Subtitle", "title" => "A detailed look" } - # ], - # "publicationYear" => "1776", - # "volume" => "776", - # "issue" => "1", - # "number" => "1", - # "numberType" => "Chapter", - # "firstPage" => "50", - # "lastPage" => "60", - # "publisher" => "Example Inc", - # "edition" => "1", - # "contributors" => [ - # "contributorType" => "ProjectLeader", - # "name" => "Hallett, Richard", - # "givenName" => "Richard", - # "familyName" => "Hallett", - # "nameType" => "Personal" - # ] - # }, - # { - # "contributors" => [], - # "creators" => [], - # "firstPage" => "249", - # "lastPage" => "264", - # "publicationYear" => "2018", - # "relatedItemIdentifier" => { "relatedItemIdentifier" => "10.1016/j.physletb.2017.11.044", - # "relatedItemIdentifierType" => "DOI" }, - # "relatedItemType" => "Journal", - # "relationType" => "IsPublishedIn", - # "titles" => [{ "title" => "Physics letters / B" } ], - # "volume" => "776" - # } - # ]) + expect(json.dig("data", "attributes", "relatedItems")).to eq([{ "relationType" => "IsPublishedIn", + "relatedItemType" => "Journal", + "relatedItemIdentifier" => { "relatedItemIdentifier" => "10.5072/john-smiths-1234", + "relatedItemIdentifierType" => "DOI", + "relatedMetadataScheme" => "citeproc+json", + "schemeURI" => "https://github.com/citation-style-language/schema/raw/master/csl-data.json", + "schemeType" => "URL" }, + "creators" => [ + { + "nameType" => "Personal", + "name" => "Smith, John", + "givenName" => "John", + "familyName" => "Smith" + } + ], + "titles" => [ + { "title" => "Understanding the fictional John Smith" }, + { "titleType" => "Subtitle", "title" => "A detailed look" } + ], + "publicationYear" => "1776", + "volume" => "776", + "issue" => "1", + "number" => "1", + "numberType" => "Chapter", + "firstPage" => "50", + "lastPage" => "60", + "publisher" => "Example Inc", + "edition" => "1", + "contributors" => [ + "contributorType" => "ProjectLeader", + "name" => "Hallett, Richard", + "givenName" => "Richard", + "familyName" => "Hallett", + "nameType" => "Personal" + ] + }, + { + "contributors" => [], + "creators" => [], + "firstPage" => "249", + "lastPage" => "264", + "publicationYear" => "2018", + "relatedItemIdentifier" => { "relatedItemIdentifier" => "10.1016/j.physletb.2017.11.044", + "relatedItemIdentifierType" => "DOI" }, + "relatedItemType" => "Journal", + "relationType" => "IsPublishedIn", + "titles" => [{ "title" => "Physics letters / B" } ], + "volume" => "776" + } + ]) xml = Maremma.from_xml(Base64.decode64(json.dig("data", "attributes", "xml"))).fetch("resource", {}) expect(xml.dig("relatedItems", "relatedItem")).to eq( From f34218884ba2de8572d295bbb5d36ea5e51991ee Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Tue, 11 Oct 2022 13:16:19 +0100 Subject: [PATCH 2/4] add test for related items optional properties --- spec/requests/datacite_dois_spec.rb | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index 1a46916f4..fa9298390 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -2310,6 +2310,42 @@ ] ) end + + it "does not require optional properties" do + valid_attributes = { + "data" => { + "type" => "dois", + "attributes" => { + "doi" => "10.14454/relateditems-optional", + "url" => "http://www.bl.uk/pdf/patspec.pdf", + "types" => { "bibtex" => "article", "citeproc" => "article-journal", "resourceType" => "BlogPosting", "resourceTypeGeneral" => "Text", "ris" => "RPRT", "schemaOrg" => "ScholarlyArticle" }, + "titles" => [{ "title" => "Eating your own Dog Food" }], + "publisher" => "DataCite", + "publicationYear" => 2016, + "creators" => [{ "familyName" => "Fenner", "givenName" => "Martin", "nameIdentifiers" => [{ "nameIdentifier" => "https://orcid.org/0000-0003-1419-2405", "nameIdentifierScheme" => "ORCID", "schemeUri" => "https://orcid.org" }], "name" => "Fenner, Martin", "nameType" => "Personal" }], + "source" => "test", + "event" => "publish", + "relatedItems" => [{ + "relatedItemType" => "Journal", + "relationType" => "IsPublishedIn", + "titles" => [{ "title" => "Physics letters / B" }] + }], + }, + }, + } + + + post "/dois", valid_attributes, headers + + expect(last_response.status).to eq(201) + expect(json.dig("data", "attributes", "relatedItems")).to eq([{ + "relatedItemType" => "Journal", + "relationType" => "IsPublishedIn", + "titles" => [{ "title" => "Physics letters / B" }] + }]) + + end + end context "with subject classificationcode" do From 167443e5b5f995ac3598ecd067462b1c63e648e1 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Tue, 11 Oct 2022 13:30:49 +0100 Subject: [PATCH 3/4] Appease rubocop --- spec/requests/datacite_dois_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index fa9298390..869f91df9 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -2310,7 +2310,7 @@ ] ) end - + it "does not require optional properties" do valid_attributes = { "data" => { @@ -2325,7 +2325,7 @@ "creators" => [{ "familyName" => "Fenner", "givenName" => "Martin", "nameIdentifiers" => [{ "nameIdentifier" => "https://orcid.org/0000-0003-1419-2405", "nameIdentifierScheme" => "ORCID", "schemeUri" => "https://orcid.org" }], "name" => "Fenner, Martin", "nameType" => "Personal" }], "source" => "test", "event" => "publish", - "relatedItems" => [{ + "relatedItems" => [{ "relatedItemType" => "Journal", "relationType" => "IsPublishedIn", "titles" => [{ "title" => "Physics letters / B" }] @@ -2333,19 +2333,16 @@ }, }, } - - + post "/dois", valid_attributes, headers expect(last_response.status).to eq(201) - expect(json.dig("data", "attributes", "relatedItems")).to eq([{ + expect(json.dig("data", "attributes", "relatedItems")).to eq([{ "relatedItemType" => "Journal", "relationType" => "IsPublishedIn", "titles" => [{ "title" => "Physics letters / B" }] }]) - end - end context "with subject classificationcode" do From 41970520fcb573813bb6f59a590d0cba9ca720a8 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Tue, 11 Oct 2022 18:36:14 +0100 Subject: [PATCH 4/4] update bolognese --- Gemfile.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 708f69e9c..2a641c26e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,8 +67,8 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) amazing_print (1.4.0) ansi (1.5.0) apollo-federation (1.1.3) @@ -110,7 +110,7 @@ GEM latex-decode (~> 0.0) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bolognese (1.9.17) + bolognese (1.9.18) activesupport (>= 4.2.5) benchmark_methods (~> 0.7) bibtex-ruby (>= 5.1.0) @@ -209,7 +209,7 @@ GEM scanf (~> 1.0) sxp (~> 1.2) unicode-types (~> 1.7) - edtf (3.0.8) + edtf (3.1.0) activesupport (>= 3.0, < 8.0) elasticsearch (7.5.0) elasticsearch-api (= 7.5.0) @@ -283,7 +283,7 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) - i18n (1.10.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) i18n_data (0.8.0) iso-639 (0.3.5) @@ -291,14 +291,14 @@ GEM jmespath (1.6.1) json (2.6.2) json-canonicalization (0.3.0) - json-ld (3.2.1) + json-ld (3.2.3) htmlentities (~> 4.3) json-canonicalization (~> 0.3) link_header (~> 0.0, >= 0.0.8) multi_json (~> 1.15) rack (~> 2.2) - rdf (~> 3.2) - json-ld-preloaded (3.2.0) + rdf (~> 3.2, >= 3.2.9) + json-ld-preloaded (3.2.1) json-ld (~> 3.2) rdf (~> 3.2) jsonapi-renderer (0.2.2) @@ -324,7 +324,7 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - latex-decode (0.3.2) + latex-decode (0.4.0) link_header (0.0.8) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -339,7 +339,7 @@ GEM logstash-event (1.2.02) logstash-logger (0.26.1) logstash-event (~> 1.2) - loofah (2.18.0) + loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) macaddr (1.7.2) @@ -371,7 +371,7 @@ GEM mini_magick (4.11.0) mini_mime (1.1.2) mini_portile2 (2.8.0) - minitest (5.16.2) + minitest (5.16.3) money (6.16.0) i18n (>= 0.6.4, <= 2) msgpack (1.5.3) @@ -383,10 +383,10 @@ GEM connection_pool (~> 2.2) netrc (0.11.0) nio4r (2.5.8) - nokogiri (1.13.6) + nokogiri (1.13.8) mini_portile2 (~> 2.8.0) racc (~> 1.4) - oj (3.13.16) + oj (3.13.21) oj_mimic_json (1.0.1) optimist (3.0.1) parallel (1.22.1) @@ -448,7 +448,7 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) rchardet (1.8.0) - rdf (3.2.8) + rdf (3.2.9) link_header (~> 0.0, >= 0.0.8) rdf-aggregate-repo (3.2.1) rdf (~> 3.2) @@ -467,7 +467,7 @@ GEM rdf-turtle (3.2.1) ebnf (~> 2.3) rdf (~> 3.2) - rdf-vocab (3.2.1) + rdf-vocab (3.2.2) rdf (~> 3.2, >= 3.2.4) rdf-xsd (3.2.1) rdf (~> 3.2) @@ -594,19 +594,19 @@ GEM climate_control (>= 0.0.3, < 1.0) test-prof (0.10.2) thor (1.2.1) - tilt (2.0.10) + tilt (2.0.11) turnout (2.5.0) i18n (>= 0.7, < 2) rack (>= 1.3, < 3) rack-accept (~> 0.4) tilt (>= 1.4, < 3) - tzinfo (2.0.4) + tzinfo (2.0.5) concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext unf_ext (0.0.8.2) unicode-display_width (2.2.0) - unicode-types (1.7.0) + unicode-types (1.8.0) unicode_utils (1.4.0) uniform_notifier (1.16.0) uuid (2.3.9) @@ -621,7 +621,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.0) + zeitwerk (2.6.1) PLATFORMS ruby @@ -729,4 +729,4 @@ DEPENDENCIES webmock (~> 3.1) BUNDLED WITH - 2.3.10 + 2.3.20