rubydora 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ca62712080b3aa661150664a1f15ccf844b5465
4
- data.tar.gz: 2cb42824b25e8186d7e915c491025eda37895777
3
+ metadata.gz: 20f394c93019a3c503e281351a32155a0d072db2
4
+ data.tar.gz: 8b15c7e959de69614abf7b997b1b8e6612bc46f0
5
5
  SHA512:
6
- metadata.gz: 0c039aad847c6ffa384b2c90120b5495493ae1b6c2e85e1cb114316ab4746d02762946f3cc9f213bf2ef003ba8c69145f662149c1c8f34cdc7d870802d1c039b
7
- data.tar.gz: 941af1f3c2a577ae384775ae1ce189cc2db04cdae3b516b5e2e49ad6c20ca99f9a347757e11683425460e0c0e17d8d3e24374b8c3bc1ae3c2c8db1e3c3521a00
6
+ metadata.gz: e9ad02488fcf5132bf7b514d3fd4272f3d3af719ad33dd3db7d1d070f67dcd0432dc2b9c47a17bbec22a321b972b0c1d53783aae2477e6af951a10f8d593da72
7
+ data.tar.gz: 7e79232528768b9407f396b3d6af606083fe813a1f00a5ada92f8fcb64d06ed77e0b9067b9bcf81e6a0e54e33d9b620713b6a359075e8874b298b7bbca300bf8
data/History.textile CHANGED
@@ -1,3 +1,6 @@
1
+ h3. 1.6.0
2
+ * Added support for accessing the audit log
3
+
1
4
  h3. 1.5.1
2
5
  * Fixed backwards incompatibility. Readded Deprecation to Rubydora::DigitalObject so 5.x versions of AF can do 'Deprecation.silence(Rubydora::DigitalObject)'
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.1
1
+ 1.6.0
data/lib/rubydora.rb CHANGED
@@ -14,7 +14,7 @@ module Rubydora
14
14
  autoload :Callbacks, "rubydora/callbacks"
15
15
  autoload :ArrayWithCallback, "rubydora/array_with_callback"
16
16
  autoload :Transactions, "rubydora/transactions"
17
-
17
+ autoload :AuditTrail, "rubydora/audit_trail"
18
18
 
19
19
  require 'csv'
20
20
  require 'time'
@@ -0,0 +1,58 @@
1
+ module Rubydora::AuditTrail
2
+
3
+ def audit_trail
4
+ @audit_trail ||= FedoraAuditTrail.new(self)
5
+ end
6
+
7
+ private
8
+
9
+ AT_NS = {'audit' => 'info:fedora/fedora-system:def/audit#'}
10
+ FOXML_NS = {'foxml' => 'info:fedora/fedora-system:def/foxml#'}
11
+ AT_XPATH = '/foxml:digitalObject/foxml:datastream[@ID = "AUDIT"]/descendant::audit:auditTrail'
12
+
13
+ class FedoraAuditTrail
14
+ def initialize(object)
15
+ @ng_xml = Nokogiri::XML(object.repository.object_xml(:pid => object.pid)).xpath(AT_XPATH, FOXML_NS.merge(AT_NS))
16
+ end
17
+ def records
18
+ if !@records
19
+ @records = []
20
+ @ng_xml.xpath('.//audit:record', AT_NS).each do |node|
21
+ @records << FedoraAuditRecord.new(node)
22
+ end
23
+ end
24
+ @records
25
+ end
26
+ def to_xml
27
+ @ng_xml.to_xml
28
+ end
29
+ end
30
+
31
+ class FedoraAuditRecord
32
+ def initialize(node)
33
+ @record = node
34
+ end
35
+ def id
36
+ @record['ID']
37
+ end
38
+ def process_type
39
+ @record.at_xpath('audit:process/@type', AT_NS).text
40
+ end
41
+ def action
42
+ @record.at_xpath('audit:action', AT_NS).text
43
+ end
44
+ def component_id
45
+ @record.at_xpath('audit:componentID', AT_NS).text
46
+ end
47
+ def responsibility
48
+ @record.at_xpath('audit:responsibility', AT_NS).text
49
+ end
50
+ def date
51
+ @record.at_xpath('audit:date', AT_NS).text
52
+ end
53
+ def justification
54
+ @record.at_xpath('audit:justification', AT_NS).text
55
+ end
56
+ end
57
+
58
+ end
@@ -14,6 +14,7 @@ module Rubydora
14
14
  include ActiveModel::Dirty
15
15
  include Rubydora::ModelsMixin
16
16
  include Rubydora::RelationshipsMixin
17
+ include Rubydora::AuditTrail
17
18
 
18
19
  extend Deprecation
