sufia-models 6.5.0 → 6.6.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: cb23478c793f2a811406c6a0300325276c116bb8
4
- data.tar.gz: 671a29122bf7e91f98cbf19907ff40d10865ed41
3
+ metadata.gz: 5003a564167c7def27510e562932d48c1da6d9de
4
+ data.tar.gz: 042427fade03dc5c1db99556b1ba5ed5d4588497
5
5
  SHA512:
6
- metadata.gz: e51fb60eba9f67dcff1df790fa046fe9d1d7aa30f0bdcc0fbfd2a1019ccc0ae9996591ea45d568c75d1810cfebbaa8ba17dbc9be95c7ee788c613afc93db0f92
7
- data.tar.gz: 10ec3b2d84b8e8b78541070b2702a0f237bad8958f1ae696e3d638364b3313bdfcd95316a588e4045a6dbbd859bb45137931571fcc0943283e079070a08ae563
6
+ metadata.gz: 654344b3315b6676b8930f570551e9c80c1894a2d6cecb51720415bf670757401a9b10eba279b9e4f3f4be19b29e95c8736e49a4923d350abdccdb1f1b9df59d
7
+ data.tar.gz: ac5f4c4950ef94041df7b28f598bc429e2eca52c642877a53dbf956ac04321e0076759bc9bac329e4927e9e09935de9de3fe03ae8b7f395fe58ec0228c83c6fd
@@ -1,6 +1,8 @@
1
1
  module Sufia::GenericFile
2
2
  # Actions are decoupled from controller logic so that they may be called from a controller or a background job.
3
3
  class Actor
4
+ include Sufia::Lockable
5
+
4
6
  attr_reader :generic_file, :user
5
7
 
6
8
  def initialize(generic_file, user)
@@ -42,9 +44,9 @@ module Sufia::GenericFile
42
44
 
43
45
  def add_file_to_collection(collection_id)
44
46
  return if collection_id.nil? || collection_id == "-1"
45
- collection = Collection.find(collection_id)
46
- return unless user.can? :edit, collection
47
47
  acquire_lock_for(collection_id) do
48
+ collection = ::Collection.find(collection_id)
49
+ return unless user.can? :edit, collection
48
50
  collection.add_members [generic_file.id]
49
51
  collection.save
50
52
  end
@@ -142,16 +144,5 @@ module Sufia::GenericFile
142
144
  featured_work = FeaturedWork.find_by_generic_file_id(generic_file.id)
143
145
  featured_work.destroy unless featured_work.nil?
144
146
  end
145
-
146
- def acquire_lock_for(lock_key, &block)
147
- lock_manager.lock(lock_key, &block)
148
- end
149
-
150
- def lock_manager
151
- @lock_manager ||= Sufia::LockManager.new(
152
- Sufia.config.lock_time_to_live,
153
- Sufia.config.lock_retry_count,
154
- Sufia.config.lock_retry_delay)
155
- end
156
147
  end
157
148
  end
@@ -13,8 +13,8 @@ class ActiveFedoraIdBasedJob
13
13
  @object ||= ActiveFedora::Base.find(id)
14
14
  end
15
15
 
16
- alias_method :generic_file, :object
17
- alias_method :generic_file_id, :id
16
+ alias generic_file object
17
+ alias generic_file_id id
18
18
 
19
19
  def run
20
20
  raise "Define #run in a subclass"
@@ -3,8 +3,8 @@ class AuditJob < ActiveFedoraIdBasedJob
3
3
  :audit
4
4
  end
5
5
 
6
- PASS = 'Passing Audit Run'
7
- FAIL = 'Failing Audit Run'
6
+ PASS = 'Passing Audit Run'.freeze
7
+ FAIL = 'Failing Audit Run'.freeze
8
8
 
9
9
  attr_accessor :uri, :id, :path
10
10
 
@@ -44,6 +44,7 @@ class BatchUpdateJob
44
44
  # @param [GenericFile] gf
45
45
  def queue_additional_jobs(gf)
46
46
  Sufia.queue.push(ContentUpdateEventJob.new(gf.id, login))
