Sha256: e4ec83a99d6e30da631841a117e2ddf3ea37532f6a2611a9c4d405341d1c8eaa

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

# Navigate from a resource to the child filesets in the resource.
module Hyrax
  module CustomQueries
    module Navigators
      class ChildFilesetsNavigator
        # Define the queries that can be fulfilled by this navigator.
        def self.queries
          [:find_child_filesets, :find_child_fileset_ids]
        end

        attr_reader :query_service

        def initialize(query_service:)
          @query_service = query_service
        end

        # Find child filesets of a given resource, and map to Valkyrie Resources
        # @param [Valkyrie::Resource]
        # @return [Array<Valkyrie::Resource>]
        # TODO: By storing all children in a single relationship, it requires that the full resource be constructed for all children
        #       and then selecting only the children of a particular type to return.
        def find_child_filesets(resource:)
          query_service.find_members(resource: resource).select(&:file_set?)
        end

        # Find the ids of child filesets of a given resource, and map to Valkyrie Resources
        # @param [Valkyrie::Resource]
        # @return [Array<Valkyrie::ID>]
        # TODO: By storing all children in a single relationship, it requires that the full resource be constructed for all children
        #       and then selecting only the children of a particular type.  If we stored works in a works relationship and filesets
        #       in a filesets relationship, then a request for IDs would return all ids from the relationship and not instantiate
        #       any resources.
        def find_child_fileset_ids(resource:)
          find_child_filesets(resource: resource).map(&:id)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyrax-3.0.0.pre.rc1 app/services/hyrax/custom_queries/navigators/child_filesets_navigator.rb
hyrax-3.0.0.pre.beta3 app/services/hyrax/custom_queries/navigators/child_filesets_navigator.rb