active-fedora 9.11.0 → 9.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bce277ca040d2e5d2b6f20ad12ded43a0d09a81e
4
- data.tar.gz: 41626c552b9571d1993bc95f3719a0b12a24eb5b
3
+ metadata.gz: 02fb3ee9bf393052113ffdd4082e741bc155266c
4
+ data.tar.gz: 674c9e4a7a00220c1bb2011414dfdaf841b76100
5
5
  SHA512:
6
- metadata.gz: b48ed0579be52f0683f6293adc4ff4908706d125f924119cabc2e01076bfcf2501e7732ef9b057948f6aeffd0f10679626d033aab52313523839020005d543ac
7
- data.tar.gz: 2dfa7a8abb57bc8dc376da0767fd5d70ecf13bc9bbcb6f0542faaad5b8d70973367c1f81776aa8e4e704655029676b9ec124836f3736d1940c36a7e470b3092d
6
+ metadata.gz: 8e8c4e554a899aa3109de27b30dfb1a64b0c3954cf2ad4c2e7c255413ed27bf8242ed8bd951f8364c18a92d49f346f800ffed9e52abc7af507143eff1e5631e2
7
+ data.tar.gz: e5d93de8c674af3aa2f27dc18a52c06bf35afd3a0e9ab0b4ad01522664015e86e8e83faa4938ec5dda2ee16df5f76bec22229f9c3c8557e6f89fcf7f41b87a58
@@ -88,6 +88,7 @@ Metrics/ClassLength:
88
88
  - 'lib/active_fedora/associations/collection_association.rb'
89
89
  - 'lib/active_fedora/reflection.rb'
90
90
  - 'lib/active_fedora/orders/ordered_list.rb'
91
+ - 'lib/active_fedora/solr_service.rb'
91
92
 
92
93
  Metrics/MethodLength:
93
94
  Enabled: false
@@ -122,6 +122,7 @@ module ActiveFedora #:nodoc:
122
122
  autoload :FinderMethods
123
123
  end
124
124
 
125
+ autoload :RuntimeRegistry
125
126
  autoload :Schema
126
127
  autoload :Scoping
127
128
  autoload :Serialization
@@ -170,6 +171,8 @@ module ActiveFedora #:nodoc:
170
171
  end
171
172
  end
172
173
 
174
+ extend Deprecation
175
+
173
176
  class << self
174
177
  attr_reader :fedora_config, :solr_config, :config_options
175
178
  attr_accessor :configurator
@@ -231,11 +234,12 @@ module ActiveFedora #:nodoc:
231
234
  end
232
235
 
233
236
  def reset_fedora!
234
- @fedora = nil
237
+ Deprecation.warn(ActiveFedora, 'ActiveFedora.reset_fedora! is deprecated; use ActiveFedora::Fedora.reset! instead. This will be removed in active-fedora 10.0')
238
+ ActiveFedora::Fedora.reset!
235
239
  end
236
240
 
237
241
  def fedora
238
- @fedora ||= Fedora.new(fedora_config.credentials)
242
+ ActiveFedora::Fedora.instance
239
243
  end
240
244
 
241
245
  delegate :predicate_config, to: :configurator
@@ -103,11 +103,11 @@ module ActiveFedora
103
103
  other_array.each { |val| raise_on_type_mismatch!(val) }
104
104
 
105
105
  load_target
106
- other = other_array.size < 100 ? other_array : other_array.to_set
107
- current = @target.size < 100 ? @target : @target.to_set
106
+ deletions = @target - other_array
107
+ additions = other_array - @target
108
108
 
109
- delete(@target.select { |v| !other.include?(v) })
110
- concat(other_array.select { |v| !current.include?(v) })
109
+ delete(deletions)
110
+ concat(additions)
111
111
  end
112
112
 
113
113
  def include?(record)
@@ -254,7 +254,7 @@ module ActiveFedora
254
254
  end
255
255
 
256
256
  def add_to_target(record, skip_callbacks = false)
257
- # transaction do
257
+ # Start transaction
258
258
  callback(:before_add, record) unless skip_callbacks
259
259
  yield(record) if block_given?
260
260
 
@@ -266,7 +266,7 @@ module ActiveFedora
266
266
 
267
267
  callback(:after_add, record) unless skip_callbacks
268
268
  set_inverse_instance(record)
