Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
lib/hydra/derivatives/services/persist_external_file_output_file_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Hydra::Derivatives | ||
class PersistExternalFileOutputFileService < PersistOutputFileService | ||
# Persists a new file object that points to external content | ||
# @param [Hash] output information about the external derivative file | ||
# @option output [String] url the location of the external content | ||
# @param [Hash] directives directions which can be used to determine where to persist to. | ||
# @option directives [String] url This can determine the path of the object. | ||
def self.call(output, directives) | ||
external_file = ActiveFedora::File.new(directives[:url]) | ||
# TODO: Replace the following two lines with the shorter call to #external_url once active_fedora/pull/1234 is merged | ||
external_file.content = '' | ||
external_file.mime_type = "message/external-body; access-type=URL; URL=\"#{output[:url]}\"" | ||
# external_file.external_url = output[:url] | ||
external_file.original_name = URI.parse(output[:url]).path.split('/').last | ||
external_file.save | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
spec/services/persist_external_file_output_file_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe Hydra::Derivatives::PersistExternalFileOutputFileService do | ||
before do | ||
class ExternalDerivativeContainerObject < ActiveFedora::Base | ||
has_subresource "external_derivative" | ||
end | ||
end | ||
after do | ||
Object.send(:remove_const, :ExternalDerivativeContainerObject) | ||
end | ||
|
||
let(:object) { ExternalDerivativeContainerObject.create } | ||
let(:directives) { { url: "#{object.uri}/external_derivative" } } | ||
let(:external_url) { 'http://www.example.com/external/content' } | ||
let(:output) { { url: external_url } } | ||
let(:destination_name) { 'external_derivative' } | ||
|
||
describe '.call' do | ||
it "persists the external file to the specified destination on the given object" do | ||
described_class.call(output, directives) | ||
expect(object.send(destination_name.to_sym).mime_type).to eq "message/external-body;access-type=URL;url=\"http://www.example.com/external/content\"" | ||
expect(object.send(destination_name.to_sym).content).to eq '' | ||
end | ||
end | ||
end |