diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 14c9872cc..356a6560c 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -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 @@ -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 = {} @@ -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] = { diff --git a/spec/fixtures/vcr_cassettes/dois/GET_/dois_all_with_metrics/when_the_record_exists/returns_the_Doi.yml b/spec/fixtures/vcr_cassettes/dois/GET_/dois_all_with_metrics/when_the_record_exists/returns_the_Doi.yml new file mode 100644 index 000000000..9c736ce23 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/dois/GET_/dois_all_with_metrics/when_the_record_exists/returns_the_Doi.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.ror.org/organizations + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.5; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '10193' + Connection: + - keep-alive + Date: + - Fri, 17 Jan 2020 03:17:10 GMT + Status: + - 200 OK + X-Frame-Options: + - SAMEORIGIN + Allow: + - GET, HEAD, OPTIONS + X-Powered-By: + - Phusion Passenger 6.0.4 + Server: + - nginx/1.17.3 + Phusion Passenger 6.0.4 + Vary: + - Accept-Encoding,Cookie,Origin + X-Cache: + - Hit from cloudfront + Via: + - 1.1 f4fd9b491f9f2f2d7eed7c38209919d4.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - TXL52-C1 + X-Amz-Cf-Id: + - cE36ff3h8-Kr6m6WjgPpR8cLJ2uFSlbStZuNtpqOqH6FpuR-rCXbXQ== + Age: + - '50301' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJudW1iZXJfb2ZfcmVzdWx0cyI6OTc5MDAsInRpbWVfdGFrZW4iOjcsIml0ZW1zIjpbeyJpZCI6Imh0dHBzOi8vcm9yLm9yZy8wNDRrMHB3NDQiLCJuYW1lIjoiS29yZWEgSW5zdGl0dXRlIG9mIEdlb3NjaWVuY2UgYW5kIE1pbmVyYWwgUmVzb3VyY2VzIiwidHlwZXMiOlsiRmFjaWxpdHkiXSwibGlua3MiOlsiaHR0cHM6Ly93d3cua2lnYW0ucmUua3IvZW5nbGlzaC8iXSwiYWxpYXNlcyI6W10sImFjcm9ueW1zIjpbIktJR0FNIl0sInN0YXR1cyI6ImFjdGl2ZSIsIndpa2lwZWRpYV91cmwiOiIiLCJsYWJlbHMiOltdLCJjb3VudHJ5Ijp7ImNvdW50cnlfbmFtZSI6IlNvdXRoIEtvcmVhIiwiY291bnRyeV9jb2RlIjoiS1IifSwiZXh0ZXJuYWxfaWRzIjp7IklTTkkiOnsicHJlZmVycmVkIjpudWxsLCJhbGwiOlsiMDAwMCAwMDAxIDA0MzYgMTYwMiJdfSwiRnV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iOjI4MDV9LHsiaWQiOiJjeiIsInRpdGxlIjoiQ3plY2ggUmVwdWJsaWMiLCJjb3VudCI6Mjc0M30seyJpZCI6InJ1IiwidGl0bGUiOiJSdXNzaWFuIEZlZGVyYXRpb24iLCJjb3VudCI6MjAxNH1dfX0= + http_version: + recorded_at: Fri, 17 Jan 2020 17:15:31 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 97354a40b..5e138dfee 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -104,6 +104,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) }