ddr-models 2.5.3 → 2.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/users/sessions_controller.rb +0 -5
  3. data/config/initializers/devise.rb +3 -2
  4. data/config/initializers/rsolr_monkey_patches.rb +7 -0
  5. data/config/initializers/subscriptions.rb +0 -2
  6. data/ddr-models.gemspec +2 -1
  7. data/lib/ddr/actions/virus_check.rb +0 -1
  8. data/lib/ddr/auth.rb +0 -4
  9. data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +9 -16
  10. data/lib/ddr/derivatives/generator.rb +0 -2
  11. data/lib/ddr/derivatives/png_generator.rb +2 -4
  12. data/lib/ddr/derivatives/ptif_generator.rb +6 -7
  13. data/lib/ddr/index/fields.rb +18 -2
  14. data/lib/ddr/jobs.rb +0 -4
  15. data/lib/ddr/managers.rb +0 -1
  16. data/lib/ddr/managers/derivatives_manager.rb +3 -4
  17. data/lib/ddr/managers/workflow_manager.rb +3 -0
  18. data/lib/ddr/models.rb +6 -3
  19. data/lib/ddr/models/base.rb +13 -0
  20. data/lib/ddr/models/has_admin_metadata.rb +4 -20
  21. data/lib/ddr/models/indexing.rb +16 -0
  22. data/lib/ddr/models/solr_document.rb +8 -0
  23. data/lib/ddr/models/version.rb +1 -1
  24. data/lib/ddr/models/year_facet.rb +60 -118
  25. data/spec/auth/ability_spec.rb +1 -1
  26. data/spec/auth/roles/role_spec.rb +9 -9
  27. data/spec/index/fields_spec.rb +96 -0
  28. data/spec/models/active_fedora_datastream_spec.rb +6 -5
  29. data/spec/models/has_admin_metadata_spec.rb +49 -125
  30. data/spec/models/indexing_spec.rb +50 -18
  31. data/spec/models/solr_document_spec.rb +28 -0
  32. data/spec/models/year_facet_spec.rb +49 -22
  33. data/spec/support/shared_examples_for_ddr_models.rb +54 -2
  34. metadata +21 -8
  35. data/lib/ddr/jobs/permanent_id.rb +0 -35
  36. data/lib/ddr/managers/permanent_id_manager.rb +0 -93
@@ -30,11 +30,63 @@ RSpec.shared_examples "a DDR model" do
30
30
  end
31
31
  end
32
32
 
