Skip to content

Commit

Permalink
define citations between publications, dataset and software. #261
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 9, 2019
1 parent 20c4131 commit 4613d85
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class DatasetDatasetConnectionWithMetaType < BaseConnection
def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-Dataset").results.total
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class DatasetPublicationConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-JournalArticle").results.total
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-ScholarlyArticle").results.total
end
end
6 changes: 3 additions & 3 deletions app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class DatasetType < BaseObject
field :usage_reports, DatasetUsageReportConnectionWithMetaType, null: false, description: "Usage reports for this dataset", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end
field :datasets, DatasetDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do
field :datasets, DatasetDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end
field :publications, DatasetPublicationConnectionWithMetaType, null: false, description: "Funded publications", connection: true do
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 :softwares, DatasetSoftwareConnectionWithMetaType, null: false, description: "Funded software", connection: true, max_page_size: 100 do
field :softwares, DatasetSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/event_data_edge_type.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class EventDataEdgeType < GraphQL::Types::Relay::BaseEdge
node_type(PublicationType)
node_type(EventType)

field :source, String, null: false, description: "Source for this event"
field :relation_type, String, null: false, description: "Relation type for this event"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class FunderPublicationConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-JournalArticle").results.total
Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-ScholarlyArticle").results.total
end
end
12 changes: 12 additions & 0 deletions app/graphql/types/publication_dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class PublicationDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-ScholarlyArticle").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class PublicationPublicationConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "ScholarlyArticle-ScholarlyArticle").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class PublicationSoftwareConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total
end
end
33 changes: 33 additions & 0 deletions app/graphql/types/publication_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,37 @@

class PublicationType < BaseObject
implements DoiItem

field :datasets, PublicationDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end
field :publications, PublicationPublicationConnectionWithMetaType, null: false, description: "Referenced publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
field :softwares, PublicationSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def datasets(**args)
ids = Event.query(nil, doi_id: 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 publications(**args)
ids = Event.query(nil, doi_id: doi_from_url(object.identifier), citation_type: "ScholarlyArticle-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 softwares(**args)
ids = Event.query(nil, doi_id: doi_from_url(object.identifier), citation_type: "ScholarlyArticle-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
12 changes: 12 additions & 0 deletions app/graphql/types/software_dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class SoftwareDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-SoftwareSourceCode").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class SoftwarePublicationConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total
end
end
12 changes: 12 additions & 0 deletions app/graphql/types/software_software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class SoftwareSoftwareConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "SoftwareSourceCode-SoftwareSourceCode").results.total
end
end
32 changes: 32 additions & 0 deletions app/graphql/types/software_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@

class SoftwareType < BaseObject
implements DoiItem

field :datasets, SoftwareDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end
field :publications, SoftwarePublicationConnectionWithMetaType, null: false, description: "Referenced publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
field :softwares, SoftwareSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def datasets(**args)
ids = Event.query(nil, doi_id: 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

def publications(**args)
ids = Event.query(nil, doi_id: doi_from_url(object.identifier), citation_type: "ScholarlyArticle-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

def softwares(**args)
ids = Event.query(nil, doi_id: doi_from_url(object.identifier), citation_type: "SoftwareSourceCode-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

0 comments on commit 4613d85

Please sign in to comment.