diff --git a/app/models/doi.rb b/app/models/doi.rb index 8b89ce446..9b8da254a 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -72,24 +72,24 @@ 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 :view_events, -> { where target_relation_type_id: "views" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - has_many :download_events, -> { where target_relation_type_id: "downloads" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - has_many :reference_events, -> { where source_relation_type_id: "references" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy - has_many :citation_events, -> { where target_relation_type_id: "citations" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - has_many :part_events, -> { where source_relation_type_id: "parts" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy - has_many :part_of_events, -> { where target_relation_type_id: "part_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - has_many :version_events, -> { where source_relation_type_id: "versions" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy - has_many :version_of_events, -> { where target_relation_type_id: "version_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :view_events, -> { where target_relation_type_id: "views" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :download_events, -> { where target_relation_type_id: "downloads" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :reference_events, -> { where source_relation_type_id: "references" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy + # has_many :citation_events, -> { where target_relation_type_id: "citations" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :part_events, -> { where source_relation_type_id: "parts" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy + # has_many :part_of_events, -> { where target_relation_type_id: "part_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :version_events, -> { where source_relation_type_id: "versions" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy + # has_many :version_of_events, -> { where target_relation_type_id: "version_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy has_many :activities, foreign_key: :auditable_id, dependent: :destroy - has_many :source_events, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy - has_many :target_events, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy + # has_many :source_events, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy + # has_many :target_events, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - has_many :references, class_name: "Doi", through: :reference_events, source: :doi_for_target - has_many :citations, class_name: "Doi", through: :citation_events, source: :doi_for_source - has_many :parts, class_name: "Doi", through: :part_events, source: :doi_for_target - has_many :part_of, class_name: "Doi", through: :part_of_events, source: :doi_for_source - has_many :versions, class_name: "Doi", through: :version_events, source: :doi_for_target - has_many :version_of, class_name: "Doi", through: :version_of_events, source: :doi_for_source + # has_many :references, class_name: "Doi", through: :reference_events, source: :doi_for_target + # has_many :citations, class_name: "Doi", through: :citation_events, source: :doi_for_source + # has_many :parts, class_name: "Doi", through: :part_events, source: :doi_for_target + # has_many :part_of, class_name: "Doi", through: :part_of_events, source: :doi_for_source + # has_many :versions, class_name: "Doi", through: :version_events, source: :doi_for_target + # has_many :version_of, class_name: "Doi", through: :version_of_events, source: :doi_for_source delegate :provider, to: :client, allow_nil: true delegate :consortium_id, to: :provider, allow_nil: true @@ -420,28 +420,28 @@ class Doi < ActiveRecord::Base consortium_organizations: { type: :object }, } indexes :resource_type, type: :object - indexes :view_count, type: :integer - indexes :download_count, type: :integer - indexes :reference_count, type: :integer - indexes :citation_count, type: :integer - indexes :part_count, type: :integer - indexes :part_of_count, type: :integer - indexes :version_count, type: :integer - indexes :version_of_count, type: :integer - indexes :views_over_time, type: :object - indexes :downloads_over_time, type: :object - indexes :reference_ids, type: :keyword - indexes :citation_ids, type: :keyword - indexes :part_ids, type: :keyword - indexes :part_of_ids, type: :keyword - indexes :version_ids, type: :keyword - indexes :version_of_ids, type: :keyword - indexes :references, type: :object - indexes :citations, type: :object - indexes :parts, type: :object - indexes :part_of, type: :object - indexes :versions, type: :object - indexes :version_of, type: :object + # indexes :view_count, type: :integer + # indexes :download_count, type: :integer + # indexes :reference_count, type: :integer + # indexes :citation_count, type: :integer + # indexes :part_count, type: :integer + # indexes :part_of_count, type: :integer + # indexes :version_count, type: :integer + # indexes :version_of_count, type: :integer + # indexes :views_over_time, type: :object + # indexes :downloads_over_time, type: :object + # indexes :reference_ids, type: :keyword + # indexes :citation_ids, type: :keyword + # indexes :part_ids, type: :keyword + # indexes :part_of_ids, type: :keyword + # indexes :version_ids, type: :keyword + # indexes :version_of_ids, type: :keyword + # indexes :references, type: :object + # indexes :citations, type: :object + # indexes :parts, type: :object + # indexes :part_of, type: :object + # indexes :versions, type: :object + # indexes :version_of, type: :object end end @@ -463,22 +463,22 @@ def as_indexed_json(options={}) "consortium_id" => consortium_id, "resource_type_id" => resource_type_id, "media_ids" => media_ids, - "view_count" => view_count, - "views_over_time" => views_over_time, - "download_count" => download_count, - "downloads_over_time" => downloads_over_time, - "reference_ids" => reference_ids, - "reference_count" => reference_count, - "citation_ids" => citation_ids, - "citation_count" => citation_count, - "part_ids" => part_ids, - "part_count" => part_count, - "part_of_ids" => part_of_ids, - "part_of_count" => part_of_count, - "version_ids" => version_ids, - "version_count" => version_count, - "version_of_ids" => version_of_ids, - "version_of_count" => version_of_count, + # "view_count" => view_count, + # "views_over_time" => views_over_time, + # "download_count" => download_count, + # "downloads_over_time" => downloads_over_time, + # "reference_ids" => reference_ids, + # "reference_count" => reference_count, + # "citation_ids" => citation_ids, + # "citation_count" => citation_count, + # "part_ids" => part_ids, + # "part_count" => part_count, + # "part_of_ids" => part_of_ids, + # "part_of_count" => part_of_count, + # "version_ids" => version_ids, + # "version_count" => version_count, + # "version_of_ids" => version_of_ids, + # "version_of_count" => version_of_count, "prefix" => prefix, "suffix" => suffix, "types" => types, @@ -514,12 +514,12 @@ 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) }, - "references" => references, - "citations" => citations, - "parts" => parts, - "part_of" => part_of, - "versions" => versions, - "version_of" => version_of, + # "references" => references, + # "citations" => citations, + # "parts" => parts, + # "part_of" => part_of, + # "versions" => versions, + # "version_of" => version_of, } end @@ -995,73 +995,73 @@ def media_ids media.pluck(:id).map { |m| Base32::URL.encode(m, split: 4, length: 16) }.compact end - def view_count - view_events.pluck(:total).inject(:+).to_i - end + # def view_count + # view_events.pluck(:total).inject(:+).to_i + # end - def views_over_time - view_events.pluck(:occurred_at, :total) - .map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } } - .sort_by { |h| h[:year_month] } - end + # def views_over_time + # view_events.pluck(:occurred_at, :total) + # .map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } } + # .sort_by { |h| h[:year_month] } + # end - def download_count - download_events.pluck(:total).inject(:+).to_i - end + # def download_count + # download_events.pluck(:total).inject(:+).to_i + # end - def downloads_over_time - download_events.pluck(:occurred_at, :total) - .map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } } - .sort_by { |h| h[:year_month] } - end + # def downloads_over_time + # download_events.pluck(:occurred_at, :total) + # .map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } } + # .sort_by { |h| h[:year_month] } + # end - def reference_ids - references.pluck(:uuid) - end + # def reference_ids + # references.pluck(:uuid) + # end - def reference_count - references.size - end + # def reference_count + # references.size + # end - def citation_ids - citations.pluck(:uuid) - end + # def citation_ids + # citations.pluck(:uuid) + # end - def citation_count - citations.size - end + # def citation_count + # citations.size + # end - def part_ids - parts.pluck(:uuid) - end + # def part_ids + # parts.pluck(:uuid) + # end - def part_count - parts.size - end + # def part_count + # parts.size + # end - def part_of_ids - part_of.pluck(:uuid) - end + # def part_of_ids + # part_of.pluck(:uuid) + # end - def part_of_count - part_of.size - end + # def part_of_count + # part_of.size + # end - def version_ids - versions.pluck(:uuid) - end + # def version_ids + # versions.pluck(:uuid) + # end - def version_count - versions.size - end + # def version_count + # versions.size + # end - def version_of_ids - version_of.pluck(:uuid) - end + # def version_of_ids + # version_of.pluck(:uuid) + # end - def version_of_count - version_of.size - end + # def version_of_count + # version_of.size + # end def xml_encoded Base64.strict_encode64(xml) if xml.present? diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index 5ab95f423..994b3d7cc 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -550,15 +550,15 @@ sleep 1 end - it "has views" do - expect(doi.view_events.count).to eq(3) - expect(doi.view_count).to eq(75) - expect(doi.views_over_time.first).to eq("total"=>25, "yearMonth"=>"2015-06") - - view = doi.view_events.first - expect(view.target_doi).to eq(doi.uid) - expect(view.total).to eq(25) - end + # it "has views" do + # expect(doi.view_events.count).to eq(3) + # expect(doi.view_count).to eq(75) + # expect(doi.views_over_time.first).to eq("total"=>25, "yearMonth"=>"2015-06") + + # view = doi.view_events.first + # expect(view.target_doi).to eq(doi.uid) + # expect(view.total).to eq(25) + # end end describe "downloads", elasticsearch: true do @@ -571,15 +571,15 @@ sleep 1 end - it "has downloads" do - expect(doi.download_events.count).to eq(3) - expect(doi.download_count).to eq(30) - expect(doi.downloads_over_time.first).to eq("total"=>10, "yearMonth"=>"2015-06") + # it "has downloads" do + # expect(doi.download_events.count).to eq(3) + # expect(doi.download_count).to eq(30) + # expect(doi.downloads_over_time.first).to eq("total"=>10, "yearMonth"=>"2015-06") - download = doi.download_events.first - expect(download.target_doi).to eq(doi.uid) - expect(download.total).to eq(10) - end + # download = doi.download_events.first + # expect(download.target_doi).to eq(doi.uid) + # expect(download.total).to eq(10) + # end end describe "references", elasticsearch: true do @@ -593,14 +593,14 @@ sleep 1 end - it "has references" do - expect(doi.references.count).to eq(1) - expect(doi.reference_ids.count).to eq(1) - expect(doi.reference_count).to eq(1) + # it "has references" do + # expect(doi.references.count).to eq(1) + # expect(doi.reference_ids.count).to eq(1) + # expect(doi.reference_count).to eq(1) - reference = doi.references.first - expect(reference.doi.downcase).to eq(target_doi.uid) - end + # reference = doi.references.first + # expect(reference.doi.downcase).to eq(target_doi.uid) + # end end describe "citations", elasticsearch: true do @@ -614,14 +614,14 @@ sleep 1 end - it "has citations" do - expect(doi.citations.count).to eq(1) - expect(doi.citation_ids.count).to eq(1) - expect(doi.citation_count).to eq(1) + # it "has citations" do + # expect(doi.citations.count).to eq(1) + # expect(doi.citation_ids.count).to eq(1) + # expect(doi.citation_count).to eq(1) - citation = doi.citations.first - expect(citation.doi.downcase).to eq(source_doi.uid) - end + # citation = doi.citations.first + # expect(citation.doi.downcase).to eq(source_doi.uid) + # end end describe "parts", elasticsearch: true do @@ -635,14 +635,14 @@ sleep 1 end - it "has parts" do - expect(doi.parts.count).to eq(1) - expect(doi.part_ids.count).to eq(1) - expect(doi.part_count).to eq(1) + # it "has parts" do + # expect(doi.parts.count).to eq(1) + # expect(doi.part_ids.count).to eq(1) + # expect(doi.part_count).to eq(1) - part = doi.parts.first - expect(part.doi.downcase).to eq(target_doi.uid) - end + # part = doi.parts.first + # expect(part.doi.downcase).to eq(target_doi.uid) + # end end describe "part of", elasticsearch: true do @@ -656,14 +656,14 @@ sleep 1 end - it "has part of" do - expect(doi.part_of.count).to eq(1) - expect(doi.part_of_ids.count).to eq(1) - expect(doi.part_of_count).to eq(1) + # it "has part of" do + # expect(doi.part_of.count).to eq(1) + # expect(doi.part_of_ids.count).to eq(1) + # expect(doi.part_of_count).to eq(1) - part_of = doi.part_of.first - expect(part_of.doi.downcase).to eq(source_doi.uid) - end + # part_of = doi.part_of.first + # expect(part_of.doi.downcase).to eq(source_doi.uid) + # end end describe "versions", elasticsearch: true do @@ -677,14 +677,14 @@ sleep 1 end - it "has versions" do - expect(doi.versions.count).to eq(1) - expect(doi.version_ids.count).to eq(1) - expect(doi.version_count).to eq(1) + # it "has versions" do + # expect(doi.versions.count).to eq(1) + # expect(doi.version_ids.count).to eq(1) + # expect(doi.version_count).to eq(1) - version = doi.versions.first - expect(version.doi.downcase).to eq(target_doi.uid) - end + # version = doi.versions.first + # expect(version.doi.downcase).to eq(target_doi.uid) + # end end describe "version of", elasticsearch: true do @@ -698,14 +698,14 @@ sleep 1 end - it "has version of" do - expect(doi.version_of.count).to eq(1) - expect(doi.version_of_ids.count).to eq(1) - expect(doi.version_of_count).to eq(1) + # it "has version of" do + # expect(doi.version_of.count).to eq(1) + # expect(doi.version_of_ids.count).to eq(1) + # expect(doi.version_of_count).to eq(1) - version_of = doi.version_of.first - expect(version_of.doi.downcase).to eq(source_doi.uid) - end + # version_of = doi.version_of.first + # expect(version_of.doi.downcase).to eq(source_doi.uid) + # end end describe "convert_affiliations" do diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index e7db5ef74..4fba58860 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -223,7 +223,7 @@ expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'name')).to eq(client.name) - expect(json.dig('meta', 'downloads')).to eq([{"count"=>30, "id"=>"2011", "title"=>"2011"}]) + # expect(json.dig('meta', 'downloads')).to eq([{"count"=>30, "id"=>"2011", "title"=>"2011"}]) end end