sufia-models 5.0.0.beta1 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/sufia/generic_file/actor.rb +10 -7
  3. data/app/jobs/active_fedora_pid_based_job.rb +3 -2
  4. data/app/jobs/audit_job.rb +31 -28
  5. data/app/jobs/batch_update_job.rb +8 -9
  6. data/app/jobs/import_url_job.rb +2 -2
  7. data/app/models/batch.rb +12 -11
  8. data/app/models/checksum_audit_log.rb +8 -7
  9. data/app/models/concerns/sufia/ability.rb +6 -4
  10. data/app/models/concerns/sufia/collection.rb +5 -4
  11. data/app/models/concerns/sufia/file_stat_utils.rb +3 -3
  12. data/app/models/concerns/sufia/generic_file.rb +14 -16
  13. data/app/models/concerns/sufia/generic_file/audit.rb +31 -50
  14. data/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
  15. data/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
  16. data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
  17. data/app/models/concerns/sufia/generic_file/metadata.rb +11 -82
  18. data/app/models/concerns/sufia/generic_file/proxy_deposit.rb +3 -12
  19. data/app/models/concerns/sufia/generic_file/reload_on_save.rb +18 -0
  20. data/app/models/concerns/sufia/generic_file/versions.rb +4 -1
  21. data/app/models/concerns/sufia/generic_file/web_form.rb +6 -13
  22. data/app/models/concerns/sufia/model_methods.rb +9 -11
  23. data/app/models/concerns/sufia/properties_datastream_behavior.rb +32 -0
  24. data/app/models/concerns/sufia/user.rb +33 -11
  25. data/app/models/concerns/sufia/user_usage_stats.rb +15 -0
  26. data/app/models/datastreams/batch_rdf_datastream.rb +6 -0
  27. data/app/models/datastreams/file_content_datastream.rb +1 -1
  28. data/app/models/datastreams/fits_datastream.rb +1 -1
  29. data/app/models/datastreams/generic_file_rdf_datastream.rb +69 -0
  30. data/app/models/datastreams/paranoid_rights_datastream.rb +22 -0
  31. data/app/models/datastreams/properties_datastream.rb +4 -0
  32. data/app/models/file_download_stat.rb +2 -2
  33. data/app/models/file_usage.rb +9 -5
  34. data/app/models/file_view_stat.rb +2 -2
  35. data/app/models/local_authority.rb +2 -2
  36. data/app/models/proxy_deposit_request.rb +1 -1
  37. data/app/models/sufia/orcid_validator.rb +8 -0
  38. data/app/models/user_stat.rb +2 -0
  39. data/app/services/sufia/id_service.rb +5 -5
  40. data/app/services/sufia/noid.rb +7 -10
  41. data/lib/generators/sufia/models/abstract_migration_generator.rb +30 -0
  42. data/lib/generators/sufia/models/cached_stats_generator.rb +2 -31
  43. data/lib/generators/sufia/models/install_generator.rb +11 -31
  44. data/lib/generators/sufia/models/orcid_field_generator.rb +19 -0
  45. data/lib/generators/sufia/models/proxies_generator.rb +2 -31
  46. data/lib/generators/sufia/models/templates/config/sufia.rb +3 -10
  47. data/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +5 -0
  48. data/lib/generators/sufia/models/templates/migrations/create_user_stats.rb +19 -0
  49. data/lib/generators/sufia/models/upgrade400_generator.rb +2 -33
  50. data/lib/generators/sufia/models/user_stats_generator.rb +31 -0
  51. data/lib/sufia/models/engine.rb +4 -13
  52. data/lib/sufia/models/file_content/versions.rb +8 -12
  53. data/lib/sufia/models/stats/user_stat_importer.rb +89 -0
  54. data/lib/sufia/models/version.rb +1 -1
  55. data/lib/sufia/permissions/writable.rb +16 -34
  56. data/lib/tasks/stats_tasks.rake +12 -0
  57. data/sufia-models.gemspec +2 -4
  58. metadata +78 -90
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1a8c6e6170dab340eb52e7102f29c63de547850
4
- data.tar.gz: 68b0a675fb176f9132a01f791ec3ea7302acd716
3
+ metadata.gz: 17d37bc139ae5fff12c2db375343268183968d59
4
+ data.tar.gz: 1babed9a02eec9f8e45d943ed47635eef776ee4c
5
5
  SHA512:
