Skip to content

Commit

Permalink
fix contributor indexing, cascade deletes on asssetresource, physical…
Browse files Browse the repository at this point in the history
…_instantiation and digial_instantiation
  • Loading branch information
orangewolf committed Dec 13, 2023
1 parent 9af0b9b commit 43ca74a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GIT

GIT
remote: https://github.com/samvera/hyrax.git
revision: 9ef64090a13abdeaabfaabdee851829093d02cc4
revision: 0108fed6c83dd4a449b37cc1a6c19787ec54921d
branch: double_combo
specs:
hyrax (5.0.0.rc2)
Expand Down
3 changes: 1 addition & 2 deletions app/models/ams/create_member_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def create_child_methods
condition = { has_model_ssim: child_class.to_s, id: self.members.map(&:id) }
ActiveFedora::Base.search_with_conditions(condition).collect { |v| SolrDocument.new(v) }
when Valkyrie::Resource
child_works = Hyrax.custom_queries.find_child_works(resource: self).to_a
child_works_of_type = child_works.select { |work| work.is_a?(child_class) }
child_works_of_type = members.select { |work| work.is_a?(child_class) }
child_works_of_type.map { |work| resource_to_solr(work) }
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ def contributor_role
self[solr_name('contributor_role')]
end

def contributor
self[solr_name('contributor')]
end

def portrayal
self[solr_name('portrayal')]
end
Expand Down
15 changes: 15 additions & 0 deletions app/services/listeners/cascade_delete_listener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Listeners
class CascadeDeleteListener

def on_object_deleted(event)
resource = event.to_h.fetch(:object) { Hyrax.query_service.find_by(id: event[:object_id]) }
return unless resource.is_a?(AssetResource) || resource.is_a?(PhysicalInstantiationResource) || resource.is_a?(DigitalInstantiationResource)
resource.members.each do |member|
Hyrax.index_adapter.delete(resource: member)
Hyrax.persister.delete(resource: member)
end
end
end
end
2 changes: 1 addition & 1 deletion app/transactions/ams/steps/handle_contributors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_or_update_contributions(change_set, contributions)

def update_members(change_set, inserts, destroys)
return if inserts.empty? && destroys.empty?
current_member_ids = change_set.member_ids.map(&:id)
current_member_ids = change_set.member_ids.map(&:to_s)
inserts = inserts - current_member_ids
destroys = destroys & current_member_ids
change_set.member_ids += inserts.map { |id| Valkyrie::ID.new(id) }
Expand Down
1 change: 1 addition & 0 deletions config/initializers/listeners.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Hyrax.publisher.subscribe(Listeners::ValidateAapbListener.new)
Hyrax.publisher.subscribe(Listeners::CascadeDeleteListener.new)
2 changes: 2 additions & 0 deletions config/metadata/basic_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ attributes:
multiple: true
form:
primary: false
index_keys:
- "contributor_tesim"
creator:
type: string
multiple: true
Expand Down
2 changes: 1 addition & 1 deletion ops/alpha-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extraEnvVars: &envVars
value: string

worker:
replicaCount: 1
replicaCount: 0
importReplicaCount: 0
podSecurityContext:
runAsUser: 1001
Expand Down

0 comments on commit 43ca74a

Please sign in to comment.