47
+ Sufia.queue.push(ResolrizeGenericFileJob.new(gf.id)) unless Sufia.config.collection_facet.nil?
47
48
  end
48
49
 
49
50
  def send_user_success_message
@@ -2,6 +2,7 @@ class Batch < ActiveFedora::Base
2
2
  include Hydra::AccessControls::Permissions
3
3
  include Sufia::ModelMethods
4
4
  include Sufia::Noid
5
+ extend Sufia::Lockable
5
6
 
6
7
  has_many :generic_files, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
7
8
 
@@ -9,22 +10,14 @@ class Batch < ActiveFedora::Base
9
10
  property :title, predicate: ::RDF::DC.title
10
11
  property :status, predicate: ::RDF::DC.type
11
12
 
12
- def self.find_or_create(id)
13
- Batch.find(id)
14
- rescue ActiveFedora::ObjectNotFoundError
15
- safe_create(id)
16
- end
17
-
18
13
  # This method handles most race conditions gracefully.
19
- # If a batch with the same ID is created by another thread
20
- # we fetch the batch that was created (rather than throwing
21
- # an error) and continute.
22
- def self.safe_create(id)
23
- Batch.create(id: id)
24
- rescue ActiveFedora::IllegalOperation
25
- # This is the exception thrown by LDP when we attempt to
26
- # create a duplicate object. If we can find the object
27
- # then we are good to go.
28
- Batch.find(id)
14
+ def self.find_or_create(id)
15
+ acquire_lock_for(id) do
16
+ begin
17
+ Batch.find(id)
18
+ rescue ActiveFedora::ObjectNotFoundError
19
+ Batch.create(id: id)
20
+ end
21
+ end
29
22
  end
30
23
  end
@@ -47,12 +47,12 @@ module Sufia::User
47
47
  end
48
48
 
49
49
  def zotero_token=(value)
50
- if value.blank?
51
- # Resetting the token
52
- self[:zotero_token] = value
53
- else
54
- self[:zotero_token] = Marshal.dump(value)
55
- end
50
+ self[:zotero_token] = if value.blank?
51
+ # Resetting the token
52
+ value
53
+ else
54
+ Marshal.dump(value)
55
+ end
56
56
  end
57
57
 
58
58
  def set_arkivo_token
@@ -18,13 +18,12 @@ module Sufia
18
18
 
19
19
  # Blocks until lock is acquired or timeout.
20
20
  def lock(key)
21
+ returned_from_block = nil
21
22
  client.lock(key, @ttl) do |locked|
22
- if locked
23
- yield
24
- else
25
- raise UnableToAcquireLockError
26
- end
23
+ raise UnableToAcquireLockError unless locked
24
+ returned_from_block = yield
27
25
  end
26
+ returned_from_block
28
27
  end
29
28
 
30
29
  private
@@ -0,0 +1,16 @@
1
+ module Sufia
2
+ module Lockable
3
+ extend ActiveSupport::Concern
4
+
5
+ def acquire_lock_for(lock_key, &block)
6
+ lock_manager.lock(lock_key, &block)
7
+ end
8
+
9
+ def lock_manager
10
+ @lock_manager ||= Sufia::LockManager.new(
11
+ Sufia.config.lock_time_to_live,
12
+ Sufia.config.lock_retry_count,
13
+ Sufia.config.lock_retry_delay)
14
+ end
15
+ end
16
+ end
@@ -12,11 +12,11 @@ class Sufia::Models::AbstractMigrationGenerator < Rails::Generators::Base
12
12
  @prev_migration_nr += 1
13
13
  else
14
14
  last_migration = Dir[File.join(path, '*.rb')].sort.last
15
- if last_migration
16
- @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
17
- else
18
- @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
19
- end
15
+ @prev_migration_nr = if last_migration
16
+ last_migration.sub(File.join(path, '/'), '').to_i + 1
17
+ else
18
+ Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
19
+ end
20
20
  end
21
21
  @prev_migration_nr.to_s
22
22
  end
@@ -71,6 +71,7 @@ module Sufia
71
71
  require 'sufia/analytics'
72
72
  require 'sufia/pageview'
