Skip to content

Commit

Permalink
include doi metadata in rest api response. #296
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 21, 2019
1 parent 639a601 commit f774e3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 8 additions & 68 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,90 +85,25 @@ 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 }
}
indexes :obj, type: :object, properties: {
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 }
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/serializers/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f774e3a

Please sign in to comment.