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

Commit

Permalink
Merge 166d580 into 61644b8
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 21, 2019
2 parents 61644b8 + 166d580 commit 83d4953
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 71 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ gem 'whenever', '~> 0.9'

# Stanford stuff
gem 'assembly-objectfile', '~> 1.5'
gem 'dor-services', '~> 6.1', require: false
# We don't require this by default, because we need it to load after hydrus models
# or we'll get a superclass mismatch for Hydrus::Item
gem 'dor-services', '~> 7.1', require: false
gem 'dor-services-client', '~> 1.1'
gem 'rubydora', '~> 2.1'
gem 'bagit', '~> 0.4'
gem 'dor-workflow-client', '~> 3.1'
gem 'net-http-persistent', '~> 2.9' # https://github.com/sul-dlss/dor-workflow-service/issues/44
gem 'blacklight', '~> 6.19'
gem 'cancancan', '~> 1.17'

Expand Down
24 changes: 5 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,22 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dor-rights-auth (1.3.0)
nokogiri
dor-services (6.8.0)
dor-services (7.1.0)
active-fedora (>= 8.7.0, < 9)
activesupport (>= 4.2.10, < 6.0.0)
activesupport (~> 5.1)
confstruct (~> 0.2.7)
deprecation (~> 0)
dor-rights-auth (~> 1.0, >= 1.2.0)
dor-services-client (~> 1.5)
dor-workflow-service (~> 2.11)
dor-workflow-client (~> 3.0)
druid-tools (>= 0.4.1)
equivalent-xml (~> 0.5, >= 0.5.1)
json (>= 1.8.1)
moab-versioning (~> 4.0)
net-sftp (~> 2.1)
nokogiri (~> 1.6)
om (~> 3.0)
rdf (~> 1.1, >= 1.1.7)
rest-client (>= 1.7, < 3)
retries
retries (~> 0.0.5)
rsolr (>= 1.0.3, < 3)
ruby-cache (~> 0.3.0)
rubydora (~> 2.1)
Expand All @@ -212,14 +210,6 @@ GEM
faraday_middleware
net-http-persistent (>= 2.9.4, < 4.a)
nokogiri (~> 1.6)
dor-workflow-service (2.12.0)
activesupport (>= 3.2.1, < 6)
confstruct (>= 0.2.7, < 2)
deprecation
faraday (~> 0.9, >= 0.9.2)
net-http-persistent (>= 2.9.4, < 4.a)
nokogiri (~> 1.6)
retries
druid-tools (1.0.0)
dry-configurable (0.8.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -342,8 +332,6 @@ GEM
net-http-persistent (2.9.4)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (5.2.0)
netrc (0.11.0)
nio4r (2.3.1)
Expand Down Expand Up @@ -579,9 +567,8 @@ DEPENDENCIES
devise (~> 4.0)
devise-remote-user (~> 1.0)
dlss-capistrano
dor-services (~> 6.1)
dor-services (~> 7.1)
dor-services-client (~> 1.1)
dor-workflow-client (~> 3.1)
dynamic_form
equivalent-xml
factory_bot_rails
Expand All @@ -591,7 +578,6 @@ DEPENDENCIES
letter_opener
listen (>= 3.0.5, < 3.2)
mysql2 (~> 0.4.5)
net-http-persistent (~> 2.9)
okcomputer
pry
rails (~> 5.2)
Expand Down
1 change: 0 additions & 1 deletion app/models/hydrus/admin_policy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Hydrus::AdminPolicyObject < Dor::AdminPolicyObject
include Hydrus::Validatable
include Hydrus::Processable
include Hydrus::Contentable
include Dor::Publishable
extend Hydrus::Delegatable

has_metadata(
Expand Down
18 changes: 18 additions & 0 deletions app/models/hydrus/desc_metadata_ds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ def self.xml_template
end.doc
end

# Required by the indexer. This is something that Dor::DescMetadataDS has
# intended for read-access, "as SearchWorks would see it", mostly for to_solr()
# @param [Nokogiri::XML::Document] content Nokogiri descMetadata document (overriding internal data)
# @param [boolean] ns_aware namespace awareness toggle for from_nk_node()
def stanford_mods(content = nil, ns_aware = true)
@stanford_mods ||= begin
m = Stanford::Mods::Record.new
desc = content.nil? ? ng_xml : content
m.from_nk_node(desc.root, ns_aware)
m
end
end

# This is something the Dor::DescMetadataDS has and the indexer expects of this class
def full_title
stanford_mods.sw_title_display
end

# This provides the prefix for the solr fields generated by ActiveFedora.
# Since we don't want a prefix, we override this to return an empty string.
def prefix
Expand Down
2 changes: 1 addition & 1 deletion app/models/hydrus/processable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Hydrus::Processable
REPO = 'dor'

def workflow_client
@workflow_client ||= Dor::Workflow::Client.new(url: Settings.workflow.url)
Dor::Config.workflow.client
end

# Takes the name of a step in the Hydrus workflow.
Expand Down
14 changes: 14 additions & 0 deletions app/models/hydrus/rights_metadata_ds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ def self.xml_template
}
end.doc
end

# Copied in from Dor::Services because this is an interface that the rights metadata is supposed to implement
def rights
xml = ng_xml
if xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length == 1
'Stanford'
elsif xml.search('//rightsMetadata/access[@type=\'read\']/machine/world').length == 1
'World'
elsif xml.search('//rightsMetadata/access[@type=\'discover\']/machine/none').length == 1
'Dark'
else
'None'
end
end
end
2 changes: 1 addition & 1 deletion app/models/hydrus/workflow_ds_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_workflow_step(step)
end

# Takes the name of a hydrusAssemblyWF step.
# Returns the staus of the corresponding process node.
# Returns the status of the corresponding process node.
def get_workflow_status(step)
node = get_workflow_step(step)
node && node['status']
Expand Down
1 change: 0 additions & 1 deletion config/initializers/dor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
end

solr.url Settings.solr.url
sdr.url Settings.sdr.url

hydrus do
initial_apo_title 'Intial Hydrus APO title'
Expand Down
6 changes: 2 additions & 4 deletions config/initializers/rights_overrides.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Dor
module Publishable
class Abstract
# need to override if we want to use the Hydra access permissions code
included do
has_metadata name: 'rightsMetadata', type: Hydra::Datastream::RightsMetadata, label: 'Rights Metadata'
end
has_metadata name: 'rightsMetadata', type: Hydra::Datastream::RightsMetadata, label: 'Rights Metadata'
end
end
5 changes: 1 addition & 4 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ stacks:

solr:
url: 'https://solr.example.com/solr/collection'

sdr:
url: 'https://sdr.example.com/solr/collection'


suri:
url: 'http://localhost:3002'
user: ~
Expand Down
40 changes: 21 additions & 19 deletions spec/features/models/item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'spec_helper'

describe(Hydrus::Item, type: :feature, integration: true) do
describe('Content metadata generation') do
it 'should be able to generate content metadata, returning blank CM when no files exist and setting content metadata stream to a blank template' do
RSpec.describe Hydrus::Item, type: :feature, integration: true do
describe 'Content metadata generation' do
it 'generates content metadata, returning blank CM when no files exist and setting content metadata stream to a blank template' do
xml = '<contentMetadata objectId="__DO_NOT_USE__" type="file"/>'
hi = Hydrus::Item.new pid: '__DO_NOT_USE__'
hi.update_content_metadata
expect(hi.datastreams['contentMetadata'].content).to be_equivalent_to(xml)
end

it 'should be able to generate content metadata, returning and setting correct cm when files exist' do
it 'generates content metadata, returning and setting correct cm when files exist' do
item = Hydrus::Item.find('druid:oo000oo0001')
expect(item.files.size).to eq(4)
expect(item.datastreams['contentMetadata'].content).to be_equivalent_to '<contentMetadata></contentMetadata>'
Expand Down Expand Up @@ -55,7 +55,7 @@
Dor::Config.configure.suri.mint_ids = @prev_mint_ids
end

it 'should accept the terms for an item, updating the appropriate hydrusProperties metadata in item and collection' do
it 'accepts the terms for an item, updating the appropriate hydrusProperties metadata in item and collection' do
expect(item.requires_terms_acceptance(user_key, collection)).to eq(true)
expect(item.accepted_terms_of_deposit).to eq('false')
expect(collection.users_accepted_terms_of_deposit.keys.include?(user_key)).to eq(false)
Expand All @@ -70,31 +70,33 @@

describe 'do_publish()' do
let(:user) { create :archivist1 }

let(:mock_wf_client) { instance_double(Dor::Workflow::Client) }

before(:each) do
let(:wfs) do
instance_double(Dor::Workflow::Client,
all_workflows_xml: '',
milestones: [],
update_workflow_status: nil,
create_workflow_by_name: nil)
end
before do
@prev_mint_ids = config_mint_ids()
allow(Dor::Workflow::Client).to receive(:new).and_return(mock_wf_client)
allow(mock_wf_client).to receive(:create_workflow_by_name)
allow(mock_wf_client).to receive(:update_workflow_status)
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end

after(:each) do
after do
config_mint_ids(@prev_mint_ids)
end

it 'should modify workflows as expected' do
it 'modifies workflows' do
druid = 'druid:oo000oo0003'
hi = ItemService.create(druid, user)
allow(hi).to receive(:should_start_assembly_wf).and_return(true)
allow(hi).to receive(:is_assemblable).and_return(true)
hi.do_publish()
expect(mock_wf_client).to have_received(:update_workflow_status).with('dor', hi.pid,
'hydrusAssemblyWF', 'approve', 'completed')
expect(mock_wf_client).to have_received(:update_workflow_status).with('dor', hi.pid,
'hydrusAssemblyWF', 'start-assembly', 'completed')
expect(mock_wf_client).to have_received(:create_workflow_by_name).with(hi.pid, 'assemblyWF')
expect(wfs).to have_received(:update_workflow_status).with('dor', hi.pid,
'hydrusAssemblyWF', 'approve', 'completed')
expect(wfs).to have_received(:update_workflow_status).with('dor', hi.pid,
'hydrusAssemblyWF', 'start-assembly', 'completed')
expect(wfs).to have_received(:create_workflow_by_name).with(hi.pid, 'assemblyWF')
end
end

Expand Down
62 changes: 44 additions & 18 deletions spec/models/hydrus/processable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
require 'spec_helper'

describe Hydrus::Processable, type: :model do
let(:mock_wf_client) { instance_double(Dor::Workflow::Client) }

before(:each) do
RSpec.describe Hydrus::Processable, type: :model do
before do
@cannot_do_regex = /\ACannot perform action/
@go = Hydrus::GenericObject.new
allow(Dor::Workflow::Client).to receive(:new).and_return(mock_wf_client)
allow(mock_wf_client).to receive(:update_workflow_status)
end

describe 'complete_workflow_step()' do
let(:wfs) { instance_double(Dor::Workflow::Client) }
before do
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end

it 'can exercise the method, stubbing out call to WF service' do
step = 'submit'
args = ['dor', @go.pid, 'hydrusAssemblyWF', step, 'completed']
expect(mock_wf_client).to receive(:update_workflow_status).with(*args)
expect(wfs).to receive(:update_workflow_status).with(*args)
allow(@go).to receive_message_chain(:workflows, :workflow_step_is_done).and_return(false)
expect(@go).to receive(:workflows_content_is_stale)
@go.complete_workflow_step(step)
end
end

it 'can exercise start_hydrus_wf() stubbed' do
expect(mock_wf_client).to receive(:create_workflow_by_name).with(@go.pid, 'hydrusAssemblyWF')
@go.start_hydrus_wf()
describe '#start_hydrus_wf' do
subject(:start_hydrus_wf) { @go.start_hydrus_wf }

let(:wfs) { instance_double(Dor::Workflow::Client, create_workflow_by_name: true) }

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

it 'creates a workflow' do
start_hydrus_wf
expect(wfs).to have_received(:create_workflow_by_name).with(@go.pid, 'hydrusAssemblyWF')
end
end

it 'can exercise workflows_content_is_stale, stubbed' do
Expand Down Expand Up @@ -60,10 +71,15 @@
end
end

describe 'start_assembly_wf()' do
it 'should do nothing if the app is not configured to start assemblyWF' do
describe '#start_assembly_wf' do
let(:wfs) { instance_double(Dor::Workflow::Client) }
before do
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end

it 'does nothing if the app is not configured to start assemblyWF' do
allow(@go).to receive(:should_start_assembly_wf).and_return(false)
expect(Dor::Workflow::Client).not_to receive(:create_workflow_by_name)
expect(wfs).not_to receive(:create_workflow_by_name)
@go.start_assembly_wf
end

Expand All @@ -73,6 +89,11 @@
end

describe 'is_accessioned()' do
let(:wfs) { instance_double(Dor::Workflow::Client) }
before do
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end

it 'can exercise all logic branches' do
# At each stage, we set a stub, call is_accessioned(), and then reverse the stub.
# Not published: false.
Expand All @@ -84,19 +105,24 @@
expect(@go.is_accessioned).to eq(true)
allow(@go).to receive(:should_treat_as_accessioned).and_return(false)
# Never accessioned: false.
allow(mock_wf_client).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(false)
allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(false)
expect(@go.is_accessioned).to eq(false)
allow(mock_wf_client).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(true)
allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(true)
# AccessionWF active for current version: true
allow(mock_wf_client).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(true)
allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(true)
expect(@go.is_accessioned).to eq(false)
allow(mock_wf_client).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(false)
allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(false)
# Survived all tests: true.
expect(@go.is_accessioned).to eq(true)
end
end

describe 'publish_time()' do
let(:wfs) { instance_double(Dor::Workflow::Client) }
before do
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end

it 'development and test mode: 1 day after submitted_for_publish_time' do
spt = '2013-02-27T00:38:22Z'
exp = '2013-02-28T00:38:22Z'
Expand All @@ -107,7 +133,7 @@
it 'production mode: query workflow service' do
allow(@go).to receive(:should_treat_as_accessioned).and_return(false)
exp = '2000-02-01T00:30:00Z'
allow(mock_wf_client).to receive(:lifecycle).and_return(exp)
allow(wfs).to receive(:lifecycle).and_return(exp)
expect(@go.publish_time).to eq(exp)
end
end
Expand Down

0 comments on commit 83d4953

Please sign in to comment.