From 4efb5582a759b2e811c234448ade32d7b39d6de6 Mon Sep 17 00:00:00 2001 From: Syphax Date: Wed, 30 Oct 2024 18:32:43 +0100 Subject: [PATCH] implement submission class children function --- lib/ontologies_linked_data/models/class.rb | 7 ++-- .../models/ontology_submission.rb | 36 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/ontologies_linked_data/models/class.rb b/lib/ontologies_linked_data/models/class.rb index fc796470..87431a36 100644 --- a/lib/ontologies_linked_data/models/class.rb +++ b/lib/ontologies_linked_data/models/class.rb @@ -468,10 +468,9 @@ def hasChildren() - def load_has_children() - if !instance_variable_get("@intlHasChildren").nil? - return - end + def load_has_children + return @intlHasChildren unless instance_variable_get("@intlHasChildren").nil? + graphs = [self.submission.id.to_s] query = has_children_query(self.id.to_s,graphs.first) has_c = false diff --git a/lib/ontologies_linked_data/models/ontology_submission.rb b/lib/ontologies_linked_data/models/ontology_submission.rb index 0c916acb..31bcbdd8 100644 --- a/lib/ontologies_linked_data/models/ontology_submission.rb +++ b/lib/ontologies_linked_data/models/ontology_submission.rb @@ -23,7 +23,7 @@ class OntologySubmission < LinkedData::Models::Base FLAT_ROOTS_LIMIT = 1000 model :ontology_submission, scheme: File.join(__dir__, '../../../config/schemes/ontology_submission.yml'), - name_with: ->(s) { submission_id_generator(s) } + name_with: ->(s) { submission_id_generator(s) } attribute :submissionId, type: :integer, enforce: [:existence] @@ -124,7 +124,7 @@ class OntologySubmission < LinkedData::Models::Base attribute :openSearchDescription, namespace: :void, type: :uri, default: -> (s) { open_search_default(s) } attribute :source, namespace: :dct, type: :list attribute :endpoint, namespace: :sd, type: %i[uri list], - default: ->(s) { default_sparql_endpoint(s) } + default: ->(s) { default_sparql_endpoint(s) } attribute :includedInDataCatalog, namespace: :schema, type: %i[list uri] # Relations @@ -741,6 +741,38 @@ def roots(extra_include = [], page = nil, pagesize = nil, concept_schemes: [], c classes end + def children(cls, includes_param: [], concept_schemes: [], concept_collections: [], page: 1, size: 50) + ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param) + unmapped = ld.delete(:properties) + + ld += LinkedData::Models::Class.concept_is_in_attributes if skos? + + page_data_query = LinkedData::Models::Class.where(parents: cls).in(self).include(ld) + aggregates = LinkedData::Models::Class.goo_aggregates_to_load(ld) + page_data_query.aggregate(*aggregates) unless aggregates.empty? + page_data = page_data_query.page(page, size).all + LinkedData::Models::Class.in(self).models(page_data).include(:unmapped).all if unmapped + + page_data.delete_if { |x| x.id.to_s == cls.id.to_s } + if ld.include?(:hasChildren) || ld.include?(:isInActiveScheme) || ld.include?(:isInActiveCollection) + page_data.each do |c| + c.load_computed_attributes(to_load: ld, + options: { schemes: concept_schemes, collections: concept_collections }) + end + end + + unless concept_schemes.empty? + page_data.delete_if { |c| Array(c.isInActiveScheme).empty? && !c.load_has_children } + if (page_data.size < size) && page_data.next_page + page_data += children(cls, includes_param: includes_param, concept_schemes: concept_schemes, + concept_collections: concept_collections, + page: page_data.next_page, size: size) + end + end + + page_data + end + def skos? self.bring :hasOntologyLanguage if bring? :hasOntologyLanguage self.hasOntologyLanguage&.skos?