Skip to content

Commit

Permalink
lookup of single dois does not use elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 23, 2020
1 parent d8cb128 commit 48b36c6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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

Expand Down
83 changes: 59 additions & 24 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/types/doi_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down

0 comments on commit 48b36c6

Please sign in to comment.