Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 18, 2020
2 parents 7dd5591 + 2c0aad9 commit 9c1bc42
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
Empty file added .rubocop_todo.yml
Empty file.
13 changes: 12 additions & 1 deletion app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def index
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
end
else

states = total > 0 ? facet_by_key(response.aggregations.states.buckets) : nil
resource_types = total > 0 ? facet_by_resource_type(response.aggregations.resource_types.buckets) : nil
years = total > 0 ? facet_by_year(response.aggregations.years.buckets) : nil
Expand All @@ -155,6 +156,13 @@ def index
subjects = total > 0 ? facet_by_key(response.aggregations.subjects.buckets) : nil
certificates = total > 0 ? facet_by_key(response.aggregations.certificates.buckets) : nil

if params[:mix_in].present?
dois_result = results.map { |result| result.dig(:_source, :doi) }.join(',') if total.positive?
citations = total.positive? ? EventsQuery.new.citations(dois_result) : nil
views = total.positive? ? EventsQuery.new.views(dois_result) : nil
downloads = total.positive? ? EventsQuery.new.downloads(dois_result) : nil
end

respond_to do |format|
format.json do
options = {}
Expand All @@ -180,7 +188,10 @@ def index
"linkChecksSchemaOrgId" => link_checks_schema_org_id,
"linkChecksDcIdentifier" => link_checks_dc_identifier,
"linkChecksCitationDoi" => link_checks_citation_doi,
subjects: subjects
subjects: subjects,
citations: citations,
views: views,
downloads: downloads,
}.compact

options[:links] = {
Expand Down

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

27 changes: 27 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@
end
end

describe 'GET /dois all with metrics', elasticsearch: true, vcr: true do
# let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") }
let!(:doi) { create(:doi, client: client, aasm_state: "findable") }
let!(:events) { create_list(:event_for_datacite_related, 3, obj_id: doi.doi) }
let!(:views) { create_list(:event_for_datacite_usage, 2, obj_id: doi.doi) }

before do
Event.import
Doi.import
sleep 3
end

context 'when the record exists' do
it 'returns the Doi' do
get "/dois?mix-in=metrics", nil, headers


expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(1)
expect(json.dig('meta', 'total')).to eq(1)
expect(json.dig('meta', 'citations').first.dig('count')).to eq(3)
expect(json.dig('meta', 'views').first.dig('count')).to be > 0
expect(json.dig('meta', 'downloads').first.dig('count')).to eq(0)
end
end
end

describe 'state' do
let(:doi_id) { "10.14454/4K3M-NYVG" }
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
Expand Down

0 comments on commit 9c1bc42

Please sign in to comment.