Skip to content

Commit

Permalink
Merge pull request #260 from sul-dlss/workflow-service
Browse files Browse the repository at this point in the history
Use the workflow service client for starting workflows
  • Loading branch information
jcoyne committed May 13, 2019
2 parents 0ed8dba + 99dc7ed commit 2a3897a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
3 changes: 2 additions & 1 deletion app/controllers/objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def apo_workflows
"#{params[:wf_name]}WF"
end

Dor::CreateWorkflowService.create_workflow(@item, name: workflow)
Honeybadger.notify("Call to deprecated API #{request.path}. Use workflow-service instead")
Dor::Config.workflow.client.create_workflow_by_name(@item.pid, workflow)

head :created
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def build_error(err)
def open_params
params.permit(
:assume_accessioned,
:create_workflows_ds,
vers_md_upd_info: [
:description,
:opening_user_name,
Expand Down
4 changes: 1 addition & 3 deletions app/services/registration_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ def ids_to_hash(ids)

def initiate_workflow(workflows:, item:, priority:)
workflows.each do |workflow_id|
Dor::CreateWorkflowService.create_workflow(item, name: workflow_id,
create_ds: !item.new_record?,
priority: priority)
Dor::Config.workflow.client.create_workflow_by_name(item.pid, workflow_id, priority: priority)
end
end

Expand Down
9 changes: 1 addition & 8 deletions app/services/version_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def initialize(work)
# Increments the version number and initializes versioningWF for the object
# @param [Hash] opts optional params
# @option opts [Boolean] :assume_accessioned If true, does not check whether object has been accessioned.
# @option opts [Boolean] :create_workflows_ds If false, create_workflow() will not initialize the workflows datastream.
# @option opts [Hash] :vers_md_upd_info If present, used to add to the events datastream and set the desc and significance on the versionMetadata datastream
# @raise [Dor::Exception] if the object hasn't been accessioned, or if a version is already opened
def open(opts = {})
Expand All @@ -33,13 +32,7 @@ def open(opts = {})
vmd_ds.sync_then_increment_version sdr_version
vmd_ds.save unless work.new_record?

k = :create_workflows_ds
if opts.key?(k)
# During local development, Hydrus (or another app w/ local Fedora) does not want to initialize workflows datastream.
Dor::CreateWorkflowService.create_workflow(work, name: 'versioningWF', create_ds: opts[k])
else
Dor::CreateWorkflowService.create_workflow(work, name: 'versioningWF')
end
Dor::Config.workflow.client.create_workflow_by_name(work.pid, 'versioningWF')

vmd_upd_info = opts[:vers_md_upd_info]
return unless vmd_upd_info
Expand Down
13 changes: 9 additions & 4 deletions spec/controllers/objects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,21 @@
end
end

describe 'apo-workflow intialization' do
it 'initiates assemblyWF' do
expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(item, name: 'assemblyWF')
describe 'apo-workflow initalization' do
let(:workflow_client) { instance_double(Dor::Workflow::Client, create_workflow_by_name: true) }

before do
allow(Dor::Config.workflow).to receive(:client).and_return(workflow_client)
end

it 'initiates assemblyWF' do
post 'apo_workflows', params: { id: item.pid, wf_name: 'assemblyWF' }
expect(workflow_client).to have_received(:create_workflow_by_name).with(item.pid, 'assemblyWF')
end

it "handles workflow names without 'WF' appended to the end" do
expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(item, name: 'accessionWF')
post 'apo_workflows', params: { id: item.pid, wf_name: 'accession' }
expect(workflow_client).to have_received(:create_workflow_by_name).with(item.pid, 'accessionWF')
end
end
end
1 change: 0 additions & 1 deletion spec/controllers/versions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
let(:open_params) do
{
assume_accessioned: false,
create_workflows_ds: false,
vers_md_upd_info: {
significance: 'minor',
description: 'bar',
Expand Down
18 changes: 13 additions & 5 deletions spec/services/registration_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,19 @@
expect(obj.label).to eq('a' * 254)
end

it 'sets workflow priority when passed in' do
expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(Dor::Item, name: 'digitizationWF', create_ds: false, priority: 50)
@params[:workflow_priority] = 50
@params[:initiate_workflow] = 'digitizationWF'
described_class.register_object(@params)
context 'when workflow priority is passed in' do
let(:workflow_client) { instance_double(Dor::Workflow::Client, create_workflow_by_name: true) }

before do
allow(Dor::Config.workflow).to receive(:client).and_return(workflow_client)
end

it 'sets priority' do
@params[:workflow_priority] = 50
@params[:initiate_workflow] = 'digitizationWF'
described_class.register_object(@params)
expect(workflow_client).to have_received(:create_workflow_by_name).with(String, 'digitizationWF', priority: 50)
end
end
end # context common cases
end
Expand Down
20 changes: 12 additions & 8 deletions spec/services/version_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@

context 'normal behavior' do
before do
allow(Dor::Config.workflow.client).to receive(:lifecycle).with('dor', druid, 'accessioned').and_return(true)
allow(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'opened').and_return(nil)
allow(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'submitted').and_return(nil)
allow(SdrClient).to receive(:current_version).and_return(1)
allow(Dor::CreateWorkflowService).to receive(:create_workflow).with(obj, name: 'versioningWF')
allow(Dor::Config.workflow).to receive(:client).and_return(workflow_client)
allow(obj).to receive(:new_record?).and_return(false)
allow(vmd_ds).to receive(:save)
end

let(:workflow_client) do
instance_double(Dor::Workflow::Client,
create_workflow_by_name: true,
lifecycle: true,
active_lifecycle: nil)
end

it 'creates the versionMetadata datastream and starts a workflow' do
expect(Dor::Config.workflow.client).to receive(:lifecycle).with('dor', druid, 'accessioned').and_return(true)
expect(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'opened').and_return(nil)
expect(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'submitted').and_return(nil)
expect(SdrClient).to receive(:current_version).and_return(1)
expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(obj, name: 'versioningWF')
expect(obj).to receive(:new_record?).and_return(false)
expect(vmd_ds).to receive(:save)
expect(vmd_ds.ng_xml.to_xml).to match(/Initial Version/)
open
expect(workflow_client).to have_received(:lifecycle).with('dor', druid, 'accessioned')
expect(workflow_client).to have_received(:active_lifecycle).with('dor', druid, 'opened')
expect(workflow_client).to have_received(:active_lifecycle).with('dor', druid, 'submitted')
expect(workflow_client).to have_received(:create_workflow_by_name).with(obj.pid, 'versioningWF')
end

it 'includes vers_md_upd_info' do
Expand Down

0 comments on commit 2a3897a

Please sign in to comment.