Class: Dor::Workflow::Client::WorkflowRoutes
- Inherits:
-
Object
- Object
- Dor::Workflow::Client::WorkflowRoutes
- Extended by:
- Deprecation
- Defined in:
- lib/dor/workflow/client/workflow_routes.rb
Overview
Makes requests relating to a workflow
Instance Method Summary collapse
-
#all_workflows(pid:) ⇒ Workflow::Response::Workflows
Retrieves all workflows for the given object.
-
#all_workflows_xml(druid) ⇒ String
Retrieves the raw XML for all the workflows for the the given object.
-
#create_workflow(_repo, druid, workflow_name, _wf_xml, opts = {}) ⇒ Boolean
This method is deprecated and calls create_workflow_by_name.
-
#create_workflow_by_name(druid, workflow_name, opts = {}) ⇒ Boolean
Creates a workflow for a given object in the repository.
-
#delete_all_workflows(pid:) ⇒ Boolean
Deletes all workflow steps for a particular druid.
-
#delete_workflow(repo, druid, workflow) ⇒ Boolean
Deletes a workflow from a particular repository and druid.
-
#initialize(requestor:) ⇒ WorkflowRoutes
constructor
A new instance of WorkflowRoutes.
-
#update_error_status(druid:, workflow:, process:, error_msg:, error_text: nil) ⇒ Workflow::Response::Update
Updates the status of one step in a workflow to error.
-
#update_status(druid:, workflow:, process:, status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil) ⇒ Boolean
Updates the status of one step in a workflow.
-
#update_workflow_error_status(_repo, druid, workflow, process, error_msg, opts = {}) ⇒ Boolean
Updates the status of one step in a workflow to error.
-
#update_workflow_status(repo, druid, workflow, process, status, opts = {}) ⇒ Boolean
Updates the status of one step in a workflow.
- #workflow(repo: 'dor', pid:, workflow_name:) ⇒ Workflow::Response::Workflow
-
#workflow_status(repo, druid, workflow, process) ⇒ String
Retrieves the process status of the given workflow for the given object identifier.
-
#workflow_xml(repo, druid, workflow) ⇒ String
Retrieves the raw XML for the given workflow.
-
#workflows(pid, repo = 'dor') ⇒ Array<String>
Get workflow names into an array for given PID This method only works when this gem is used in a project that is configured to connect to DOR.
Constructor Details
#initialize(requestor:) ⇒ WorkflowRoutes
10 11 12 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 10 def initialize(requestor:) @requestor = requestor end |
Instance Method Details
#all_workflows(pid:) ⇒ Workflow::Response::Workflows
Retrieves all workflows for the given object
202 203 204 205 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 202 def all_workflows(pid:) xml = all_workflows_xml(pid) Workflow::Response::Workflows.new(xml: xml) end |
#all_workflows_xml(druid) ⇒ String
Retrieves the raw XML for all the workflows for the the given object
195 196 197 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 195 def all_workflows_xml(druid) requestor.request "objects/#{druid}/workflows" end |
#create_workflow(_repo, druid, workflow_name, _wf_xml, opts = {}) ⇒ Boolean
This method is deprecated and calls create_workflow_by_name.
24 25 26 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 24 def create_workflow(_repo, druid, workflow_name, _wf_xml, opts = {}) create_workflow_by_name(druid, workflow_name, opts) end |
#create_workflow_by_name(druid, workflow_name, opts = {}) ⇒ Boolean
Creates a workflow for a given object in the repository. If this particular workflow for this objects exists, it will replace the old workflow. You have the option of creating a datastream or not. Returns true on success. Caller must handle any exceptions.
name that is known by the workflow service.
41 42 43 44 45 46 47 48 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 41 def create_workflow_by_name(druid, workflow_name, opts = {}) params = { 'lane-id' => opts.fetch(:lane_id, 'default') } params['version'] = opts[:version] if opts[:version] requestor.request "objects/#{druid}/workflows/#{workflow_name}", 'post', '', content_type: 'application/xml', params: params true end |
#delete_all_workflows(pid:) ⇒ Boolean
Deletes all workflow steps for a particular druid
243 244 245 246 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 243 def delete_all_workflows(pid:) requestor.request "objects/#{pid}/workflows", 'delete' true end |
#delete_workflow(repo, druid, workflow) ⇒ Boolean
Deletes a workflow from a particular repository and druid
235 236 237 238 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 235 def delete_workflow(repo, druid, workflow) requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}", 'delete' true end |
#update_error_status(druid:, workflow:, process:, error_msg:, error_text: nil) ⇒ Workflow::Response::Update
Updates the status of one step in a workflow to error. Returns true on success. Caller must handle any exceptions
Http Call
The method does an HTTP PUT to the URL defined in Dor::WF_URI.
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"error\" />"
185 186 187 188 189 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 185 def update_error_status(druid:, workflow:, process:, error_msg:, error_text: nil) xml = create_process_xml(name: process, status: 'error', errorMessage: error_msg, error_text: error_text) response = requestor.request "objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml, content_type: 'application/xml' Workflow::Response::Update.new(json: response) end |
#update_status(druid:, workflow:, process:, status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil) ⇒ Boolean
Updates the status of one step in a workflow. Returns true on success. Caller must handle any exceptions
Http Call
The method does an HTTP PUT to the URL defined in Dor::WF_URI. As an example:
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"completed\" />"
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 69 def update_status(druid:, workflow:, process:, status:, elapsed: 0, lifecycle: nil, note: nil, current_status: nil) raise ArgumentError, "Unknown status value #{status}" unless VALID_STATUS.include?(status) raise ArgumentError, "Unknown current_status value #{current_status}" if current_status && !VALID_STATUS.include?(current_status) xml = create_process_xml(name: process, status: status, elapsed: elapsed, lifecycle: lifecycle, note: note) uri = "objects/#{druid}/workflows/#{workflow}/#{process}" uri += "?current-status=#{current_status}" if current_status response = requestor.request(uri, 'put', xml, content_type: 'application/xml') Workflow::Response::Update.new(json: response) end |
#update_workflow_error_status(_repo, druid, workflow, process, error_msg, opts = {}) ⇒ Boolean
Updates the status of one step in a workflow to error. Returns true on success. Caller must handle any exceptions
Http Call
The method does an HTTP PUT to the URL defined in Dor::WF_URI.
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"error\" />"
163 164 165 166 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 163 def update_workflow_error_status(_repo, druid, workflow, process, error_msg, opts = {}) update_error_status(druid: druid, workflow: workflow, process: process, error_msg: error_msg, error_text: opts[:error_text]) true end |
#update_workflow_status(repo, druid, workflow, process, status, opts = {}) ⇒ Boolean
Updates the status of one step in a workflow. Returns true on success. Caller must handle any exceptions
Http Call
The method does an HTTP PUT to the URL defined in Dor::WF_URI. As an example:
PUT "/dor/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"completed\" />"
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 102 def update_workflow_status(repo, druid, workflow, process, status, opts = {}) raise ArgumentError, "Unknown status value #{status}" unless VALID_STATUS.include?(status.downcase) opts = { elapsed: 0, lifecycle: nil, note: nil }.merge!(opts) opts[:elapsed] = opts[:elapsed].to_s current_status = opts.delete(:current_status) xml = create_process_xml({ name: process, status: status.downcase }.merge!(opts)) uri = "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}" uri += "?current-status=#{current_status.downcase}" if current_status response = requestor.request(uri, 'put', xml, content_type: 'application/xml') Workflow::Response::Update.new(json: response) end |
#workflow(repo: 'dor', pid:, workflow_name:) ⇒ Workflow::Response::Workflow
225 226 227 228 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 225 def workflow(repo: 'dor', pid:, workflow_name:) xml = workflow_xml(repo, pid, workflow_name) Workflow::Response::Workflow.new(xml: xml) end |
#workflow_status(repo, druid, workflow, process) ⇒ String
Retrieves the process status of the given workflow for the given object identifier
123 124 125 126 127 128 129 130 131 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 123 def workflow_status(repo, druid, workflow, process) workflow_md = workflow_xml(repo, druid, workflow) doc = Nokogiri::XML(workflow_md) raise Dor::WorkflowException, "Unable to parse response:\n#{workflow_md}" if doc.root.nil? processes = doc.root.xpath("//process[@name='#{process}']") process = processes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i } process&.attr('status') end |
#workflow_xml(repo, druid, workflow) ⇒ String
Retrieves the raw XML for the given workflow
139 140 141 142 143 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 139 def workflow_xml(repo, druid, workflow) raise ArgumentError, 'missing workflow' unless workflow requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}" end |
#workflows(pid, repo = 'dor') ⇒ Array<String>
Get workflow names into an array for given PID This method only works when this gem is used in a project that is configured to connect to DOR
216 217 218 219 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 216 def workflows(pid, repo = 'dor') xml_doc = Nokogiri::XML(workflow_xml(repo, pid, '')) xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] } end |