Skip to content

Commit

Permalink
include subj and/or obj with events. #671
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 14, 2020
1 parent 8abdfc2 commit 946ea52
Show file tree
Hide file tree
Showing 17 changed files with 1,103 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ docker-compose.override.yml
.ruby-version
.vscode
.solargraph.yml
.devspace
12 changes: 12 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class EventsController < ApplicationController
prepend_before_action :authenticate_user!, except: [:index, :show]
before_action :detect_crawler
before_action :load_event, only: [:show]
before_action :set_include, only: [:index, :show, :create, :update]
authorize_resource only: [:destroy]

def create
Expand Down Expand Up @@ -58,6 +59,7 @@ def update

def show
options = {}
options[:include] = @include
options[:is_collection] = false

render json: EventSerializer.new(@event, options).serialized_json, status: :ok
Expand Down Expand Up @@ -147,6 +149,7 @@ def index
results = response.results

options = {}
options[:include] = @include
options[:meta] = {
total: total,
"totalPages" => total_pages,
Expand Down Expand Up @@ -206,6 +209,15 @@ def load_event
fail ActiveRecord::RecordNotFound if @event.blank?
end

def set_include
if params[:include].present?
@include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym }
@include = @include & [:subj, :obj]
else
@include = []
end
end

private

def safe_params
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/old_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class OldEventsController < ApplicationController
prepend_before_action :authenticate_user!, except: [:index, :show]
before_action :detect_crawler
before_action :load_event, only: [:show]
before_action :set_include, only: [:index, :show, :create, :update]
authorize_resource only: [:destroy]

def create
Expand Down Expand Up @@ -193,6 +194,15 @@ def load_event
fail ActiveRecord::RecordNotFound unless @event.present?
end

def set_include
if params[:include].present?
@include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym }
@include = @include & [:subj, :obj]
else
@include = []
end
end

private

def safe_params
Expand Down
54 changes: 27 additions & 27 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ def self.update_crossref(options = {})

# walk through results using cursor
if response.results.total > 0
while response.results.results.length > 0 do
while response.results.length > 0 do
response = Event.query(nil, source_id: "crossref", page: { size: size, cursor: cursor })
break unless response.results.results.length.positive?
break unless response.results.length.positive?

Rails.logger.info "[Update] Updating #{response.results.results.length} crossref events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "[Update] Updating #{response.results.length} crossref events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]

dois = response.results.results.map(&:subj_id).uniq
dois = response.results.map(&:subj_id).uniq
OtherDoiJob.perform_later(dois)
end
end
Expand Down Expand Up @@ -412,14 +412,14 @@ def self.update_datacite_ra(options = {})

# walk through results using cursor
if response.results.total > 0
while response.results.results.length > 0 do
while response.results.length > 0 do
response = Event.query(nil, source_id: source_id, page: { size: size, cursor: cursor })
break unless response.results.results.length > 0
break unless response.results.length > 0

Rails.logger.info "[Update] Updating #{response.results.length} #{source_id} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]

dois = response.results.results.map(&:obj_id).uniq
dois = response.results.map(&:obj_id).uniq

# use same job for all non-DataCite dois
OtherDoiJob.perform_later(dois, options)
Expand All @@ -442,14 +442,14 @@ def self.update_registrant(options = {})

# walk through results using cursor
if response.results.total > 0
while response.results.results.length > 0 do
while response.results.length > 0 do
response = Event.query(query, source_id: source_id, citation_type: citation_type, page: { size: size, cursor: cursor })
break unless response.results.results.length > 0
break unless response.results.length > 0

Rails.logger.info "[Update] Updating #{response.results.results.length} #{source_id} events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "[Update] Updating #{response.results.length} #{source_id} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]

ids = response.results.results.map(&:uuid).uniq
ids = response.results.map(&:uuid).uniq

EventRegistrantUpdateJob.perform_later(ids, options)
end
Expand All @@ -467,14 +467,14 @@ def self.update_datacite_orcid_auto_update(options = {})

# walk through results using cursor
if response.results.total > 0
while response.results.results.length > 0 do
while response.results.length > 0 do
response = Event.query(nil, source_id: "datacite-orcid-auto-update", page: { size: size, cursor: cursor })
break unless response.results.results.length > 0
break unless response.results.length > 0

Rails.logger.info "[Update] Updating #{response.results.results.length} datacite-orcid-auto-update events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "[Update] Updating #{response.results.length} datacite-orcid-auto-update events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]

