Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I161 import collection resources #933

Merged
merged 16 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ class ObjectFactory # rubocop:disable Metrics/ClassLength
##
# @!group Class Method Interface

##
# @note This does not save either object. We need to do that in another
# loop. Why? Because we might be adding many items to the parent.
def self.add_child_to_parent_work(parent:, child:)
return true if parent.ordered_members.to_a.include?(child_record)

parent.ordered_members << child
end

def self.add_resource_to_collection(collection:, resource:, user:)
collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX) if
defined?(Hyrax::Adapters::NestingIndexAdapter)
resource.member_of_collections << collection
save!(resource: resource, user: user)
end

def self.update_index_for_file_sets_of(resource:)
resource.file_sets.each(&:update_index) if resource.respond_to?(:file_sets)
end

##
# @see Bulkrax::ObjectFactoryInterface
def self.export_properties
Expand All @@ -28,6 +48,10 @@ def self.find(id)
raise ObjectFactoryInterface::ObjectNotFoundError, e.message
end

def self.publish(**)
return true
end

##
# @param value [String]
# @param klass [Class, #where]
Expand Down Expand Up @@ -93,9 +117,17 @@ def self.solr_name(field_name)
end
end

def self.ordered_file_sets_for(object)
object&.ordered_members.to_a.select(&:file_set?)
end

def self.save!(resource:, **)
resource.save!
end

def self.update_index(resources: [])
Array(resources).each(&:update_index)
end
# @!endgroup Class Method Interface
##

Expand Down
52 changes: 40 additions & 12 deletions app/factories/bulkrax/object_factory_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ class RecordInvalid < ActiveRecord::RecordInvalid
end

class_methods do
##
# @note This does not save either object. We need to do that in another
# loop. Why? Because we might be adding many items to the parent.
def add_child_to_parent_work(parent:, child:)
raise NotImplementedError, "#{self}.#{__method__}"
end

def add_resource_to_collection(collection:, resource:, user:)
raise NotImplementedError, "#{self}.#{__method__}"
end

##
# @yield when Rails application is running in test environment.
def clean!
return true unless Rails.env.test?
yield
end

##
# @param resource [Object] something that *might* have file_sets members.
def update_index_for_file_sets_of(resource:)
raise NotImplementedError, "#{self}.#{__method__}"
end

##
# @return [Array<String>]
def export_properties
raise NotImplementedError, "#{self}.#{__method__}"
end

##
# @see ActiveFedora::Base.find
def find(id)
Expand All @@ -36,32 +66,30 @@ def find_or_nil(id)
nil
end

##
# @return [Array<String>]
def export_properties
def publish(event:, **kwargs)
raise NotImplementedError, "#{self}.#{__method__}"
end

def solr_name(field_name)
def query(q, **kwargs)
raise NotImplementedError, "#{self}.#{__method__}"
end

# @yield when Rails application is running in test environment.
def clean!
return true unless Rails.env.test?
yield
def save!(resource:, user:)
raise NotImplementedError, "#{self}.#{__method__}"
end

def query(q, **kwargs)
# rubocop:disable Metrics/ParameterLists
def search_by_property(value:, klass:, field: nil, search_field: nil, name_field: nil, verify_property: false)
raise NotImplementedError, "#{self}.#{__method__}"
end

def save!(resource:, user:)
def solr_name(field_name)
raise NotImplementedError, "#{self}.#{__method__}"
end

# rubocop:disable Metrics/ParameterLists
def search_by_property(value:, klass:, field: nil, search_field: nil, name_field: nil, verify_property: false)
##
# @param resources [Array<Object>]
def update_index(resources: [])
raise NotImplementedError, "#{self}.#{__method__}"
end
# rubocop:enable Metrics/ParameterLists
Expand Down
Loading
Loading