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 rubocop:disable Metrics/ClassLength
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, version: nil, 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(*args) ⇒ 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.
-
#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: nil, pid:, workflow_name:) ⇒ Workflow::Response::Workflow
-
#workflow_status(*args) ⇒ String
Retrieves the process status of the given workflow for the given object identifier rubocop:disable Metrics/AbcSize.
-
#workflow_xml(*args) ⇒ String
rubocop:enable Metrics/AbcSize.
-
#workflows(pid, repo = nil) ⇒ 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.
11 12 13 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 11 def initialize(requestor:) @requestor = requestor end |
Instance Method Details
#all_workflows(pid:) ⇒ Workflow::Response::Workflows
Retrieves all workflows for the given object
234 235 236 237 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 234 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
227 228 229 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 227 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.
25 26 27 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 25 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, version: nil, 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.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 41 def create_workflow_by_name(druid, workflow_name, version: nil, lane_id: 'default') params = { 'lane-id' => lane_id } if version params['version'] = version else Deprecation.warn(self, 'Calling create_workflow_by_name without passing version is deprecated and will result in an error in dor-workflow-client 4.0') end 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
302 303 304 305 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 302 def delete_all_workflows(pid:) requestor.request "objects/#{pid}/workflows", 'delete' true end |
#delete_workflow(*args) ⇒ Boolean
Deletes a workflow from a particular repository and druid. This is only used by Hydrus.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 277 def delete_workflow(*args) case args.length when 3..4 Deprecation.warn(self, 'Calling delete_workflow with positional args is deprecated, use kwargs instead') (_repo, druid, workflow, version_hash) = *args version = version_hash && version_hash[:version] when 1 opts = args.first druid = opts[:druid] workflow = opts[:workflow] version = opts[:version] end qs_args = if version "?version=#{version}" else Deprecation.warn(self, 'Calling delete_workflow without passing version is deprecated and will result in an error in dor-workflow-client 4.0') '' end requestor.request "/objects/#{druid}/workflows/#{workflow}#{qs_args}", 'delete' true end |
#process(pid:, workflow_name:, process:) ⇒ Workflow::Response::Process
268 269 270 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 268 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\" />"
217 218 219 220 221 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 217 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\" />"
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 73 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 base URL.
PUT "/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"error\" />"
195 196 197 198 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 195 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 base URL. As an example:
PUT "/dor/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"completed\" />"
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 106 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: nil, pid:, workflow_name:) ⇒ Workflow::Response::Workflow
258 259 260 261 262 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 258 def workflow(repo: nil, pid:, workflow_name:) Deprecation.warn(self, 'passing the repo parameter is deprecated and will be removed in the next major versions') if repo xml = fetch_workflow(druid: pid, workflow: workflow_name) Workflow::Response::Workflow.new(xml: xml) end |
#workflow_status(*args) ⇒ String
Retrieves the process status of the given workflow for the given object identifier rubocop:disable Metrics/AbcSize
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 128 def workflow_status(*args) case args.length when 4 Deprecation.warn(self, 'Calling workflow_status with positional args is deprecated, use kwargs instead') (_repo, druid, workflow, process) = *args when 1 opts = args.first repo = opts[:repo] Deprecation.warn(self, 'Passing `:repo` to workflow_status is deprecated and can be omitted') if repo druid = opts[:druid] workflow = opts[:workflow] process = opts[:process] end 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 |
#workflow_xml(*args) ⇒ String
rubocop:enable Metrics/AbcSize
Retrieves the raw XML for the given workflow
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 157 def workflow_xml(*args) case args.length when 3 Deprecation.warn(self, 'Calling workflow_xml with positional args is deprecated, use kwargs instead') (repo, druid, workflow) = *args when 1 opts = args.first repo = opts[:repo] Deprecation.warn(self, 'Passing `:repo` to workflow_xml is deprecated and can be omitted') if repo druid = opts[:druid] workflow = opts[:workflow] end raise ArgumentError, 'missing workflow' unless workflow return requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}" if repo fetch_workflow(druid: druid, workflow: workflow) end |
#workflows(pid, repo = nil) ⇒ 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
248 249 250 251 252 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 248 def workflows(pid, repo = nil) Deprecation.warn(self, 'Passing the second argument (repo) to workflows is deprecated and can be omitted') if repo xml_doc = Nokogiri::XML(fetch_workflow(druid: pid, workflow: '')) xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] } end |