Class: CurationConcerns::Workflow::WorkflowFactory

Inherits:
Object
  • Object
show all
Defined in:
app/services/curation_concerns/workflow/workflow_factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, attributes, user, strategy) ⇒ WorkflowFactory

Returns a new instance of WorkflowFactory.

Parameters:

  • work (#to_global_id)
  • attributes (Hash)
  • strategy (#name)

    strategy for finding which workflow to use



19
20
21
22
23
24
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 19

def initialize(work, attributes, user, strategy)
  @work = work
  @attributes = attributes
  @user = user
  @strategy = strategy
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



26
27
28
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 26

def user
  @user
end

Class Method Details

.create(work, attributes, user, strategy = nil) ⇒ TrueClass

Parameters:

  • work (#to_global_id)
  • attributes (Hash)
  • strategy (#name) (defaults to: nil)

    strategy for finding which workflow to use. Defaults to an instance of DefaultWorkflowStrategy

Returns:

  • (TrueClass)


11
12
13
14
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 11

def self.create(work, attributes, user, strategy = nil)
  strategy ||= workflow_strategy.new(work, attributes)
  new(work, attributes, user, strategy).create
end

Instance Method Details

#createTrueClass

Creates a Sipity::Entity for the work. The Sipity::Entity acts as a proxy to a work within a workflow

Returns:

  • (TrueClass)


32
33
34
35
36
37
38
39
40
41
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 32

def create
  Sipity::Entity.create!(proxy_for_global_id: work.to_global_id.to_s,
                         workflow: workflow,
                         workflow_state: nil)

  subject = WorkflowActionInfo.new(work, user)
  Workflow::WorkflowActionService.run(subject: subject,
                                      action: find_deposit_action)
  true
end

#find_deposit_actionObject

Find an action that has no starting state. This is the deposit action. # @return [Sipity::WorkflowAction]



56
57
58
59
60
61
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 56

def find_deposit_action
  actions_that_lead_to_states = Sipity::WorkflowStateAction.all.pluck(:workflow_action_id)
  relation = Sipity::WorkflowAction.where(workflow: workflow)
  relation = relation.where('id NOT IN (?)', actions_that_lead_to_states) if actions_that_lead_to_states.any?
  relation.first!
end

#workflowSipity::Workflow

This tells us which workflow to use. If no workflow is found with the expected name then load the workflows in config/workflows/*.json and try again.

Returns:



46
47
48
49
50
# File 'app/services/curation_concerns/workflow/workflow_factory.rb', line 46

def workflow
  @workflow ||= Sipity::Workflow.find_by(name: workflow_name) ||
                (CurationConcerns::Workflow::WorkflowImporter.load_workflows &&
                 Sipity::Workflow.find_by!(name: workflow_name))
end