Sha256: a3187a6085bc02525b44f02e44774e1d4040c5dadd0879fcfe11424a024f650a

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

class AuditJob < ActiveJob::Base
  # URI of the resource to audit.
  # This URI could include the actual resource (e.g. content) and the version to audit:
  #     http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content/fcr:versions/version1
  # but it could also just be:
  #     http://localhost:8983/fedora/rest/test/a/b/c/abcxyz/content
  # @param [FileSet] the parent object
  # @param [String] file_id used to find the file within its parent object (usually "original_file")
  # @param [String] uri of the specific file/version to be audited
  def perform(file_set, file_id, uri)
    log = run_audit(file_set, file_id, uri)
    fixity_ok = log.pass == 1
    unless fixity_ok
      if Hyrax.config.callback.set?(:after_audit_failure)
        login = file_set.depositor
        user = User.find_by_user_key(login)
        Hyrax.config.callback.run(:after_audit_failure, file_set, user, log.created_at)
      end
    end
    fixity_ok
  end

  protected

    def run_audit(file_set, file_id, uri)
      begin
        fixity_ok = ActiveFedora::FixityService.new(uri).check
      rescue Ldp::NotFound
        error_msg = 'resource not found'
      end

      if fixity_ok
        passing = 1
        ChecksumAuditLog.prune_history(file_set.id, file_id)
      else
        logger.warn "***AUDIT*** Audit failed for #{uri} #{error_msg}"
        passing = 0
      end
      ChecksumAuditLog.create!(pass: passing, file_set_id: file_set.id, version: uri, file_id: file_id)
    end

  private

    def logger
      ActiveFedora::Base.logger
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test_hyrax-0.0.1.alpha app/jobs/audit_job.rb