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

Feature: Not found message by context #228

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions app/controllers/ajax_proxy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def jsonp
end

def json_class
not_found if params[:conceptid].nil? || params[:conceptid].empty?
concept_not_found if params[:conceptid].nil? || params[:conceptid].empty?
params[:ontology] ||= params[:ontologyid]

if params[:ontologyid].to_i > 0
Expand All @@ -48,18 +48,18 @@ def json_class
end

@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?

@concept = @ontology.explore.single_class({}, params[:conceptid])
not_found if @concept.nil?
concept_not_found(params[:conceptid]) if @concept.nil?

render_json @concept.to_json
end


def json_ontology
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?
simple_ontology = simplify_ontology_model(@ontology) # application_controller (cached)
render_json simple_ontology.to_json
end
Expand Down
33 changes: 23 additions & 10 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
helper_method :bp_config_json, :current_license, :using_captcha?

rescue_from ActiveRecord::RecordNotFound, with: :not_found_record
# Pull configuration parameters for REST connection.
REST_URI = $REST_URL
API_KEY = $API_KEY
Expand Down Expand Up @@ -82,13 +82,21 @@ def anonymous_user
user ||= User.new({"id" => 0})
end

def not_found
def ontology_not_found(ontology_acronym)
not_found("Ontology #{ontology_acronym} not found")
end

def concept_not_found(concept_id)
not_found("Concept #{concept_id} not found")
end

def not_found(message = '')
if request.xhr?
render plain: "Error: load failed"
render plain: message || "Error: load failed"
return
end
raise ActiveRecord::RecordNotFound.new('Not Found')

raise ActiveRecord::RecordNotFound.new(message || 'Not Found')
end

NOTIFICATION_TYPES = { :notes => "CREATE_NOTE_NOTIFICATION", :all => "ALL_NOTIFICATION" }
Expand Down Expand Up @@ -225,7 +233,7 @@ def redirect_new_api(class_view = false)
return
end
acronym = BPIDResolver.id_to_acronym(params[:ontology])
not_found unless acronym
ontology_not_found(acronym) unless acronym
if class_view
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first
concept = get_class(params).first.to_s
Expand Down Expand Up @@ -390,7 +398,7 @@ def get_class(params)
roots = @ontology.explore.roots
if roots.nil? || roots.empty?
LOG.add :debug, "Missing roots for #{@ontology.acronym}"
not_found
not_found("Missing roots for #{@ontology.acronym}")
end

@root = LinkedData::Client::Models::Class.new(read_only: true)
Expand All @@ -403,14 +411,14 @@ def get_class(params)
# Some ontologies have "too many children" at their root. These will not process and are handled here.
if @concept.nil?
LOG.add :debug, "Missing class #{root_child.links.self}"
not_found
not_found("Missing class #{root_child.links.self}")
end
else
# if the id is coming from a param, use that to get concept
@concept = @ontology.explore.single_class({full: true}, params[:conceptid])
if @concept.nil? || @concept.errors
LOG.add :debug, "Missing class #{@ontology.acronym} / #{params[:conceptid]}"
not_found
not_found("Missing class #{@ontology.acronym} / #{params[:conceptid]}")
end

# Create the tree
Expand All @@ -419,7 +427,7 @@ def get_class(params)
roots = @ontology.explore.roots
if roots.nil? || roots.empty?
LOG.add :debug, "Missing roots for #{@ontology.acronym}"
not_found
not_found("Missing roots for #{@ontology.acronym}")
end
if roots.any? {|c| c.id == @concept.id}
rootNode = roots
Expand Down Expand Up @@ -686,4 +694,9 @@ def init_trial_license
end
end

private
def not_found_record(exception)
@error_message = exception.message
render 'errors/not_found', status: 404
end
end
20 changes: 10 additions & 10 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def show
if request.xhr?
display = params[:callback].eql?('load') ? {full: true} : {display: "prefLabel"}
@concept = @ontology.explore.single_class(display, params[:id])
not_found if @concept.nil?
concept_not_found(params[:id]) if @concept.nil?
show_ajax_request # process an ajax call
else
# Get the latest 'ready' submission, or fallback to any latest submission
# TODO: change the logic here if the fallback will crash the visualization
@submission = get_ontology_submission_ready(@ontology) # application_controller

@concept = @ontology.explore.single_class({full: true}, params[:id])
not_found if @concept.nil?
concept_not_found(params[:id]) if @concept.nil?

show_uri_request # process a full call
render :file => '/ontologies/visualize', :use_full_path => true, :layout => 'ontology'
Expand All @@ -47,7 +47,7 @@ def show_label
end
@ontology = LinkedData::Client::Models::Ontology.find(ont_id)
@ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(ont_id).first
not_found unless @ontology
ontology_not_found(ont_id) unless @ontology
# Retrieve a class prefLabel or return the class ID (URI)
# - mappings may contain class URIs that are not in bioportal (e.g. obo-xrefs)
cls = @ontology.explore.single_class(cls_id)
Expand Down Expand Up @@ -79,7 +79,7 @@ def show_tree
end
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
if @ontology.nil?
not_found
ontology_not_found(params[:ontology])
else
get_class(params) # application_controller
render :partial => "ontologies/treeview"
Expand All @@ -94,14 +94,14 @@ def property_tree
return
end
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?
@root = @ontology.property_tree
render json: LinkedData::Client::Models::Property.properties_to_hash(@root.children)
end

# Renders a details pane for a given ontology/concept
def details
not_found if params[:conceptid].nil? || params[:conceptid].empty?
concept_not_found('') if params[:conceptid].nil? || params[:conceptid].empty?

if params[:ontology].to_i > 0
orig_id = params[:ontology]
Expand All @@ -112,10 +112,10 @@ def details
end

@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?

@concept = @ontology.explore.single_class({full: true}, CGI.unescape(params[:conceptid]))
not_found if @concept.nil?
concept_not_found(CGI.unescape(params[:conceptid])) if @concept.nil?

if params[:styled].eql?("true")
render :partial => "details", :layout => "partial"
Expand All @@ -126,10 +126,10 @@ def details

def biomixer
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?

@concept = @ontology.explore.single_class({full: true}, params[:conceptid])
not_found if @concept.nil?
concept_not_found(params[:conceptid]) if @concept.nil?

@immediate_load = true

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def show

# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found if @ontology.nil?
ontology_not_found(params[:ontology]) if @ontology.nil?

# Handle the case where an ontology is converted to summary only.
# See: https://github.com/ncbo/bioportal_web_ui/issues/133.
Expand Down
4 changes: 3 additions & 1 deletion app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= content_tag :div, id: "bd", style: "clear: both; text-align: center; margin-top: 100px; margin-bottom: 100px;" do -%>
<h1>The page you are looking for wasn't found. Please try again.</h1>
<h1>
<%= @error_message || "The page you are looking for wasn't found. Please try again." %>
</h1>
<% end -%>