Skip to content

Commit

Permalink
transaction exercise: transaction solution
Browse files Browse the repository at this point in the history
  • Loading branch information
tamsin johnson committed Oct 23, 2023
1 parent 8f16983 commit bcab2bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
11 changes: 5 additions & 6 deletions koppie/app/indexers/monograph_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ class MonographIndexer < Hyrax::ValkyrieWorkIndexer
include Hyrax::Indexer(:monograph)

# Uncomment this block if you want to add custom indexing behavior:
# def to_solr
# super.tap do |index_document|
# index_document[:my_field_tesim] = resource.my_field.map(&:to_s)
# index_document[:other_field_ssim] = resource.other_field
# end
# end
def to_solr
super.tap do |index_document|
index_document[:identifier_ssim] = Array(resource.identifier).map(&:to_s)
end
end
end
20 changes: 20 additions & 0 deletions koppie/app/transactions/mint_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class MintId
include Dry::Monads[:result]

def call(obj)
return Failure[:no_identifier_attribute] unless
obj.respond_to?(:identifier=)

return Failure[:object_not_persisted] unless
obj.try(:persisted?)

user = User.find_by_user_key(obj.depositor)

obj.identifier = "my_id_scheme:#{obj.id}"

result = Hyrax.persister.save(resource: obj)
Hyrax.publisher.publish("object.metadata.updated", object: obj, user: user)

Success(result)
end
end
23 changes: 23 additions & 0 deletions koppie/config/initializers/10_transactions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Hyrax::Transactions::Container.register('work_resource.mint_id', MintId.new)

class ApplicationContainerOverrides
extend Dry::Container::Mixin

namespace 'change_set' do |ops|
ops.register 'create_work' do
Hyrax::Transactions::WorkCreate.new(steps:
['change_set.set_default_admin_set',
'change_set.ensure_admin_set',
'change_set.set_user_as_depositor',
'change_set.apply',
'work_resource.mint_id',
'work_resource.apply_permission_template',
'work_resource.save_acl',
'work_resource.add_file_sets',
'work_resource.change_depositor',
'work_resource.add_to_parent'])
end
end
end

Hyrax::Transactions::Container.merge(ApplicationContainerOverrides)

0 comments on commit bcab2bb

Please sign in to comment.