269
- # end
269
+ # End transaction
270
270
 
271
271
  record
272
272
  end
@@ -14,7 +14,6 @@ module ActiveFedora
14
14
  return false unless record.save(validate: validate)
15
15
  end
16
16
  end
17
-
18
17
  owner[reflection.foreign_key] ||= []
19
18
  owner[reflection.foreign_key] += [record.id]
20
19
 
@@ -4,11 +4,12 @@ module ActiveFedora
4
4
  def replace(values)
5
5
  ids = Array(values).reject(&:blank?)
6
6
  raise "can't modify frozen #{owner.class}" if owner.frozen?
7
- destroy
8
- ids.each do |id|
9
- uri = ::RDF::URI(ActiveFedora::Base.id_to_uri(id))
10
- owner.resource.insert [owner.rdf_subject, reflection.predicate, uri]
11
- end
7
+ current_objects = filtered_results
8
+ incoming_objects = ids.map { |id| ::RDF::URI(ActiveFedora::Base.id_to_uri(id)) }
9
+ deletions = current_objects - incoming_objects
10
+ additions = incoming_objects - current_objects
11
+ deletions.each { |object| owner.resource.delete([owner.rdf_subject, reflection.predicate, object]) }
12
+ additions.each { |object| owner.resource.insert([owner.rdf_subject, reflection.predicate, object]) }
12
13
  owner.send(:attribute_will_change!, reflection.name)
13
14
  end
14
15
 
@@ -44,7 +44,7 @@ module ActiveFedora
44
44
  end
45
45
 
46
46
  def self.reinitialize_repo
47
- ActiveFedora.reset_fedora!
47
+ ActiveFedora::Fedora.reset!
48
48
  end
49
49
 
50
50
  def self.log(message)
@@ -1,5 +1,21 @@
1
1
  module ActiveFedora
2
2
  class Fedora
3
+ class << self
4
+ def register(options = {})
5
+ ActiveFedora::RuntimeRegistry.fedora_connection = Fedora.new(ActiveFedora.fedora_config.credentials.merge(options))
6
+ end
7
+
8
+ def instance
9
+ register unless ActiveFedora::RuntimeRegistry.fedora_connection
10
+
11
+ ActiveFedora::RuntimeRegistry.fedora_connection
12
+ end
13
+
14
+ def reset!
15
+ ActiveFedora::RuntimeRegistry.fedora_connection = nil
16
+ end
17
+ end
18
+
3
19
  def initialize(config)
4
20
  @config = config
5
21
  end
@@ -24,7 +24,7 @@ module ActiveFedora::File::Streaming
24
24
 
25
25
  def each(no_of_requests_limit = 3, &block)
26
26
  raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit == 0
27
- Net::HTTP.start(uri.host, uri.port) do |http|
27
+ Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
28
28
  request = Net::HTTP::Get.new uri, headers
29
29
  http.request request do |response|
30
30
  case response
@@ -0,0 +1,9 @@
1
+ require 'active_support/per_thread_registry'
2
+
3
+ module ActiveFedora
4
+ class RuntimeRegistry
5
+ extend ActiveSupport::PerThreadRegistry
6
+
7
+ attr_accessor :solr_service, :fedora_connection
8
+ end
9
+ end
@@ -21,6 +21,7 @@ module ActiveFedora
21
21
  attr_reader :document
22
22
 
23
23
  def initialize(document)
24
+ document = document.with_indifferent_access
24
25
  super
25
26
  @document = document
26
27
  end
@@ -5,22 +5,34 @@ module ActiveFedora
5
5
  class SolrService
6
6
  extend Deprecation
7
7
 
8
- attr_reader :conn
8
+ attr_writer :conn
9
9
 
10
- def initialize(host, args)
11
- host = 'http://localhost:8080/solr' unless host
12
- args = { read_timeout: 120, open_timeout: 120 }.merge(args.dup)
13
- args[:url] = host
14
- @conn = RSolr.connect args
10
+ def initialize(options = {})
11
+ @options = { read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge(options)
12
+ end
13
+
14
+ def conn
15
+ @conn ||= RSolr.connect @options
15
16
  end
16
17
 
17
18
  class << self
18
- def register(host = nil, args = {})
19
- Thread.current[:solr_service] = new(host, args)
19
+ def register(*args)
20
+ options = args.extract_options!
21
+
22
+ if args.length == 1
23
+ Deprecation.warn(SolrService, "SolrService.register with a host argument is deprecated. Use `SolrService.register(url: host)` instead. This will be removed in active-fedora 10.0")
24
+
25
+ host = args.first
26
+ options[:url] = host if host
27
+ elsif args.length > 1
28
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)"
29
+ end
30
+
31
+ ActiveFedora::RuntimeRegistry.solr_service = new(options)
20
32
  end
