From a21cf0c1f0941b391fc5b41ef0526a1a03544912 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 22 Apr 2019 11:46:04 -0500 Subject: [PATCH] Move the Sdr::Client to dor-services-app --- .rubocop_todo.yml | 8 ----- lib/dor-services.rb | 1 - lib/dor/config.rb | 3 -- lib/dor/utils/sdr_client.rb | 35 ------------------- spec/utils/sdr_client_spec.rb | 63 ----------------------------------- 5 files changed, 110 deletions(-) delete mode 100644 lib/dor/utils/sdr_client.rb delete mode 100644 spec/utils/sdr_client_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0901b61e..7787e9e2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -195,14 +195,6 @@ RSpec/DescribeClass: - 'spec/models/concerns/releaseable_no_vcr_spec.rb' - 'spec/services/cleanup_service_filesystem_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: SkipBlocks, EnforcedStyle. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Exclude: - - 'spec/utils/sdr_client_spec.rb' - # Offense count: 131 # Configuration parameters: Max. RSpec/ExampleLength: diff --git a/lib/dor-services.rb b/lib/dor-services.rb index 7c5b2bda..1a60b6c9 100644 --- a/lib/dor-services.rb +++ b/lib/dor-services.rb @@ -4,7 +4,6 @@ require 'active_fedora/version' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/object/blank' -require 'dor/utils/sdr_client' module Dor extend ActiveSupport::Autoload diff --git a/lib/dor/config.rb b/lib/dor/config.rb index 8ccf3a38..1880435d 100644 --- a/lib/dor/config.rb +++ b/lib/dor/config.rb @@ -63,9 +63,6 @@ def make_solr_connection(add_opts = {}) purl_services: { rest_client: Confstruct.deferred { |_c| RestResourceFactory.create(:purl_services) } }, - sdr: { - rest_client: Confstruct.deferred { |_c| RestResourceFactory.create(:sdr) } - }, workflow: { client: Confstruct.deferred do |c| @wfs ||= Dor::Workflow::Client.new(url: c.url, logger: c.client_logger, timeout: c.timeout) diff --git a/lib/dor/utils/sdr_client.rb b/lib/dor/utils/sdr_client.rb deleted file mode 100644 index cf02c67c..00000000 --- a/lib/dor/utils/sdr_client.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'moab' -module Sdr - class Client - class << self - # @param [String] druid id of the object you want the version of - # @return [Integer] the current version from SDR - def current_version(druid) - xml = client["objects/#{druid}/current_version"].get - - begin - doc = Nokogiri::XML xml - raise if doc.root.name != 'currentVersion' - - return Integer(doc.text) - rescue StandardError - raise "Unable to parse XML from SDR current_version API call: #{xml}" - end - end - - def client - if Dor::Config.sdr.url - # dor-services-app takes this path - Dor::Config.sdr.rest_client - elsif Dor::Config.dor_services.url - # Anything that is not dor-servics-app should be through here. - raise 'you are using dor-services to invoke calls to dor-services-app. Use dor-services-client instead.' - else - raise Dor::ParameterError, 'Missing Dor::Config.sdr and/or Dor::Config.dor_services configuration' - end - end - end - end -end diff --git a/spec/utils/sdr_client_spec.rb b/spec/utils/sdr_client_spec.rb deleted file mode 100644 index 652d8dc4..00000000 --- a/spec/utils/sdr_client_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'dor/utils/sdr_client' - -RSpec.describe Sdr::Client do - describe '.get_current_version' do - it 'returns the current of the object from SDR' do - stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) - .to_return(body: '2') - expect(described_class.current_version('druid:ab123cd4567')).to eq 2 - end - - context 'raises an exception if the xml' do - it 'has the wrong root element' do - stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) - .to_return(body: '2') - expect { described_class.current_version('druid:ab123cd4567') } - .to raise_error(Exception, 'Unable to parse XML from SDR current_version API call: 2') - end - - it 'does not contain an Integer as its text' do - stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) - .to_return(body: 'two') - expect { described_class.current_version('druid:ab123cd4567') } - .to raise_error(Exception, 'Unable to parse XML from SDR current_version API call: two') - end - end - end - - describe '.client' do - context 'with SDR configuration' do - before do - allow(Dor::Config.sdr).to receive(:url).and_return('http://example.com') - end - - it 'is configured to use SDR' do - expect(described_class.client.url).to eq 'http://example.com' - end - end - - context 'with DOR services configuration' do - before do - allow(Dor::Config.sdr).to receive(:url).and_return(nil) - end - - it 'is configured to use SDR' do - expect { Sdr::Client.client }.to raise_error 'you are using dor-services to invoke calls to dor-services-app. Use dor-services-client instead.' - end - end - - context 'without any configuration' do - before do - allow(Dor::Config.sdr).to receive(:url).and_return(nil) - allow(Dor::Config.dor_services).to receive(:url).and_return(nil) - end - - it 'raises an exception' do - expect { described_class.client }.to raise_error Dor::ParameterError - end - end - end -end