From 78ee576c97d00245af15c5ed9346bfc93fc52af4 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 19 Sep 2020 08:16:44 +0200 Subject: [PATCH] show all dois associated with a ror_id via the member. #635 --- app/graphql/types/organization_type.rb | 7 +------ app/models/doi.rb | 28 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 267b15809..5b41b4969 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -122,7 +122,6 @@ class OrganizationType < BaseObject argument :user_id, String, required: false argument :funder_id, String, required: false argument :repository_id, String, required: false - argument :member_id, String, required: false argument :registration_agency, String, required: false argument :resource_type_id, String, required: false argument :resource_type, String, required: false @@ -181,10 +180,6 @@ def identifiers object.isni.map { |o| { "identifierType" => "isni", "identifier" => o } } end - def provider_id - member["member_id"] && %w(direct_member consortium_organization).include?(member["member_role_id"]) ? member["member_id"] : nil - end - def publications(**args) args[:resource_type_id] = "Text" ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after]) @@ -240,6 +235,6 @@ def citation_count end def response(**args) - Doi.gql_query(args[:query], ids: args[:ids], affiliation_id: object.id, organization_id: object.id, provider_id: args[:member_id] || provider_id, user_id: args[:user_id], client_id: args[:repository_id], funder_id: args[:funder_id] || object.fundref.join(","), resource_type_id: args[:resource_type_id], resource_type: args[:resource_type], agency: args[:registration_agency], language: args[:language], license: args[:license], has_person: args[:has_person], has_funder: args[:has_funder], 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], published: args[:published], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [], size: args[:first] }) + Doi.gql_query(args[:query], ids: args[:ids], affiliation_id: object.id, organization_id: object.id, member_id: %w(direct_member consortium_organization).include?(member["member_role_id"]) ? object.id : nil, user_id: args[:user_id], client_id: args[:repository_id], funder_id: args[:funder_id] || object.fundref.join(","), resource_type_id: args[:resource_type_id], resource_type: args[:resource_type], agency: args[:registration_agency], language: args[:language], license: args[:license], has_person: args[:has_person], has_funder: args[:has_funder], 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], published: args[:published], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [], size: args[:first] }) end end diff --git a/app/models/doi.rb b/app/models/doi.rb index fad0e7a6b..6b4aa5b8e 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -824,6 +824,7 @@ def self.gql_query(query, options={}) filter << { terms: { doi: options[:ids].map(&:upcase) }} if options[:ids].present? filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize }} if options[:resource_type_id].present? filter << { terms: { "types.resourceType": options[:resource_type].split(",") }} if options[:resource_type].present? + filter << { terms: { provider_id: options[:provider_id].split(",") } } if options[:provider_id].present? filter << { terms: { client_id: options[:client_id].to_s.split(",") } } if options[:client_id].present? filter << { terms: { agency: options[:agency].split(",").map(&:downcase) } } if options[:agency].present? filter << { terms: { prefix: options[:prefix].to_s.split(",") } } if options[:prefix].present? @@ -869,7 +870,7 @@ def self.gql_query(query, options={}) filter << { term: { "creators.nameIdentifiers.nameIdentifier" => "https://orcid.org/#{orcid_from_url(options[:user_id])}" }} if options[:user_id].present? filter << { term: { "creators.nameIdentifiers.nameIdentifierScheme" => "ORCID" }} if options[:has_person].present? - # match either one of has_affiliation, has_organization, or has_funder + # match either one of has_affiliation, has_organization, has_funder or has_member if options[:has_organization].present? should << { term: { "creators.nameIdentifiers.nameIdentifierScheme" => "ROR" }} should << { term: { "contributors.nameIdentifiers.nameIdentifierScheme" => "ROR" }} @@ -884,9 +885,13 @@ def self.gql_query(query, options={}) filter << { term: { "funding_references.funderIdentifierType" => "Crossref Funder ID" }} minimum_should_match = 1 end + if options[:has_member].present? + should << { exists: { field: "provider.ror_id" }} + minimum_should_match = 1 + end - # match either ROR ID, Crossref Funder ID or Member ID if either organization_id, affiliation_id, - # funder_id or provider_id is a query parameter + # match either ROR ID or Crossref Funder ID if either organization_id, affiliation_id, + # funder_id or member_id is a query parameter if options[:organization_id].present? should << { term: { "creators.nameIdentifiers.nameIdentifier" => "https://#{ror_from_url(options[:organization_id])}" }} should << { term: { "contributors.nameIdentifiers.nameIdentifier" => "https://#{ror_from_url(options[:organization_id])}" }} @@ -900,8 +905,8 @@ def self.gql_query(query, options={}) should << { terms: { "funding_references.funderIdentifier" => options[:funder_id].split(",").map { |f| "https://doi.org/#{doi_from_url(f)}" } } } minimum_should_match = 1 end - if options[:provider_id].present? - should << { terms: { provider_id: options[:provider_id].split(",") } } + if options[:member_id].present? + should << { term: { "provider.ror_id" => "https://#{ror_from_url(options[:member_id])}" }} minimum_should_match = 1 end @@ -1015,6 +1020,7 @@ def self.query(query, options={}) filter << { terms: { doi: options[:ids].map(&:upcase) }} if options[:ids].present? filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize }} if options[:resource_type_id].present? filter << { terms: { "types.resourceType": options[:resource_type].split(",") }} if options[:resource_type].present? + filter << { terms: { provider_id: options[:provider_id].split(",") } } if options[:provider_id].present? filter << { terms: { client_id: options[:client_id].to_s.split(",") } } if options[:client_id].present? filter << { terms: { agency: options[:agency].split(",").map(&:downcase) } } if options[:agency].present? filter << { terms: { prefix: options[:prefix].to_s.split(",") } } if options[:prefix].present? @@ -1075,9 +1081,13 @@ def self.query(query, options={}) filter << { term: { "funding_references.funderIdentifierType" => "Crossref Funder ID" }} minimum_should_match = 1 end + if options[:has_member].present? + should << { exists: { field: "provider.ror_id" }} + minimum_should_match = 1 + end - # match either ROR ID, Crossref Funder ID or Member ID if either organization_id, affiliation_id, - # funder_id or provider_id is a query parameter + # match either ROR ID or Crossref Funder ID if either organization_id, affiliation_id, + # funder_id or member_id is a query parameter if options[:organization_id].present? should << { term: { "creators.nameIdentifiers.nameIdentifier" => "https://#{ror_from_url(options[:organization_id])}" }} should << { term: { "contributors.nameIdentifiers.nameIdentifier" => "https://#{ror_from_url(options[:organization_id])}" }} @@ -1091,8 +1101,8 @@ def self.query(query, options={}) should << { terms: { "funding_references.funderIdentifier" => options[:funder_id].split(",").map { |f| "https://doi.org/#{doi_from_url(f)}" } } } minimum_should_match = 1 end - if options[:provider_id].present? - should << { terms: { provider_id: options[:provider_id].split(",") } } + if options[:member_id].present? + should << { term: { "provider.ror_id" => "https://#{ror_from_url(options[:member_id])}" }} minimum_should_match = 1 end