Skip to content

Commit

Permalink
handle orcid id as http. #258
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 13, 2019
1 parent 7f53b7a commit 912142d
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/graphql/types/client_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClientType < GraphQL::Schema::Object
argument :first, Int, required: false, default_value: 25
end

field :datasets, [Types::DatasetType], null: false, description: "Datasets managed by the client" do
field :datasets, [DatasetType], null: false, description: "Datasets managed by the client" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
Expand Down
16 changes: 8 additions & 8 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ module DoiItem
field :titles, [TitleType], null: true, description: "A name or title by which a resource is known"
field :publication_year, Int, null: true, description: "The year when the data was or will be made publicly available"
field :publisher, String, null: true, description: "The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource"
field :subjects, [Types::SubjectType], null: true, description: "Subject, keyword, classification code, or key phrase describing the resource"
field :subjects, [SubjectType], null: true, description: "Subject, keyword, classification code, or key phrase describing the resource"
field :resource_type_general, String, null: true, hash_key: "resource_type_id", description: "The general type of a resource"
field :dates, [Types::DateType], null: true, description: "Different dates relevant to the work"
field :dates, [DateType], null: true, description: "Different dates relevant to the work"
field :language, String, null: true, description: "The primary language of the resource"
field :identifiers, [Types::IdentifierType], null: true, description: "An identifier or identifiers applied to the resource being registered"
field :related_identifiers, [Types::RelatedIdentifierType], null: true, description: "Identifiers of related resources. These must be globally unique identifiers"
field :types, Types::ResourceTypeType, null: true, description: "The resource type"
field :identifiers, [IdentifierType], null: true, description: "An identifier or identifiers applied to the resource being registered"
field :related_identifiers, [RelatedIdentifierType], null: true, description: "Identifiers of related resources. These must be globally unique identifiers"
field :types, ResourceTypeType, null: true, description: "The resource type"
field :formats, [String], null: true, description: "Technical format of the resource"
field :sizes, [String], null: true, description: "Size (e.g. bytes, pages, inches, etc.) or duration (extent), e.g. hours, minutes, days, etc., of a resource"
field :version, String, null: true, hash_key: "version_info", description: "The version number of the resource"
field :rights, [Types::RightsType], null: true, hash_key: "rights_list", description: "Any rights information for this resource"
field :descriptions, [Types::DescriptionType], null: true, description: "All additional information that does not fit in any of the other categories"
field :funding_references, [Types::FundingType], null: true, description: "Information about financial support (funding) for the resource being registered"
field :rights, [RightsType], null: true, hash_key: "rights_list", description: "Any rights information for this resource"
field :descriptions, [DescriptionType], null: true, description: "All additional information that does not fit in any of the other categories"
field :funding_references, [FundingType], null: true, description: "Information about financial support (funding) for the resource being registered"
field :url, String, null: true, description: "The URL registered for the resource"
field :client, ClientType, null: true, description: "The client account managing this resource"
field :provider, ProviderType, null: true, description: "The provider account managing this resource"
Expand Down
11 changes: 10 additions & 1 deletion app/graphql/types/event_data_edge.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

class EventDataEdge < GraphQL::Relay::Edge
RELATION_TYPES = {
"funds" => "isFundedBy",
"isFundedBy" => "funds",
"authors" => "isAuthoredBy",
"isAuthoredBy" => "authors"
}

def event_data
@event_data ||= begin
Event.query(nil, subj_id: self.node[:id], obj_id: self.parent[:id])[:data].first
Expand All @@ -11,8 +18,10 @@ def source
event_data[:source_id].underscore.camelcase(:lower)
end

# We are switching subj and obj, and thus need to change direction of relation type
def relation_type
event_data[:relation_type_id].underscore.camelcase(:lower)
rt = event_data[:relation_type_id].underscore.camelcase(:lower)
RELATION_TYPES.fetch(rt, rt)
end

def total
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class ResearcherDatasetConnectionWithMetaType < GraphQL::Types::Relay::BaseConne
field :total_count, Integer, null: false

def total_count
Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Person").fetch(:meta, "total")
Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Dataset-Person").fetch(:meta, "total")
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class ResearcherPublicationConnectionWithMetaType < GraphQL::Types::Relay::BaseC
field :total_count, Integer, null: false

def total_count
Event.query(nil, obj_id: object[:id], citation_type: "JournalArticle-Person").fetch(:meta, "total")
Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "JournalArticle-Person").fetch(:meta, "total")
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class ResearcherSoftwareConnectionWithMetaType < GraphQL::Types::Relay::BaseConn
field :total_count, Integer, null: false

def total_count
Event.query(nil, obj_id: object[:id], citation_type: "Person-SoftwareSourceCode").fetch(:meta, "total")
Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-SoftwareSourceCode").fetch(:meta, "total")
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
end
end
12 changes: 9 additions & 3 deletions app/graphql/types/researcher_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class ResearcherType < BaseObject
end

def datasets(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Person").fetch(:data, []).map do |e|
ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Dataset-Person").fetch(:data, []).map do |e|
doi_from_url(e[:subj_id])
end.join(",")
Doi.find_by_ids(ids, page: { number: 1, size: args[:first] }).to_a
end

def publications(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Person-ScholarlyArticle").fetch(:data, []).map do |e|
ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-ScholarlyArticle").fetch(:data, []).map do |e|
doi_from_url(e[:subj_id])
end.join(",")
Doi.find_by_ids(ids, page: { number: 1, size: args[:first] }).to_a
end

def softwares(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Person-SoftwareSourceCode").fetch(:data, []).map do |e|
ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-SoftwareSourceCode").fetch(:data, []).map do |e|
doi_from_url(e[:subj_id])
end.join(",")
Doi.find_by_ids(ids, page: { number: 1, size: args[:first] }).to_a
Expand All @@ -48,4 +48,10 @@ def doi_from_url(url)
uri.path.gsub(/^\//, "").downcase
end
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
end
end
6 changes: 6 additions & 0 deletions app/models/concerns/helpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def encode_doi(prefix, options={})
def epoch_to_utc(epoch)
Time.at(epoch).to_datetime.utc.iso8601
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http"
uri.to_s
end
end

module ClassMethods
Expand Down
12 changes: 12 additions & 0 deletions spec/concerns/helpable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@
expect(response.body.dig("data", "values")).to eq([{"index"=>1, "type"=>"URL", "data"=>{"format"=>"string", "value"=>"https://blog.datacite.org/"}, "ttl"=>86400, "timestamp"=>"2019-05-10T12:45:27Z"}])
end

context "https to http" do
it "should convert" do
url = "https://orcid.org/0000-0003-1419-2405"
expect(subject.https_to_http(url)).to eq("http://orcid.org/0000-0003-1419-2405")
end

it "should ignore http" do
url = "http://orcid.org/0000-0003-1419-2405"
expect(subject.https_to_http(url)).to eq(url)
end
end

# it 'should register on save' do
# url = "https://blog.datacite.org/"
# subject = create(:doi, doi: "10.5438/hpc4-5t22", url: url, client: client, aasm_state: "findable")
Expand Down

0 comments on commit 912142d

Please sign in to comment.