Skip to content

Commit

Permalink
some final tidying up, in particualr removed the fetch ols as JSON se…
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Dec 13, 2023
1 parent f4a24ae commit 5fcca0c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 102 deletions.
26 changes: 0 additions & 26 deletions app/assets/javascripts/controlled_vocabs.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,6 @@ CVTerms = {
handleOntologyTermsHTMLResponse: function (html) {
$j('#add-term-button-row').before(html);
},
// processes the JSON response when fetching terms, and populates the term list
handleOntologyTermsJSONResponse: function (json) {
let index=0
$j.each(json, function (key, term) {
//make a new term
let newTerm = $j('#new-term-row tbody').clone().html();

newTerm = newTerm.replace(/--index--/g, index);
$j('#add-term-button-row').before($j(newTerm));

let row = $j('table#new-terms tr.sample-cv-term').last();

let inputs = $j(row).find('td input');
$j(inputs).prop('readonly',true);

//inputs 0,1,2 are label, iri, and parent_iri

$j(inputs[0]).val(term.label);
$j(inputs[1]).val(term.iri);
$j(inputs[2]).val(term.parent_iri);

index++;
});
},
// adds a new blank row to the terms list
addNewTermRow: function () {
let newTerm = $j('#new-term-row tbody').clone().html();
Expand All @@ -130,8 +106,6 @@ CVTerms = {
},
// reports the error when the ajax method to fetch the terms is unsuccessful
reportFetchError: function (error_message) {
// let json = JSON.parse(response);
// const error_message = json.errors[0].details;
$j('div#fetch-error-message').text("An error occurred fetching the terms: " + error_message);
$j('div#fetch-error-message').show();
},
Expand Down
25 changes: 0 additions & 25 deletions app/controllers/sample_controlled_vocabs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,6 @@ def destroy
end
end

def fetch_ols_terms
error_msg = nil
begin
source_ontology = params[:source_ontology_id]
root_uri = params[:root_uri]

raise 'No root URI provided' if root_uri.blank?

client = Ebi::OlsClient.new
terms = client.all_descendants(source_ontology, root_uri)
terms.reject! { |t| t[:iri] == root_uri } unless params[:include_root_term] == '1'
error_msg = "There are no descendant terms to populate the list." unless terms.present?
rescue StandardError => e
error_msg = e.message
end

respond_to do |format|
if error_msg
format.json { render json: { errors: [{ details: error_msg }] }, status: :unprocessable_entity }
else
format.json { render json: terms.to_json }
end
end
end

def fetch_ols_terms_html
error_msg = nil
begin
Expand Down
1 change: 0 additions & 1 deletion app/views/sample_controlled_vocabs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

<div class="form-group">
<label>Ontology</label>
<%#= f.select :source_ontology, Ebi::OlsClient.ontology_choices, { include_blank: 'No Ontology' }, class: 'form-control' -%>
<%= select_cv_source_ontology(@sample_controlled_vocab) %>
<br/>

Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@
resources :sample_controlled_vocabs do
collection do
get :typeahead
get :fetch_ols_terms
get :fetch_ols_terms_html
end
end
Expand Down
50 changes: 1 addition & 49 deletions test/functional/sample_controlled_vocabs_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'test_helper'

class SampleControlledVocabsControllerTest < ActionController::TestCase

include AuthenticatedTestHelper

test 'show' do
Expand Down Expand Up @@ -267,55 +268,6 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase
end
end

test 'fetch ols terms as JSON with root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
get :fetch_ols_terms, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/GO_0090395',
include_root_term: '1' }, format: :json

assert_response :success
res = JSON.parse(response.body)
assert_equal 4, res.length
iris = res.map { |term| term['iri'] }
assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090395'
assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090396'
assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090397'
end
end

test 'fetch ols terms as JSON without root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
get :fetch_ols_terms, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/GO_0090395' }, format: :json

assert_response :success
res = JSON.parse(response.body)
assert_equal 3, res.length
iris = res.map { |term| term['iri'] }
refute_includes iris, 'http://purl.obolibrary.org/obo/GO_0090395'
assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090396'
assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090397'
end
end

test 'fetch ols terms as JSON with wrong URI' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_bad_term') do
get :fetch_ols_terms, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/banana',
include_root_term: '1' }, format: :json

assert_response :unprocessable_entity
res = JSON.parse(response.body)
assert_equal '404 Not Found', res.dig('errors', 0, 'details')
end
end

test 'fetch ols terms as HTML with wrong URI' do
person = FactoryBot.create(:person)
login_as(person)
Expand Down

0 comments on commit 5fcca0c

Please sign in to comment.