Skip to content

Commit

Permalink
WIP - try to import filesets with valkyrie resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Mar 11, 2024
1 parent 1afc94f commit 4ab31b6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def self.solr_name(field_name)
ActiveFedora.index_field_mapper.solr_name(field_name)
end
end

def self.ordered_file_sets_for(object)
object&.ordered_members.to_a.select(&:file_set?)
end
# @!endgroup Class Method Interface
##

Expand Down
34 changes: 29 additions & 5 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def self.schema_properties(klass)
@schema_properties_map[klass_key]
end

def self.ordered_file_sets_for(object)
return [] if object.blank?

Hyrax.custom_queries.find_child_file_sets(resource: object)
end

def run!
run
return object if object.persisted?
Expand Down Expand Up @@ -101,7 +107,7 @@ def create_work(object:, attrs:)
transactions["work_resource.create_with_bulk_behavior"]
.with_step_args(
"work_resource.add_to_parent" => { parent_id: attrs[related_parents_parsed_mapping], user: @user },
"work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user },
"work_resource.add_bulkrax_files" => { files: get_files(attrs) }, #get_s3_files(remote_files: attrs["remote_files"]), user: @user },
"change_set.set_user_as_depositor" => { user: @user },
"work_resource.change_depositor" => { user: @user },
'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
Expand Down Expand Up @@ -142,7 +148,7 @@ def update_work(object:, attrs:)
perform_transaction_for(object: object, attrs: attrs) do
transactions["work_resource.update_with_bulk_behavior"]
.with_step_args(
"work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attrs["remote_files"]), user: @user },
"work_resource.add_bulkrax_files" => { files: get_files(attrs) }, # get_s3_files(remote_files: attrs["remote_files"]), user: @user }
'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
)
end
Expand Down Expand Up @@ -172,7 +178,8 @@ def perform_transaction_for(object:, attrs:)

transaction = yield

result = transaction.call(form)
# result = transaction.call(form)
result = transaction.call(form, files: @files, user: @user)

result.value_or do
msg = result.failure[0].to_s
Expand All @@ -181,6 +188,23 @@ def perform_transaction_for(object:, attrs:)
end
end

def get_files(attrs)
get_local_files(attrs) #+ get_s3_files(remote_files: attrs["remote_files"])
end

def get_local_files(attrs)
# byebug # what properties will we get here?
# {:title=>["valkyrie resource 3"], :admin_set_id=>"admin_set/default", :contributor=>[], :creator=>["jg"], :description=>[], :identifier=>[], :keyword=>["bulk test"], :publisher=>[], :language=>[], :license=>[], :resource_type=>["Image"], :rights_statement=>[""], :source=>["6"], :subject=>[], :uploaded_files=>[40], :alternate_ids=>["6"]}
# Hyrax::UploadedFile.find'40'
return [] if attrs[:uploaded_files].blank?

@files = attrs[:uploaded_files].map do |file_id|
Hyrax::UploadedFile.find(file_id)
end

@files
end

def get_s3_files(remote_files: {})
if remote_files.blank?
Hyrax.logger.info "No remote files listed for #{attributes['source_identifier']}"
Expand Down Expand Up @@ -231,9 +255,9 @@ def new_remote_files
def conditionally_destroy_existing_files
return unless @replace_files

if [Hyrax::PcdmCollection, Hyrax::FileSet].include?(klass)
if [Hyrax::PcdmCollection, Hyrax::FileSet, Bulkrax::ValkyrieObjectFactory].include?(klass)
return
elsif klass.ancestors.include?(Valkyrie::Resource)
elsif klass.ancestors.include?(Valkyrie::Resource) && klass != CollectionResource
destroy_existing_files
else
raise "Unexpected #{klass} for #{self.class}##{__method__}"
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/bulkrax/file_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def local_file_sets
end

def ordered_file_sets
# Bulkrax.object_factory.ordered_file_sets_for
# OVERRIDE Hyrda-works 1.2.0 - this method was deprecated in v1.0
object&.ordered_members.to_a.select(&:file_set?)
Bulkrax.object_factory.ordered_file_sets_for(object)
end

def import_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def initialize(query_service:)
@query_service = query_service
end

def find_by_source_identifier(identifier:, use_valkyrie: true)
# TODO: Make more dynamic. Not all application use bulkrax_identifier
# Fetch the app's source_identifier and search by that instead
af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first
def find_by_source_identifier(work_identifier:, source_identifier_value:, use_valkyrie: Hyrax.config.use_valkyrie?)
work_identifier_key = Bulkrax.object_factory.solr_name(work_identifier)
af_object = ActiveFedora::Base.where("#{work_identifier_key}:#{source_identifier_value}").first

return af_object unless use_valkyrie

Expand Down

0 comments on commit 4ab31b6

Please sign in to comment.