Skip to content

Commit

Permalink
support references and citations in graphql. #422, #424, #438, #439, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 4, 2020
1 parent 9e13bdf commit 519550e
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 314 deletions.
8 changes: 8 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ def index
schema_version: params[:schema_version],
subject: params[:subject],
has_citations: params[:has_citations],
has_references: params[:has_references],
has_parts: params[:has_parts],
has_part_of: params[:has_part_of],
has_versions: params[:has_versions],
has_version_of: params[:has_version_of],
has_views: params[:has_views],
has_downloads: params[:has_downloads],
has_person: params[:has_person],
has_affiliation: params[:has_affiliation],
has_funder: params[:has_funder],
link_check_status: params[:link_check_status],
link_check_has_schema_org: params[:link_check_has_schema_org],
link_check_body_has_pid: params[:link_check_body_has_pid],
Expand Down
3 changes: 2 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,8 @@ def years
end

def response(**args)
@response ||= Doi.query(args[:query],
@response ||= Doi.query(args[:query],
ids: args[:ids],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
Expand Down
12 changes: 0 additions & 12 deletions app/graphql/types/dataset_dataset_connection_with_meta_type.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/graphql/types/dataset_publication_connection_with_meta_type.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/graphql/types/dataset_software_connection_with_meta_type.rb

This file was deleted.

34 changes: 1 addition & 33 deletions app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,11 @@ class DatasetType < BaseObject
field :usage_reports, DatasetUsageReportConnectionWithMetaType, null: false, description: "Usage reports for this dataset", connection: true do
argument :first, Int, required: false, default_value: 25
end
field :datasets, DatasetDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true do
argument :first, Int, required: false, default_value: 25
end
field :publications, DatasetPublicationConnectionWithMetaType, null: false, description: "Referenced publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
field :software_source_codes, DatasetSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true do
argument :first, Int, required: false, default_value: 25
end


def usage_reports(**args)
ids = Event.query(nil, obj_id: object.id).results.to_a.map do |e|
e[:subj_id]
end
UsageReport.find_by_id(ids, page: { number: 1, size: args[:first] }).fetch(:data, [])
end

def datasets(**args)
ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-Dataset").results.to_a.map do |e|
object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id)
end

ElasticsearchLoader.for(Doi).load_many(ids)
end

def publications(**args)
ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-ScholarlyArticle").results.to_a.map do |e|
object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def software_source_codes(**args)
ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-SoftwareSourceCode").results.to_a.map do |e|
object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end
end
126 changes: 118 additions & 8 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,78 @@ module DoiItem
field :citations_over_time, [YearTotalType], null: true, description: "Citations by year."
field :views_over_time, [YearMonthTotalType], null: true, description: "Views by month."
field :downloads_over_time, [YearMonthTotalType], null: true, description: "Downloads by month."
field :citations, [WorkType], null: true, description: "Citations."
field :references, [WorkType], null: true, description: "References."
field :references, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "References for this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end
field :citations, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "Citations for this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end
field :parts, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "Parts of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end
field :part_of, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "The DOI is a part of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end
field :versions, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "Versions of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end
field :version_of, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 100, description: "The DOI is a version of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def type
object.types["resourceTypeGeneral"]
Expand Down Expand Up @@ -86,15 +156,55 @@ def formatted_citation(style: nil, locale: nil)
end
bibliography.first.gsub(url, doi_link(url))
end

def references(**args)
ids = object.reference_ids
return [] if ids.blank?

response(**args)
end

def citations
ids = object.citation_events.map {|e| e.source_doi }
ElasticsearchLoader.for(Doi).load_many(ids)
def citations(**args)
args[:ids] = object.citation_ids
return [] if args[:ids].blank?

Rails.logger.warn args[:ids]

response(**args)
end

def parts(**args)
args[:ids] = object.part_ids
return [] if args[:ids].blank?

response(**args)
end

def part_of(**args)
args[:ids] = object.part_of_ids
return [] if args[:ids].blank?

response(**args)
end

def versions(**args)
args[:ids] = object.version_ids
return [] if args[:ids].blank?

response(**args)
end

def version_of(**args)
args[:ids] = object.version_of_ids
return [] if args[:ids].blank?

response(**args)
end

def references
ids = object.reference_events.map { |e| e.target_doi }
ElasticsearchLoader.for(Doi).load_many(ids)
def response(**args)
return [] if args[:ids].blank?

@response ||= Doi.query(args[:query], ids: args[:ids], funder_id: object[:id], user_id: args[:user_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], state: "findable", page: { number: 1, size: args[:first] }).results.to_a
end

def doi_link(url)
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FunderType < BaseObject

field :datasets, DatasetConnectionWithMetaType, null: true, description: "Funded datasets", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
Expand All @@ -25,6 +26,7 @@ class FunderType < BaseObject

field :publications, PublicationConnectionWithMetaType, null: true, description: "Funded publications", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
Expand All @@ -36,6 +38,7 @@ class FunderType < BaseObject

field :softwares, SoftwareConnectionWithMetaType, null: true, description: "Funded software", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
Expand All @@ -47,6 +50,7 @@ class FunderType < BaseObject

field :works, WorkConnectionWithMetaType, null: true, description: "Funded works", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OrganizationType < BaseObject

field :datasets, DatasetConnectionWithMetaType, null: true, description: "Datasets from this organization", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
Expand All @@ -28,6 +29,7 @@ class OrganizationType < BaseObject

field :publications, PublicationConnectionWithMetaType, null: true, description: "Publications from this organization", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
Expand All @@ -40,6 +42,7 @@ class OrganizationType < BaseObject

field :softwares, SoftwareConnectionWithMetaType, null: true, description: "Software from this organization", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
Expand All @@ -52,6 +55,7 @@ class OrganizationType < BaseObject

field :works, WorkConnectionWithMetaType, null: true, description: "Works from this organization", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :client_id, String, required: false
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PersonType < BaseObject

field :datasets, DatasetConnectionWithMetaType, null: true, connection: true, max_page_size: 1000, description: "Authored datasets" do
argument :query, String, required: false
argument :ids, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
Expand All @@ -24,6 +25,7 @@ class PersonType < BaseObject

field :publications, PublicationConnectionWithMetaType, null: true, connection: true, max_page_size: 1000, description: "Authored publications" do
argument :query, String, required: false
argument :ids, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
Expand All @@ -34,6 +36,7 @@ class PersonType < BaseObject

field :softwares, SoftwareConnectionWithMetaType, null: true, connection: true, max_page_size: 1000, description: "Authored software" do
argument :query, String, required: false
argument :ids, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
Expand All @@ -44,6 +47,7 @@ class PersonType < BaseObject

field :works, WorkConnectionWithMetaType, null: true, connection: true, max_page_size: 1000, description: "Authored works" do
argument :query, String, required: false
argument :ids, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_citations, Int, required: false
Expand Down
5 changes: 3 additions & 2 deletions app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def years
end

def response(**args)
@response ||= Doi.query(args[:query],
user_id: args[:user_id],
@response ||= Doi.query(args[:query],
ids: args[:ids],
user_id: args[:user_id],
client_id: args[:client_id],
provider_id: args[:provider_id],
funder_id: args[:funder_id],
Expand Down
12 changes: 0 additions & 12 deletions app/graphql/types/publication_dataset_connection_with_meta_type.rb

This file was deleted.

This file was deleted.

Loading

0 comments on commit 519550e

Please sign in to comment.