Skip to content

Commit

Permalink
Fix: isInActiveScheme attribute in the class/tree endpoint (#50)
Browse files Browse the repository at this point in the history
* add class tree test with scheme and collection filters

* make the class tree endpoit load isInActiveScheme and isInActiveCollection for the select class
  • Loading branch information
syphax-bouazzouni authored Oct 17, 2023
1 parent 1b4c7eb commit dd803c0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
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) && params[:concept_schemes]
extra_include << :isInActiveCollection if load_attrs.include?(:memberOf) && params[:concept_collections]

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
18 changes: 18 additions & 0 deletions test/controllers/test_schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ 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
concept_schemes = ["http://opendata.inrae.fr/thesaurusINRAE/domainesINRAE"]
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?concept_schemes=#{concept_schemes.join(',')}&concept_collections=#{concept_schemes.join(',')}"

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 dd803c0

Please sign in to comment.