Skip to content

Commit

Permalink
Merge pull request #1227 from samvera/full_text_utf8
Browse files Browse the repository at this point in the history
Update dependencies which saves and retreives charset
  • Loading branch information
mjgiarlo authored Jun 16, 2017
2 parents 1e446ce + cabb295 commit 65f99fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ class PersistDirectlyContainedOutputFileService < Hydra::Derivatives::PersistBas
# This method conforms to the signature of the .call method on Hydra::Derivatives::PersistOutputFileService
# * Persists the file within the DirectContainer specified by :container
#
# @param [String] the data to be persisted
# @param [Hash] directives directions which can be used to determine where to persist to.
# @param content [String] the data to be persisted
# @param directives [Hash] directions which can be used to determine where to persist to.
# @option directives [String] url URI for the parent object.
# @option directives [String] container Name of the container association.
def self.call(string, directives)
file = Hydra::Derivatives::IoDecorator.new(string, new_mime_type(directives.fetch(:format)))
o_name = determine_original_name(file)
m_type = determine_mime_type(file)
uri = URI(directives.fetch(:url))
raise ArgumentError, "#{uri} is not an http(s) uri" unless uri.is_a?(URI::HTTP)
file_set = ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri.to_s))
remote_file = file_set.send("build_#{directives.fetch(:container)}".to_sym)
def self.call(content, directives)
file = io(content, directives)
file_set = retrieve_file_set(directives)
remote_file = retrieve_remote_file(file_set, directives)
remote_file.content = file
remote_file.mime_type = m_type
remote_file.original_name = o_name
remote_file.mime_type = determine_mime_type(file)
remote_file.original_name = determine_original_name(file)
file_set.save
end

# @param directives [Hash] directions which can be used to determine where to persist to.
# @option directives [String] url URI for the parent object.
def self.retrieve_file_set(directives)
uri = URI(directives.fetch(:url))
raise ArgumentError, "#{uri} is not an http(s) uri" unless uri.is_a?(URI::HTTP)
ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri.to_s))
end
private_class_method :retrieve_file_set

# Override this implementation if you need a remote file from a different location
# @param file_set [FileSet] the container of the remote file
# @param directives [Hash] directions which can be used to determine where to persist to
# @option directives [String] container Name of the container association.
# @return [ActiveFedora::File]
def self.retrieve_remote_file(file_set, directives)
file_set.send("build_#{directives.fetch(:container)}".to_sym)
end
private_class_method :retrieve_remote_file
end
end
3 changes: 2 additions & 1 deletion hyrax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ EOF
spec.add_dependency 'hydra-head', '>= 10.5.0'
spec.add_dependency 'hydra-editor', '~> 3.3'
spec.add_dependency 'hydra-works', '~> 0.16'
spec.add_dependency 'hydra-derivatives', '~> 3.3'
spec.add_dependency 'browse-everything', '>= 0.10.5'
spec.add_dependency 'blacklight', '~> 6.9'
spec.add_dependency 'blacklight-gallery', '~> 0.7'
Expand Down Expand Up @@ -69,7 +70,7 @@ EOF
spec.add_dependency 'dry-struct', '~> 0.1'
spec.add_dependency 'redlock', '>= 0.1.2'
spec.add_dependency 'retriable', '>= 2.9', '< 4.0'
spec.add_dependency 'active-fedora', '>= 11.1.3'
spec.add_dependency 'active-fedora', '>= 11.3.1'
spec.add_dependency 'linkeddata' # Required for getting values from geonames

spec.add_development_dependency 'engine_cart', '~> 1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
RSpec.describe Hyrax::PersistDirectlyContainedOutputFileService do
# PersistDirectlyContainedOutputFileService is used by FullTextExtract.output_file_service
let(:object) { FileSet.create! { |fs| fs.apply_depositor_metadata('justin') } }
let(:stream) { "fake file content" }
let(:file_set) { FileSet.create! { |fs| fs.apply_depositor_metadata('justin') } }
let(:content) { "fake file content" }
subject(:call) do
described_class.call(stream,
described_class.call(content,
format: 'txt',
url: object.uri,
url: file_set.uri,
container: 'extracted_text')
end
let(:resource) { file_set.reload.extracted_text }

it "persists the file to the specified destination on the given object" do
expect(call).to be true
expect(object.reload.extracted_text.content).to eq("fake file content")
expect(resource.content).to eq("fake file content")
expect(resource.content.encoding).to eq(Encoding::UTF_8)
end
end

0 comments on commit 65f99fb

Please sign in to comment.