33
+ describe "notification on create" do
34
+ let(:events) { [] }
35
+ before {
36
+ @subscriber = ActiveSupport::Notifications.subscribe("create.#{described_class.to_s.underscore}") do |name, start, finish, id, payload|
37
+ events << payload
38
+ end
39
+ }
40
+ after {
41
+ ActiveSupport::Notifications.unsubscribe(@subscriber)
42
+ }
43
+ it "happens after create" do
44
+ subject.title = [ "My Title Changed" ]
45
+ subject.save
46
+ subject.title = [ "My Title Changed Again" ]
47
+ subject.save
48
+ expect(events.size).to eq(1)
49
+ expect(events.first[:pid]).to eq(subject.pid)
50
+ end
51
+ end
52
+
53
+ describe "notification on workflow state change" do
54
+ let(:events) { [] }
55
+ before {
56
+ @subscriber = ActiveSupport::Notifications.subscribe(/workflow\.#{described_class.to_s.underscore}/) do |*args|
57
+ events << ActiveSupport::Notifications::Event.new(*args)
58
+ end
59
+ }
60
+ after {
61
+ ActiveSupport::Notifications.unsubscribe(@subscriber)
62
+ }
63
+ it "doesn't happen on create" do
64
+ subject.workflow_state = "published"
65
+ subject.save(validate: false)
66
+ expect(events).to be_empty
67
+ end
68
+ describe "with a previously persisted object" do
69
+ before do
70
+ subject.save(validate: false)
71
+ end
72
+ it "happens on publish!" do
73
+ subject.workflow_state = "published"
74
+ subject.save(validate: false)
75
+ expect(events.size).to eq(1)
76
+ expect(events.first.name).to eq("published.workflow.#{described_class.to_s.underscore}")
77
+ end
78
+ it "happens on unpublish!" do
79
+ subject.workflow_state = "unpublished"
80
+ subject.save(validate: false)
81
+ expect(events.size).to eq(1)
82
+ expect(events.first.name).to eq("unpublished.workflow.#{described_class.to_s.underscore}")
83
+ end
84
+ end
85
+ end
86
+
33
87
  describe "events" do
34
88
  before {
35
- subject.permanent_id = "ark:/99999/fk4zzz"
36
89
  subject.save(validate: false)
37
- allow(Ddr::Jobs::PermanentId::MakeUnavailable).to receive(:perform) { nil }
38
90
  }
39
91
  describe "deaccession" do
40
92
  it "creates a deaccession event" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-02 00:00:00.000000000 Z
12
+ date: 2016-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 4.1.6
20
+ version: '4.1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 4.1.6
27
+ version: '4.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activeresource
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -241,6 +241,20 @@ dependencies:
241
241
  - - "<"
242
242
  - !ruby/object:Gem::Version
243
243
  version: 3.4.4
244
+ - !ruby/object:Gem::Dependency
245
+ name: edtf
246
+ requirement: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '3.0'
251
+ type: :runtime
252
+ prerelease: false
253
+ version_requirements: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '3.0'
244
258
  - !ruby/object:Gem::Dependency
245
259
  name: bundler
246
260
  requirement: !ruby/object:Gem::Requirement
@@ -382,6 +396,7 @@ files:
382
396
  - config/initializers/active_fedora_base.rb
383
397
  - config/initializers/active_fedora_datastream.rb
384
398
  - config/initializers/devise.rb
399
+ - config/initializers/rsolr_monkey_patches.rb
385
400
  - config/initializers/subscriptions.rb
386
401
  - config/locales/ddr-models.en.yml
387
402
  - config/routes.rb
@@ -501,13 +516,11 @@ files:
501
516
  - lib/ddr/jobs/fits_file_characterization.rb
502
517
  - lib/ddr/jobs/fixity_check.rb
503
518
  - lib/ddr/jobs/job.rb
504
- - lib/ddr/jobs/permanent_id.rb
505
519
  - lib/ddr/jobs/queue.rb
506
520
  - lib/ddr/jobs/update_index.rb
507
521
  - lib/ddr/managers.rb
508
522
  - lib/ddr/managers/derivatives_manager.rb
509
523
  - lib/ddr/managers/manager.rb
510
- - lib/ddr/managers/permanent_id_manager.rb
511
524
  - lib/ddr/managers/technical_metadata_manager.rb
512
525
  - lib/ddr/managers/workflow_manager.rb
513
526
  - lib/ddr/metadata.rb
@@ -723,9 +736,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
723
736
  version: '0'
724
737
  required_rubygems_version: !ruby/object:Gem::Requirement
725
738
  requirements:
726
- - - ">="
739
+ - - ">"
727
740
  - !ruby/object:Gem::Version
728
- version: '0'
741
+ version: 1.3.1
729
742
  requirements: []
730
743
  rubyforge_project:
731
744
  rubygems_version: 2.4.3
@@ -1,35 +0,0 @@
1
- require "ezid-client"
2
-
3
- module Ddr
4
- module Jobs
5
- module PermanentId
6
-
7
- class Job
8
- def self.inherited(subclass)
9
- subclass.instance_variable_set("@queue", :permanent_id)
10
- end
11
- end
12
-
13
- class MakeUnavailable < Job
14
- def self.call(*args)
15
- event = ActiveSupport::Notifications::Event.new(*args)
16
- id = event.payload[:permanent_id]
17
- reason = case event.name.split(".").first
18
- when "destroy"
19
- "deleted"
20
- when "deaccession"
21
- "deaccessioned"
22
- end
23
- Resque.enqueue(self, id, reason) if id.present?
24
- end
25
-
26
- def self.perform(id, reason = nil)
27
- identifier = Ezid::Identifier.find(id)
28
- identifier.unavailable!(reason)
29
- identifier.save
30
- end
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,93 +0,0 @@
1
- require "ezid-client"
2
- require "resque"
3
-
4
- module Ddr
5
- module Managers
6
- #
7
- # PermanentIdManager is responsible for managing the permanent id for an object.
8
- #
9
- # @api private
10
- #
11
- class PermanentIdManager
12
-
13
- PERMANENT_URL_BASE = "https://idn.duke.edu/"
14
- ASSIGN_EVENT_SUMMARY = "Permanent ID assignment"
15
- SOFTWARE = Ezid::Client.version
16
- FCREPO3_PID = "fcrepo3.pid"
17
-
18
- attr_reader :object
19
-
20
- def initialize(object)
21
- @object = object
22
- end
23
-
24
- def assign_later
25
- Resque.enqueue(AssignmentJob, object.pid)
26
- end
27
-
28
- def assign
29
- raise Ddr::Models::Error, "Permanent ID already assigned." if object.permanent_id
30
- ActiveSupport::Notifications.instrument(Ddr::Notifications::UPDATE,
31
- pid: object.pid,
32
- software: SOFTWARE,
33
- summary: ASSIGN_EVENT_SUMMARY
34
- ) do |payload|
35
-
36
- assign!
37
- payload[:detail] = <<-EOS
38
- Permanent ID: #{object.permanent_id}
39
- Permanent URL: #{object.permanent_url}
40
- EZID Metadata:
41
- #{record.metadata}
42
- EOS
43
- end
44
- end
45
-
46
- # A job class for background execution
47
- class AssignmentJob
48
- @queue = :permanent_id
49
-
50
- def self.perform(pid)
51
- object = ActiveFedora::Base.find(pid)
52
- object.permanent_id_manager.assign
53
- end
54
- end
55
-
56
- def default_metadata
57
- { :profile => "dc",
58
- :export => "no",
59
- FCREPO3_PID => object.pid
60
- }
61
- end
62
-
63
- def record
64
- return @record if @record
65
- if object.permanent_id
66
- @record = Ezid::Identifier.find(object.permanent_id.to_s)
67
- end
68
- end
69
-
70
- private
71
-
72
- def assign!
73
- @record = mint
74
- object.permanent_id = record.id
75
- object.permanent_url = (PERMANENT_URL_BASE + object.permanent_id)
76
- object.save!
77
- end
78
-
79
- # @return [Ezid::Identifier]
80
- def mint
81
- ezid = Ezid::Identifier.create(default_metadata)
82
- ezid.target = default_target_url(ezid.id)
83
- ezid.save
84
- ezid
85
- end
86
-
87
- def default_target_url(id)
88
- Ddr::Models.permanent_id_target_url_base + id
89
- end
90
-
91
- end
92
- end
93
- end