Skip to content

Commit

Permalink
fix missing roots message for nil classes
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Apr 29, 2024
1 parent 7ce5d10 commit fe6fd32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,20 @@ def get_class(params)
# get the top level nodes for the root
# TODO_REV: Support views? Replace old view call: @ontology.top_level_classes(view)
@roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if @roots.nil? || @roots.empty?

if @roots.nil? || response_error?(@roots) || @roots.compact&.empty?
LOG.add :debug, t('application.missing_roots_for_ontology', acronym: @ontology.acronym)
classes = @ontology.explore.classes.collection
@concept = classes.first.explore.self(full: true) if classes.first
@concept = classes.first.explore.self(full: true) if classes&.first
return
end

@root = LinkedData::Client::Models::Class.new(read_only: true)
@root.children = @roots.sort{|x,y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}
@root.children = @roots.sort{|x,y| (x&.prefLabel || "").downcase <=> (y&.prefLabel || "").downcase}

# get the initial concept to display
root_child = @root.children&.first
not_found(t('application.missing_roots', id: @roots.id)) if root_child.nil?
not_found(t('application.missing_roots')) if root_child.nil?

@concept = root_child.explore.self(full: true, lang: lang)
# Some ontologies have "too many children" at their root. These will not process and are handled here.
Expand All @@ -445,7 +446,7 @@ def get_class(params)
rootNode = @concept.explore.tree(include: include, concept_schemes: params[:concept_schemes], lang: lang)
if rootNode.nil? || rootNode.empty?
@roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if @roots.nil? || @roots.empty?
if @roots.nil? || response_error?(@roots) || @roots.compact&.empty?
LOG.add :debug, t('application.missing_roots_for_ontology', acronym: @ontology.acronym)
@concept = @ontology.explore.classes.collection.first.explore.self(full: true)
return
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ en:
provide_ontology_or_concept: Please provide an ontology id or concept id with an ontology id.
search_for_class: Please search for a class using the Jump To field above
missing_roots_for_ontology: Missing @roots for %{acronym}
missing_roots: Missing roots %{id}
missing_roots: Missing roots
missing_class: Missing class %{root_child}
missing_class_ontology: Missing class %{acronym} / %{concept_id}
error_simplify_class: "Failure to simplify class: %{cls}"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fr:
provide_ontology_or_concept: Veuillez fournir un identifiant d'ontologie ou un identifiant de concept avec un identifiant d'ontologie.
search_for_class: Veuillez rechercher une classe à l'aide du champ Jump To ci-dessus
missing_roots_for_ontology: Racines manquantes pour %{acronym}
missing_roots: Racines manquantes %{id}
missing_roots: Racines manquantes
missing_class: Classe manquante %{root_child}
missing_class_ontology: Classe manquante %{acronym} / %{concept_id}
error_simplify_class: "Échec de la simplification de la classe : %{cls}"
Expand Down

0 comments on commit fe6fd32

Please sign in to comment.