Module: Hyrax::Collections::NestedCollectionQueryService
- Defined in:
- app/services/hyrax/collections/nested_collection_query_service.rb
Overview
A query service handling nested collection queries.
Class Method Summary collapse
-
.available_child_collections(parent:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>
What possible collections can be nested within the given parent collection?.
-
.available_parent_collections(child:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>
What possible collections can the given child be nested within?.
-
.parent_and_child_can_nest?(parent:, child:, scope:) ⇒ Boolean
Is it valid to nest the given child within the given parent?.
-
.parent_collections(child:, scope:, page: 1) ⇒ Blacklight::Solr::Response
What collections is the given child nested within?.
Class Method Details
.available_child_collections(parent:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>
What possible collections can be nested within the given parent collection?
16 17 18 19 20 |
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 16 def self.available_child_collections(parent:, scope:, limit_to_id: nil) return [] unless nestable?(collection: parent) return [] unless scope.can?(:deposit, parent) query_solr(collection: parent, access: :read, scope: scope, limit_to_id: limit_to_id, nest_direction: :as_child).documents end |
.available_parent_collections(child:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>
What possible collections can the given child be nested within?
34 35 36 37 38 |
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 34 def self.available_parent_collections(child:, scope:, limit_to_id: nil) return [] unless nestable?(collection: child) return [] unless scope.can?(:read, child) query_solr(collection: child, access: :deposit, scope: scope, limit_to_id: limit_to_id, nest_direction: :as_parent).documents end |
.parent_and_child_can_nest?(parent:, child:, scope:) ⇒ Boolean
Consider expanding from same collection type to a lookup table that says “This collection type can have within it, these collection types”
There is a short-circuit of logic; To be robust, we should ensure that the child and parent are in the corresponding available collections
Is it valid to nest the given child within the given parent?
97 98 99 100 101 102 103 |
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 97 def self.parent_and_child_can_nest?(parent:, child:, scope:) return false if parent == child # Short-circuit return false unless parent.collection_type_gid == child.collection_type_gid return false if available_parent_collections(child: child, scope: scope, limit_to_id: parent.id.to_s).none? return false if available_child_collections(parent: parent, scope: scope, limit_to_id: child.id.to_s).none? true end |
.parent_collections(child:, scope:, page: 1) ⇒ Blacklight::Solr::Response
What collections is the given child nested within?
51 52 53 54 55 |
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 51 def self.parent_collections(child:, scope:, page: 1) return [] unless nestable?(collection: child) query_builder = Hyrax::NestedCollectionsParentSearchBuilder.new(scope: scope, child: child, page: page) scope.blacklight_config.repository.search(query_builder.query) end |