Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge 9c4655c into 36c5a3c
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Dec 21, 2018
2 parents 36c5a3c + 9c4655c commit 4e34f99
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ gem 'jbuilder', '~> 2.0'

gem 'nokogiri'

gem 'faraday'
gem 'okcomputer' # for 'upness' monitoring
gem 'honeybadger' # for exception reporting

# Stanford Gems
gem 'dor-services-client'

group :development do
gem 'sdoc', '~> 0.4.0'
gem 'spring'
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ GEM
capistrano-one_time_key
capistrano-shared_configs
docile (1.3.1)
dor-services-client (0.5.0)
activesupport (>= 4.2, < 6)
faraday (~> 0.15)
nokogiri (~> 1.8)
dry-configurable (0.7.0)
concurrent-ruby (~> 1.0)
dry-container (0.6.0)
Expand Down Expand Up @@ -330,8 +334,8 @@ DEPENDENCIES
config
coveralls
dlss-capistrano
dor-services-client
equivalent-xml
faraday
honeybadger
jbuilder (~> 2.0)
jquery-rails
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/dor_services_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# Configure dor-services-client to use the dor-services URL
Dor::Services::Client.configure(url: Settings.DOR_SERVICES.URL,
username: Settings.DOR_SERVICES.USER,
password: Settings.DOR_SERVICES.PASS)
8 changes: 5 additions & 3 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ seed_apo: 'oo000oo0000'
# this XML is read later by was_robot_suite wasSeedPreassemblyWF step
seed_staging_path: './'

# dor_services_url: dor-services REST API used to register objects.
# format: No trailing slash; '/object' is appended in the code
dor_services_url: 'http://localhost:3000'
# Dor Services Client configuration
DOR_SERVICES:
URL: 'http://localhost:3003'
USER: 'user'
PASS: 'password'

# argo_view_url: prepended to druid; used for links to registered objects in views
# format: yes, trailing slash, e.g. 'https://argo-stage.stanford.edu/catalog/'
Expand Down
19 changes: 3 additions & 16 deletions lib/was/registrar/register_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,14 @@ def register(item_hash)
def register_object_using_web_service(register_params)
Rails.logger.debug "Registering an object with params #{register_params}"
begin
connection = Faraday.new(
url: Settings.dor_services_url,
headers: { accept: 'text/plain' } # we explicitly want text response so the body is only the druid
) do |faraday|
faraday.use Faraday::Response::RaiseError
end

response = connection.post do |req|
req.url = '/objects'
req.body = register_params
req.options.timeout = 300
req.options.open_timeout = 60
end
Rails.logger.debug response.inspect
rescue Faraday::Error => e
response = Dor::Services::Client.register(params: register_params)
rescue Dor::ParameterError, StandardError => e
Rails.logger.error 'Error in registering the object. ' + e.message
Honeybadger.notify(e)
raise
end

druid = response.body
druid = response[:pid]
if valid_druid?(druid)
return druid
else
Expand Down
9 changes: 5 additions & 4 deletions spec/lib/was/registrar/register_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
describe Was::Registrar::RegisterSeedObject do
describe '#register_object_using_web_service' do

let(:dor_registration) { { pid: 'druid:aa111aa1111' } }
let(:invalid_dor_registration) { { pid: 'not_valid_druid' } }

it 'registers object with valid params' do
params = {
object_type: 'item',
Expand All @@ -13,19 +16,17 @@
initiate_workflow: 'wasSeedPreassemblyWF',
rights: 'world'
}
response = double('net http response', to_hash: { 'Status' => ['200 OK'] }, code: 200, body: 'druid:aa111aa1111')

expect_any_instance_of(Faraday::Connection).to receive(:post).and_return(response)
expect(Dor::Services::Client).to receive(:register).and_return(dor_registration)

registrar = Was::Registrar::RegisterObject.new
expect(registrar.register_object_using_web_service(params)).to eq('druid:aa111aa1111')
end

it 'raises an error if the response is not valid druid' do
params = {}
response = double('net http response', to_hash: { 'Status' => ['200 OK'] }, code: 200, body: 'not_valid_druid')

expect_any_instance_of(Faraday::Connection).to receive(:post).and_return(response)
expect(Dor::Services::Client).to receive(:register).and_return(invalid_dor_registration)

registrar = Was::Registrar::RegisterObject.new
exp_regex = /Error in registering the object/
Expand Down

0 comments on commit 4e34f99

Please sign in to comment.