Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 7, 2020
1 parent 65a6c0f commit 64f0eea
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def totals
page = { size: 0, number: 1 }
state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable"
response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: "client")
registrant = response.results.total.positive? ? clients_totals(response.response.aggregations.clients_totals.buckets) : []
registrant = response.results.total.positive? ? clients_totals(response.aggregations.clients_totals.buckets) : []

render json: registrant, status: :ok
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def index
"citationTypes" => citation_types,
"relationTypes" => relation_types,
registrants: registrants,
"states": states,
}.compact

options[:links] = {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def repositories
response = Doi.query(nil, state: "registered,findable", page: { size: 0, number: 1 }, totals_agg: "client_export")

client_totals = {}
totals_buckets = response.response.aggregations.clients_totals.buckets
totals_buckets = response.aggregations.clients_totals.buckets
totals_buckets.each do |totals|
client_totals[totals["key"]] = {
"count" => totals["doc_count"],
Expand Down
12 changes: 0 additions & 12 deletions app/controllers/old_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class OldEventsController < ApplicationController
prepend_before_action :authenticate_user!, except: [:index, :show]
before_action :detect_crawler
before_action :load_event, only: [:show, :destroy]
before_action :set_include, only: [:index, :show, :create, :update]
authorize_resource only: [:destroy]

def create
Expand Down Expand Up @@ -56,7 +55,6 @@ def update

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

render json: OldEventSerializer.new(@event, options).serialized_json, status: :ok
Expand Down Expand Up @@ -171,7 +169,6 @@ def index
"page[number]" => page[:cursor].nil? && page[:number].present? ? page[:number] + 1 : nil,
"page[size]" => page[:size] }.compact.to_query
}.compact
options[:include] = @include
options[:is_collection] = true

render json: OldEventSerializer.new(results, options).serialized_json, status: :ok
Expand All @@ -195,15 +192,6 @@ 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
14 changes: 7 additions & 7 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def index
begin
total = response.results.total
total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0
years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil
software = total > 0 ? facet_by_software(response.response.aggregations.software.buckets) : nil
certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil
client_types = total > 0 ? facet_by_key(response.response.aggregations.client_types.buckets) : nil
repository_types = total > 0 ? facet_by_key(response.response.aggregations.repository_types.buckets) : nil
years = total > 0 ? facet_by_year(response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_combined_key(response.aggregations.providers.buckets) : nil
software = total > 0 ? facet_by_software(response.aggregations.software.buckets) : nil
certificates = total > 0 ? facet_by_key(response.aggregations.certificates.buckets) : nil
client_types = total > 0 ? facet_by_key(response.aggregations.client_types.buckets) : nil
repository_types = total > 0 ? facet_by_key(response.aggregations.repository_types.buckets) : nil

respond_to do |format|
format.json do
Expand Down Expand Up @@ -194,7 +194,7 @@ def totals

state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable"
response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: "client")
registrant = response.results.total.positive? ? clients_totals(response.response.aggregations.clients_totals.buckets) : []
registrant = response.results.total.positive? ? clients_totals(response.aggregations.clients_totals.buckets) : []

render json: registrant, status: :ok
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ def self.query(query, options={})
aggregations = client_export_aggregations
elsif options[:totals_agg] == "prefix"
aggregations = prefix_aggregations
else
aggregations = query_aggregations
end

# Cursor nav use the search after, this should always be an array of values that match the sort.
Expand Down
3 changes: 0 additions & 3 deletions app/serializers/old_event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class OldEventSerializer
set_id :uuid

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: 0 additions & 11 deletions app/serializers/old_object_serializer.rb

This file was deleted.

28 changes: 0 additions & 28 deletions spec/concerns/indexable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,33 +207,5 @@
expect(subject.ror_from_url(ror_id)).to be_nil
end
end

context "aggregations" do
it 'returns query_aggregation when filters aggregation with empty' do
aggregations = Doi.get_aggregations_hash({aggregations:""})
expect(aggregations[:resource_types]).not_to be_nil
expect(aggregations[:states]).not_to be_nil
expect(aggregations[:created]).not_to be_nil
expect(aggregations[:schema_versions]).not_to be_nil
end

it 'returns multiple aggregations when filters aggregations with multiple' do
aggregations = Doi.get_aggregations_hash({aggregations:""})
expect(aggregations[:resource_types]).not_to be_nil
expect(aggregations[:states]).not_to be_nil
expect(aggregations[:created]).not_to be_nil
expect(aggregations[:schema_versions]).not_to be_nil
end
end
end

context "when event" do
let!(:event) { create(:event) }
let!(:events) { create_list(:event, 3) }

before do
Event.import
sleep 2
end
end
end
2 changes: 1 addition & 1 deletion spec/requests/exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

it 'returns repositories', vcr: false do
get "/export/repositories", nil, admin_headers

puts last_response.body
expect(last_response.status).to eq(200)
csv = last_response.body.lines
expect(csv.length).to eq(2)
Expand Down

0 comments on commit 64f0eea

Please sign in to comment.