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

Commit

Permalink
Merge pull request #412 from sul-dlss/workflow-ds
Browse files Browse the repository at this point in the history
Workflow datastream should set its dsLocation
  • Loading branch information
jcoyne committed Dec 4, 2018
2 parents 517c9f1 + 60448ee commit fe1b012
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -8,6 +8,10 @@ notifications:
rvm:
- 2.5.3

before_install:
- docker run -d -p 8983:8080 suldlss/fcrepo:no-messaging-latest
- docker ps

env:
- 'RAILS_VERSION="~> 4.2"'
- 'RAILS_VERSION="~> 5.1.0"'
Expand Down
13 changes: 13 additions & 0 deletions lib/dor/datastreams/workflow_ds.rb
Expand Up @@ -3,6 +3,7 @@
module Dor
# TODO: class docs
class WorkflowDs < ActiveFedora::OmDatastream
before_save :build_location
set_terminology do |t|
t.root(path: 'workflows')
t.workflow do
Expand All @@ -18,6 +19,18 @@ class WorkflowDs < ActiveFedora::OmDatastream
end
end

# Called before saving, but after a pid has been assigned
def build_location
return unless new?

self.dsLocation = File.join(Dor::Config.workflow.url, "dor/objects/#{pid}/workflows")
end

# Called by rubydora. This lets us customize the mime-type
def self.default_attributes
super.merge(mimeType: 'application/xml')
end

def get_workflow(wf, repo = 'dor')
xml = Dor::Config.workflow.client.get_workflow_xml(repo, pid, wf)
xml = Nokogiri::XML(xml)
Expand Down
18 changes: 5 additions & 13 deletions lib/dor/models/concerns/processable.rb
Expand Up @@ -7,8 +7,11 @@ module Processable
extend ActiveSupport::Concern

included do
has_metadata name: 'workflows', type: Dor::WorkflowDs, label: 'Workflows', control_group: 'E'
after_initialize :set_workflows_datastream_location
has_metadata name: 'workflows',
type: Dor::WorkflowDs,
label: 'Workflows',
control_group: 'E',
autocreate: true
end

# verbiage we want to use to describe an item when it has completed a particular step
Expand Down Expand Up @@ -38,17 +41,6 @@ module Processable
'opened' => 9
}.freeze

# This is a work-around for some strange logic in ActiveFedora that
# don't allow self.workflows.new? to work if we load the object using
# .load_instance_from_solr.
def set_workflows_datastream_location
return if respond_to?(:inner_object) && inner_object.is_a?(ActiveFedora::SolrDigitalObject)
return unless workflows.new?

workflows.mimeType = 'application/xml'
workflows.dsLocation = File.join(Dor::Config.workflow.url, "dor/objects/#{pid}/workflows")
end

def empty_datastream?(datastream)
return true if datastream.new?

Expand Down
17 changes: 17 additions & 0 deletions spec/models/item_spec.rb
Expand Up @@ -11,4 +11,21 @@

it { is_expected.to include 'active_fedora_model_ssi' => 'Dor::Item' }
end

describe 'the dsLocation for workflow' do
let(:obj) { described_class.new }
before do
allow(Dor::SuriService).to receive(:mint_id).and_return('changeme:1231231')
allow(Dor::Config.suri).to receive(:mint_ids).and_return(true)
allow(obj).to receive(:update_index)
obj.save!
end
let(:reloaded) { Dor::Item.find(obj.pid) }
let(:workflows) { reloaded.workflows }

it 'is set automatically' do
expect(workflows.dsLocation).to eq 'http://example.edu/workflow/dor/objects/changeme:1231231/workflows'
expect(workflows.mimeType).to eq 'application/xml'
end
end
end
2 changes: 1 addition & 1 deletion spec/services/search_service_spec.rb
Expand Up @@ -17,7 +17,7 @@
['druid:tx361mw6047', 'druid:cm977wg2520', 'druid:tk695fn1971', 'druid:jk486qb3656', 'druid:cd252xn6059'], []
]
@responses = @druids.collect { |group| { body: %("object"\n) + group.collect { |d| "info:fedora/#{d}" }.join("\n") } }
stub_request(:post, 'http://fedora.edu/fedora/risearch')
stub_request(:post, 'http://localhost:8983/fedora/risearch')
.to_return(body: @responses[0][:body]).then
.to_return(body: @responses[1][:body]).then
.to_return(body: @responses[2][:body])
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -34,7 +34,6 @@ def stub_config
Dor::Config.push! do
suri.mint_ids false
solr.url 'http://solr.edu/solrizer'
fedora.url 'http://fedora.edu/fedora'
stacks.document_cache_host 'purl-test.stanford.edu'
stacks.local_workspace_root File.join(fixture_dir, 'workspace')
stacks.local_stacks_root File.join(fixture_dir, 'stacks')
Expand Down
2 changes: 1 addition & 1 deletion spec/support/dor_config.rb
Expand Up @@ -9,7 +9,7 @@
key_pass 'thisisatleast4bytes'
end

fedora.url 'http://fedoraUser:fedoraPass@example.edu/fedora'
fedora.url 'http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora'

suri do
mint_ids true
Expand Down

0 comments on commit fe1b012

Please sign in to comment.