Skip to content

Commit

Permalink
fix for handling missing filename in biomodels result #1729
Browse files Browse the repository at this point in the history
also added some more general resilience
  • Loading branch information
stuzart committed Jan 31, 2024
1 parent c695902 commit fe23d3d
Show file tree
Hide file tree
Showing 4 changed files with 1,628 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
<% end %>
</div>
<% unless resource.unreleased %>
<% unless resource.unreleased || resource.main_filename.blank? %>
<div class="col-sm-2 text-right list_item_actions">
<%
biomodel_download_link = resource.download_link
Expand Down
15 changes: 10 additions & 5 deletions lib/seek/biomodels_search/search_biomodels_adaptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def perform_search(query)

json = JSON.parse(json)
json['models'].collect do |result|
BiomodelsSearchResult.new result['id']
begin
BiomodelsSearchResult.new result['id']
rescue NoMethodError=>e
Seek::Errors::ExceptionForwarder.send_notification(exception, data: { error: 'error reading response from BioModels', item_id: result['id'], query: query })
end
end.compact.reject do |biomodels_result|
biomodels_result.title.blank?
end
Expand Down Expand Up @@ -62,14 +66,15 @@ def populate
self.publication_title = json.dig('publication', 'title')
self.authors = (json.dig('publication', 'authors') || []).collect { |author| author['name'] }
self.published_date = Time.at(json['firstPublished'] / 1000)
latest_version = json['history']['revisions'].sort { |rev| rev['version'] }.first
self.last_modification_date = Time.at(latest_version['submitted'] / 1000)
self.main_filename = json['files']['main'].first['name']
latest_version = (json.dig('history','revisions') || []).sort { |rev| rev['version'] }&.first
if latest_version&.fetch('submitted')
self.last_modification_date = Time.at(latest_version['submitted'] / 1000)
end
self.main_filename = (json.dig('files','main') || []).first&.fetch('name')
self.unreleased = false
else
self.unreleased = true
end

end
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/unit/search_biomodels_adaptor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SearchBiomodelsAdaptorTest < ActiveSupport::TestCase
assert_equal DateTime.parse('2012-12-14 14:24:40 +0000'), result.last_modification_date
assert_equal 'search/partials/test_partial', result.partial_path
assert_equal 'EBI Biomodels', result.tab
assert_equal 'BIOMD0000000429_url.xml', result.main_filename
end

end
Expand All @@ -64,5 +65,13 @@ class SearchBiomodelsAdaptorTest < ActiveSupport::TestCase
end
end

test 'search does not files' do
VCR.use_cassette('biomodels/search-2024') do
adaptor = Seek::BiomodelsSearch::SearchBiomodelsAdaptor.new('partial_path' => 'search/partials/test_partial')
results = adaptor.search('2024')
assert_equal 25, results.count
end
end


end
1,608 changes: 1,608 additions & 0 deletions test/vcr_cassettes/biomodels/search-2024.yml

Large diffs are not rendered by default.

0 comments on commit fe23d3d

Please sign in to comment.