From 42a07ddb73c01263123cd5f0e40a3b729cfe10db Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 3 Nov 2020 10:20:17 +0100 Subject: [PATCH 1/2] Add provider relationships to serializer on detail When detail is requested, additionally return the provider relationship. --- app/serializers/datacite_doi_serializer.rb | 7 ++++--- spec/requests/datacite_dois_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/serializers/datacite_doi_serializer.rb b/app/serializers/datacite_doi_serializer.rb index b82e3c930..9b2917429 100644 --- a/app/serializers/datacite_doi_serializer.rb +++ b/app/serializers/datacite_doi_serializer.rb @@ -8,8 +8,9 @@ class DataciteDoiSerializer attributes :doi, :prefix, :suffix, :identifiers, :alternate_identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :views_over_time, :download_count, :downloads_over_time, :reference_count, :citation_count, :citations_over_time, :part_count, :part_of_count, :version_count, :version_of_count, :created, :registered, :published, :updated attributes :prefix, :suffix, :views_over_time, :downloads_over_time, :citations_over_time, if: Proc.new { |object, params| params && params[:detail] } - + belongs_to :client, record_type: :clients + belongs_to :provider, record_type: :providers, if: Proc.new { |object, params| params && params[:detail] } has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]} has_many :references, record_type: :dois, serializer: DataciteDoiSerializer, object_method_name: :indexed_references, if: Proc.new { |object, params| params && params[:detail] } has_many :citations, record_type: :dois, serializer: DataciteDoiSerializer, object_method_name: :indexed_citations, if: Proc.new { |object, params| params && params[:detail] } @@ -38,7 +39,7 @@ class DataciteDoiSerializer if params[:affiliation] a else - a["name"] + a["name"] end end.compact c @@ -53,7 +54,7 @@ class DataciteDoiSerializer if params[:affiliation] a else - a["name"] + a["name"] end end.compact c diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index da1bc7d9c..22e66c511 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -127,6 +127,15 @@ expect(doi.dig('attributes')).to include('xml') end end + + it 'returns related provider when detail is enabled', vcr: true do + get '/dois?detail=true', nil, headers + + expect(last_response.status).to eq(200) + json['data'].each do |doi| + expect(doi.dig('relationships', 'provider','data','id')).to eq(provider.symbol.downcase) + end + end end describe "GET /dois with query", elasticsearch: true do From 3eb2b1d5748a6ca13c85f1100b9fef330f5d7897 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Thu, 5 Nov 2020 12:01:02 +0100 Subject: [PATCH 2/2] Don't reindex on doi transfer if no db update --- app/jobs/transfer_job.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/jobs/transfer_job.rb b/app/jobs/transfer_job.rb index d37a0e080..8da3513ff 100644 --- a/app/jobs/transfer_job.rb +++ b/app/jobs/transfer_job.rb @@ -10,9 +10,13 @@ def perform(doi_id, options={}) doi = Doi.where(doi: doi_id).first if doi.present? && options[:client_target_id].present? - doi.update_attributes(datacentre: options[:client_target_id]) + # Success starts as true because update_attributes only returns false on error. + success = true + success = doi.update_attributes(datacentre: options[:client_target_id]) - doi.__elasticsearch__.index_document + if success + self.__elasticsearch__.index_document + end Rails.logger.info "[Transfer] Transferred DOI #{doi.doi}." elsif doi.present?