From f774e3a6b82e34bcb7583147b3a7b83788c96e11 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 21 Jun 2019 12:34:07 -0400 Subject: [PATCH] include doi metadata in rest api response. #296 --- app/controllers/events_controller.rb | 2 +- app/models/event.rb | 76 +++------------------------- app/serializers/event_serializer.rb | 5 +- 3 files changed, 11 insertions(+), 72 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index ccc151c5e..4cd501ac7 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -180,7 +180,7 @@ def load_event def set_include if params[:include].present? @include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym } - @include &= [:subj, :obj] + @include &= [:dois] else @include = [] end diff --git a/app/models/event.rb b/app/models/event.rb index 442878104..74efe7cbb 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -85,49 +85,17 @@ class Event < ActiveRecord::Base indexes :subj_id, type: :keyword indexes :obj_id, type: :keyword indexes :doi, type: :keyword + indexes :dois, type: :keyword indexes :orcid, type: :keyword indexes :prefix, type: :keyword indexes :subtype, type: :keyword indexes :citation_type, type: :keyword indexes :issn, type: :keyword indexes :subj, type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, + type: { type: :keyword }, + id: { type: :keyword }, uid: { type: :keyword }, - name: { type: :text }, - givenName: { type: :text }, - familyName: { type: :text }, - author: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text }, - givenName: { type: :text }, - familyName: { type: :text } - }}, - periodical: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text }, - "issn" => { type: :keyword } - }}, - alternateName: { type: :text }, - volumeNumber: { type: :keyword }, - issueNumber: { type: :keyword }, - pagination: { type: :keyword }, - publisher: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text } - }}, - funder: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text } - }}, proxyIdentifiers: { type: :keyword }, - version: { type: :keyword }, - datePublished: { type: :date, format: "date_optional_time||yyyy-MM-dd||yyyy-MM||yyyy", ignore_malformed: true }, - dateModified: { type: :date, format: "date_optional_time", ignore_malformed: true }, registrantId: { type: :keyword }, cache_key: { type: :keyword } } @@ -135,40 +103,7 @@ class Event < ActiveRecord::Base type: { type: :keyword }, id: { type: :keyword }, uid: { type: :keyword }, - name: { type: :text }, - givenName: { type: :text }, - familyName: { type: :text }, - author: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text }, - givenName: { type: :text }, - familyName: { type: :text } - }}, - periodical: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text }, - "issn" => { type: :keyword } - }}, - alternateName: { type: :text }, - volumeNumber: { type: :keyword }, - issueNumber: { type: :keyword }, - pagination: { type: :keyword }, - publisher: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text } - }}, - funder: { type: :object, properties: { - "@type" => { type: :keyword }, - "@id" => { type: :keyword }, - name: { type: :text } - }}, proxyIdentifiers: { type: :keyword }, - version: { type: :keyword }, - datePublished: { type: :date, format: "date_optional_time||yyyy-MM-dd||yyyy-MM||yyyy", ignore_malformed: true }, - dateModified: { type: :date, format: "date_optional_time", ignore_malformed: true }, registrantId: { type: :keyword }, cache_key: { type: :keyword } } @@ -201,6 +136,7 @@ def as_indexed_json(options={}) "subj" => subj.merge(cache_key: subj_cache_key), "obj" => obj.merge(cache_key: obj_cache_key), "doi" => doi, + "dois" => dois, "orcid" => orcid, "issn" => issn, "prefix" => prefix, @@ -451,6 +387,10 @@ def doi [doi_from_url(subj_id), doi_from_url(obj_id)].compact end + def dois + Doi.query(nil, doi: doi.map(&:upcase)).results + end + def prefix [doi.map { |d| d.to_s.split('/', 2).first }].compact end diff --git a/app/serializers/event_serializer.rb b/app/serializers/event_serializer.rb index dfecd88b2..c125fd7e1 100644 --- a/app/serializers/event_serializer.rb +++ b/app/serializers/event_serializer.rb @@ -6,8 +6,7 @@ class EventSerializer attributes :subj_id, :obj_id, :source_id, :relation_type_id, :total, :message_action, :source_token, :license, :occurred_at, :timestamp - belongs_to :subj, serializer: ObjectSerializer, record_type: :objects - belongs_to :obj, serializer: ObjectSerializer, record_type: :objects - + belongs_to :dois, record_type: :dois, id_method_name: :doi, object_method_name: :dois + attribute :timestamp, &:updated_at end