Skip to content

Commit

Permalink
Merge branch 'development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 6, 2023
2 parents 04607f7 + 4aeb619 commit 7e7df65
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ group :test do
gem 'simplecov', require: false
gem 'simplecov-cobertura' # for codecov.io
gem 'webmock'
end
end
6 changes: 0 additions & 6 deletions controllers/classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,7 @@ def includes_param_check
end
end

def concept_schemes
params["concept_schemes"]&.split(',') || []
end

def concept_collections
params["concept_collections"]&.split(',') || []
end

def request_display(attrs)

Expand Down
41 changes: 26 additions & 15 deletions helpers/classes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,19 @@ def get_class(submission, load_attrs=nil)
load_children = load_attrs.delete :children
load_has_children = load_attrs.delete :hasChildren

if !load_children
unless load_children
load_children = load_attrs.select { |x| x.instance_of?(Hash) && x.include?(:children) }

if load_children.length == 0
load_children = nil
end
if !load_children.nil?
load_attrs = load_attrs.select { |x| !(x.instance_of?(Hash) && x.include?(:children)) }
end
load_children = nil if load_children.length == 0
load_attrs = load_attrs.select { |x| !(x.instance_of?(Hash) && x.include?(:children)) } unless load_children.nil?
end


cls_uri = notation_to_class_uri(submission)

if cls_uri.nil?
cls_uri = RDF::URI.new(params[:cls])

if !cls_uri.valid?
unless cls_uri.valid?
error 400, "The input class id '#{params[:cls]}' is not a valid IRI"
end
end
Expand All @@ -62,23 +58,38 @@ def get_class(submission, load_attrs=nil)
error 404,
"Resource '#{params[:cls]}' not found in ontology #{submission.ontology.acronym} submission #{submission.submissionId}"
end
unless load_has_children.nil?
cls.load_has_children
end

if !load_children.nil?

extra_include = []

extra_include << :hasChildren if load_has_children
extra_include << :isInActiveScheme if load_attrs.include?(:inScheme)
extra_include << :isInActiveCollection if load_attrs.include?(:memberOf)

cls.load_computed_attributes(to_load: extra_include ,
options: {schemes: concept_schemes, collections: concept_collections})


unless load_children.nil?
LinkedData::Models::Class.partially_load_children(
[cls],500,cls.submission)
[cls], 500, cls.submission)
unless load_has_children.nil?
cls.children.each do |c|
c.load_has_children
end
end
end
return cls
cls
end

end
def concept_schemes
params["concept_schemes"]&.split(',') || []
end

def concept_collections
params["concept_collections"]&.split(',') || []
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/controllers/test_annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,16 @@ def test_default_properties_output
assert last_response.ok?
annotations = MultiJson.load(last_response.body)
assert_equal 9, annotations.length
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].downcase <=> b["annotatedClass"]["prefLabel"].downcase }
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].first.downcase <=> b["annotatedClass"]["prefLabel"].first.downcase }
assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first["annotatedClass"]["@id"]
assert_equal "Aggregate Human Data", annotations.first["annotatedClass"]["prefLabel"]
assert_equal "Aggregate Human Data", Array(annotations.first["annotatedClass"]["prefLabel"]).first

params = {text: text, include: "prefLabel,definition"}
get "/annotator", params
assert last_response.ok?
annotations = MultiJson.load(last_response.body)
assert_equal 9, annotations.length
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].downcase <=> b["annotatedClass"]["prefLabel"].downcase }
annotations.sort! { |a,b| Array(a["annotatedClass"]["prefLabel"]).first.downcase <=> Array(b["annotatedClass"]["prefLabel"]).first.downcase }
assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first["annotatedClass"]["@id"]
assert_equal ["A resource that provides data from clinical care that comprises combined data from multiple individual human subjects."], annotations.first["annotatedClass"]["definition"]
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/test_mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def mappings_with_display
get "/ontologies/#{ontology}/mappings?pagesize=#{pagesize}&page=#{page}&display=prefLabel"
assert last_response.ok?
mappings = MultiJson.load(last_response.body)
assert mappings["collection"].all? { |m| m["classes"].all? { |c| c["prefLabel"].is_a?(String) && c["prefLabel"].length > 0 } }
assert mappings["collection"].all? { |m| m["classes"].all? { |c| c["prefLabel"].first.is_a?(String) && c["prefLabel"].first.length > 0 } }

def_count = 0
next_page = 1
Expand Down
17 changes: 17 additions & 0 deletions test/controllers/test_schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ def test_calls_not_found
assert_equal 404, last_response.status
end


def test_class_tree
ont = Ontology.find('INRAETHES-0').include(:acronym).first
sub = ont.latest_submission
sub.bring_remaining
sub.uri = RDF::URI.new('http://opendata.inrae.fr/thesaurusINRAE/domainesINRAE')
sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first
sub.save

cls = 'http://opendata.inrae.fr/thesaurusINRAE/d_6'
get "ontologies/INRAETHES-0/classes/#{CGI.escape(cls)}/tree"

classes = MultiJson.load(last_response.body)

refute_nil classes.select{|x| x['@id'].eql?(cls)}.first['isInActiveScheme']
refute_nil classes.select{|x| x['@id'].eql?(cls)}.first['isInActiveCollection']
end
end

0 comments on commit 7e7df65

Please sign in to comment.