Class: Robots::SdrRepo::SdrIngest::VerifyAgreement

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

Overview

Robot for verifying that an APO or agreement object exists for each object

Constant Summary collapse

@@valid_apo_ids =

A cache of APO/agreement object identifiers that have already been verified to exist in Sedora

[]

Class Method Summary collapse

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 = {}) ⇒ VerifyAgreement

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


22
23
24
25
# File 'lib/sdr_ingest/verify_agreement.rb', line 22

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

Class Method Details

.valid_apo_idsObject


13
14
15
# File 'lib/sdr_ingest/verify_agreement.rb', line 13

def self.valid_apo_ids
  @@valid_apo_ids
end

Instance Method Details

#find_apo_id(druid, relationship_md_pathname) ⇒ String

Extract the APO id from the relationship metadata

Parameters:

  • druid (String)

    The object identifier

  • relationship_md_pathname (Pathname)

    The location of the relationshipMetadata.xml file

Returns:

  • (String)

    The 'isGovernedBy' APO identifier found in the relationshipMetadata, or raise exception


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sdr_ingest/verify_agreement.rb', line 91

def find_apo_id(druid, relationship_md_pathname)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter find_apo_id")
  relationship_md = Nokogiri::XML(relationship_md_pathname.read)
  nodeset = relationship_md.xpath("//hydra:isGovernedBy", 'hydra' => 'http://projecthydra.org/ns/relations#')
  unless nodeset.empty?
    apo_id = nodeset.first.attribute_with_ns('resource', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    if apo_id
      return apo_id.text.split('/')[-1]
    else
      raise ItemError.new("Unable to find resource attribute in isGovernedBy node of relationshipMetadata")
    end
  else
    raise ItemError.new("Unable to find isGovernedBy node of relationshipMetadata")
  end
rescue StandardError => e
  raise ItemError.new("Unable to find APO id in relationshipMetadata")
end

#find_deposit_version(druid, deposit_pathname) ⇒ Pathname

Find the location of the file containing the relationshipMetadata

Parameters:

  • druid (String)

    The object identifier

  • deposit_pathname (Pathname)

    The location of the deposited object version

Returns:

  • (Pathname)

    The location of the relationshipMetadata.xml file, or raise exception


75
76
77
78
79
80
81
82
83
84
# File 'lib/sdr_ingest/verify_agreement.rb', line 75

def find_deposit_version(druid, deposit_pathname)
  vmfile = deposit_pathname.join('data', 'metadata', 'versionMetadata.xml')
  doc = Nokogiri::XML(vmfile.read)
  nodeset = doc.xpath("/versionMetadata/version")
  version_id = nodeset.last['versionId']
  raise "version_id is nil" if version_id.nil?
  version_id.to_i
rescue StandardError => e
  raise ItemError.new("Unable to find deposit version")
end

#find_relationship_metadata(deposit_pathname) ⇒ Object


66
67
68
69
# File 'lib/sdr_ingest/verify_agreement.rb', line 66

def (deposit_pathname)
  relationship_md_pathname = deposit_pathname.join('data', 'metadata', 'relationshipMetadata.xml')
  relationship_md_pathname.file? ? relationship_md_pathname : nil
end

#perform(druid) ⇒ void

This method returns an undefined value.

Process an object from the queue through this robot

Parameters:

  • druid (String)

    The item to be processed


31
32
33
34
# File 'lib/sdr_ingest/verify_agreement.rb', line 31

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

#verification_files(druid) ⇒ Object


135
136
137
138
# File 'lib/sdr_ingest/verify_agreement.rb', line 135

def verification_files(druid)
  files = []
  files
end

#verification_queries(druid) ⇒ Object


130
131
132
133
# File 'lib/sdr_ingest/verify_agreement.rb', line 130

def verification_queries(druid)
  queries = []
  queries
end

#verify_agreement(druid) ⇒ Boolean

Find the APO identifier in the relationshipMetadata,

and verify that the identifer belongs to a previously ingested object

Parameters:

  • druid (String)

    The object identifier

Returns:

  • (Boolean)

    true if APO was found, raise exception if verification fails


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/sdr_ingest/verify_agreement.rb', line 40

def verify_agreement(druid)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter verify_agreement")
  LyberCore::Log.debug("Druid being processed is #{druid}")
  deposit_pathname = Replication::SdrObject.new(druid).deposit_bag_pathname
  if relationship_md_pathname = (deposit_pathname)
    if apo_id = find_apo_id(druid, relationship_md_pathname)
      if verify_apo_id(druid, apo_id)
        LyberCore::Log.debug("APO id #{apo_id} was verified")
        true
      else
        raise ItemError.new("APO object #{apo_id} was not found in repository")
      end
    else
      raise ItemError.new("APO ID not found in relationshipMetadata")
    end
  else
    version = find_deposit_version(druid, deposit_pathname)
    if version > 1
      LyberCore::Log.debug("APO verification skipped for version > 1")
      true
    else
      raise ItemError.new("relationshipMetadata.xml not found in deposited metadata files")
    end
  end
end

#verify_apo_id(druid, apo_druid) ⇒ Boolean

Confirm that the APO identifier for the object corresponds to an already ingested object

Parameters:

  • druid (String)

    The object identifier

  • apo_druid (String)

    The APO identifier

Returns:

  • (Boolean)

    Return true if the object for the apo_druid is found in storage, or raise exception


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sdr_ingest/verify_agreement.rb', line 113

def verify_apo_id(druid, apo_druid)
  LyberCore::Log.debug("( #{__FILE__} : #{__LINE__} ) Enter verify_identifier")
  if @@valid_apo_ids.include?(apo_druid)
    true
  else
    apo_object = Moab::StorageServices.find_storage_object(apo_druid)
    if apo_object.object_pathname.directory?
      @@valid_apo_ids << apo_druid
      true
    else
      raise ItemError.new("APO object #{apo_druid} not found")
    end
  end
rescue StandardError => e
  raise ItemError.new("Unable to verify APO object #{apo_druid}")
end