Skip to content

Commit

Permalink
🐛 Add conditional to .fileset_for_directives
Browse files Browse the repository at this point in the history
We are noticing that when ingesting a PDF, the
`ValkyrieCreateDerivativesJob` is failing because the file_set doesn't
get found in `ValkyriePersistDerivatives.fileset_for_directives` when
the directives[:url] is an id instead of an actual uri, see
`FileSetDerivativesService#extract_full_text`.  I'm suggesting that we
check if we have a "/" and if not we assume that it is an id so we can
just look for that.
  • Loading branch information
kirkkwang committed Feb 14, 2024
1 parent 616f3bf commit 8aa7ec6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/services/hyrax/valkyrie_persist_derivatives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ def self.call(stream,
# @return [Hyrax::FileSet]
def self.fileset_for_directives(directives)
path = URI(directives.fetch(:url)).path
id = path.sub(Hyrax.config.derivatives_path.to_s, "")
.delete('/')
.match(/^(.*)-\w*(\.\w+)*$/) { |m| m[1] }
# checks if it's a file path, else assuming it is already an id
# Hyrax::FileSetDerivativesService#extract_full_text passes in the raw uri
# and not a derivative_url like the other derivative formats
id = if path.include?("/")
path.sub(Hyrax.config.derivatives_path.to_s, "")
.delete('/')
.match(/^(.*)-\w*(\.\w+)*$/) { |m| m[1] }
else
path
end
raise "Could not extract fileset id from path #{path}" unless id

Hyrax.metadata_adapter.query_service.find_by(id: id)
Expand Down
12 changes: 12 additions & 0 deletions spec/services/hyrax/valkyrie_persist_derivatives_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,17 @@
.to raise_error(/Could not extract fileset id from path/)
end
end

context 'with an id' do
let (:directives) do
{ url: '123' }
end

it 'extracts the id' do
expect(Hyrax.metadata_adapter.query_service)
.to receive(:find_by).with(id: '123')
described_class.fileset_for_directives(directives)
end
end
end
end

0 comments on commit 8aa7ec6

Please sign in to comment.