ids = response.results.results.map(&:obj_id).uniq
ids = response.results.map(&:obj_id).uniq
OrcidAutoUpdateJob.perform_later(ids, options)
end
end
Expand Down Expand Up @@ -588,15 +588,15 @@ def self.subj_id_check(options = {})

# walk through results using cursor
if response.results.total.positive?
while response.results.results.length.positive?
while response.results.length.positive?
response = Event.query(nil, source_id: "datacite-crossref",page: { size: size, cursor: cursor })
break unless response.results.results.length.positive?
break unless response.results.length.positive?

Rails.logger.warn "[DoubleCheck] DoubleCheck #{response.results.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.warn "[DoubleCheck] DoubleCheck #{response.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]
Rails.logger.warn "[DoubleCheck] Cursor: #{cursor} "

events = response.results.results.map { |item| { uuid: item.uuid, subj_id: item.subj_id } }
events = response.results.map { |item| { uuid: item.uuid, subj_id: item.subj_id } }
SubjCheckJob.perform_later(events, options)
end
end
Expand All @@ -611,15 +611,15 @@ def self.modify_nested_objects(options = {})

# walk through results using cursor
if response.results.total.positive?
while response.results.results.length.positive?
while response.results.length.positive?
response = Event.query(nil, page: { size: size, cursor: cursor })
break unless response.results.results.length.positive?
break unless response.results.length.positive?

Rails.logger.info "[modify_nested_objects] modify_nested_objects #{response.results.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "[modify_nested_objects] modify_nested_objects #{response.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]
Rails.logger.info "[modify_nested_objects] Cursor: #{cursor} "

ids = response.results.results.map(&:uuid).uniq
ids = response.results.map(&:uuid).uniq
ids.each do |id|
CamelcaseNestedObjectsByIdJob.perform_later(id, options)
end
Expand Down Expand Up @@ -662,15 +662,15 @@ def self.loop_through_events(options)

# walk through results using cursor
if response.results.total.positive?
while response.results.results.length.positive?
while response.results.length.positive?
response = Event.query(query, filter.merge(page: { size: size, cursor: cursor }))
break unless response.results.results.length.positive?
break unless response.results.length.positive?

Rails.logger.info "#{label} #{response.results.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
Rails.logger.info "#{label} #{response.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]
Rails.logger.info "#{label} Cursor: #{cursor} "

ids = response.results.results.map(&:uuid).uniq
ids = response.results.map(&:uuid).uniq
ids.each do |id|
Object.const_get(job_name).perform_later(id, filter)
end
Expand Down
3 changes: 3 additions & 0 deletions app/serializers/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ class EventSerializer
attribute :target_doi do |object|
object.target_doi.downcase if object.target_doi.present?
end

belongs_to :subj, serializer: ObjectSerializer, record_type: :objects
belongs_to :obj, serializer: ObjectSerializer, record_type: :objects
end
11 changes: 11 additions & 0 deletions app/serializers/object_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ObjectSerializer
include FastJsonapi::ObjectSerializer
set_key_transform :camel_lower
set_type :objects

attributes :subtype, :name, :author, :publisher, :periodical, :included_in_data_catalog, :version, :date_published, :date_modified, :funder, :proxy_identifiers, :registrant_id

attribute :subtype do |object|
object["@type"]
end
end
3 changes: 3 additions & 0 deletions app/serializers/old_event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ class OldEventSerializer

attributes :subj_id, :obj_id, :source_id, :relation_type_id, :total, :message_action, :source_token, :license, :occurred_at, :timestamp

belongs_to :subj, serializer: OldObjectSerializer, record_type: :objects
belongs_to :obj, serializer: OldObjectSerializer, record_type: :objects

attribute :timestamp, &:updated_at
end
11 changes: 11 additions & 0 deletions app/serializers/old_object_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class OldObjectSerializer
include FastJsonapi::ObjectSerializer
set_key_transform :dash
set_type :objects

attributes :subtype, :name, :author, :periodical, :volume_number, :issue_number, :pagination, :publisher, :issn, :version, :date_published

attribute :subtype do |object|
object["@type"]
end
end
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.1'
version: "3"

services:
web:
Expand All @@ -20,8 +20,7 @@ services:
networks:
- public
depends_on:
elasticsearch:
condition: service_healthy
- elasticsearch
memcached:
image: memcached:1.4.31
networks:
Expand Down Expand Up @@ -68,5 +67,4 @@ networks:
ipam:
driver: default
config:
- subnet: 10.0.40.0/24
gateway: 10.0.40.1
- subnet: 10.0.40.0/24

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 946ea52

Please sign in to comment.