Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge a52cd6b into 90b71cf
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Apr 3, 2019
2 parents 90b71cf + a52cd6b commit 4b0b3bc
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 51 deletions.
2 changes: 1 addition & 1 deletion config/dev_console_env.rb.example
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dor-services.gemspec
Expand Up @@ -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'
Expand Down
8 changes: 5 additions & 3 deletions lib/dor/datastreams/workflow_ds.rb
Expand Up @@ -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

Expand All @@ -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(%(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<workflows objectId="#{pid}"/>))
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
Expand Down
4 changes: 2 additions & 2 deletions lib/dor/models/concerns/versionable.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/dor/services/cleanup_reset_service.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/dor/services/cleanup_service.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/dor/services/status_service.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/dor/services/version_service.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/datastreams/rights_metadata_spec.rb
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/datastreams/workflow_ds_spec.rb
Expand Up @@ -41,12 +41,12 @@
datetime="2012-11-06T16:19:15-0800" status="completed" name="descriptive-metadata"/>
<process version="2" elapsed="0.0" archived="true" attempts="2"
datetime="2012-11-06T16:19:16-0800" status="completed" name="content-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
Expand Down Expand Up @@ -81,16 +81,16 @@
datetime="2012-11-06T16:19:15-0800" status="completed" name="descriptive-metadata"/>
<process version="2" elapsed="0.0" archived="true" attempts="2"
datetime="2012-11-06T16:19:16-0800" status="completed" name="content-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
Expand Down
2 changes: 1 addition & 1 deletion spec/indexers/workflows_indexer_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/admin_policy_object_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/collection_spec.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/models/concerns/processable_spec.rb
Expand Up @@ -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('<workflows/>')
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>')
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('<workflows/>')
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>') # should be cached copy
expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('<workflows>with some data</workflows>')
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows>with some data</workflows>')
# pass refresh flag and should be refreshed copy
expect(item.workflows.content(true)).to eq('<workflows>with some data</workflows>')
expect(item.workflows.content).to eq('<workflows>with some data</workflows>')
Expand Down
8 changes: 4 additions & 4 deletions spec/models/concerns/versionable_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/item_spec.rb
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions spec/services/version_service_spec.rb
Expand Up @@ -28,19 +28,19 @@ 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)
allow(vmd_ds).to receive(:save)
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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/dor_config.rb
Expand Up @@ -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'
Expand Down

0 comments on commit 4b0b3bc

Please sign in to comment.