6
- metadata.gz: e90c6e067dae4e9aa8c10bbf7d914e4cc28b18355822244cf46be1622d2c7068aba56730e004bea8112fa4083fe77d66635b45e9de8f84c1ce765695db1f15a3
7
- data.tar.gz: c2cf9171d0cfaa461c0afc944e250bf9adf0b240f10be8d36d840b48429b73c823d9d170f8514453d9b66b3eef6d820e449ea019bd0bf6b1ff3ce27521a38b7c
6
+ metadata.gz: c47b59504252a0b21f4017a241ce900f11356c1f09f1e9a17998bbc6daa69c0450c203d9a7348a5dec74e7b8c2971e4caf1778c47b7384e5e6579964cd4c610b
7
+ data.tar.gz: c646da67011dd0fa9a6688fe130c18ce647a478b90ea4bac599900239ccac2714914fe07154ee2d0c6082fc58e64ee1ac3759c17efe84ba7991cbbad6e7243f3
@@ -20,7 +20,7 @@ module Sufia::GenericFile
20
20
  generic_file.creator = [user.name]
21
21
 
22
22
  if batch_id
23
- generic_file.batch_id = batch_id
23
+ generic_file.batch_id = Sufia::Noid.namespaceize(batch_id)
24
24
  else
25
25
  ActiveFedora::Base.logger.warn "unable to find batch to attach to"
26
26
  end
@@ -28,7 +28,8 @@ module Sufia::GenericFile
28
28
  end
29
29
 
30
30
  def create_content(file, file_name, dsid)
31
- generic_file.add_file(file, dsid, file_name.truncate(255))
31
+ fname = generic_file.label.blank? ? file_name.truncate(255) : generic_file.label
32
+ generic_file.add_file(file, dsid, fname)
32
33
  save_characterize_and_record_committer do
33
34
  if Sufia.config.respond_to?(:after_create_content)
34
35
  Sufia.config.after_create_content.call(generic_file, user)
@@ -36,8 +37,9 @@ module Sufia::GenericFile
36
37
  end
37
38
  end
38
39
 
39
- def revert_content(revision_id)
40
- generic_file.content.restore_version(revision_id)
40
+ def revert_content(revision_id, datastream_id)
41
+ revision = generic_file.content.get_version(revision_id)
42
+ generic_file.add_file(revision.content, datastream_id, revision.label)
41
43
  save_characterize_and_record_committer do
42
44
  if Sufia.config.respond_to?(:after_revert_content)
43
45
  Sufia.config.after_revert_content.call(generic_file, user, revision_id)
@@ -67,10 +69,11 @@ module Sufia::GenericFile
67
69
  end
68
70
 
69
71
  def destroy
72
+ pid = generic_file.pid #Work around for https://github.com/projecthydra/active_fedora/issues/422
70
73
  generic_file.destroy
71
- FeaturedWork.where(generic_file_id: generic_file.id).destroy_all
74
+ FeaturedWork.where(generic_file_id: pid).destroy_all
72
75
  if Sufia.config.respond_to?(:after_destroy)
73
- Sufia.config.after_destroy.call(generic_file.id, user)
76
+ Sufia.config.after_destroy.call(pid, user)
74
77
  end
75
78
  end
76
79
 
@@ -100,7 +103,7 @@ module Sufia::GenericFile
100
103
  end
101
104
 
102
105
  def push_characterize_job
103
- Sufia.queue.push(CharacterizeJob.new(@generic_file.id))
106
+ Sufia.queue.push(CharacterizeJob.new(@generic_file.pid))
104
107
  end
105
108
 
106
109
  class << self
@@ -10,9 +10,10 @@ class ActiveFedoraPidBasedJob
10
10
  end
11
11
 
12
12
  def object
13
- @object ||= ActiveFedora::Base.find(pid)
13
+ @object ||= ActiveFedora::Base.find(pid, cast: true).tap do |f|
14
+ f.reload_on_save = true
15
+ end
14
16
  end
15
-
16
17
  alias_method :generic_file, :object
17
18
  alias_method :generic_file_id, :pid
18
19
 
@@ -6,41 +6,44 @@ class AuditJob < ActiveFedoraPidBasedJob
6
6
  PASS = 'Passing Audit Run'
7
7
  FAIL = 'Failing Audit Run'
8
8
 
9
- attr_accessor :uri, :pid, :path
9
+ attr_accessor :pid, :datastream_id, :version_id
10
10
 
11
- # URI of the resource to audit.
12
- # This URI could include the actual resource (e.g. content) and the version to audit:
13
- # http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content/fcr:versions/version1
14
- # but it could also just be:
15
- # http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content
16
- def initialize(id, path, uri)
17
- super(uri)
18
- self.pid = id
19
- self.path = path
20
- self.uri = uri
11
+ def initialize(pid, datastream_id, version_id)
12
+ super(pid)
13
+ self.datastream_id = datastream_id
14
+ self.version_id = version_id
21
15
  end
22
16
 
23
17
  def run
24
- fixity_ok = false
25
- log = run_audit(pid, path, uri)
26
- fixity_ok = (log.pass == 1)
27
- unless fixity_ok
28
- # send the user a message about the failing audit
29
- login = generic_file.depositor
30
- user = User.find_by_user_key(login)
31
- ActiveFedora::Base.logger.warn "User '#{login}' not found" unless user
32
- job_user = User.audituser()
33
- file_title = generic_file.title.first
34
- message = "The audit run at #{log.created_at} for #{file_title} (#{uri}) failed."
35
- subject = FAIL
36
- job_user.send_message(user, message, subject)
18
+ if generic_file
19
+ datastream = generic_file.datastreams[datastream_id]
20
+ if datastream
21
+ version = datastream.versions.select { |v| v.versionID == version_id}.first
22
+ log = run_audit(version)
23
+
24
+ # look up the user for sending the message to
25
+ login = generic_file.depositor
26
+ if login
27
+ user = User.find_by_user_key(login)
28
+ ActiveFedora::Base.logger.warn "User '#{login}' not found" unless user
29
+ job_user = User.audituser()
30
+ # send the user a message about the failing audit
31
+ unless (log.pass == 1)
32
+ message = "The audit run at #{log.created_at} for #{log.pid}:#{log.dsid}:#{log.version} was #{log.pass == 1 ? 'passing' : 'failing'}."
33
+ subject = (log.pass == 1 ? PASS : FAIL)
34
+ job_user.send_message(user, message, subject)
35
+ end
36
+ end
37
+ else
38
+ ActiveFedora::Base.logger.warn "No datastream for audit!!!!! pid: #{pid} dsid: #{datastream_id}"
39
+ end
40
+ else
41
+ ActiveFedora::Base.logger.warn "No generic file for data stream audit!!!!! pid: #{pid} dsid: #{datastream_id}"
37
42
  end
38
- fixity_ok
39
43
  end
40
44
 
41
45
  private
42
- def run_audit(id, path, uri)
43
- object.class.run_audit(id, path, uri)
46
+ def run_audit(version)
47
+ object.class.run_audit(version)
44
48
  end
45
-
46
49
  end
@@ -10,7 +10,7 @@ class BatchUpdateJob
10
10
 
11
11
  def initialize(login, params)
12
12
  self.login = login
13
- self.title = params[:title] || {}
13
+ self.title = params[:title]
14
14
  self.file_attributes = params[:generic_file]
15
15
  self.visibility = params[:visibility]
16
16
  self.batch_id = params[:id]
@@ -25,9 +25,7 @@ class BatchUpdateJob
25
25
  batch.generic_files.each do |gf|
26
26
  update_file(gf, user)
27
27
  end
28
-
29
- batch.update(status: ["Complete"])
30
-
28
+ batch.update_attributes({status:["Complete"]})
31
29
  if denied.empty?
32
30
  send_user_success_message(user, batch) unless saved.empty?
33
31
  else
@@ -37,12 +35,12 @@ class BatchUpdateJob
37
35
 
38
36
  def update_file(gf, user)
39
37
  unless user.can? :edit, gf
40
- ActiveFedora::Base.logger.error "User #{user.user_key} DENIED access to #{gf.id}!"
38
+ ActiveFedora::Base.logger.error "User #{user.user_key} DENIED access to #{gf.pid}!"
41
39
  denied << gf
42
40
  return
43
41
  end
44
- gf.title = title[gf.id] if title[gf.id]
45
- gf.attributes = file_attributes
42
+ gf.title = title[gf.pid] if title[gf.pid] rescue gf.label
43
+ gf.attributes=file_attributes
46
44
  gf.visibility= visibility
47
45
 
48
46
  save_tries = 0
@@ -50,13 +48,13 @@ class BatchUpdateJob
50
48
  gf.save!
51
49
  rescue RSolr::Error::Http => error
52
50
  save_tries += 1
53
- ActiveFedora::Base.logger.warn "BatchUpdateJob caught RSOLR error on #{gf.id}: #{error.inspect}"
51
+ ActiveFedora::Base.logger.warn "BatchUpdateJob caught RSOLR error on #{gf.pid}: #{error.inspect}"
54
52
  # fail for good if the tries is greater than 3
55
53
  raise error if save_tries >=3
56
54
  sleep 0.01
57
55
  retry
58
56
  end #
59
- Sufia.queue.push(ContentUpdateEventJob.new(gf.id, login))
57
+ Sufia.queue.push(ContentUpdateEventJob.new(gf.pid, login))
60
58
  saved << gf
61
59
  end
62
60
 
@@ -69,4 +67,5 @@ class BatchUpdateJob
69
67
  message = denied.count > 1 ? multiple_failure(batch.noid, denied) : single_failure(batch.noid, denied.first)
70
68
  User.batchuser.send_message(user, message, failure_subject, sanitize_text = false)
71
69
  end
70
+
72
71
  end
@@ -11,12 +11,12 @@ class ImportUrlJob < ActiveFedoraPidBasedJob
11
11
  def run
12
12
  user = User.find_by_user_key(generic_file.depositor)
13
13
 
14
- Tempfile.open(pid.gsub('/', '_')) do |f|
14
+ Tempfile.open(self.pid) do |f|
15
15
  path = copy_remote_file(generic_file.import_url, f)
16
16
  # attach downloaded file to generic file stubbed out
17
17
  if Sufia::GenericFile::Actor.new(generic_file, user).create_content(f, path, 'content')
18
18
  # add message to user for downloaded file
19
- message = "The file (#{generic_file.label}) was successfully imported."
19
+ message = "The file (#{generic_file.content.label}) was successfully imported."
20
20
  job_user.send_message(user, message, 'File Import')
21
21
  else
22
22
  job_user.send_message(user, generic_file.errors.full_messages.join(', '), 'File Import Error')
data/app/models/batch.rb CHANGED
@@ -3,23 +3,24 @@ class Batch < ActiveFedora::Base
3
3
  include Sufia::ModelMethods
4
4
  include Sufia::Noid
5
5
 
6
- has_many :generic_files, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
6
+ has_metadata name: "descMetadata", type: BatchRdfDatastream
7
7
 
8
- property :creator, predicate: ::RDF::DC.creator
9
- property :title, predicate: ::RDF::DC.title
10
- property :status, predicate: ::RDF::DC.type
8
+ belongs_to :user, property: "creator"
9
+ has_many :generic_files, property: :is_part_of
11
10
 
12
- def self.find_or_create(id)
11
+ has_attributes :title, :creator, :part, :status, datastream: :descMetadata, multiple: true
12
+
13
+ def self.find_or_create(pid)
13
14
  begin
14
- Batch.find(id)
15
+ Batch.find(pid)
15
16
  rescue ActiveFedora::ObjectNotFoundError
16
- Batch.create(id: id)
17
+ Batch.create({pid: pid})
17
18
  end
18
19
  end
19
20
 
20
- def to_solr(solr_doc={})
21
- super.tap do |solr_doc|
22
- solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)] = noid
23
- end
21
+ def to_solr(solr_doc={}, opts={})
22
+ solr_doc = super(solr_doc, opts)
23
+ solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)] = noid
24
+ return solr_doc
24
25
  end
25
26
  end
@@ -1,15 +1,16 @@
1
1
  class ChecksumAuditLog < ActiveRecord::Base
2
2
 
3
- def ChecksumAuditLog.get_audit_log(id, path, version_uri)
4
- ChecksumAuditLog.find_or_create_by(pid: id, dsid: path, version: version_uri)
3
+ def ChecksumAuditLog.get_audit_log(version)
4
+ ChecksumAuditLog.find_or_create_by_pid_and_dsid_and_version(pid: version.pid,
5
+ dsid: version.dsid,
6
+ version: version.versionID)
5
7
  end
6
8
 
7
- def ChecksumAuditLog.prune_history(id, path)
8
- # Check to see if there are previous passing logs that we can delete
9
- # we want to keep the first passing event after a failure, the most current passing event,
10
- # and all failures so that this table doesn't grow too large
9
+ def ChecksumAuditLog.prune_history(version)
10
+ ## Check to see if there are previous passing logs that we can delete
11
+ # we want to keep the first passing event after a failure, the most current passing event, and all failures so that this table doesn't grow too large
11
12
  # Simple way (a little naieve): if the last 2 were passing, delete the first one
12
- logs = GenericFile.load_instance_from_solr(id).logs(path)
13
+ logs = GenericFile.load_instance_from_solr(version.pid).logs(version.dsid)
13
14
  list = logs.limit(2)
14
15
  if list.size > 1 && (list[0].pass == 1) && (list[1].pass == 1)
15
16
  list[0].destroy
@@ -15,8 +15,8 @@ module Sufia
15
15
  end
16
16
 
17
17
  def proxy_deposit_abilities
18
- can :transfer, String do |id|
19
- depositor_for_document(id) == current_user.user_key
18
+ can :transfer, String do |pid|
19
+ get_depositor_from_pid(pid) == current_user.user_key
20
20
  end
21
21
  can :create, ProxyDepositRequest if user_groups.include? 'registered'
22
22
  can :accept, ProxyDepositRequest, receiving_user_id: current_user.id, status: 'pending'
@@ -47,8 +47,10 @@ module Sufia
47
47
 
48
48
  private
49
49
 
50
- def depositor_for_document(document_id)
51
- ::GenericFile.load_instance_from_solr(document_id).depositor
50
+ def get_depositor_from_pid(pid)
51
+ ::GenericFile.load_instance_from_solr(pid).depositor
52
+ rescue
53
+ nil
52
54
  end
53
55
  end
54
56
  end
@@ -11,6 +11,7 @@ module Sufia
11
11
  before_save :update_permissions
12
12
  validates :title, presence: true
13
13
 
14
+ has_metadata "properties", type: PropertiesDatastream
14
15
  end
15
16
 
16
17
  def terms_for_display
@@ -34,10 +35,10 @@ module Sufia
34
35
  noid
35
36
  end
36
37
 
37
- def to_solr(solr_doc={})
38
- super.tap do |solr_doc|
39
- solr_doc[Solrizer.solr_name("noid", Sufia::GenericFile.noid_indexer)] = noid
40
- end
38
+ def to_solr(solr_doc={}, opts={})
39
+ super(solr_doc, opts)
40
+ solr_doc[Solrizer.solr_name("noid", Sufia::GenericFile.noid_indexer)] = noid
41
+ return solr_doc
41
42
  end
42
43
 
43
44
  def update_permissions
@@ -17,13 +17,13 @@ module Sufia
17
17
  {ga_start_date: ga_start_date, cached_stats: stats.to_a }
18
18
  end
19
19
 
20
- def combined_stats file_id, start_date, object_method, ga_key
20
+ def combined_stats file_id, start_date, object_method, ga_key, user_id=nil
21
21
  stat_cache_info = cached_stats( file_id, start_date, object_method)
22
22
  stats = stat_cache_info[:cached_stats]
23
23
  if stat_cache_info[:ga_start_date] < Date.today
24
24
  ga_stats = ga_statistics(stat_cache_info[:ga_start_date], file_id)
25
25
  ga_stats.each do |stat|
26
- lstat = self.new file_id:file_id, date: stat[:date], object_method => stat[ga_key]
26
+ lstat = self.new file_id: file_id, date: stat[:date], object_method => stat[ga_key], user_id: user_id
27
27
  lstat.save unless Date.parse(stat[:date]) == Date.today
28
28
  stats << lstat
29
29
  end
@@ -32,4 +32,4 @@ module Sufia
32
32
  end
33
33
 
34
34
  end
35
- end
35
+ end
@@ -17,16 +17,17 @@ module Sufia
17
17
  include Sufia::GenericFile::Metadata
18
18
  include Sufia::GenericFile::Versions
19
19
  include Sufia::GenericFile::VirusCheck
20
+ include Sufia::GenericFile::ReloadOnSave
20
21
  include Sufia::GenericFile::FullTextIndexing
21
22
  include Sufia::GenericFile::ProxyDeposit
22
23
  include Hydra::Collections::Collectible
23
24
 
24
25
  included do
25
- belongs_to :batch, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
26
+ belongs_to :batch, property: :is_part_of
26
27
 
27
- # around_save :retry_warming
28
+ around_save :retry_warming
28
29
 
29
- attr_accessible *(terms_for_display + [:part_of, :permissions_attributes])
30
+ attr_accessible *(terms_for_display + [:part_of, :permissions])
30
31
  end
31
32
 
32
33
  def persistent_url
@@ -36,7 +37,6 @@ module Sufia
36
37
  def retry_warming
37
38
  save_tries = 0
38
39
  conflict_tries = 0
39
- etag_tries = 0
40
40
  begin
41
41
  yield
42
42
  rescue RSolr::Error::Http => error
@@ -46,15 +46,6 @@ module Sufia
46
46
  raise if save_tries >=3
47
47
  sleep 0.01
48
48
  retry
49
- rescue Ldp::EtagMismatch
50
- prev_changes = changes.dup
51
- # There was a version conflict, so reload the previous version, then apply the changed attributes
52
- reload
53
- prev_changes.each do |key, (_, value)|
54
- self[key] = value
55
- end
56
- raise if etag_tries >= 1
57
- retry
58
49
  rescue ActiveResource::ResourceConflict => error
59
50
  conflict_tries += 1
60
51
  logger.warn "Retry caught Active Resource Conflict #{self.pid}: #{error.inspect}"
@@ -90,14 +81,21 @@ module Sufia
90
81
  @noid_indexer ||= Solrizer::Descriptor.new(:text, :indexed, :stored)
91
82
  end
92
83
 
93
- def to_solr(solr_doc={})
94
- super.tap do |solr_doc|
84
+ def to_solr(solr_doc={}, opts={})
85
+ super(solr_doc, opts).tap do |solr_doc|
95
86
  solr_doc[Solrizer.solr_name('label')] = self.label
96
87
  solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)] = noid
97
88
  solr_doc[Solrizer.solr_name('file_format')] = file_format
98
89
  solr_doc[Solrizer.solr_name('file_format', :facetable)] = file_format
99
90
  solr_doc['all_text_timv'] = full_text.content
100
- solr_doc = index_collection_ids(solr_doc)
91
+ solr_doc = index_collection_pids(solr_doc)
92
+ end
93
+ end
94
+
95
+ def label=(new_label)
96
+ @inner_object.label = new_label
97
+ if self.title.empty?
98
+ self.title = [new_label].compact
101
99
  end
102
100
  end
103
101
 
@@ -5,43 +5,25 @@ module Sufia
5
5
 
6
6
  NO_RUNS = 999
7
7
 
8
- # provides a human readable version of the audit status
9
- def human_readable_audit_status
10
- stat = audit_stat(false)
11
- case stat
12
- when 0
13
- 'failing'
14
- when 1
15
- 'passing'
16
- else
17
- stat
18
- end
19
- end
20
-
21
- # TODO: Run audits on all attached files. We're only audting "content" at tht moment
22
- def audit force = false
23
- @audit_log ||= Array.new
24
- @force = force
25
- audit_content
26
- return @audit_log
27
- end
28
-
29
- def audit_content
30
- if content.has_versions?
31
- audit_file_versions("content")
32
- else
33
- @audit_log << audit_file("content", content.uri)
8
+ def audit(force = false)
9
+ logs = []
10
+ self.per_version do |ver|
11
+ logs << audit_each(ver, force)
34
12
  end
13
+ logs
35
14
  end
36
15
 
37
- def audit_file_versions file
38
- attached_files[file].versions.all.each do |version|
39
- @audit_log << audit_file(file, version.uri, version.label)
16
+ def per_version(&block)
17
+ self.datastreams.each do |dsid, ds|
18
+ next if ds == full_text
19
+ ds.versions.each do |ver|
20
+ block.call(ver)
21
+ end
40
22
  end
41
23
  end
42
24
 
43
- def logs(file)
44
- ChecksumAuditLog.where(pid: self.id, dsid: file).order('created_at desc, id desc')
25
+ def logs(dsid)
26
+ ChecksumAuditLog.where(dsid: dsid, pid: self.pid).order('created_at desc, id desc')
45
27
  end
46
28
 
47
29
  def audit!
@@ -69,11 +51,16 @@ module Sufia
69
51
  end
70
52
  end
71
53
 
72
- def audit_file(file, uri, label = nil)
73
- latest_audit = logs(file).first
74
- return latest_audit unless @force || ::GenericFile.needs_audit?(uri, latest_audit)
75
- Sufia.queue.push(AuditJob.new(id, file, uri))
76
- latest_audit ||= ChecksumAuditLog.new(pass: NO_RUNS, pid: id, dsid: file, version: label)
54
+ def audit_each(version, force = false)
55
+ latest_audit = logs(version.dsid).first
56
+ return latest_audit unless force || ::GenericFile.needs_audit?(version, latest_audit)
57
+
58
+ # Resque.enqueue(AuditJob, version.pid, version.dsid, version.versionID)
59
+ Sufia.queue.push(AuditJob.new(version.pid, version.dsid, version.versionID))
60
+
61
+ # run the find just incase the job has finished already
62
+ latest_audit = logs(version.dsid).first
63
+ latest_audit = ChecksumAuditLog.new(pass: NO_RUNS, pid: version.pid, dsid: version.dsid, version: version.versionID) unless latest_audit
77
64
  latest_audit
78
65
  end
79
66
 
@@ -83,9 +70,8 @@ module Sufia
83
70
  ::GenericFile.audit(version, true)
84
71
  end
85
72
 
86
- def audit(version_uri, force = false)
87
- return { pass: true } # TODO Just skipping the audit for now
88
- latest_audit = self.find(version_uri).audit_each( version, force)
73
+ def audit(version, force = false)
74
+ latest_audit = self.find(version.pid).audit_each( version, force)
89
75
  end
90
76
 
91
77
  def needs_audit?(version, latest_audit)
@@ -112,21 +98,16 @@ module Sufia
112
98
  ::GenericFile.audit_everything(true)
113
99
  end
114
100
 
115
- def run_audit(id, path, uri)
116
- begin
117
- fixity_ok = ActiveFedora::FixityService.new(uri).check
118
- rescue Ldp::NotFound
119
- error_msg = "resource not found"
120
- end
121
-
122
- if fixity_ok
101
+ def run_audit(version)
102
+ if version.dsChecksumValid
123
103
  passing = 1
124
- ChecksumAuditLog.prune_history(id, path)
104
+ ChecksumAuditLog.prune_history(version)
125
105
  else
126
- logger.warn "***AUDIT*** Audit failed for #{uri} #{error_msg}"
106
+ logger.warn "***AUDIT*** Audit failed for #{version.pid} #{version.versionID}"
127
107
  passing = 0
128
108
  end
129
- check = ChecksumAuditLog.create!(pass: passing, pid: id, version: uri, dsid: path)
109
+ check = ChecksumAuditLog.create!(pass: passing, pid: version.pid,
110
+ dsid: version.dsid, version: version.versionID)
130
111
  check
131
112
  end
132
113
  end