Sha256: 1201821dbecbe7f279fa41cfdb182f0eeaf39cdd7e0f9456be8c9766d8f77d9a

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module CurationConcerns
  module Actors
    class AddToWorkActor < AbstractActor
      def create(attributes)
        work_ids = attributes.delete(:in_works_ids)
        next_actor.create(attributes) && add_to_works(work_ids)
      end

      def update(attributes)
        work_ids = attributes.delete(:in_works_ids)
        add_to_works(work_ids) && next_actor.update(attributes)
      end

      private

        def add_to_works(new_work_ids)
          return true unless new_work_ids.present?
          (curation_concern.in_works_ids - new_work_ids).each do |old_id|
            work = ::ActiveFedora::Base.find(old_id)
            work.ordered_members.delete(curation_concern)
            work.members.delete(curation_concern)
            work.save
          end

          # add to new
          (new_work_ids - curation_concern.in_works_ids).each do |work_id|
            work = ::ActiveFedora::Base.find(work_id)
            work.ordered_members << curation_concern
            work.save
          end
          true
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curation_concerns-1.0.0.beta9 app/actors/curation_concerns/actors/add_to_work_actor.rb
curation_concerns-1.0.0.beta8 app/actors/curation_concerns/actors/add_to_work_actor.rb
curation_concerns-1.0.0.beta7 app/actors/curation_concerns/actors/add_to_work_actor.rb