Class: Sipity::Workflow

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sipity/workflow.rb

Overview

A named workflow for processing an entity. Originally I had thought of calling this a Type, but once I extracted the Processing submodule, type felt to much of a noun, not conveying potentiality. Workflow conveys “things will happen” because of this.

Constant Summary collapse

DEFAULT_INITIAL_WORKFLOW_STATE =
'new'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activate!(permission_template:, workflow_id: nil, workflow_name: nil) ⇒ TrueClass

Within the given permission_template scope:

* Deactivate the current active workflow (if one exists)
* Activate the specified workflow_id

Parameters:

  • permission_template (Hyrax::PermissionTemplate)

    The scope for activation of the workflow id

  • workflow_id (Integer) (defaults to: nil)

    The workflow_id within the given permission_template that should be activated

  • workflow_name (String) (defaults to: nil)

    The name of the workflow within the given permission template that should be activated

Returns:

  • (TrueClass)

Raises:

  • (ActiveRecord::RecordNotFound)

    When we have a mismatch on permission template and workflow id

  • (RuntimeError)

    When you don’t specify a workflow_id or workflow_name



49
50
51
52
53
54
55
56
# File 'app/models/sipity/workflow.rb', line 49

def self.activate!(permission_template:, workflow_id: nil, workflow_name: nil)
  raise "You must specify a workflow_id or workflow_name to activate!" if workflow_id.blank? && workflow_name.blank?
  finder_attributes = { permission_template: permission_template, id: workflow_id, name: workflow_name }.compact
  Sipity::Workflow.find_by!(finder_attributes).tap do |workflow|
    Sipity::Workflow.where(permission_template: permission_template, active: true).update(active: nil)
    workflow.update!(active: true)
  end
end

.find_active_workflow_for(admin_set_id:) ⇒ Sipity::Workflow

Returns that is active for the given administrative set`.

Parameters:

  • admin_set_id (#to_s)

    the admin set to which we will scope our query.

Returns:

Raises:

  • (ActiveRecord::RecordNotFound)

    when we don’t have an active admin set for the given administrative set’s ID



27
28
29
30
31
32
33
34
35
# File 'app/models/sipity/workflow.rb', line 27

def self.find_active_workflow_for(admin_set_id:)
  templates = Hyrax::PermissionTemplate.arel_table
  workflows = Sipity::Workflow.arel_table
  Sipity::Workflow.where(active: true).where(
    workflows[:permission_template_id].in(
      templates.project(templates[:id]).where(templates[:admin_set_id].eq(admin_set_id))
    )
  ).first!
end

Instance Method Details

#initial_workflow_stateObject



19
20
21
# File 'app/models/sipity/workflow.rb', line 19

def initial_workflow_state
  workflow_states.find_or_create_by!(name: DEFAULT_INITIAL_WORKFLOW_STATE)
end

#update_responsibilities(role:, agents:) ⇒ Object

Grant a workflow responsibility to a set of agents and remove it from any agents who currently have the workflow responsibility, but are not in the provided list

Parameters:



63
64
65
66
# File 'app/models/sipity/workflow.rb', line 63

def update_responsibilities(role:, agents:)
  add_workflow_responsibilities(role, agents)
  remove_workflow_responsibilities(role, agents)
end