Skip to content

Commit

Permalink
fix dois by re3data lookup. #441
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 30, 2020
1 parent e9e9108 commit 5696a19
Show file tree
Hide file tree
Showing 26 changed files with 217 additions and 102 deletions.
6 changes: 4 additions & 2 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def orcid_from_url(url)
end

def prepare_args(args)
args[:user_id] ||= object.parent.try(:orcid).present? ? object.parent.orcid : nil
args[:user_id] = orcid_from_url(args[:user_id]) if args[:user_id].present?
args[:user_id] ||= object.parent.try(:type) == "Person" ? object.parent.orcid : nil
args[:client_id] ||= object.parent.try(:client_type).present? ? object.parent.symbol.downcase : nil
args[:provider_id] ||= object.parent.try(:region).present? ? object.parent.symbol.downcase : nil
args[:affiliation_id] ||= object.parent.try(:type) == "Organization" ? object.parent[:id] : nil
args[:funder_id] ||= object.parent.try(:type) == "Funder" ? object.parent[:id] : nil
args[:re3data_id] ||= object.parent.try(:type) == "DataCatalog" ? object.parent[:id] : nil
args.compact
end

Expand Down
4 changes: 0 additions & 4 deletions app/graphql/types/data_catalog_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class DataCatalogType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def type
"DataCatalog"
end

def identifier
Array.wrap(object.re3data_id).map { |o| { "name" => "re3data", "value" => "r3d#{o}" } }
end
Expand Down
14 changes: 13 additions & 1 deletion app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ def years
end

def response(**args)
@response ||= Doi.query(args[:query], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], year: args[:year], resource_type_id: "Dataset", has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], page: { number: 1, size: 0 })
@response ||= Doi.query(args[:query],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
funder_id: args[:funder_id],
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Dataset",
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
page: { number: 1, size: 0 })
end

def dataset_connection_count
Expand Down
4 changes: 0 additions & 4 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ class FunderType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def type
"Funder"
end

def address
{ "type" => "postalAddress",
"country" => object.country.to_h.fetch("name", nil) }
Expand Down
4 changes: 0 additions & 4 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class OrganizationType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def type
"Organization"
end

def alternate_name
object.aliases + object.acronyms
end
Expand Down
4 changes: 0 additions & 4 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class PersonType < BaseObject
argument :first, Int, required: false, default_value: 25
end

def type
"Person"
end

def publications(**args)
Doi.query(args[:query], user_id: orcid_from_url(object[:id]), client_id: args[:client_id], provider_id: args[:provider_id], has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.to_a
end
Expand Down
20 changes: 20 additions & 0 deletions app/graphql/types/provider_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class ProviderType < BaseObject
field :organization_type, String, null: true, description: "Type of organization"
field :focus_area, String, null: true, description: "Field of science covered by provider"
field :joined, String, null: true, description: "Date provider joined DataCite"
field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice."
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
field :citation_count, Integer, null: true, description: "The number of citations."

field :datasets, DatasetConnectionWithMetaType, null: true, connection: true, max_page_size: 1000, description: "Authored datasets" do
argument :query, String, required: false
argument :client_id, String, required: false
Expand Down Expand Up @@ -106,4 +110,20 @@ def prefixes(**args)
def clients(**args)
Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { number: 1, size: args[:first] }).results.to_a
end

def view_count
response.results.total.positive? ? aggregate_count(response.response.aggregations.views.buckets) : []
end

def download_count
response.results.total.positive? ? aggregate_count(response.response.aggregations.downloads.buckets) : []
end

def citation_count
response.results.total.positive? ? aggregate_count(response.response.aggregations.citations.buckets) : []
end

def response
@response ||= Doi.query(nil, provider_id: object.uid, state: "findable", page: { number: 1, size: 0 })
end
end
14 changes: 13 additions & 1 deletion app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ def years
end

def response(**args)
@response ||= Doi.query(args[:query], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], year: args[:year], resource_type_id: "Text", has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], page: { number: 1, size: 0 })
@response ||= Doi.query(args[:query],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
funder_id: args[:funder_id],
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Text",
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
page: { number: 1, size: 0 })
end

def publication_connection_count
Expand Down
14 changes: 13 additions & 1 deletion app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ def years
end

def response(**args)
@response ||= Doi.query(args[:query], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], year: args[:year], resource_type_id: "Software", has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], page: { number: 1, size: 0 })
@response ||= Doi.query(args[:query],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
funder_id: args[:funder_id],
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Software",
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
page: { number: 1, size: 0 })
end

def software_connection_count
Expand Down
15 changes: 14 additions & 1 deletion app/graphql/types/work_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WorkConnectionWithMetaType < BaseConnection

def total_count
args = prepare_args(object.arguments)
Rails.logger.warn object.parent.inspect

response(**args).results.total
end
Expand All @@ -29,6 +30,18 @@ def resource_types
end

def response(**args)
@response ||= Doi.query(args[:query], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], year: args[:year], resource_type_id: args[:resource_type_id], has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], page: { number: 1, size: 0 })
@response ||= Doi.query(args[:query],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
funder_id: args[:funder_id],
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: args[:resource_type_id],
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
page: { number: 1, size: 0 })
end
end
1 change: 1 addition & 0 deletions app/models/data_catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def self.query(query, options={})
def self.parse_message(id: nil, message: nil)
Hashie::Mash.new({
id: id,
type: "DataCatalog",
re3data_id: message["re3dataId"],
name: message["repositoryName"],
url: message["repositoryUrl"],
Expand Down
1 change: 1 addition & 0 deletions app/models/funder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def self.parse_message(id: nil, message: nil)

Hashie::Mash.new({
id: id,
type: "Funder",
name: message["name"],
alternate_name: message["alt-names"],
country: country,
Expand Down
1 change: 1 addition & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def self.parse_message(id: nil, message: nil)

Hashie::Mash.new({
id: id,
type: "Organization",
name: message["name"],
aliases: message["aliases"],
acronyms: message["acronyms"],
Expand Down
1 change: 1 addition & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def self.query(query, options={})
def self.parse_message(id: nil, message: nil)
Hashie::Mash.new({
id: id,
type: "Person",
orcid: message["orcid"],
name: message["name"],
given_name: message["givenName"],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5696a19

Please sign in to comment.