Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Deprecate methods that are not used anymore #401

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/dor/models/concerns/contentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Dor
module Contentable
extend ActiveSupport::Concern
extend Deprecation
self.deprecation_horizon = 'dor-services version 7.0.0'

# add a file to a resource, not to be confused with add a resource to an object
def add_file(file, resource, file_name, mime_type = nil, publish = 'no', shelve = 'no', preserve = 'no')
Expand Down Expand Up @@ -41,6 +43,7 @@ def add_file(file, resource, file_name, mime_type = nil, publish = 'no', shelve
end
# can only arrive at this point if a non status exception occurred.
end
deprecation_deprecate add_file: 'Add file will be removed and will not be replaced'

def replace_file(file, file_name)
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
Expand All @@ -63,6 +66,7 @@ def replace_file(file, file_name)
item.contentMetadata.update_file(file_hash, file_name)
end
end
deprecation_deprecate replace_file: 'will be removed without replacement'

def get_preserved_file(file, version)
Sdr::Client.get_preserved_file_content(pid, file, version)
Expand Down Expand Up @@ -98,6 +102,7 @@ def remove_file(filename)
end
contentMetadata.remove_file filename
end
deprecation_deprecate remove_file: 'will be removed without replacement'

# @param [String] old_name
# @param [String] new_name
Expand All @@ -113,6 +118,7 @@ def rename_file(old_name, new_name)
end
contentMetadata.rename_file(old_name, new_name)
end
deprecation_deprecate rename_file: 'will be removed without replacement'

# @param [String] resource_name ID of the resource elememnt
def remove_resource(resource_name)
Expand All @@ -123,7 +129,9 @@ def remove_resource(resource_name)
# remove the resource record from the metadata and renumber the resource sequence
contentMetadata.remove_resource resource_name
end
deprecation_deprecate remove_resource: 'will be removed without replacement'

# TODO: Move to Argo
# list files in the workspace
# @return [Array] workspace files
def list_files
Expand Down Expand Up @@ -155,7 +163,9 @@ def is_file_in_workspace?(filename)
druid_obj = DruidTools::Druid.new(pid, Dor::Config.stacks.local_workspace_root)
!druid_obj.find_content(filename).nil?
end
deprecation_deprecate is_file_in_workspace?: 'will be removed without replacement'

# TODO: move to MergeService
# Appends contentMetadata file resources from the source objects to this object
# @param [Array<String>] source_obj_pids ids of the secondary objects that will get their contentMetadata merged into this one
def copy_file_resources(source_obj_pids)
Expand Down Expand Up @@ -202,6 +212,7 @@ def copy_file_resources(source_obj_pids)
end
end

# TODO: move to MergeService
def new_secondary_file_name(old_name, sequence_num)
old_name =~ /^(.*)\.(.*)$/ ? "#{$1}_#{sequence_num}.#{$2}" : "#{old_name}_#{sequence_num}"
end
Expand All @@ -224,6 +235,7 @@ def decommission(tag)
add_tag "Decommissioned : #{tag}"
end

# TODO: Move to Dor-Utils.
# Adds a RELS-EXT constituent relationship to the given druid
# @param [String] druid the parent druid of the constituent relationship
# e.g.: <fedora:isConstituentOf rdf:resource="info:fedora/druid:hj097bm8879" />
Expand Down
24 changes: 23 additions & 1 deletion spec/models/concerns/contentable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def internal_uri
@file = File.new(File.expand_path(file_path))
end
describe 'add_file' do
before do
expect(Deprecation).to receive(:warn)
end
it 'should generate the md5, find the size, attempt to sftp, and call the metadata update' do
@item.add_file(@file, '0001', 'ab123cd4567_descMetadata.xml')
xml = @item.contentMetadata.ng_xml
Expand Down Expand Up @@ -108,6 +111,10 @@ def internal_uri
end

describe 'replace_file' do
before do
expect(Deprecation).to receive(:warn)
end

it 'should update the md5, sha1, and size for the file, and attempt to ftp it to the workspace' do
@item.replace_file(@file, 'ab123cd4567_00_0001.tif')
xml = @item.contentMetadata.ng_xml
Expand All @@ -123,10 +130,12 @@ def internal_uri
end
end
end

it 'should raise an exception if there isnt a matching file record in the metadata' do
expect{ @item.replace_file(@file, 'abcdab123cd4567_00_0001.tif') }.to raise_error(StandardError)
end
end

describe 'get_preserved_file' do
let(:filename) { 'old_file' }
let(:item_version) { 2 }
Expand All @@ -145,24 +154,37 @@ def internal_uri
expect(Digest::MD5.hexdigest(data)).to eq('55251c7b93b3fbab83354f28e267f42f')
end
end

describe 'rename_file' do
before do
expect(Deprecation).to receive(:warn)
end

it 'should attempt to rename the file in the workspace and update the metadata' do
expect(@sftp).to receive(:rename!)
@item.rename_file('ab123cd4567_05_0001.jp2', 'test.jp2')
end
end

describe 'remove_file' do
before do
expect(Deprecation).to receive(:warn)
end

it 'should use sftp to remove the file and update the metadata' do
expect(@sftp).to receive(:remove!)
@item.remove_file('ab123cd4567_05_0001.jp2')
end
end

describe 'is_file_in_workspace?' do
before :each do
before do
expect(Deprecation).to receive(:warn)
@mock_filename = 'fake_file'
@mock_druid_obj = double(DruidTools::Druid)
expect(DruidTools::Druid).to receive(:new).and_return(@mock_druid_obj)
end

it 'should return true if the file is in the workspace for the object' do
expect(@mock_druid_obj).to receive(:find_content).with(@mock_filename).and_return('this is not nil')
expect(@item.is_file_in_workspace?(@mock_filename)).to be_truthy
Expand Down