Skip to content

Commit

Permalink
disable breaking changes for #395
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 25, 2020
1 parent 6ee6dcc commit 538eda4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class Doi < ActiveRecord::Base
belongs_to :client, foreign_key: :datacentre
has_many :media, -> { order "created DESC" }, foreign_key: :dataset, dependent: :destroy
has_many :metadata, -> { order "created DESC" }, foreign_key: :dataset, dependent: :destroy
has_many :views, -> { where relation_type_id: "unique-dataset-investigations-regular" }, class_name: "Event", primary_key: :doi, foreign_key: :doi_id, dependent: :destroy
has_many :downloads, -> { where relation_type_id: "unique-dataset-requests-regular" }, class_name: "Event", primary_key: :doi, foreign_key: :doi_id, dependent: :destroy
# has_many :views, -> { where relation_type_id: "unique-dataset-investigations-regular" }, class_name: "Event", primary_key: :doi, foreign_key: :doi_id, dependent: :destroy
# has_many :downloads, -> { where relation_type_id: "unique-dataset-requests-regular" }, class_name: "Event", primary_key: :doi, foreign_key: :doi_id, dependent: :destroy

delegate :provider, to: :client, allow_nil: true
delegate :consortium_id, to: :provider, allow_nil: true
Expand Down Expand Up @@ -403,10 +403,10 @@ class Doi < ActiveRecord::Base
consortium_organizations: { type: :object }
}
indexes :resource_type, type: :object
indexes :view_ids, type: :keyword
indexes :views, type: :object
indexes :download_ids, type: :keyword
indexes :downloads, type: :object
# indexes :view_ids, type: :keyword
# indexes :views, type: :object
# indexes :download_ids, type: :keyword
# indexes :downloads, type: :object
end
end

Expand All @@ -428,8 +428,8 @@ def as_indexed_json(options={})
"consortium_id" => consortium_id,
"resource_type_id" => resource_type_id,
"media_ids" => media_ids,
"view_ids" => view_ids,
"download_ids" => download_ids,
# "view_ids" => view_ids,
# "download_ids" => download_ids,
"prefix" => prefix,
"suffix" => suffix,
"types" => types,
Expand Down Expand Up @@ -465,8 +465,8 @@ def as_indexed_json(options={})
"provider" => provider.try(:as_indexed_json),
"resource_type" => resource_type.try(:as_indexed_json),
"media" => media.map { |m| m.try(:as_indexed_json) },
"views" => views.map { |m| m.try(:as_indexed_json) },
"downloads" => downloads.map { |m| m.try(:as_indexed_json) }
# "views" => views.map { |m| m.try(:as_indexed_json) },
# "downloads" => downloads.map { |m| m.try(:as_indexed_json) }
}
end

Expand Down Expand Up @@ -858,13 +858,13 @@ def media_ids
media.pluck(:id).map { |m| Base32::URL.encode(m, split: 4, length: 16) }.compact
end

def view_ids
views.pluck(:doi_id)
end
# def view_ids
# views.pluck(:doi_id)
# end

def download_ids
downloads.pluck(:doi_id)
end
# def download_ids
# downloads.pluck(:doi_id)
# end


def xml_encoded
Expand Down
20 changes: 10 additions & 10 deletions app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class DoiSerializer
set_id :uid
# don't cache dois, as works are cached using the doi model

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, :citations, :views, :downloads
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, :citations
attributes :prefix, :suffix, if: Proc.new { |object, params| params && params[:detail] }

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]}
has_many :views, record_type: :events, if: Proc.new { |object, params| params && params[:events]}
has_many :downloads, record_type: :events, if: Proc.new { |object, params| params && params[:events]}
# has_many :views, record_type: :events, if: Proc.new { |object, params| params && params[:events]}
# has_many :downloads, record_type: :events, if: Proc.new { |object, params| params && params[:events]}

attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object|
begin
Expand Down Expand Up @@ -89,15 +89,15 @@ class DoiSerializer
object.landing_page
end

attribute :citations, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
attribute :citations, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
doi_citations(object.uid)
end

attribute :views, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
doi_views(object.uid)
end
# attribute :views, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
# doi_views(object.uid)
# end

attribute :downloads, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
doi_downloads(object.uid)
end
# attribute :downloads, if: Proc.new { |object, params| params && params[:mix_in] == "metrics" } do |object|
# doi_downloads(object.uid)
# end
end
4 changes: 2 additions & 2 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
expect(json.dig('data', 0, 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 0, 'attributes', 'titles')).to eq(doi.titles)
expect(json.dig('data',0,'attributes','citations')).to eq(3)
expect(json.dig('data',0,'attributes','views')).to be > 0
expect(json.dig('data',0,'attributes','downloads')).to eq(0)
# expect(json.dig('data',0,'attributes','views')).to be > 0
# expect(json.dig('data',0,'attributes','downloads')).to eq(0)
end
end
end
Expand Down

0 comments on commit 538eda4

Please sign in to comment.