Class: Robots::SdrRepo::SdrIngest::ValidateBag

Inherits:
Robots::SdrRepo::SdrRobot show all
Defined in:
lib/sdr_ingest/validate_bag.rb

Overview

Robot for Validating BagIt bags that are transferred to SDR's deposit area.

Instance Method Summary collapse

Methods inherited from Robots::SdrRepo::SdrRobot

#create_workflow_rows, #get_workflow_status, #get_workflow_xml, #process_item, #transmit, #update_workflow_error_status, #update_workflow_status

Constructor Details

#initialize(opts = {}) ⇒ ValidateBag


16
17
18
# File 'lib/sdr_ingest/validate_bag.rb', line 16

def initialize(opts = {})
  super(self.class.workflow_name, self.class.step_name, opts)
end

Instance Method Details

#inventory_version_id(pathname) ⇒ Integer


77
78
79
80
81
82
# File 'lib/sdr_ingest/validate_bag.rb', line 77

def inventory_version_id(pathname)
  doc = Nokogiri::XML(File.open(pathname.to_s))
  nodeset = doc.xpath("/fileInventory")
  version_id = nodeset.first['versionId']
  version_id.nil? ? nil : version_id.to_i
end

#perform(druid) ⇒ void


23
24
25
26
# File 'lib/sdr_ingest/validate_bag.rb', line 23

def perform(druid)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter perform")
  validate_bag(druid)
end

#validate_bag(druid) ⇒ Boolean


30
31
32
33
34
35
36
37
38
39
# File 'lib/sdr_ingest/validate_bag.rb', line 30

def validate_bag(druid)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter validate_bag")
  storage_object = Replication::SdrObject.new(druid)
  bag = Archive::BagitBag.open_bag(storage_object.deposit_bag_pathname)
  verify_version_number(bag, storage_object.current_version_id)
  bag.verify_bag
  true
rescue StandardError => e
  raise ItemError.new("Bag validation failure")
end

#verification_files(druid) ⇒ Object


89
90
91
92
93
94
# File 'lib/sdr_ingest/validate_bag.rb', line 89

def verification_files(druid)
  deposit_bag_pathname = Replication::SdrObject.new(druid).deposit_bag_pathname
  files = []
  files << deposit_bag_pathname.join("bag-info.txt").to_s
  files
end

#verification_queries(druid) ⇒ Object


84
85
86
87
# File 'lib/sdr_ingest/validate_bag.rb', line 84

def verification_queries(druid)
  queries = []
  queries
end

#verify_version_id(pathname, expected, found) ⇒ Object


61
62
63
64
# File 'lib/sdr_ingest/validate_bag.rb', line 61

def verify_version_id(pathname, expected, found)
  raise "Version mismatch in #{pathname}, expected #{expected}, found #{found}" unless (expected == found)
  true
end

#verify_version_number(bag, current_version_id) ⇒ Boolean


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sdr_ingest/validate_bag.rb', line 44

def verify_version_number(bag, current_version_id)
  expected = current_version_id + 1
  vmfile = bag.bag_pathname.join('data', 'metadata', 'versionMetadata.xml')
  bag.verify_pathname(vmfile)
  verify_version_id(vmfile, expected, vmfile_version_id(vmfile))
  inventory_file = bag.bag_pathname.join('versionAdditions.xml')
  bag.verify_pathname(inventory_file)
  verify_version_id(inventory_file, expected, inventory_version_id(inventory_file))
  inventory_file = bag.bag_pathname.join('versionInventory.xml')
  bag.verify_pathname(inventory_file)
  verify_version_id(inventory_file, expected, inventory_version_id(inventory_file))
  true
end

#vmfile_version_id(pathname) ⇒ Integer


68
69
70
71
72
73
# File 'lib/sdr_ingest/validate_bag.rb', line 68

def vmfile_version_id(pathname)
  doc = Nokogiri::XML(File.open(pathname.to_s))
  nodeset = doc.xpath("/versionMetadata/version")
  version_id = nodeset.last['versionId']
  version_id.nil? ? nil : version_id.to_i
end