73
73
  require 'sufia/download'
74
+ require 'sufia/lockable'
74
75
  end
75
76
 
76
77
  initializer 'configure' do
@@ -22,12 +22,12 @@ module Sufia
22
22
  # @yeild block [] code you want to run and retry
23
23
  #
24
24
  # @return result of the block call
25
- def retry_unless(number_of_tries, condition, &block)
25
+ def retry_unless(number_of_tries, condition, &_block)
26
26
  raise ArgumentError, "First argument must be an enumerator" unless number_of_tries.is_a? Enumerator
27
27
  raise ArgumentError, "Second argument must be a lambda" unless condition.respond_to? :call
28
28
  raise ArgumentError, "Must pass a block of code to retry" unless block_given?
29
29
  number_of_tries.each do
30
- result = block.call
30
+ result = yield
31
31
  return result unless condition.call
32
32
  sleep(Sufia.config.retry_unless_sleep) if Sufia.config.retry_unless_sleep > 0
33
33
  end
@@ -1,5 +1,5 @@
1
1
  module Sufia
2
2
  module Models
3
- VERSION = "6.5.0"
3
+ VERSION = "6.6.0".freeze
4
4
  end
5
5
  end
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'rails', '~> 4.0'
30
30
  spec.add_dependency 'activeresource', "~> 4.0" # No longer a dependency of rails 4.0
31
31
 
32
- spec.add_dependency "hydra-head", "~> 9.0"
32
+ spec.add_dependency "hydra-head", "< 9.6"
33
33
  spec.add_dependency "active-fedora", "~> 9.4"
34
34
  spec.add_dependency "hydra-collections", [">= 5.0.3", "< 6.0"]
35
35
  spec.add_dependency 'hydra-derivatives', '~> 1.0'
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency 'acts_as_follower', '>= 0.1.1', '< 0.3'
42
42
  spec.add_dependency 'carrierwave', '~> 0.9'
43
43
  spec.add_dependency 'oauth2', '~> 0.9'
44
- spec.add_dependency 'google-api-client', '~> 0.7'
44
+ spec.add_dependency 'google-api-client', '~> 0.7', '< 0.9'
45
45
  spec.add_dependency 'legato', '~> 0.3'
46
46
  spec.add_dependency 'activerecord-import', '~> 0.5'
47
47
  if RUBY_VERSION < '2.1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sufia-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.5.0
4
+ version: 6.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: hydra-head
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: '9.0'
75
+ version: '9.6'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: '9.0'
82
+ version: '9.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: active-fedora
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,9 @@ dependencies:
253
253
  - - "~>"
254
254
  - !ruby/object:Gem::Version
255
255
  version: '0.7'
256
+ - - "<"
257
+ - !ruby/object:Gem::Version
258
+ version: '0.9'
256
259
  type: :runtime
257
260
  prerelease: false
258
261
  version_requirements: !ruby/object:Gem::Requirement
@@ -260,6 +263,9 @@ dependencies:
260
263
  - - "~>"
261
264
  - !ruby/object:Gem::Version
262
265
  version: '0.7'
266
+ - - "<"
267
+ - !ruby/object:Gem::Version
268
+ version: '0.9'
263
269
  - !ruby/object:Gem::Dependency
264
270
  name: legato
265
271
  requirement: !ruby/object:Gem::Requirement
@@ -395,6 +401,7 @@ files:
395
401
  - app/services/sufia/generic_file_csv_service.rb
396
402
  - app/services/sufia/generic_file_indexing_service.rb
397
403
  - app/services/sufia/lock_manager.rb
404
+ - app/services/sufia/lockable.rb
398
405
  - app/services/sufia/noid.rb
399
406
  - app/services/sufia/repository_audit_service.rb
400
407
  - config/locales/sufia.en.yml
@@ -500,7 +507,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
500
507
  version: '0'
501
508
  requirements: []
502
509
  rubyforge_project:
503
- rubygems_version: 2.4.5
510
+ rubygems_version: 2.2.2
504
511
  signing_key:
505
512
  specification_version: 4
506
513
  summary: Models and services for sufia