From 48b36c6da83896babc8ae2bfd675919a3e0fdfa5 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 23 Feb 2020 17:36:28 +0100 Subject: [PATCH] lookup of single dois does not use elasticsearch --- Gemfile.lock | 2 +- app/controllers/dois_controller.rb | 12 +++-- app/graphql/schema.graphql | 83 ++++++++++++++++++++--------- app/models/doi.rb | 2 +- spec/graphql/types/doi_item_spec.rb | 2 +- 5 files changed, 69 insertions(+), 32 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e22721467..74a211edd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,7 +109,7 @@ GEM latex-decode (~> 0.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bolognese (1.5.1) + bolognese (1.5.2) activesupport (>= 4.2.5) benchmark_methods (~> 0.7) bibtex-ruby (>= 5.1.0) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index cdf6a132a..94989722a 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -250,11 +250,13 @@ def show # only show findable DOIs to anonymous users and role user # use current_user role to determine permissions to access draft and registered dois # instead of using ability - response = Doi.find_by_id(params[:id]) + # response = Doi.find_by_id(params[:id]) + doi = Doi.where(doi: params[:id]).first + fail ActiveRecord::RecordNotFound if not_allowed_by_doi_and_user(doi: doi, user: current_user) respond_to do |format| format.json do - doi = response.results.first + # doi = response.results.first fail ActiveRecord::RecordNotFound if not_allowed_by_doi_and_user(doi: doi, user: current_user) options = {} @@ -269,16 +271,16 @@ def show render json: DoiSerializer.new(doi, options).serialized_json, status: :ok end - doi = response.records.first + # doi = response.records.first fail ActiveRecord::RecordNotFound if not_allowed_by_doi_and_user(doi: doi, user: current_user) - format.citation do + format.citation do # fetch formatted citation render citation: doi, style: params[:style] || "apa", locale: params[:locale] || "en-US" end header = %w(doi url registered state resourceTypeGeneral resourceType title author publisher publicationYear) format.any(:bibtex, :citeproc, :codemeta, :crosscite, :datacite, :datacite_json, :jats, :ris, :schema_org) { render request.format.to_sym => doi } - format.csv { render request.format.to_sym => doi, header: header } + format.csv { render request.format.to_sym => doi, header: header } end end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 9a68c01ed..a8f86627b 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -57,7 +57,7 @@ type Audiovisual implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -457,7 +457,7 @@ type Collection implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -634,7 +634,7 @@ type CreativeWork implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -808,6 +808,41 @@ type CreativeWorkEdge { node: CreativeWork } +""" +A creator. +""" +type Creator { + """ + The organizational or institutional affiliation of the creator. + """ + affiliation: [Organization!] + + """ + Family name. In the U.S., the last name of an Person. + """ + familyName: String + + """ + Given name. In the U.S., the first name of a Person. + """ + givenName: String + + """ + The ID of the creator. + """ + id: ID + + """ + The name of the creator. + """ + name: String + + """ + The type of the item. + """ + type: String! +} + """ A collection of datasets. """ @@ -1065,7 +1100,7 @@ type DataPaper implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -1227,7 +1262,7 @@ type Dataset implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Referenced datasets @@ -1666,7 +1701,7 @@ interface DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -1828,7 +1863,7 @@ type Event implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -1990,7 +2025,7 @@ type EventData implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -2425,14 +2460,14 @@ Information about identifiers """ type Identifier { """ - The name of the identifier. + The value of the identifier. """ - name: String + identifier: String """ - The value of the identifier. + The type of identifier. """ - value: String + identifierType: String } type Image implements DoiItem { @@ -2459,7 +2494,7 @@ type Image implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -2621,7 +2656,7 @@ type InteractiveResource implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -2783,7 +2818,7 @@ type Model implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -2959,12 +2994,12 @@ type Organization { """ ROR ID """ - id: ID! + id: ID """ The identifier(s) for the organization. """ - identifier: [Identifier!] + identifiers: [Identifier!] """ The name of the organization. @@ -3149,7 +3184,7 @@ type Other implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -3590,7 +3625,7 @@ type PhysicalObject implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -3980,7 +4015,7 @@ type Publication implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Referenced datasets @@ -4685,7 +4720,7 @@ type Service implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -4868,7 +4903,7 @@ type Software implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Referenced datasets @@ -5210,7 +5245,7 @@ type Sound implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work @@ -5525,7 +5560,7 @@ type Workflow implements DoiItem { """ The main researchers involved in producing the data, or the authors of the publication, in priority order """ - creators(first: Int = 20): [Person!] + creators(first: Int = 20): [Creator!] """ Different dates relevant to the work diff --git a/app/models/doi.rb b/app/models/doi.rb index 2da859ce1..74e01fdb2 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -860,7 +860,7 @@ def self.import_one(doi_id: nil) # update_attributes will trigger validations and Elasticsearch indexing doi.update_attributes(attrs) - Rails.logger.info "[MySQL] Imported metadata for DOI " + doi.doi + "." + Rails.logger.warn "[MySQL] Imported metadata for DOI " + doi.doi + "." doi rescue TypeError, NoMethodError, RuntimeError, ActiveRecord::StatementInvalid, ActiveRecord::LockWaitTimeout => e if doi.present? diff --git a/spec/graphql/types/doi_item_spec.rb b/spec/graphql/types/doi_item_spec.rb index f3f47fc1a..57e300eda 100644 --- a/spec/graphql/types/doi_item_spec.rb +++ b/spec/graphql/types/doi_item_spec.rb @@ -6,7 +6,7 @@ it { is_expected.to have_field(:id).of_type(!types.ID) } it { is_expected.to have_field(:type).of_type("String!") } - it { is_expected.to have_field(:creators).of_type("[Person!]") } + it { is_expected.to have_field(:creators).of_type("[Creator!]") } it { is_expected.to have_field(:titles).of_type("[Title!]") } it { is_expected.to have_field(:publicationYear).of_type("Int") } it { is_expected.to have_field(:publisher).of_type("String") }