Class: CurationConcerns::Workflow::WorkflowFactory
- Inherits:
-
Object
- Object
- CurationConcerns::Workflow::WorkflowFactory
- Defined in:
- app/services/curation_concerns/workflow/workflow_factory.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#create ⇒ TrueClass
Creates a Sipity::Entity for the work.
-
#find_deposit_action ⇒ Object
Find an action that has no starting state.
-
#initialize(work, attributes, user, strategy) ⇒ WorkflowFactory
constructor
A new instance of WorkflowFactory.
-
#workflow ⇒ Sipity::Workflow
This tells us which workflow to use.
Constructor Details
#initialize(work, attributes, user, strategy) ⇒ WorkflowFactory
Returns a new instance of WorkflowFactory.
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
#user ⇒ Object (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
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
#create ⇒ TrueClass
Creates a Sipity::Entity for the work. The Sipity::Entity acts as a proxy to a work within a workflow
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_action ⇒ Object
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 |
#workflow ⇒ Sipity::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.
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 |