From a52cd6bc09fb0e88d40957704ca6c34771864d25 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 3 Apr 2019 13:14:17 -0500 Subject: [PATCH] Upgrade to dor-workflow-service 2.11 --- config/dev_console_env.rb.example | 2 +- dor-services.gemspec | 2 +- lib/dor/datastreams/workflow_ds.rb | 8 +++-- lib/dor/models/concerns/versionable.rb | 4 +-- lib/dor/services/cleanup_reset_service.rb | 2 +- lib/dor/services/cleanup_service.rb | 2 +- lib/dor/services/status_service.rb | 2 +- lib/dor/services/version_service.rb | 8 ++--- spec/datastreams/rights_metadata_spec.rb | 2 +- spec/datastreams/workflow_ds_spec.rb | 10 +++--- spec/indexers/workflows_indexer_spec.rb | 2 +- spec/models/admin_policy_object_spec.rb | 2 +- spec/models/collection_spec.rb | 2 +- spec/models/concerns/processable_spec.rb | 6 ++-- spec/models/concerns/versionable_spec.rb | 8 ++--- spec/models/item_spec.rb | 2 +- spec/services/version_service_spec.rb | 38 +++++++++++------------ spec/support/dor_config.rb | 2 +- 18 files changed, 53 insertions(+), 51 deletions(-) diff --git a/config/dev_console_env.rb.example b/config/dev_console_env.rb.example index 3d1aff94..4bdb1d85 100644 --- a/config/dev_console_env.rb.example +++ b/config/dev_console_env.rb.example @@ -37,7 +37,7 @@ Dor::Config.configure do end solr.url 'https://host/solr' - workflow.url 'https://host/workflow/' + workflow.url 'https://workflow.example.edu/' dor_services.url 'https://host/dor/v1' cleanup do diff --git a/dor-services.gemspec b/dor-services.gemspec index a706b75a..c478083d 100644 --- a/dor-services.gemspec +++ b/dor-services.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |s| # Stanford dependencies s.add_dependency 'dor-rights-auth', '~> 1.0', '>= 1.2.0' - s.add_dependency 'dor-workflow-service', '~> 2.0', '>= 2.0.1' + s.add_dependency 'dor-workflow-service', '~> 2.11' s.add_dependency 'druid-tools', '>= 0.4.1' s.add_dependency 'moab-versioning', '~> 4.0' s.add_dependency 'stanford-mods', '>= 2.3.1' diff --git a/lib/dor/datastreams/workflow_ds.rb b/lib/dor/datastreams/workflow_ds.rb index 9c8af69e..57ed88b8 100644 --- a/lib/dor/datastreams/workflow_ds.rb +++ b/lib/dor/datastreams/workflow_ds.rb @@ -35,7 +35,7 @@ def self.default_attributes end def get_workflow(wf, repo = 'dor') - xml = Dor::Config.workflow.client.get_workflow_xml(repo, pid, wf) + xml = Dor::Config.workflow.client.workflow_xml(repo, pid, wf) xml = Nokogiri::XML(xml) return nil if xml.xpath('workflow').length == 0 @@ -55,14 +55,16 @@ def ng_xml # service directly def content(refresh = false) @content = nil if refresh - @content ||= Dor::Config.workflow.client.get_workflow_xml 'dor', pid, nil + @content ||= Dor::Config.workflow.client.all_workflows_xml pid rescue Dor::WorkflowException => e + # TODO: I don't understand when this would be useful as this block ends up calling the workflow service too. + # Why not just raise an exception here? Dor.logger.warn "Unable to connect to the workflow service #{e}. Falling back to placeholder XML" xml = Nokogiri::XML(%(\n)) digital_object.datastreams.keys.each do |dsid| next unless dsid =~ /WF$/ - ds_content = Nokogiri::XML(Dor::Config.workflow.client.get_workflow_xml('dor', pid, dsid)) + ds_content = Nokogiri::XML(Dor::Config.workflow.client.workflow_xml('dor', pid, dsid)) xml.root.add_child(ds_content.root) end @content ||= xml.to_xml diff --git a/lib/dor/models/concerns/versionable.rb b/lib/dor/models/concerns/versionable.rb index 26da740c..a118aa6f 100644 --- a/lib/dor/models/concerns/versionable.rb +++ b/lib/dor/models/concerns/versionable.rb @@ -49,9 +49,9 @@ def new_version_open? # @return [Boolean] true if the object is in a state that allows it to be modified. # States that will allow modification are: has not been submitted for accessioning, has an open version or has sdr-ingest set to hold def allows_modification? - if Dor::Config.workflow.client.get_lifecycle('dor', pid, 'submitted') && + if Dor::Config.workflow.client.lifecycle('dor', pid, 'submitted') && !VersionService.new(self).open? && - Dor::Config.workflow.client.get_workflow_status('dor', pid, 'accessionWF', 'sdr-ingest-transfer') != 'hold' + Dor::Config.workflow.client.workflow_status('dor', pid, 'accessionWF', 'sdr-ingest-transfer') != 'hold' false else true diff --git a/lib/dor/services/cleanup_reset_service.rb b/lib/dor/services/cleanup_reset_service.rb index a45b79fd..f140591c 100644 --- a/lib/dor/services/cleanup_reset_service.rb +++ b/lib/dor/services/cleanup_reset_service.rb @@ -19,7 +19,7 @@ def self.get_druid_last_version(druid) last_version = druid_obj.current_version.to_i # if the current version is still open, avoid this versioned directory - last_version -= 1 if Dor::Config.workflow.client.get_lifecycle('dor', druid, 'accessioned').nil? + last_version -= 1 if Dor::Config.workflow.client.lifecycle('dor', druid, 'accessioned').nil? last_version end diff --git a/lib/dor/services/cleanup_service.rb b/lib/dor/services/cleanup_service.rb index bd012c4b..8e31e3a0 100644 --- a/lib/dor/services/cleanup_service.rb +++ b/lib/dor/services/cleanup_service.rb @@ -70,7 +70,7 @@ def self.cleanup_purl_doc_cache(druid) def self.remove_active_workflows(druid) %w(dor sdr).each do |repo| - dor_wfs = Dor::Config.workflow.client.get_workflows(druid, repo) + dor_wfs = Dor::Config.workflow.client.workflows(druid, repo) dor_wfs.each { |wf| Dor::Config.workflow.client.delete_workflow(repo, druid, wf) } end end diff --git a/lib/dor/services/status_service.rb b/lib/dor/services/status_service.rb index 2a0cb27a..e42f17ce 100644 --- a/lib/dor/services/status_service.rb +++ b/lib/dor/services/status_service.rb @@ -76,7 +76,7 @@ def status(include_time = false) end def milestones - @milestones ||= Dor::Config.workflow.client.get_milestones('dor', work.pid) + @milestones ||= Dor::Config.workflow.client.milestones('dor', work.pid) end private diff --git a/lib/dor/services/version_service.rb b/lib/dor/services/version_service.rb index 82ccdb99..0acd2c1c 100644 --- a/lib/dor/services/version_service.rb +++ b/lib/dor/services/version_service.rb @@ -24,9 +24,9 @@ def initialize(work) def open(opts = {}) # During local development, we need a way to open a new version even if the object has not been accessioned. raise(Dor::Exception, 'Object net yet accessioned') unless - opts[:assume_accessioned] || Dor::Config.workflow.client.get_lifecycle('dor', work.pid, 'accessioned') + opts[:assume_accessioned] || Dor::Config.workflow.client.lifecycle('dor', work.pid, 'accessioned') raise Dor::VersionAlreadyOpenError, 'Object already opened for versioning' if open? - raise Dor::Exception, 'Object currently being accessioned' if Dor::Config.workflow.client.get_active_lifecycle('dor', work.pid, 'submitted') + raise Dor::Exception, 'Object currently being accessioned' if Dor::Config.workflow.client.active_lifecycle('dor', work.pid, 'submitted') sdr_version = Sdr::Client.current_version work.pid @@ -67,14 +67,14 @@ def close(opts = {}) raise Dor::Exception, 'latest version in versionMetadata requires tag and description before it can be closed' unless work.versionMetadata.current_version_closeable? raise Dor::Exception, 'Trying to close version on an object not opened for versioning' unless open? - raise Dor::Exception, 'accessionWF already created for versioned object' if Dor::Config.workflow.client.get_active_lifecycle('dor', work.pid, 'submitted') + raise Dor::Exception, 'accessionWF already created for versioned object' if Dor::Config.workflow.client.active_lifecycle('dor', work.pid, 'submitted') Dor::Config.workflow.client.close_version 'dor', work.pid, opts.fetch(:start_accession, true) # Default to creating accessionWF when calling close_version end # @return [Boolean] true if 'opened' lifecycle is active, false otherwise def open? - return true if Dor::Config.workflow.client.get_active_lifecycle('dor', work.pid, 'opened') + return true if Dor::Config.workflow.client.active_lifecycle('dor', work.pid, 'opened') false end diff --git a/spec/datastreams/rights_metadata_spec.rb b/spec/datastreams/rights_metadata_spec.rb index a848d3df..50e3c7a7 100644 --- a/spec/datastreams/rights_metadata_spec.rb +++ b/spec/datastreams/rights_metadata_spec.rb @@ -10,7 +10,7 @@ before do @item = instantiate_fixture('druid:bb046xn0881', Dor::Item) allow(Dor).to receive(:find).with(@item.pid).and_return(@item) - allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) + allow(Dor::Config.workflow.client).to receive(:milestones).and_return([]) end it '#new' do diff --git a/spec/datastreams/workflow_ds_spec.rb b/spec/datastreams/workflow_ds_spec.rb index 3d2eec6b..3b9e3a24 100644 --- a/spec/datastreams/workflow_ds_spec.rb +++ b/spec/datastreams/workflow_ds_spec.rb @@ -41,12 +41,12 @@ datetime="2012-11-06T16:19:15-0800" status="completed" name="descriptive-metadata"/> ' - allow(Dor::Config.workflow.client).to receive(:get_workflow_xml).and_return(xml) + allow(Dor::Config.workflow.client).to receive(:workflow_xml).and_return(xml) accessionWF = @item.workflows['accessionWF'] expect(accessionWF).not_to be_nil end it 'returns nil if the xml is empty' do - allow(Dor::Config.workflow.client).to receive(:get_workflow_xml).and_return('') + allow(Dor::Config.workflow.client).to receive(:workflow_xml).and_return('') expect(@item.workflows['accessionWF']).to be_nil end end @@ -81,16 +81,16 @@ datetime="2012-11-06T16:19:15-0800" status="completed" name="descriptive-metadata"/> ' - allow(Dor::Config.workflow.client).to receive(:get_workflow_xml).and_return(xml) + allow(Dor::Config.workflow.client).to receive(:workflow_xml).and_return(xml) accessionWF = @item.workflows.get_workflow 'accessionWF' expect(accessionWF).not_to be_nil end it 'returns nil if the xml is empty' do - allow(Dor::Config.workflow.client).to receive(:get_workflow_xml).and_return('') + allow(Dor::Config.workflow.client).to receive(:workflow_xml).and_return('') expect(@item.workflows.get_workflow('accessionWF')).to be_nil end it 'requests the workflow for a different repository if one is specified' do - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('sdr', 'druid:ab123cd4567', 'accessionWF').and_return('') + expect(Dor::Config.workflow.client).to receive(:workflow_xml).with('sdr', 'druid:ab123cd4567', 'accessionWF').and_return('') @item.workflows.get_workflow('accessionWF', 'sdr') end end diff --git a/spec/indexers/workflows_indexer_spec.rb b/spec/indexers/workflows_indexer_spec.rb index f77245f3..54bea3b5 100644 --- a/spec/indexers/workflows_indexer_spec.rb +++ b/spec/indexers/workflows_indexer_spec.rb @@ -79,7 +79,7 @@ Dor::Workflow::Document.class_variable_set(:@@definitions, {}) WebMock.disable_net_connect! allow(Dor::WorkflowObject).to receive(:find_by_name).and_return(assemblyWF) - allow(Dor::Config.workflow.client).to receive(:get_workflow_xml).and_return(xml) + allow(Dor::Config.workflow.client).to receive(:all_workflows_xml).and_return(xml) end describe 'workflow_status_ssim' do diff --git a/spec/models/admin_policy_object_spec.rb b/spec/models/admin_policy_object_spec.rb index c0442050..11d419fc 100644 --- a/spec/models/admin_policy_object_spec.rb +++ b/spec/models/admin_policy_object_spec.rb @@ -24,7 +24,7 @@ let(:apo) { described_class.new(pid: 'foo:123') } - before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } + before { allow(Dor::Config.workflow.client).to receive(:milestones).and_return([]) } it { is_expected.to include 'active_fedora_model_ssi' => 'Dor::AdminPolicyObject' } end diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index bfa21941..0ece8ac3 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -18,7 +18,7 @@ let(:collection) { described_class.new(pid: 'foo:123') } - before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } + before { allow(Dor::Config.workflow.client).to receive(:milestones).and_return([]) } it { is_expected.to have_key :id } end diff --git a/spec/models/concerns/processable_spec.rb b/spec/models/concerns/processable_spec.rb index e5aa9a2d..285177dd 100644 --- a/spec/models/concerns/processable_spec.rb +++ b/spec/models/concerns/processable_spec.rb @@ -36,15 +36,15 @@ class ProcessableWithApoItem < ActiveFedora::Base end it 'loads its content directly from the workflow service' do - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('') + expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('') expect(item.workflows.content).to eq('') end it 'is able to invalidate the cache of its content' do - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('') + expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('') expect(item.workflows.content).to eq('') expect(item.workflows.content).to eq('') # should be cached copy - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('with some data') + expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('with some data') # pass refresh flag and should be refreshed copy expect(item.workflows.content(true)).to eq('with some data') expect(item.workflows.content).to eq('with some data') diff --git a/spec/models/concerns/versionable_spec.rb b/spec/models/concerns/versionable_spec.rb index d1c2a28f..04c46996 100644 --- a/spec/models/concerns/versionable_spec.rb +++ b/spec/models/concerns/versionable_spec.rb @@ -41,20 +41,20 @@ class VersionableItem < ActiveFedora::Base describe 'allows_modification?' do it "allows modification if the object hasn't been submitted" do - allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(false) + allow(Dor::Config.workflow.client).to receive(:lifecycle).and_return(false) expect(obj).to be_allows_modification end it 'allows modification if there is an open version' do - allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(true) + allow(Dor::Config.workflow.client).to receive(:lifecycle).and_return(true) allow_any_instance_of(Dor::VersionService).to receive(:open?).and_return(true) expect(obj).to be_allows_modification end it 'allows modification if the item has sdr-ingest-transfer set to hold' do - allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(true) + allow(Dor::Config.workflow.client).to receive(:lifecycle).and_return(true) allow_any_instance_of(Dor::VersionService).to receive(:open?).and_return(false) - allow(Dor::Config.workflow.client).to receive(:get_workflow_status).and_return('hold') + allow(Dor::Config.workflow.client).to receive(:workflow_status).and_return('hold') expect(obj).to be_allows_modification end end diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index 45709be7..73f90a04 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -8,7 +8,7 @@ let(:item) { described_class.new(pid: 'foo:123') } - before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } + before { allow(Dor::Config.workflow.client).to receive(:milestones).and_return([]) } it { is_expected.to include 'active_fedora_model_ssi' => 'Dor::Item' } end diff --git a/spec/services/version_service_spec.rb b/spec/services/version_service_spec.rb index dc842935..4adbf260 100644 --- a/spec/services/version_service_spec.rb +++ b/spec/services/version_service_spec.rb @@ -28,9 +28,9 @@ class VersionableItem < ActiveFedora::Base context 'normal behavior' do before do - allow(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(true) - allow(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(nil) - allow(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'submitted').and_return(nil) + 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(Sdr::Client).to receive(:current_version).and_return(1) allow(Dor::CreateWorkflowService).to receive(:create_workflow).with(obj, name: 'versioningWF') allow(obj).to receive(:new_record?).and_return(false) @@ -38,9 +38,9 @@ class VersionableItem < ActiveFedora::Base end it 'creates the versionMetadata datastream and starts a workflow' do - expect(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(true) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(nil) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'submitted').and_return(nil) + 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(Sdr::Client).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) @@ -73,33 +73,33 @@ class VersionableItem < ActiveFedora::Base context 'when the object has not been accessioned' do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(false) + expect(Dor::Config.workflow.client).to receive(:lifecycle).with('dor', druid, 'accessioned').and_return(false) expect { open }.to raise_error(Dor::Exception, 'Object net yet accessioned') end end context 'when the object has already been opened' do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(true) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(Time.new) + 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(Time.new) expect { open }.to raise_error(Dor::VersionAlreadyOpenError, 'Object already opened for versioning') end end context 'when the object is still being accessioned' do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(true) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(nil) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'submitted').and_return(Time.new) + 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(Time.new) expect { open }.to raise_error(Dor::Exception, 'Object currently being accessioned') end end context "SDR's current version is greater than the current version" do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_lifecycle).with('dor', druid, 'accessioned').and_return(true) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(nil) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'submitted').and_return(nil) + 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(Sdr::Client).to receive(:current_version).and_return(3) expect { open }.to raise_error(Dor::Exception, 'Cannot sync to a version greater than current: 1, requested 3') end @@ -111,7 +111,7 @@ class VersionableItem < ActiveFedora::Base it 'sets tag and description if passed in as optional paramaters' do allow(vmd_ds).to receive(:pid).and_return('druid:ab123cd4567') - allow(Dor::Config.workflow.client).to receive(:get_active_lifecycle).and_return(true, false) + allow(Dor::Config.workflow.client).to receive(:active_lifecycle).and_return(true, false) # Stub out calls to update and archive workflow allow(Dor::Config.workflow.client).to receive(:update_workflow_status) @@ -139,15 +139,15 @@ class VersionableItem < ActiveFedora::Base context 'when the object has not been opened for versioning' do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(nil) + expect(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'opened').and_return(nil) expect { close }.to raise_error(Dor::Exception, 'Trying to close version on an object not opened for versioning') end end context 'when the object already has an active instance of accesssionWF' do it 'raises an exception' do - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'opened').and_return(Time.new) - expect(Dor::Config.workflow.client).to receive(:get_active_lifecycle).with('dor', druid, 'submitted').and_return(true) + expect(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'opened').and_return(Time.new) + expect(Dor::Config.workflow.client).to receive(:active_lifecycle).with('dor', druid, 'submitted').and_return(true) expect { close }.to raise_error(Dor::Exception, 'accessionWF already created for versioned object') end end diff --git a/spec/support/dor_config.rb b/spec/support/dor_config.rb index e86c90b7..386ceafa 100644 --- a/spec/support/dor_config.rb +++ b/spec/support/dor_config.rb @@ -26,7 +26,7 @@ end solr.url 'https://example.edu/solr/solrizer' - workflow.url 'http://example.edu/workflow/' + workflow.url 'https://workflow.example.edu/' sdr.url 'http://example.edu/sdr' dor_services.url 'https://example.edu/dor' dor_indexing_app.url 'https://example.edu/dor'