19
20
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#audit_trail" do
4
+
5
+ before do
6
+ path = File.join(File.dirname(__FILE__), 'fixtures', 'audit_trail.foxml.xml')
7
+ File.open(path, 'rb') do |f|
8
+ @xml = f.read
9
+ end
10
+ @repo = Rubydora::Repository.new
11
+ @repo.stub(:object_xml).with(hash_including(:pid => 'foo:bar')).and_return(@xml)
12
+ @test_object = Rubydora::DigitalObject.new('foo:bar', @repo)
13
+ end
14
+ it "should have the correct number of audit records" do
15
+ @test_object.audit_trail.records.length.should == 3
16
+ end
17
+ it "should return all the data from each audit record" do
18
+ record = @test_object.audit_trail.records.first
19
+ record.id.should == "AUDREC1"
20
+ record.process_type.should == "Fedora API-M"
21
+ record.action.should == "addDatastream"
22
+ record.component_id.should == "RELS-EXT"
23
+ record.responsibility.should == "fedoraAdmin"
24
+ record.date.should == "2013-02-25T16:43:06.219Z"
25
+ record.justification.should == ""
26
+ end
27
+
28
+ end
@@ -0,0 +1,110 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foxml:digitalObject VERSION="1.1" PID="changeme:242"
3
+ xmlns:foxml="info:fedora/fedora-system:def/foxml#"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
6
+ <foxml:objectProperties>
7
+ <foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="Active"/>
8
+ <foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE=""/>
9
+ <foxml:property NAME="info:fedora/fedora-system:def/model#ownerId" VALUE="fedoraAdmin"/>
10
+ <foxml:property NAME="info:fedora/fedora-system:def/model#createdDate" VALUE="2013-02-25T16:43:05.802Z"/>
11
+ <foxml:property NAME="info:fedora/fedora-system:def/view#lastModifiedDate" VALUE="2013-02-25T16:43:06.379Z"/>
12
+ </foxml:objectProperties>
13
+ <foxml:datastream ID="AUDIT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="false">
14
+ <foxml:datastreamVersion ID="AUDIT.0" LABEL="Audit Trail for this object" CREATED="2013-02-25T16:43:05.802Z" MIMETYPE="text/xml" FORMAT_URI="info:fedora/fedora-system:format/xml.fedora.audit">
15
+ <foxml:xmlContent>
16
+ <audit:auditTrail xmlns:audit="info:fedora/fedora-system:def/audit#">
17
+ <audit:record ID="AUDREC1">
18
+ <audit:process type="Fedora API-M"/>
19
+ <audit:action>addDatastream</audit:action>
20
+ <audit:componentID>RELS-EXT</audit:componentID>
21
+ <audit:responsibility>fedoraAdmin</audit:responsibility>
22
+ <audit:date>2013-02-25T16:43:06.219Z</audit:date>
23
+ <audit:justification></audit:justification>
24
+ </audit:record>
25
+ <audit:record ID="AUDREC2">
26
+ <audit:process type="Fedora API-M"/>
27
+ <audit:action>addDatastream</audit:action>
28
+ <audit:componentID>descMetadata</audit:componentID>
29
+ <audit:responsibility>fedoraAdmin</audit:responsibility>
30
+ <audit:date>2013-02-25T16:43:06.315Z</audit:date>
31
+ <audit:justification></audit:justification>
32
+ </audit:record>
33
+ <audit:record ID="AUDREC3">
34
+ <audit:process type="Fedora API-M"/>
35
+ <audit:action>addDatastream</audit:action>
36
+ <audit:componentID>rightsMetadata</audit:componentID>
37
+ <audit:responsibility>fedoraAdmin</audit:responsibility>
38
+ <audit:date>2013-02-25T16:43:06.379Z</audit:date>
39
+ <audit:justification></audit:justification>
40
+ </audit:record>
41
+ </audit:auditTrail>
42
+ </foxml:xmlContent>
43
+ </foxml:datastreamVersion>
44
+ </foxml:datastream>
45
+ <foxml:datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
46
+ <foxml:datastreamVersion ID="DC1.0" LABEL="Dublin Core Record for this object" CREATED="2013-02-25T16:43:05.802Z" MIMETYPE="text/xml" FORMAT_URI="http://www.openarchives.org/OAI/2.0/oai_dc/" SIZE="341">
47
+ <foxml:contentDigest TYPE="SHA-256" DIGEST="eb075bf6da5903e54464631dc998f66f95bffde9f4137132796457d31de5cd44"/>
48
+ <foxml:xmlContent>
49
+ <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
50
+ <dc:identifier>changeme:242</dc:identifier>
51
+ </oai_dc:dc>
52
+ </foxml:xmlContent>
53
+ </foxml:datastreamVersion>
54
+ </foxml:datastream>
55
+ <foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
56
+ <foxml:datastreamVersion ID="RELS-EXT.0" LABEL="Fedora Object-to-Object Relationship Metadata" CREATED="2013-02-25T16:43:06.219Z" MIMETYPE="application/rdf+xml" SIZE="284">
57
+ <foxml:contentDigest TYPE="SHA-256" DIGEST="013d2229de7bd91c61256563eff1b475cd1e8f7e45a2f15de5a36f2d20ec2852"/>
58
+ <foxml:xmlContent>
59
+ <rdf:RDF xmlns:ns0="info:fedora/fedora-system:def/model#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
60
+ <rdf:Description rdf:about="info:fedora/changeme:242">
61
+ <ns0:hasModel rdf:resource="info:fedora/afmodel:TestModel"></ns0:hasModel>
62
+ </rdf:Description>
63
+ </rdf:RDF>
64
+ </foxml:xmlContent>
65
+ </foxml:datastreamVersion>
66
+ </foxml:datastream>
67
+ <foxml:datastream ID="descMetadata" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
68
+ <foxml:datastreamVersion ID="descMetadata.0" LABEL="" CREATED="2013-02-25T16:43:06.315Z" MIMETYPE="text/xml" SIZE="215">
69
+ <foxml:contentDigest TYPE="SHA-256" DIGEST="3f588eca58dea77b31c9ed0b90e4560288a419856c4bb744fab9c7fe8749ad19"/>
70
+ <foxml:xmlContent>
71
+ <dc xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
72
+ <dcterms:title>DulHydra Test Object</dcterms:title>
73
+ <dcterms:identifier>test00001</dcterms:identifier>
74
+ </dc>
75
+ </foxml:xmlContent>
76
+ </foxml:datastreamVersion>
77
+ </foxml:datastream>
78
+ <foxml:datastream ID="rightsMetadata" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
79
+ <foxml:datastreamVersion ID="rightsMetadata.0" LABEL="" CREATED="2013-02-25T16:43:06.379Z" MIMETYPE="text/xml" SIZE="596">
80
+ <foxml:contentDigest TYPE="SHA-256" DIGEST="472f8634b31bd425dadd9206531ab02a70c08c22e4250bb2b0d3dd0314cfb240"/>
81
+ <foxml:xmlContent>
82
+ <rightsMetadata xmlns="http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1" version="0.1">
83
+ <copyright>
84
+ <human type="title"></human>
85
+ <human type="description"></human>
86
+ <machine type="uri"></machine>
87
+ </copyright>
88
+ <access type="discover">
89
+ <human></human>
90
+ <machine></machine>
91
+ </access>
92
+ <access type="read">
93
+ <human></human>
94
+ <machine>
95
+ <group>public</group>
96
+ </machine>
97
+ </access>
98
+ <access type="edit">
99
+ <human></human>
100
+ <machine></machine>
101
+ </access>
102
+ <embargo>
103
+ <human></human>
104
+ <machine></machine>
105
+ </embargo>
106
+ </rightsMetadata>
107
+ </foxml:xmlContent>
108
+ </foxml:datastreamVersion>
109
+ </foxml:datastream>
110
+ </foxml:digitalObject>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydora
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -237,6 +237,7 @@ files:
237
237
  - VERSION
238
238
  - lib/rubydora.rb
239
239
  - lib/rubydora/array_with_callback.rb
240
+ - lib/rubydora/audit_trail.rb
240
241
  - lib/rubydora/callbacks.rb
241
242
  - lib/rubydora/datastream.rb
242
243
  - lib/rubydora/digital_object.rb
@@ -249,6 +250,8 @@ files:
249
250
  - lib/rubydora/transactions.rb
250
251
  - lib/rubydora/version.rb
251
252
  - rubydora.gemspec
253
+ - spec/audit_trail_spec.rb
254
+ - spec/fixtures/audit_trail.foxml.xml
252
255
  - spec/lib/datastream_spec.rb
253
256
  - spec/lib/digital_object_spec.rb
254
257
  - spec/lib/integration_test_spec.rb
@@ -281,6 +284,8 @@ signing_key:
281
284
  specification_version: 4
282
285
  summary: Fedora Commons REST API ruby library
283
286
  test_files:
287
+ - spec/audit_trail_spec.rb
288
+ - spec/fixtures/audit_trail.foxml.xml
284
289
  - spec/lib/datastream_spec.rb
285
290
  - spec/lib/digital_object_spec.rb
286
291
  - spec/lib/integration_test_spec.rb