File Coverage

blib/lib/WebService/Cmis/ChangeEntry.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package WebService::Cmis::ChangeEntry;
2              
3             =head1 NAME
4              
5             WebService::Cmis::ChangeEntry - Representation of an entry in a change log feed
6              
7             =head1 DESCRIPTION
8              
9             Objects of this class are collected as part of a L.
10              
11             Parent class: L
12              
13             =cut
14              
15 1     1   9967 use strict;
  1         3  
  1         455  
16 1     1   12 use warnings;
  1         4  
  1         49  
17 1     1   8 use WebService::Cmis qw(:namespaces :relations);
  1         2  
  1         332  
18 1     1   459 use WebService::Cmis::AtomEntry ();
  0            
  0            
19             use Error qw(:try);
20              
21             our @ISA = qw(WebService::Cmis::AtomEntry);
22              
23             our $CMIS_XPATH_PROPERTIES = new XML::LibXML::XPathExpression('./*[local-name()="object" and namespace-uri()="'.CMISRA_NS.'"]/*[local-name()="properties" and namespace-uri()="'.CMIS_NS.'"]/*[@propertyDefinitionId]');
24             our $CMIS_XPATH_CHANGETYPE = new XML::LibXML::XPathExpression('./*[local-name()="object" and namespace-uri()="'.CMISRA_NS.'"]/*[local-name()="changeEventInfo" and namespace-uri()="'.CMIS_NS.'"]/*[local-name()="changeType" and namespace-uri()="'.CMIS_NS.'"]');
25             our $CMIS_XPATH_CHANGETIME = new XML::LibXML::XPathExpression('./*[local-name()="object" and namespace-uri()="'.CMISRA_NS.'"]/*[local-name()="changeEventInfo" and namespace-uri()="'.CMIS_NS.'"]/*[local-name()="changeTime" and namespace-uri()="'.CMIS_NS.'"]');
26             our $CMIS_XPATH_ACL = new XML::LibXML::XPathExpression('./*[local-name()="object" and namespace-uri()="'.CMISRA_NS.'"]/*[local-name()="acl" and namespace-uri()="'.CMIS_NS.'"]');
27              
28             =head1 METHODS
29              
30             =over 4
31              
32             =cut
33              
34             sub DESTROY {
35             my $this = shift;
36              
37             undef $this->{xmlDoc};
38             undef $this->{properties};
39             }
40              
41             =item _initData
42              
43             resets the internal cache of this entry.
44              
45             =cut
46              
47             sub _initData {
48             my $this = shift;
49              
50             $this->SUPER::_initData;
51              
52             $this->{properties} = undef;
53             $this->{changeTime} = undef;
54             $this->{changeType} = undef;
55             }
56              
57              
58             =item getProperties() -> %properties
59              
60             returns a hash of L of the change entry. Note that depending on the
61             capabilities of the repository ("capabilityChanges") the list may not
62             include the actual property values that changed.
63              
64             =cut
65              
66             sub getProperties {
67             my $this = shift;
68              
69             unless (defined $this->{properties}) {
70             require WebService::Cmis::Property;
71             my $doc = $this->_getDocumentElement;
72             foreach my $propNode ($doc->findnodes($CMIS_XPATH_PROPERTIES)) {
73             my $property = WebService::Cmis::Property::load($propNode);
74             my $propId = $property->getId;
75             #print STDERR "property = ".$property->toString."\n";
76             if (defined $this->{properties}{$propId}) {
77             die "duplicate property $propId in ".$doc->toString(1);
78             }
79             $this->{properties}{$propId} = $property;
80             }
81             }
82              
83             return $this->{properties};
84             }
85              
86             =item getProperty($propName) -> $propValue
87              
88             returns the value of a given property or undef if not available.
89              
90             This is not covered by the cmis specs but makes live easier.
91              
92             =cut
93              
94             sub getProperty {
95             my ($this, $propName) = @_;
96              
97             my $props = $this->getProperties;
98             return unless $props->{$propName};
99             return $props->{$propName}->getValue;
100             }
101              
102             =item getObjectId -> $objectId
103              
104             returns the object ID of the object that changed.
105              
106             =cut
107             sub getObjectId {
108             return $_[0]->getProperty('cmis:objectId');
109             }
110              
111             =item getChangeTime -> $epochSeconds
112              
113             returns epoch seconds representing the time the change occurred.
114              
115             =cut
116              
117             sub getChangeTime {
118             my $this = shift;
119              
120             unless (defined $this->{changeTime}) {
121             $this->{changeTime} = WebService::Cmis::Property::parseDateTime($this->{xmlDoc}->findvalue($CMIS_XPATH_CHANGETIME));
122             }
123             return $this->{changeTime};
124             }
125              
126             =item getChangeType -> $changeType
127              
128             returns the type of change that occurred. The resulting value must be
129             one of:
130              
131             =over 4
132              
133             =item * created
134              
135             =item * updated
136              
137             =item * deleted
138              
139             =item * security
140              
141             =back
142              
143             =cut
144              
145             sub getChangeType {
146             my $this = shift;
147              
148             unless (defined $this->{changeType}) {
149             require WebService::Cmis::Property;
150             $this->{changeType} = $this->{xmlDoc}->findvalue($CMIS_XPATH_CHANGETYPE);
151             }
152             return $this->{changeType};
153             }
154              
155             =item getACL -> $aclObject
156              
157             returns the ACL object that is included with this Change Entry, or undef
158             if the change type is "deleted".
159              
160             if you call getContentChanges with includeACL=true, you will get a ACL
161             information embedded in this ChangeEntry object. Change entries don't appear to
162             have a self URL so instead of doing a reload with includeACL set to true, we'll
163             either see if the XML already has an ACL element and instantiate an ACL with
164             it, or we'll get the ACL_REL link, invoke that, and return the result.
165              
166             SMELL: duplicates WebService::Cmis::Object::ACL
167              
168             =cut
169              
170             sub getACL {
171             my $this = shift;
172              
173             # TODO: add the normal cache dance
174              
175             unless ($this->{repository}->getCapabilities()->{'ACL'}) {
176             throw WebService::Cmis::NotSupportedException("This repository does not support ACLs");
177             }
178              
179             my $result;
180              
181             if ($this->{xmlDoc}->exists($CMIS_XPATH_ACL)) {
182             ($result) = $this->{xmlDoc}->findnodes($CMIS_XPATH_ACL);
183             } else {
184             my $url = $this->getLink(ACL_REL);
185             $result = $this->{repository}{client}->get($url) if $url;
186             }
187              
188             return unless $result;
189              
190             require WebService::Cmis::ACL;
191             return new WebService::Cmis::ACL(xmlDoc=>$result);
192             }
193              
194              
195             =back
196              
197             =head1 COPYRIGHT AND LICENSE
198              
199             Copyright 2012-2013 Michael Daum
200              
201             This module is free software; you can redistribute it and/or modify it under
202             the same terms as Perl itself. See F.
203              
204             =cut
205              
206             1;