From 4613d857ebd5efc5d4a69c432a5aaef6d0c0aa94 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 9 Jun 2019 10:06:17 +0200 Subject: [PATCH] define citations between publications, dataset and software. #261 --- ...taset_dataset_connection_with_meta_type.rb | 2 +- ...t_publication_connection_with_meta_type.rb | 2 +- app/graphql/types/dataset_type.rb | 6 ++-- app/graphql/types/event_data_edge_type.rb | 2 +- ...r_publication_connection_with_meta_type.rb | 2 +- ...ation_dataset_connection_with_meta_type.rb | 12 +++++++ ...n_publication_connection_with_meta_type.rb | 12 +++++++ ...tion_software_connection_with_meta_type.rb | 12 +++++++ app/graphql/types/publication_type.rb | 33 +++++++++++++++++++ ...tware_dataset_connection_with_meta_type.rb | 12 +++++++ ...e_publication_connection_with_meta_type.rb | 12 +++++++ ...ware_software_connection_with_meta_type.rb | 12 +++++++ app/graphql/types/software_type.rb | 32 ++++++++++++++++++ 13 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 app/graphql/types/publication_dataset_connection_with_meta_type.rb create mode 100644 app/graphql/types/publication_publication_connection_with_meta_type.rb create mode 100644 app/graphql/types/publication_software_connection_with_meta_type.rb create mode 100644 app/graphql/types/software_dataset_connection_with_meta_type.rb create mode 100644 app/graphql/types/software_publication_connection_with_meta_type.rb create mode 100644 app/graphql/types/software_software_connection_with_meta_type.rb diff --git a/app/graphql/types/dataset_dataset_connection_with_meta_type.rb b/app/graphql/types/dataset_dataset_connection_with_meta_type.rb index 29b93eff7..5352fef1d 100644 --- a/app/graphql/types/dataset_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_dataset_connection_with_meta_type.rb @@ -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 \ No newline at end of file +end diff --git a/app/graphql/types/dataset_publication_connection_with_meta_type.rb b/app/graphql/types/dataset_publication_connection_with_meta_type.rb index 3d0d54080..b08be44d8 100644 --- a/app/graphql/types/dataset_publication_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_publication_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/dataset_type.rb b/app/graphql/types/dataset_type.rb index 3551929e0..b087888ba 100644 --- a/app/graphql/types/dataset_type.rb +++ b/app/graphql/types/dataset_type.rb @@ -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 diff --git a/app/graphql/types/event_data_edge_type.rb b/app/graphql/types/event_data_edge_type.rb index a614f6e4c..fb5797776 100644 --- a/app/graphql/types/event_data_edge_type.rb +++ b/app/graphql/types/event_data_edge_type.rb @@ -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" diff --git a/app/graphql/types/funder_publication_connection_with_meta_type.rb b/app/graphql/types/funder_publication_connection_with_meta_type.rb index e414797e1..45e302473 100644 --- a/app/graphql/types/funder_publication_connection_with_meta_type.rb +++ b/app/graphql/types/funder_publication_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/publication_dataset_connection_with_meta_type.rb b/app/graphql/types/publication_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..a5a561597 --- /dev/null +++ b/app/graphql/types/publication_dataset_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/publication_publication_connection_with_meta_type.rb b/app/graphql/types/publication_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..3d35e2018 --- /dev/null +++ b/app/graphql/types/publication_publication_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/publication_software_connection_with_meta_type.rb b/app/graphql/types/publication_software_connection_with_meta_type.rb new file mode 100644 index 000000000..f740c408f --- /dev/null +++ b/app/graphql/types/publication_software_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/publication_type.rb b/app/graphql/types/publication_type.rb index 5e8cc5450..c63938d89 100644 --- a/app/graphql/types/publication_type.rb +++ b/app/graphql/types/publication_type.rb @@ -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 diff --git a/app/graphql/types/software_dataset_connection_with_meta_type.rb b/app/graphql/types/software_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..b6bd14333 --- /dev/null +++ b/app/graphql/types/software_dataset_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/software_publication_connection_with_meta_type.rb b/app/graphql/types/software_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..1f0e689c6 --- /dev/null +++ b/app/graphql/types/software_publication_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/software_software_connection_with_meta_type.rb b/app/graphql/types/software_software_connection_with_meta_type.rb new file mode 100644 index 000000000..0860809c6 --- /dev/null +++ b/app/graphql/types/software_software_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/software_type.rb b/app/graphql/types/software_type.rb index 3c2aaf777..036c1a726 100644 --- a/app/graphql/types/software_type.rb +++ b/app/graphql/types/software_type.rb @@ -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