diff --git a/app/graphql/types/base_object.rb b/app/graphql/types/base_object.rb index 7a35fad54..469f40e04 100644 --- a/app/graphql/types/base_object.rb +++ b/app/graphql/types/base_object.rb @@ -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 diff --git a/app/graphql/types/researcher_type.rb b/app/graphql/types/researcher_type.rb index a63e86367..b049a2623 100644 --- a/app/graphql/types/researcher_type.rb +++ b/app/graphql/types/researcher_type.rb @@ -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