From c763621e2edd2407c2f52997b4d786b59a3cfd5c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 26 Oct 2019 21:39:55 +0200 Subject: [PATCH] use doi serializer --- app/controllers/dois_controller.rb | 4 ++-- app/serializers/client_serializer.rb | 10 +++++++++- app/serializers/doi_serializer.rb | 2 +- spec/requests/providers_spec.rb | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 364b61c78..ad1925445 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -482,9 +482,9 @@ def set_doi def set_include if params[:include].present? @include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym } - @include = @include & [:repository, :media] + @include = @include & [:client, :media] else - @include = [:repository, :media] + @include = [:client, :media] end end diff --git a/app/serializers/client_serializer.rb b/app/serializers/client_serializer.rb index 09035d9ba..5debe454b 100644 --- a/app/serializers/client_serializer.rb +++ b/app/serializers/client_serializer.rb @@ -4,7 +4,7 @@ class ClientSerializer set_type :clients set_id :uid - attributes :name, :symbol, :year, :contact_email, :alternate_name, :description, :language, :client_type, :domains, :issn, :url, :salesforce_id, :created, :updated + attributes :name, :symbol, :year, :contact_email, :alternate_name, :description, :language, :client_type, :domains, :re3data, :opendoar, :issn, :url, :salesforce_id, :created, :updated belongs_to :provider, record_type: :providers belongs_to :consortium, record_type: :providers, serializer: ProviderSerializer, if: Proc.new { |client| client.consortium_id } @@ -21,4 +21,12 @@ class ClientSerializer attribute :salesforce_id, if: Proc.new { |object, params| params[:current_ability] && params[:current_ability].can?(:read_salesforce_id, object) == true } do |object| object.salesforce_id end + + attribute :re3data do |object| + "https://doi.org/#{object.re3data_id}" if object.re3data_id.present? + end + + attribute :opendoar do |object| + "https://v2.sherpa.ac.uk/id/repository/#{object.opendoar_id}" if object.opendoar_id.present? + end end diff --git a/app/serializers/doi_serializer.rb b/app/serializers/doi_serializer.rb index 6182cd0c6..908494d42 100644 --- a/app/serializers/doi_serializer.rb +++ b/app/serializers/doi_serializer.rb @@ -8,7 +8,7 @@ class DoiSerializer attributes :doi, :prefix, :suffix, :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, :created, :registered, :published, :updated attributes :prefix, :suffix, if: Proc.new { |object, params| params && params[:detail] } - belongs_to :repository, record_type: :repositories + belongs_to :client, record_type: :clients has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]} attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object| diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index 47424688b..e89e83cdb 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -596,7 +596,7 @@ put "/providers/#{provider.symbol}", params, headers expect(last_response.status).to eq(422) - expect(json["errors"].first).to eq("source" => "ror_id", "title" => "Ror id should be a url") + expect(json["errors"].first).to eq("source" => "ror_id", "title" => "ROR ID should be a url") end end