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_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
Returns a new instance of WorkflowRoutes.
12 13 14 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 12 def initialize(requestor:) @requestor = requestor end |
Instance Method Details
#all_workflows(pid:) ⇒ Workflow::Response::Workflows
Retrieves all workflows for the given object
151 152 153 154 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 151 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
144 145 146 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 144 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.
26 27 28 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 26 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.
43 44 45 46 47 48 49 50 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 43 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
192 193 194 195 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 192 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
184 185 186 187 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 184 def delete_workflow(repo, druid, workflow) requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}", 'delete' true 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 "/dor/objects/pid:123/workflows/GoogleScannedWF/convert"
<process name=\"convert\" status=\"error\" />"
133 134 135 136 137 138 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 133 def update_workflow_error_status(repo, druid, workflow, process, error_msg, opts = {}) opts = { error_text: nil }.merge!(opts) xml = create_process_xml({ name: process, status: 'error', errorMessage: error_msg }.merge!(opts)) requestor.request "#{repo}/objects/#{druid}/workflows/#{workflow}/#{process}", 'put', xml, content_type: 'application/xml' 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\" />"
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 73 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
174 175 176 177 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 174 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
94 95 96 97 98 99 100 101 102 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 94 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
110 111 112 113 114 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 110 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
165 166 167 168 |
# File 'lib/dor/workflow/client/workflow_routes.rb', line 165 def workflows(pid, repo = 'dor') xml_doc = Nokogiri::XML(workflow_xml(repo, pid, '')) xml_doc.xpath('//workflow').collect { |workflow| workflow['id'] } end |