From 8fa369148decd43b13b74cf1c4a2896d2d562ec7 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 3 Nov 2014 15:37:09 -0600 Subject: [PATCH] Get rid of the properties datastream --- spec/models/generic_file_spec.rb | 26 +----------- spec/models/properties_datastream_spec.rb | 42 ------------------- .../concerns/sufia/generic_file/metadata.rb | 26 ++++++++---- .../sufia/generic_file/proxy_deposit.rb | 19 ++++++++- .../sufia/properties_datastream_behavior.rb | 39 ----------------- .../datastreams/properties_datastream.rb | 4 -- 6 files changed, 38 insertions(+), 118 deletions(-) delete mode 100644 spec/models/properties_datastream_spec.rb delete mode 100644 sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb delete mode 100644 sufia-models/app/models/datastreams/properties_datastream.rb diff --git a/spec/models/generic_file_spec.rb b/spec/models/generic_file_spec.rb index c2277be036..f3c9eaa6ab 100644 --- a/spec/models/generic_file_spec.rb +++ b/spec/models/generic_file_spec.rb @@ -12,9 +12,6 @@ before do @transfer_to = FactoryGirl.find_or_create(:jill) end - after do - @file.destroy - end it "transfers the request" do @file.on_behalf_of = @transfer_to.user_key @@ -160,9 +157,6 @@ end describe "attributes" do - it "should have properties datastream for depositor" do - expect(subject.properties).to be_instance_of PropertiesDatastream - end it "should have apply_depositor_metadata" do expect(subject.edit_users).to eq ['jcoyne'] expect(subject.depositor).to eq 'jcoyne' @@ -189,12 +183,10 @@ end end - describe "delegations" do - it "should delegate methods to properties metadata" do + describe "metadata" do + it "should have descriptive metadata" do expect(subject).to respond_to(:relative_path) expect(subject).to respond_to(:depositor) - end - it "should delegate methods to descriptive metadata" do expect(subject).to respond_to(:related_url) expect(subject).to respond_to(:based_near) expect(subject).to respond_to(:part_of) @@ -229,10 +221,6 @@ end describe "that have been saved" do - after do - subject.delete unless subject.new_record? - end - it "should have activity stream-related methods defined" do subject.save f = subject.reload @@ -337,9 +325,6 @@ @f = GenericFile.new @f.apply_depositor_metadata('mjg36') end - after do - @f.delete - end describe "with a video", if: Sufia.config.enable_ffmpeg do before do allow(@f).to receive(mime_type: 'video/quicktime') #Would get set by the characterization job @@ -598,9 +583,6 @@ describe "file content validation" do context "when file contains a virus" do let(:f) { File.new(fixture_path + '/small_file.txt') } - after(:each) do - subject.destroy if subject.persisted? - end it "populates the errors hash during validation" do allow(Sufia::GenericFile::Actor).to receive(:virus_check).and_raise(Sufia::VirusFoundError, "A virus was found in #{f.path}: EL CRAPO VIRUS") subject.add_file(f, 'content', 'small_file.txt') @@ -651,10 +633,6 @@ file.to_solr } - after do - subject.destroy - end - context "without terms" do specify "title is nil" do expect(no_terms[title_key]).to be_nil diff --git a/spec/models/properties_datastream_spec.rb b/spec/models/properties_datastream_spec.rb deleted file mode 100644 index 9885c0f1e6..0000000000 --- a/spec/models/properties_datastream_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -describe PropertiesDatastream do - describe "import_url" do - #let(:datastream) { PropertiesDatastream.new(double('base object', uri: "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/foo", new_record?: true), 'properties') } - before do - subject.import_url = 'http://example.com/somefile.txt' - end - - it "serializes" do - expect(subject.import_url).to eq ['http://example.com/somefile.txt'] - expect(subject.ng_xml.to_xml).to be_equivalent_to "http://example.com/somefile.txt" - end - end - - describe "proxy_depositor" do - before do - subject.proxy_depositor = 'kim@example.com' - end - - it "serializes proxy_depositor" do - expect(subject.proxy_depositor).to eq ['kim@example.com'] - expect(subject.ng_xml.to_xml).to be_equivalent_to "kim@example.com" - end - end - - describe "to_solr" do - let(:doc) { - PropertiesDatastream.new(nil, 'properties').tap do |ds| - ds.import_url = 'http://example.com/somefile.txt' - ds.proxy_depositor = 'kim@example.com' - end - } - subject { doc.to_solr} - it "solrizes import_url" do - expect(subject['import_url_ssim']).to eq ['http://example.com/somefile.txt'] - end - it "solrizes proxy_depositor" do - expect(subject['proxy_depositor_ssim']).to eq ['kim@example.com'] - end - end -end diff --git a/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb b/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb index 2858ea5051..b3e827734d 100644 --- a/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +++ b/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb @@ -4,18 +4,21 @@ module Metadata extend ActiveSupport::Concern included do - contains "properties", class_name: 'PropertiesDatastream' contains "content", class_name: 'FileContentDatastream' contains "thumbnail" - has_attributes :relative_path, :import_url, datastream: :properties, multiple: false - property :label, predicate: RDF::DC.title property :depositor, predicate: RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt") do |index| index.as :symbol, :stored_searchable end + property :relative_path, predicate: RDF::URI.new('http://scholarsphere.psu.edu/ns#relativePath') + + property :import_url, predicate: RDF::URI.new('http://scholarsphere.psu.edu/ns#importUrl') do |index| + index.as :symbol + end + property :part_of, predicate: RDF::DC.isPartOf property :resource_type, predicate: RDF::DC.type do |index| index.as :stored_searchable, :facetable @@ -84,13 +87,20 @@ module Metadata puts "tables for vocabularies missing" end - # For singular-valued properties - # Hack until https://github.com/no-reply/ActiveTriples/pull/37 is merged + def depositor + super.first + end + + def relative_path + super.first + end - def depositor_with_first - depositor_without_first.first + def import_url + super.first end - alias_method_chain :depositor, :first + + # For singular-valued properties + # Hack until https://github.com/no-reply/ActiveTriples/pull/37 is merged def label_with_first label_without_first.first diff --git a/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb b/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb index b04721a2c9..bacfe7b6ce 100644 --- a/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +++ b/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb @@ -4,10 +4,27 @@ module ProxyDeposit extend ActiveSupport::Concern included do - has_attributes :proxy_depositor, :on_behalf_of, datastream: :properties, multiple: false + property :proxy_depositor, predicate: RDF::URI.new('http://scholarsphere.psu.edu/ns#proxyDepositor') do |index| + index.as :symbol + end + + # This value is set when a user indicates they are depositing this for someone else + property :on_behalf_of, predicate: RDF::URI.new('http://scholarsphere.psu.edu/ns#onBehalfOf') do |index| + index.as :symbol + end + after_create :create_transfer_request + + def proxy_depositor + super.first + end + + def on_behalf_of + super.first + end end + def create_transfer_request Sufia.queue.push(ContentDepositorChangeEventJob.new(pid, on_behalf_of)) if on_behalf_of.present? end diff --git a/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb b/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb deleted file mode 100644 index 34eb16da75..0000000000 --- a/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Sufia - module PropertiesDatastreamBehavior - extend ActiveSupport::Concern - - included do - has_many_versions - set_terminology do |t| - t.root(path: "fields") - # This is where we put the user id of the object depositor -- impacts permissions/access controls - t.depositor index_as: [:symbol, :stored_searchable] - # This is where we put the relative path of the file if submitted as a folder - t.relative_path - t.import_url path: 'importUrl', index_as: :symbol - t.proxy_depositor path: 'proxyDepositor', index_as: :symbol - # This value is set when a user indicates they are depositing this for someone else - t.on_behalf_of path: 'onBehalfOf', index_as: :symbol - end - end - - module ClassMethods - def xml_template - builder = Nokogiri::XML::Builder.new do |xml| - xml.fields - end - builder.doc - end - end - - def prefix - "" - end - end - - def save - super.tap do |passing| - create_version if passing - end - end -end diff --git a/sufia-models/app/models/datastreams/properties_datastream.rb b/sufia-models/app/models/datastreams/properties_datastream.rb deleted file mode 100644 index 144b926f0d..0000000000 --- a/sufia-models/app/models/datastreams/properties_datastream.rb +++ /dev/null @@ -1,4 +0,0 @@ -# properties datastream: catch-all for info that didn't have another home. Particularly depositor. -class PropertiesDatastream < ActiveFedora::OmDatastream - include Sufia::PropertiesDatastreamBehavior -end