Skip to content

Commit

Permalink
show all dois associated with a ror_id via the member. #635
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 19, 2020
1 parent 4dac152 commit 78ee576
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
7 changes: 1 addition & 6 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
28 changes: 19 additions & 9 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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" }}
Expand All @@ -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])}" }}
Expand All @@ -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

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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])}" }}
Expand All @@ -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

Expand Down

0 comments on commit 78ee576

Please sign in to comment.