Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for BioModels search error #1731

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 11 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,12 @@ def perform_search(query)

json = JSON.parse(json)
json['models'].collect do |result|
BiomodelsSearchResult.new result['id']
begin
BiomodelsSearchResult.new result['id']
rescue NoMethodError=>exception
Seek::Errors::ExceptionForwarder.send_notification(exception, data: { error: 'error reading response from BioModels', item_id: result['id'], query: query })
nil
end
end.compact.reject do |biomodels_result|
biomodels_result.title.blank?
end
Expand Down Expand Up @@ -62,14 +67,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.

Loading