21
33
 
22
34
  def reset!
23
- Thread.current[:solr_service] = nil
35
+ ActiveFedora::RuntimeRegistry.solr_service = nil
24
36
  end
25
37
 
26
38
  def select_path
@@ -30,12 +42,11 @@ module ActiveFedora
30
42
  def instance
31
43
  # Register Solr
32
44
 
33
- unless Thread.current[:solr_service]
34
- register(ActiveFedora.solr_config[:url], ActiveFedora.solr_config)
45
+ unless ActiveFedora::RuntimeRegistry.solr_service
46
+ register(ActiveFedora.solr_config)
35
47
  end
36
48
 
37
- raise SolrNotInitialized unless Thread.current[:solr_service]
38
- Thread.current[:solr_service]
49
+ ActiveFedora::RuntimeRegistry.solr_service
39
50
  end
40
51
 
41
52
  def lazy_reify_solr_results(solr_results, opts = {})
@@ -150,5 +161,4 @@ module ActiveFedora
150
161
  end
151
162
  end
152
163
  end # SolrService
153
- class SolrNotInitialized < StandardError; end
154
164
  end # ActiveFedora
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.11.0".freeze
2
+ VERSION = "9.12.0".freeze
3
3
  end
@@ -24,8 +24,7 @@ describe ActiveFedora::SolrHit do
24
24
  title: 'My Title'
25
25
  ) }
26
26
 
27
- let(:profile) { { "foo" => ["baz"], "bar" => "quix", "title" => "My Title" }.to_json }
28
- let(:doc) { { 'id' => 'test-123', 'has_model_ssim' => ['Foo'], 'object_profile_ssm' => profile } }
27
+ let(:doc) { obj.to_solr }
29
28
  let(:solr_hit) { described_class.new(doc) }
30
29
 
31
30
  after do
@@ -44,6 +43,8 @@ describe ActiveFedora::SolrHit do
44
43
  describe "#instantiate_with_json" do
45
44
  subject { solr_hit.instantiate_with_json }
46
45
 
46
+ it { is_expected.to be_persisted }
47
+
47
48
  it "finds the document in solr" do
48
49
  expect(subject).to be_instance_of Foo
49
50
  expect(subject.title).to eq 'My Title'
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::File::Streaming do
4
+ let(:test_class) do
5
+ tc = Class.new
6
+ tc.send(:include, described_class)
7
+ tc
8
+ end
9
+ let(:streamer) do
10
+ streamer = test_class.new
11
+ allow(streamer).to receive(:uri).and_return(uri)
12
+ allow(streamer).to receive(:authorization_key).and_return("authorization_key")
13
+ streamer
14
+ end
15
+
16
+ context "without ssl" do
17
+ let(:uri) { "http://localhost/file/1" }
18
+
19
+ it do
20
+ expect(Net::HTTP).to receive(:start).with('localhost', 80, use_ssl: false).and_return(nil)
21
+ streamer.stream.each
22
+ end
23
+ end
24
+
25
+ context "with ssl" do
26
+ let(:uri) { "https://localhost/file/1" }
27
+
28
+ it do
29
+ expect(Net::HTTP).to receive(:start).with('localhost', 443, use_ssl: true).and_return(nil)
30
+ streamer.stream.each
31
+ end
32
+ end
33
+ end
@@ -2,43 +2,50 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::SolrService do
4
4
  before do
5
- Thread.current[:solr_service] = nil
5
+ described_class.reset!
6
6
  end
7
7
 
8
- after(:all) do
9
- described_class.register(ActiveFedora.solr_config[:url])
8
+ after do
9
+ described_class.reset!
10
10
  end
11
11
 
