Skip to content

Commit

Permalink
Merge 8955b01 into 1d37b3d
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed Apr 21, 2017
2 parents 1d37b3d + 8955b01 commit 4656d35
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/hydra/derivatives.rb
Expand Up @@ -36,9 +36,9 @@ module Derivatives
autoload :RemoteSourceFile
autoload :PersistOutputFileService
autoload :PersistBasicContainedOutputFileService
autoload :PersistExternalFileOutputFileService
autoload :TempfileService
autoload :MimeTypeService
autoload :NullOutputFileService
end

# Raised if the timout elapses
Expand Down
4 changes: 3 additions & 1 deletion lib/hydra/derivatives/processors/active_encode.rb
Expand Up @@ -18,7 +18,9 @@ class ActiveEncode < Processor
def process
encode = ::ActiveEncode::Base.create(source_path, directives)
timeout ? wait_for_encode_with_timeout(encode) : wait_for_encode(encode)
# TODO: call output_file_service with the output url
encode.output.each do |output|
output_file_service.call(output, directives)
end
end

def wait_for_encode_with_timeout(encode)
Expand Down
2 changes: 1 addition & 1 deletion lib/hydra/derivatives/runners/active_encode_derivatives.rb
Expand Up @@ -20,7 +20,7 @@ def self.source_file_service

# Use the output service configured for this class or default to the null output service
def self.output_file_service
@output_file_service || NullOutputFileService
@output_file_service || PersistExternalFileOutputService
end

def self.processor_class
Expand Down
7 changes: 0 additions & 7 deletions lib/hydra/derivatives/services/null_output_file_service.rb

This file was deleted.

@@ -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 spec/services/persist_external_file_output_file_service_spec.rb
@@ -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

0 comments on commit 4656d35

Please sign in to comment.