Class: Hyrax::FileSetFixityCheckService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/file_set_fixity_check_service.rb

Overview

This class runs fixity checks on a FileSet, potentially on multiple files each with multiple versions in the FileSet.

The FixityCheck itself is performed by FixityCheckJob, which just uses the fedora service to ask for fixity verification. The outcome will be some created ChecksumAuditLog (ActiveRecord) objects, recording the checks and their results.

By default this runs the checks async using ActiveJob, so returns no useful info – the checks are still going on. Use FixityStatusService if you'd like a human-readable status based on latest recorded checks, or ChecksumAuditLog.latest_for_fileset_id if you'd like the the machine-readable checks.

But if you initialize with `async_jobs: false`, checks will be done blocking in foreground, and you can get back the ChecksumAuditLog records created.

It will only run fixity checks if there are not recent ChecksumAuditLogs on record. “recent” is defined by `max_days_between_fixity_checks` arg, which defaults to config'd `Hyrax.config.max_days_between_fixity_checks`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set, async_jobs: true, max_days_between_fixity_checks: Hyrax.config.max_days_between_fixity_checks, latest_version_only: false) ⇒ FileSetFixityCheckService

Returns a new instance of FileSetFixityCheckService.

Parameters:

  • file_set (ActiveFedora::Base, String)

    file_set

  • async_jobs (Boolean) (defaults to: true)

    Run actual fixity checks in background. Default true.

  • max_days_between_fixity_checks (int) (defaults to: Hyrax.config.max_days_between_fixity_checks)

    if an exisitng fixity check is recorded within this window, no new one will be created. Default `Hyrax.config.max_days_between_fixity_checks`. Set to -1 to force

    check.
    
  • latest_version_only (Booelan) (defaults to: false)

    . Check only latest version instead of all versions. Default false.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 36

def initialize(file_set,
               async_jobs: true,
               max_days_between_fixity_checks: Hyrax.config.max_days_between_fixity_checks,
               latest_version_only: false)
  @max_days_between_fixity_checks = max_days_between_fixity_checks || 0
  @async_jobs = async_jobs
  @latest_version_only = latest_version_only
  if file_set.is_a?(String)
    @id = file_set
  else
    @id = file_set.id
    @file_set = file_set
  end
end

Instance Attribute Details

#async_jobsObject (readonly)

Returns the value of attribute async_jobs


25
26
27
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 25

def async_jobs
  @async_jobs
end

#idObject (readonly)

Returns the value of attribute id


25
26
27
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 25

def id
  @id
end

#latest_version_onlyObject (readonly)

Returns the value of attribute latest_version_only


25
26
27
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 25

def latest_version_only
  @latest_version_only
end

#max_days_between_fixity_checksObject (readonly)

Returns the value of attribute max_days_between_fixity_checks


25
26
27
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 25

def max_days_between_fixity_checks
  @max_days_between_fixity_checks
end

Instance Method Details

#fixity_checkObject

Fixity checks each version of each file if it hasn't been checked recently If object async_jobs is false, will returns the set of most recent fixity check status for each version of the content file(s). As a hash keyed by file_id, values arrays of possibly multiple version checks.

If async_jobs is true (default), just returns nil, stuff is still going on.


57
58
59
60
61
62
63
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 57

def fixity_check
  results = file_set.files.collect { |f| fixity_check_file(f) }

  return if async_jobs

  results.flatten.group_by(&:file_id)
end

#logged_fixity_statusObject

Return current fixity status for this FileSet based on ChecksumAuditLog records on file.


67
68
69
70
# File 'app/services/hyrax/file_set_fixity_check_service.rb', line 67

def logged_fixity_status
  Deprecation.warn(self, "logged_fixity_status is deprecated, use FixityStatusPresenter instead")
  FixityStatusPresenter.new(file_set.id).render_file_set_status
end