diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 918f8d3ee..314799911 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -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 diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 90affba19..d1ad4c7a8 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -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, diff --git a/app/services/registration_service.rb b/app/services/registration_service.rb index 389f20861..9029ad8c2 100644 --- a/app/services/registration_service.rb +++ b/app/services/registration_service.rb @@ -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 diff --git a/app/services/version_service.rb b/app/services/version_service.rb index 22518c346..015cbf8c3 100644 --- a/app/services/version_service.rb +++ b/app/services/version_service.rb @@ -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 = {}) @@ -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 diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb index bee0f0947..223937f83 100644 --- a/spec/controllers/objects_controller_spec.rb +++ b/spec/controllers/objects_controller_spec.rb @@ -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 diff --git a/spec/controllers/versions_controller_spec.rb b/spec/controllers/versions_controller_spec.rb index e55c797bc..9d58bacf1 100644 --- a/spec/controllers/versions_controller_spec.rb +++ b/spec/controllers/versions_controller_spec.rb @@ -41,7 +41,6 @@ let(:open_params) do { assume_accessioned: false, - create_workflows_ds: false, vers_md_upd_info: { significance: 'minor', description: 'bar', diff --git a/spec/services/registration_service_spec.rb b/spec/services/registration_service_spec.rb index eaa9647c3..ec71d0ef5 100644 --- a/spec/services/registration_service_spec.rb +++ b/spec/services/registration_service_spec.rb @@ -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 diff --git a/spec/services/version_service_spec.rb b/spec/services/version_service_spec.rb index d203953d0..f6538aedc 100644 --- a/spec/services/version_service_spec.rb +++ b/spec/services/version_service_spec.rb @@ -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