Sha256: 8ba7ad3db05f772e4abbd1d213087a1044ab5ccae235b0789a642c68423b4d3c

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

module Rubydora::AuditTrail

  def audit_trail(pid)
    FedoraAuditTrail.new(object_xml(pid: pid))
  end

  private
    
  AT_NS = {'audit' => 'info:fedora/fedora-system:def/audit#'}
  FOXML_NS = {'foxml' => 'info:fedora/fedora-system:def/foxml#'}
  AT_XPATH = '/foxml:digitalObject/foxml:datastream[@ID = "AUDIT"]/descendant::audit:auditTrail'
    
  class FedoraAuditTrail
    def initialize(object_xml)
      @ng_xml = Nokogiri::XML(object_xml).xpath(AT_XPATH, FOXML_NS.merge(AT_NS))  
    end
    def records
      if !@records
        @records = []
        @ng_xml.xpath('.//audit:record', AT_NS).each do |node| 
          @records << FedoraAuditRecord.new(node)
        end
      end
      @records
    end
    def to_xml
      @ng_xml.to_xml
    end
  end
  
  class FedoraAuditRecord
    def initialize(node)
      @record = node
    end
    def id
      @record['ID']
    end
    def process_type
      @record.at_xpath('audit:process/@type', AT_NS).text
    end
    def action
      @record.at_xpath('audit:action', AT_NS).text
    end
    def component_id
      @record.at_xpath('audit:componentID', AT_NS).text
    end
    def responsibility
      @record.at_xpath('audit:responsibility', AT_NS).text
    end
    def date
      @record.at_xpath('audit:date', AT_NS).text
    end
    def justification
      @record.at_xpath('audit:justification', AT_NS).text
    end
  end    

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubydora-1.8.1 lib/rubydora/audit_trail.rb
rubydora-1.8.0 lib/rubydora/audit_trail.rb
rubydora-1.7.5 lib/rubydora/audit_trail.rb
rubydora-1.7.4 lib/rubydora/audit_trail.rb
rubydora-1.7.3 lib/rubydora/audit_trail.rb
rubydora-1.7.1 lib/rubydora/audit_trail.rb
rubydora-1.7.0 lib/rubydora/audit_trail.rb
rubydora-1.7.0.pre1 lib/rubydora/audit_trail.rb