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

Returns set workflow name, step name, log location, log severity level


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

Returns the versionId found in the last version element, or nil if missing

Parameters:

  • pathname (Pathname)

    the location of the inventory file

Returns:

  • (Integer)

    the versionId found in the last version element, or nil if missing


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

This method returns an undefined value.

Returns process an object from the queue through this robot See LyberCore::Robot#work

Parameters:

  • druid (String)

    The item to be processed


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

Returns Validate the bag containing the digital object

Parameters:

  • druid (String)

    The object identifier

Returns:

  • (Boolean)

    Validate the bag containing the digital object


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

Parameters:

  • pathname (Pathname)

    The location of the file containing a version number

  • expected (Integer)

    The version number that should be in the file

  • found (Integer)

    The version number that is actually in the file


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

Returns Test existence and correct version number of versionMetadata. Return true if OK, raise exception if not

Parameters:

  • bag (Archive::BagitBag)

    the BagIt bag whose versionMetadata is to be verified

  • current_version_id (Integer)

    The version number of the object's current version (or 0 if none)

Returns:

  • (Boolean)

    Test existence and correct version number of versionMetadata. Return true if OK, raise exception if not


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

Returns the versionId found in the last version element, or nil if missing

Parameters:

  • pathname (Pathname)

    the location of the versionMetadata file

Returns:

  • (Integer)

    the versionId found in the last version element, or nil if missing


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