12
- it "takes a n-arg constructor and configure for localhost" do
13
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr')
14
- described_class.register
15
- end
16
- it "accepts host arg into constructor" do
17
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://fubar')
18
- described_class.register('http://fubar')
19
- end
20
- it "clobbers options" do
21
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr', autocommit: :off, foo: :bar)
22
- described_class.register(nil, autocommit: :off, foo: :bar)
12
+ describe '#conn' do
13
+ it "takes a n-arg constructor and configure for localhost" do
14
+ expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr')
15
+ described_class.register.conn
16
+ end
17
+ it "accepts host arg into constructor" do
18
+ expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://fubar')
19
+ Deprecation.silence(described_class) do
20
+ described_class.register('http://fubar').conn
21
+ end
22
+ end
23
+ it "clobbers options" do
24
+ expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr', autocommit: :off, foo: :bar)
25
+ described_class.register(autocommit: :off, foo: :bar).conn
26
+ end
23
27
  end
24
28
 
25
- it "sets the threadlocal solr service" do
26
- expect(RSolr).to receive(:connect).with(read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr', autocommit: :off, foo: :bar)
27
- ss = described_class.register(nil, autocommit: :off, foo: :bar)
28
- expect(Thread.current[:solr_service]).to eq ss
29
- expect(described_class.instance).to eq ss
30
- end
31
- it "tries to initialize if the service not initialized, and fail if it does not succeed" do
32
- expect(Thread.current[:solr_service]).to be_nil
33
- expect(described_class).to receive(:register)
34
- expect(proc { described_class.instance }).to raise_error(ActiveFedora::SolrNotInitialized)
29
+ describe '#conn=' do
30
+ let(:new_connection) { double }
31
+ it 'is settable' do
32
+ described_class.instance.conn = new_connection
33
+ expect(described_class.instance.conn).to eq new_connection
34
+ end
35
35
  end
36
- it "passes on solr_config when initializing the service" do
37
- allow(RSolr).to receive(:connect)
38
- expect(Thread.current[:solr_service]).to be_nil
39
- allow(ActiveFedora).to receive(:solr_config).and_return(url: 'http://fubar', update_path: 'update_test')
40
- expect(described_class).to receive(:register).with('http://fubar', hash_including(update_path: 'update_test')).and_call_original
41
- described_class.instance
36
+
37
+ describe '.instance' do
38
+ it "sets the threadlocal solr service" do
39
+ ss = described_class.register(autocommit: :off, foo: :bar)
40
+ expect(ActiveFedora::RuntimeRegistry.solr_service).to eq ss
41
+ expect(described_class.instance).to eq ss
42
+ end
43
+ it "passes on solr_config when initializing the service" do
44
+ allow(RSolr).to receive(:connect)
45
+ allow(ActiveFedora).to receive(:solr_config).and_return(url: 'http://fubar', update_path: 'update_test')
46
+ expect(described_class).to receive(:register).with(hash_including(url: 'http://fubar', update_path: 'update_test')).and_call_original
47
+ described_class.instance
48
+ end
42
49
  end
43
50
 
44
51
  describe '#construct_query_for_pids' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.11.0
4
+ version: 9.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-04-15 00:00:00.000000000 Z
13
+ date: 2016-04-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -522,6 +522,7 @@ files:
522
522
  - lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb
523
523
  - lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
524
524
  - lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
525
+ - lib/active_fedora/runtime_registry.rb
525
526
  - lib/active_fedora/schema.rb
526
527
  - lib/active_fedora/schema_indexing_strategy.rb
527
528
  - lib/active_fedora/scoping.rb
@@ -688,6 +689,7 @@ files:
688
689
  - spec/unit/core_spec.rb
689
690
  - spec/unit/default_model_mapper_spec.rb
690
691
  - spec/unit/fedora_spec.rb
692
+ - spec/unit/file/streaming_spec.rb
691
693
  - spec/unit/file_configurator_spec.rb
692
694
  - spec/unit/file_path_builder_spec.rb
693
695
  - spec/unit/file_spec.rb
@@ -763,9 +765,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
763
765
  version: '0'
764
766
  requirements: []
765
767
  rubyforge_project:
766
- rubygems_version: 2.4.5.1
768
+ rubygems_version: 2.5.1
767
769
  signing_key:
768
770
  specification_version: 4
769
771
  summary: A convenience libary for manipulating documents in the Fedora Repository.
770
772
  test_files: []
771
- has_rdoc: