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.
- checksums.yaml +4 -4
- data/app/actors/sufia/generic_file/actor.rb +10 -7
- data/app/jobs/active_fedora_pid_based_job.rb +3 -2
- data/app/jobs/audit_job.rb +31 -28
- data/app/jobs/batch_update_job.rb +8 -9
- data/app/jobs/import_url_job.rb +2 -2
- data/app/models/batch.rb +12 -11
- data/app/models/checksum_audit_log.rb +8 -7
- data/app/models/concerns/sufia/ability.rb +6 -4
- data/app/models/concerns/sufia/collection.rb +5 -4
- data/app/models/concerns/sufia/file_stat_utils.rb +3 -3
- data/app/models/concerns/sufia/generic_file.rb +14 -16
- data/app/models/concerns/sufia/generic_file/audit.rb +31 -50
- data/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
- data/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
- data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
- data/app/models/concerns/sufia/generic_file/metadata.rb +11 -82
- data/app/models/concerns/sufia/generic_file/proxy_deposit.rb +3 -12
- data/app/models/concerns/sufia/generic_file/reload_on_save.rb +18 -0
- data/app/models/concerns/sufia/generic_file/versions.rb +4 -1
- data/app/models/concerns/sufia/generic_file/web_form.rb +6 -13
- data/app/models/concerns/sufia/model_methods.rb +9 -11
- data/app/models/concerns/sufia/properties_datastream_behavior.rb +32 -0
- data/app/models/concerns/sufia/user.rb +33 -11
- data/app/models/concerns/sufia/user_usage_stats.rb +15 -0
- data/app/models/datastreams/batch_rdf_datastream.rb +6 -0
- data/app/models/datastreams/file_content_datastream.rb +1 -1
- data/app/models/datastreams/fits_datastream.rb +1 -1
- data/app/models/datastreams/generic_file_rdf_datastream.rb +69 -0
- data/app/models/datastreams/paranoid_rights_datastream.rb +22 -0
- data/app/models/datastreams/properties_datastream.rb +4 -0
- data/app/models/file_download_stat.rb +2 -2
- data/app/models/file_usage.rb +9 -5
- data/app/models/file_view_stat.rb +2 -2
- data/app/models/local_authority.rb +2 -2
- data/app/models/proxy_deposit_request.rb +1 -1
- data/app/models/sufia/orcid_validator.rb +8 -0
- data/app/models/user_stat.rb +2 -0
- data/app/services/sufia/id_service.rb +5 -5
- data/app/services/sufia/noid.rb +7 -10
- data/lib/generators/sufia/models/abstract_migration_generator.rb +30 -0
- data/lib/generators/sufia/models/cached_stats_generator.rb +2 -31
- data/lib/generators/sufia/models/install_generator.rb +11 -31
- data/lib/generators/sufia/models/orcid_field_generator.rb +19 -0
- data/lib/generators/sufia/models/proxies_generator.rb +2 -31
- data/lib/generators/sufia/models/templates/config/sufia.rb +3 -10
- data/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +5 -0
- data/lib/generators/sufia/models/templates/migrations/create_user_stats.rb +19 -0
- data/lib/generators/sufia/models/upgrade400_generator.rb +2 -33
- data/lib/generators/sufia/models/user_stats_generator.rb +31 -0
- data/lib/sufia/models/engine.rb +4 -13
- data/lib/sufia/models/file_content/versions.rb +8 -12
- data/lib/sufia/models/stats/user_stat_importer.rb +89 -0
- data/lib/sufia/models/version.rb +1 -1
- data/lib/sufia/permissions/writable.rb +16 -34
- data/lib/tasks/stats_tasks.rake +12 -0
- data/sufia-models.gemspec +2 -4
- metadata +78 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d37bc139ae5fff12c2db375343268183968d59
|
4
|
+
data.tar.gz: 1babed9a02eec9f8e45d943ed47635eef776ee4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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:
|
74
|
+
FeaturedWork.where(generic_file_id: pid).destroy_all
|
72
75
|
if Sufia.config.respond_to?(:after_destroy)
|
73
|
-
Sufia.config.after_destroy.call(
|
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.
|
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
|
|
data/app/jobs/audit_job.rb
CHANGED
@@ -6,41 +6,44 @@ class AuditJob < ActiveFedoraPidBasedJob
|
|
6
6
|
PASS = 'Passing Audit Run'
|
7
7
|
FAIL = 'Failing Audit Run'
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :pid, :datastream_id, :version_id
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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(
|
43
|
-
object.class.run_audit(
|
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.
|
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.
|
45
|
-
gf.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.
|
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.
|
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
|
data/app/jobs/import_url_job.rb
CHANGED
@@ -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
|
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
|
-
|
6
|
+
has_metadata name: "descMetadata", type: BatchRdfDatastream
|
7
7
|
|
8
|
-
|
9
|
-
|
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
|
-
|
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(
|
15
|
+
Batch.find(pid)
|
15
16
|
rescue ActiveFedora::ObjectNotFoundError
|
16
|
-
Batch.create(
|
17
|
+
Batch.create({pid: pid})
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
def to_solr(solr_doc={})
|
21
|
-
|
22
|
-
|
23
|
-
|
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(
|
4
|
-
ChecksumAuditLog.
|
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(
|
8
|
-
|
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(
|
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 |
|
19
|
-
|
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
|
51
|
-
::GenericFile.load_instance_from_solr(
|
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
|
39
|
-
|
40
|
-
|
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,
|
26
|
+
belongs_to :batch, property: :is_part_of
|
26
27
|
|
27
|
-
|
28
|
+
around_save :retry_warming
|
28
29
|
|
29
|
-
attr_accessible *(terms_for_display + [:part_of, :
|
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 =
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
38
|
-
|
39
|
-
|
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(
|
44
|
-
ChecksumAuditLog.where(
|
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
|
73
|
-
latest_audit = logs(
|
74
|
-
return latest_audit unless
|
75
|
-
|
76
|
-
|
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(
|
87
|
-
|
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(
|
116
|
-
|
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(
|
104
|
+
ChecksumAuditLog.prune_history(version)
|
125
105
|
else
|
126
|
-
logger.warn "***AUDIT*** Audit failed for #{
|
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:
|
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
|