Class: Dor::Workflow::Client::WorkflowRoutes
- Inherits:
-
Object
- Object
- Dor::Workflow::Client::WorkflowRoutes
- 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_by_name(druid, workflow_name, version:, lane_id: 'default') ⇒ 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(druid:, workflow:, version:) ⇒ Boolean
Deletes a workflow from a particular repository and druid.
-
#initialize(requestor:) ⇒ WorkflowRoutes
constructor
A new instance of WorkflowRoutes.
- #process(pid:, workflow_name:, process:) ⇒ Workflow::Response::Process
-
#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.
- #workflow(pid:, workflow_name:) ⇒ Workflow::Response::Workflow
-
#workflow_status(druid:, workflow:, process:) ⇒ String
Retrieves the process status of the given workflow for the given object identifier.
-
#workflows(pid) ⇒ 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
Returns a new instance of WorkflowRoutes.
8 9 10 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 8 def initialize(requestor:) @requestor = requestor end |
Instance Method Details
#all_workflows(pid:) ⇒ Workflow::Response::Workflows
Retrieves all workflows for the given object
112 113 114 115 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 112 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
105 106 107 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 105 def all_workflows_xml(druid) requestor.request "objects/#{druid}/workflows" end |
#create_workflow_by_name(druid, workflow_name, version:, lane_id: 'default') ⇒ 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. Returns true on success. Caller must handle any exceptions.
name that is known by the workflow service.
23 24 25 26 27 28 29 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 23 def create_workflow_by_name(druid, workflow_name, version:, lane_id: 'default') params = { 'lane-id' => lane_id, 'version' => 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
160 161 162 163 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 160 def delete_all_workflows(pid:) requestor.request "objects/#{pid}/workflows", 'delete' true end |
#delete_workflow(druid:, workflow:, version:) ⇒ Boolean
Deletes a workflow from a particular repository and druid. This is only used by Hydrus.
151 152 153 154 155 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 151 def delete_workflow(druid:, workflow:, version:) qs_args = "?version=#{version}" requestor.request "/objects/#{druid}/workflows/#{workflow}#{qs_args}", 'delete' true end |
#process(pid:, workflow_name:, process:) ⇒ Workflow::Response::Process
142 143 144 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 142 def process(pid:, workflow_name:, process:) workflow(pid: pid, workflow_name: workflow_name).process_for_recent_version(name: process) 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 base URL.
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"error\" />"
95 96 97 98 99 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 95 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 base URL. As an example:
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"completed\" />"
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 50 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 |
#workflow(pid:, workflow_name:) ⇒ Workflow::Response::Workflow
133 134 135 136 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 133 def workflow(pid:, workflow_name:) xml = fetch_workflow(druid: pid, workflow: workflow_name) Workflow::Response::Workflow.new(xml: xml) end |
#workflow_status(druid:, workflow:, process:) ⇒ String
Retrieves the process status of the given workflow for the given object identifier
69 70 71 72 73 74 75 76 77 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 69 def workflow_status(druid:, workflow:, process:) workflow_md = fetch_workflow(druid: druid, workflow: 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 |
#workflows(pid) ⇒ 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
125 126 127 128 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 125 def workflows(pid) xml_doc = Nokogiri::XML(fetch_workflow(druid: pid, workflow: '')) xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] } end |