Class: Ddr::Batch::UpdateBatchObject

Inherits:
BatchObject
  • Object
show all
Defined in:
app/models/ddr/batch/update_batch_object.rb

Constant Summary

Constants inherited from BatchObject

BatchObject::EVENT_SUMMARY, BatchObject::VERIFICATION_FAIL, BatchObject::VERIFICATION_PASS

Instance Method Summary collapse

Methods inherited from BatchObject

#error_prefix, pid_from_identifier, #validate

Instance Method Details

#event_log_commentObject



53
54
55
# File 'app/models/ddr/batch/update_batch_object.rb', line 53

def event_log_comment
  "Updated by batch process (Batch #{batch.id}, BatchObject #{id})"
end

#local_validationsObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/models/ddr/batch/update_batch_object.rb', line 5

def local_validations
  errs = []
  errs << "#{error_prefix} PID required for UPDATE operation" unless pid
  if pid
    if ActiveFedora::Base.exists?(pid)
      errs << "#{error_prefix} #{batch.user.user_key} not permitted to edit #{pid}" unless batch.user.can?(:edit, ActiveFedora::Base.find(pid, :cast => true))
    else
      errs << "#{error_prefix} PID #{pid} not found in repository" unless ActiveFedora::Base.exists?(pid)
    end
  end
  errs
end

#model_datastream_keysObject



18
19
20
21
22
23
24
25
26
27
# File 'app/models/ddr/batch/update_batch_object.rb', line 18

def model_datastream_keys
  if pid
    begin
      obj = ActiveFedora::Base.find(pid, :cast => true)
      obj.datastreams.keys
    rescue
      nil
    end
  end
end

#process(user, opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/ddr/batch/update_batch_object.rb', line 29

def process(user, opts = {})
  unless verified
    repo_object = update_repository_object(user, opts)
    verifications = verify_repository_object
    verification_outcome_detail = []
    verified = true
    verifications.each do |key, value|
      verification_outcome_detail << "#{key}...#{value}"
      verified = false if value.eql?(VERIFICATION_FAIL)
    end
    update_attributes(:verified => verified)
    repo_object
  end
end

#results_messageObject



44
45
46
47
48
49
50
51
# File 'app/models/ddr/batch/update_batch_object.rb', line 44

def results_message
  if pid
    verification_result = (verified ? "Verified" : "VERIFICATION FAILURE")
    message = "Updated #{pid}...#{verification_result}"
  else
    message = "Attempt to update #{model} #{identifier} FAILED"
  end
end