Skip to content

Commit

Permalink
show nested publications
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 29, 2019
1 parent 49502fd commit f71a0b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/graphql/types/base_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ def doi_from_url(url)
uri.path.gsub(/^\//, "").downcase
end
end

def orcid_from_url(url)
if /\A(?:(http|https):\/\/(orcid.org)\/)(.+)\z/.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(/^\//, "").downcase
end
end
end
13 changes: 7 additions & 6 deletions app/graphql/types/researcher_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,30 @@ def family_name
end

def datasets(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid ? "https://orcid.org/#{object.uid}" : nil || object[:id]), citation_type: "Dataset-Person").results.to_a.map do |e|
ids = Event.query(nil, obj_id: https_to_http(object.uid || object[:id] || object.fetch("nameIdentifiers", []).find { |n| n.fetch("nameIdentifierScheme", nil) == "ORCID" }.to_h.fetch("nameIdentifier", nil)), citation_type: "Dataset-Person").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def publications(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid ? "https://orcid.org/#{object.uid}" : nil || object[:id]), citation_type: "Person-ScholarlyArticle").results.to_a.map do |e|
ids = Event.query(nil, obj_id: https_to_http(object.uid || object[:id] || object.fetch("nameIdentifiers", []).find { |n| n.fetch("nameIdentifierScheme", nil) == "ORCID" }.to_h.fetch("nameIdentifier", nil)), citation_type: "Person-ScholarlyArticle").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def softwares(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid ? "https://orcid.org/#{object.uid}" : nil || object[:id]), citation_type: "Person-SoftwareSourceCode").results.to_a.map do |e|
ids = Event.query(nil, obj_id: https_to_http(object.uid || object[:id] || object.fetch("nameIdentifiers", []).find { |n| n.fetch("nameIdentifierScheme", nil) == "ORCID" }.to_h.fetch("nameIdentifier", nil)), citation_type: "Person-SoftwareSourceCode").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
orcid = orcid_from_url(url)
return nil unless orcid.present?

"https://orcid.org/#{orcid}"
end
end

0 comments on commit f71a0b6

Please sign in to comment.