diff --git a/controllers/classes_controller.rb b/controllers/classes_controller.rb index c8e55bf8..d792c172 100644 --- a/controllers/classes_controller.rb +++ b/controllers/classes_controller.rb @@ -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) diff --git a/helpers/classes_helper.rb b/helpers/classes_helper.rb index fa6c48cf..c8fb8099 100644 --- a/helpers/classes_helper.rb +++ b/helpers/classes_helper.rb @@ -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 @@ -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 diff --git a/test/controllers/test_schemes_controller.rb b/test/controllers/test_schemes_controller.rb index ebabc42f..874e131b 100644 --- a/test/controllers/test_schemes_controller.rb +++ b/test/controllers/test_schemes_controller.rb @@ -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