From d67ddd6bd0b67f3064f546913d80ab4f1c462545 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 6 Oct 2020 18:21:30 +0200 Subject: [PATCH] filter citations by resource_type_id. #636 --- app/graphql/types/doi_item.rb | 2 +- .../returns_citations.yml | 203 ++++++++++++++++++ .../returns_all_datasets_with_counts.yml | 203 ++++++++++++++++++ .../types/data_management_plan_type_spec.rb | 41 ++++ spec/graphql/types/dataset_type_spec.rb | 10 +- 5 files changed, 453 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/DataManagementPlanType/find_data_management_plan_with_citations/returns_citations.yml create mode 100644 spec/fixtures/vcr_cassettes/DatasetType/query_with_citations/returns_all_datasets_with_counts.yml diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index 3bde62d8b..e5e6d25d3 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -451,7 +451,7 @@ def response(**args) # make sure no dois are returnded if there are no :ids args[:ids] = "999" if args[:ids].blank? - Doi.gql_query(args[:query], ids: args[:ids], funder_id: args[:funder_id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], organization_id: args[:organization_id], has_person: args[:has_person], has_funder: args[:has_funder], has_affiliation: args[:has_affiliation], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], field_of_science: args[:field_of_science], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [], size: args[:first] }) + Doi.gql_query(args[:query], ids: args[:ids], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], resource_type_id: args[:resource_type_id], resource_type: args[:resource_type], published: args[:published], agency: args[:registration_agency], language: args[:language], license: args[:license], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_affiliation: args[:has_affiliation], has_member: args[:has_member], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], field_of_science: args[:field_of_science], pid_entity: args[:pid_entity], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [], size: args[:first] }) end def doi_link(url) diff --git a/spec/fixtures/vcr_cassettes/DataManagementPlanType/find_data_management_plan_with_citations/returns_citations.yml b/spec/fixtures/vcr_cassettes/DataManagementPlanType/find_data_management_plan_with_citations/returns_citations.yml new file mode 100644 index 000000000..8bdf0c312 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DataManagementPlanType/find_data_management_plan_with_citations/returns_citations.yml @@ -0,0 +1,203 @@ +--- +http_interactions: +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 15:39:48 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d568a9d7294654e8ae48f9fec855dd63c1601998788; expires=Thu, 05-Nov-20 + 15:39:48 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 05a02aaf390000d6b5119a0200000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5de07a2b8d62d6b5-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 15:39:48 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 15:39:48 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=ded066c4450a30fce4c78dcec0f90ffda1601998788; expires=Thu, 05-Nov-20 + 15:39:48 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 05a02ab0f300001f518a3fc200000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5de07a2e5fae1f51-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 15:39:49 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 15:39:49 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d83e4cf7aba99f16d669268fee502e84e1601998789; expires=Thu, 05-Nov-20 + 15:39:49 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 05a02ab30100002bca37a41200000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5de07a3199ab2bca-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 15:39:49 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 15:39:49 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=def803e20fb3d192af9add84048588aee1601998789; expires=Thu, 05-Nov-20 + 15:39:49 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 05a02ab5000000c27c0d8c9200000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5de07a34ca64c27c-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 15:39:50 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/DatasetType/query_with_citations/returns_all_datasets_with_counts.yml b/spec/fixtures/vcr_cassettes/DatasetType/query_with_citations/returns_all_datasets_with_counts.yml new file mode 100644 index 000000000..4ae7c8852 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DatasetType/query_with_citations/returns_all_datasets_with_counts.yml @@ -0,0 +1,203 @@ +--- +http_interactions: +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 12:53:04 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d84744b675929c88fd252e75ec0d9c4391601988784; expires=Thu, 05-Nov-20 + 12:53:04 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '059f9207bf00000614f5afe200000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5ddf85ec69bd0614-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 12:53:04 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 12:53:04 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=dc3c2d4fb4d29365adcb595d71bd6adf51601988784; expires=Thu, 05-Nov-20 + 12:53:04 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '059f9208a100001756cabd0200000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5ddf85edcc7a1756-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 12:53:04 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 12:53:04 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d58ba5c783f8fe8f11ec35838571868e61601988784; expires=Thu, 05-Nov-20 + 12:53:04 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '059f920a67000097cc4d0b4200000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5ddf85f0a9f097cc-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 12:53:04 GMT +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Tue, 06 Oct 2020 12:53:04 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d459fba30d2de5e2a218a8e40c645ff361601988784; expires=Thu, 05-Nov-20 + 12:53:04 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '059f920aef0000c2dba00c7200000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5ddf85f17e84c2db-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Tue, 06 Oct 2020 12:53:04 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/graphql/types/data_management_plan_type_spec.rb b/spec/graphql/types/data_management_plan_type_spec.rb index 13010bb62..7546507ba 100644 --- a/spec/graphql/types/data_management_plan_type_spec.rb +++ b/spec/graphql/types/data_management_plan_type_spec.rb @@ -359,4 +359,45 @@ expect(response.dig("data", "dataManagementPlans", "nodes").length).to eq(3) end end + + describe "find data management plan with citations", elasticsearch: true, vcr: true do + let(:client) { create(:client) } + let(:doi) { create(:doi, client: client, types: { "resourceTypeGeneral" => "Text", "resourceType" => "Data Management Plan" }, aasm_state: "findable") } + let(:source_doi) { create(:doi, client: client, types: { "resourceTypeGeneral" => "Dataset" }, aasm_state: "findable") } + let(:source_doi2) { create(:doi, client: client, types: { "resourceTypeGeneral" => "Software" }, aasm_state: "findable") } + let!(:citation_event) { create(:event_for_datacite_crossref, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi.doi}", relation_type_id: "is-referenced-by", occurred_at: "2015-06-13T16:14:19Z") } + let!(:citation_event2) { create(:event_for_datacite_crossref, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi2.doi}", relation_type_id: "is-referenced-by", occurred_at: "2015-06-13T16:14:19Z") } + + before do + Doi.import + sleep 2 + end + + let(:query) do + %(query { + dataManagementPlan(id: "https://doi.org/#{doi.doi}") { + id + partOf { + nodes { + id + } + } + citations(resourceTypeId: "Dataset") { + totalCount + nodes { + id + type + } + } + } + }) + end + + it "returns citations" do + response = LupoSchema.execute(query).as_json + + expect(response.dig("data", "dataManagementPlan", "id")).to eq("https://handle.test.datacite.org/#{doi.doi.downcase}") + expect(response.dig("data", "dataManagementPlan", "citations", "totalCount")).to eq(1) + end + end end diff --git a/spec/graphql/types/dataset_type_spec.rb b/spec/graphql/types/dataset_type_spec.rb index cdd5f2f6d..8c7c29fec 100644 --- a/spec/graphql/types/dataset_type_spec.rb +++ b/spec/graphql/types/dataset_type_spec.rb @@ -215,7 +215,7 @@ year total } - citations { + citations(resourceTypeId: "Dataset") { totalCount nodes { id @@ -229,15 +229,15 @@ it "returns all datasets with counts" do response = LupoSchema.execute(query).as_json - + puts response expect(response.dig("data", "datasets", "totalCount")).to eq(3) expect(Base64.urlsafe_decode64(response.dig("data", "datasets", "pageInfo", "endCursor")).split(",", 2).last).to eq(@dois.last.uid) expect(response.dig("data", "datasets", "pageInfo", "hasNextPage")).to be false expect(response.dig("data", "datasets", "nodes").length).to eq(3) - # expect(response.dig("data", "datasets", "nodes", 0, "citationCount")).to eq(2) + expect(response.dig("data", "datasets", "nodes", 0, "citationCount")).to eq(2) # expect(response.dig("data", "datasets", "nodes", 0, "citationsOverTime")).to eq([{"total"=>1, "year"=>2015}, {"total"=>1, "year"=>2016}]) - # expect(response.dig("data", "datasets", "nodes", 0, "citations", "totalCount")).to eq(2) - # expect(response.dig("data", "datasets", "nodes", 0, "citations", "nodes").length).to eq(2) + expect(response.dig("data", "datasets", "nodes", 0, "citations", "totalCount")).to eq(2) + expect(response.dig("data", "datasets", "nodes", 0, "citations", "nodes").length).to eq(2) # expect(response.dig("data", "datasets", "nodes", 0, "citations", "nodes", 0)).to eq("id"=>"https://handle.test.datacite.org/#{source_doi.uid}", "publicationYear"=>2011) end end