Sha256: 57897aaf1b40db54b2d9035d3611ca4699cb2690fdb5b0aae8f9b511682cadd4

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Workflow
    # Responsible for coordinating the behavior of an action taken within a workflow
    class WorkflowActionService
      def self.run(subject:, action:, comment: nil)
        new(subject: subject, action: action, comment: comment).run
      end

      def initialize(subject:, action:, comment:)
        @subject = subject
        @action = action
        @comment_text = comment
      end

      attr_reader :subject, :action, :comment_text

      def run
        update_sipity_workflow_state
        comment = create_sipity_comment
        handle_sipity_notifications(comment: comment)
        handle_additional_sipity_workflow_action_processing(comment: comment)
        subject.work.try(:update_index) # So that the new actions and state are written into solr.
      end

      private

      def update_sipity_workflow_state
        return true if action.resulting_workflow_state_id.blank?
        subject.entity.update!(workflow_state_id: action.resulting_workflow_state_id)
      end

      def create_sipity_comment
        return Sipity::NullComment.new(entity: subject.entity, agent: subject.agent) if
          comment_text.blank?
        Sipity::Comment.create!(entity: subject.entity, agent: subject.agent, comment: comment_text)
      end

      def handle_sipity_notifications(comment:)
        Hyrax::Workflow::NotificationService.deliver_on_action_taken(
          entity: subject.entity,
          comment: comment,
          action: action,
          user: subject.user
        )
      end

      ##
      # Run any configured custom methods
      #
      def handle_additional_sipity_workflow_action_processing(comment:)
        Hyrax::Workflow::ActionTakenService.handle_action_taken(
          target: subject.work,
          comment: comment,
          action: action,
          user: subject.user
        )
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hyrax-5.0.4 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.3 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.2 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.1 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.0 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.0.rc3 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.0.rc2 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-5.0.0.rc1 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.6.0 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0.rc3 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0.rc2 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0.rc1 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.5.0 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0.beta2 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.4.2 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-4.0.0.beta1 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.4.1 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.4.0 app/services/hyrax/workflow/workflow_action_service.rb
hyrax-3.3.0 app/services/hyrax/workflow/workflow_action_service.rb