Class: AuditJob

Inherits:
Object
  • Object
show all
Defined in:
lib/sufia/jobs/audit_job.rb

Overview

Copyright © 2012 The Pennsylvania State University

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constant Summary collapse

PASS =
'Passing Audit Run'
FAIL =
'Failing Audit Run'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generic_file_id, datastream_id, version_id) ⇒ AuditJob

Returns a new instance of AuditJob.



25
26
27
28
29
# File 'lib/sufia/jobs/audit_job.rb', line 25

def initialize(generic_file_id, datastream_id, version_id)
  self.generic_file_id = generic_file_id
  self.datastream_id = datastream_id
  self.version_id = version_id
end

Instance Attribute Details

#datastream_idObject

Returns the value of attribute datastream_id.



23
24
25
# File 'lib/sufia/jobs/audit_job.rb', line 23

def datastream_id
  @datastream_id
end

#generic_file_idObject

Returns the value of attribute generic_file_id.



23
24
25
# File 'lib/sufia/jobs/audit_job.rb', line 23

def generic_file_id
  @generic_file_id
end

#version_idObject

Returns the value of attribute version_id.



23
24
25
# File 'lib/sufia/jobs/audit_job.rb', line 23

def version_id
  @version_id
end

Instance Method Details

#queue_nameObject



16
17
18
# File 'lib/sufia/jobs/audit_job.rb', line 16

def queue_name
  :audit
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sufia/jobs/audit_job.rb', line 31

def run
  generic_file = GenericFile.find(generic_file_id)
  #logger.info "GF is #{generic_file.pid}"
  if generic_file
    datastream = generic_file.datastreams[datastream_id]
    #logger.info "DS is #{datastream.inspect}"
    if datastream
      #logger.info "Datastream for audit = #{datastream.inspect}"
      version =  datastream.versions.select { |v| v.versionID == version_id}.first
      log = GenericFile.run_audit(version)

      # look up the user for sending the message to
       = generic_file.depositor
      #logger.info "User login is #{login}"`
      #logger.info "All users = #{User.all}"
      if 
        user = User.find_by_user_key()
        logger.warn "User '#{}' not found" unless user
        #logger.info "ZZZ user = #{user.inspect}"
        job_user = User.audituser()
        #send the user a message about the failing audit
        unless (log.pass == 1)
          message = "The audit run at #{log.created_at} for #{log.pid}:#{log.dsid}:#{log.version} was #{log.pass == 1 ? 'passing' : 'failing'}."
          subject = (log.pass == 1 ? PASS : FAIL)
          job_user.send_message(user, message, subject)
        end 
      end
    else
      logger.warn "No datastream for audit!!!!! pid: #{generic_file_id} dsid: #{datastream_id}"
    end
  else
    logger.warn "No generic file for data stream audit!!!!! pid: #{generic_file_id} dsid: #{datastream_id}"
  end
end