File Coverage

blib/lib/WebService/Cmis/Folder.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::Folder;
2              
3             =head1 NAME
4              
5             WebService::Cmis::Folder - Representation of a cmis folder
6              
7             See CMIS specification document 2.1.5 Folder Object
8              
9             =head1 DESCRIPTION
10              
11             This is a container object that holds other objects thus establishing a
12             hierarchical structure.
13              
14             Parent class: L
15              
16             =cut
17              
18 1     1   19916 use strict;
  1         3  
  1         47  
19 1     1   7 use warnings;
  1         3  
  1         47  
20 1     1   6 use WebService::Cmis qw(:relations :contenttypes :utils);
  1         4  
  1         1507  
21 1     1   98 use WebService::Cmis::Object();
  0            
  0            
22             use WebService::Cmis::NotImplementedException ();
23             use WebService::Cmis::NotSupportedException ();
24             use WebService::Cmis::AtomFeed::Objects ();
25             use Error qw(:try);
26             our @ISA = ('WebService::Cmis::Object');
27              
28             =head1 METHODS
29              
30             =over 4
31              
32             =cut
33              
34             =item getChildren(%params) -> $atomFeed
35              
36             returns a paged AtomFeed. The result set contains a list of objects for each
37             child of the Folder. The actual type of the object returned depends on the
38             object's CMIS base type id. For example, the method might return a list that
39             contains both Document objects and Folder objects.
40              
41             See CMIS specification document 2.2.3.1 getChildren
42              
43             The following optional arguments are supported:
44              
45             =over 4
46              
47             =item * maxItems
48              
49             =item * skipCount
50              
51             =item * orderBy
52              
53             =item * filter
54              
55             =item * includeRelationships
56              
57             =item * renditionFilter
58              
59             =item * includeAllowableActions
60              
61             =item * includePathSegment
62              
63             =back
64              
65             =cut
66              
67             sub getChildren {
68             my $this = shift;
69              
70             # get the appropriate 'down' link
71             my $childrenUrl = $this->getChildrenLink();
72              
73             # invoke the URL
74             my $result = $this->{repository}{client}->get($childrenUrl, @_); # here go the params
75              
76             #print STDERR "### getting children for\n".$result->toString(1)."\n###\n";
77              
78             # return the result set
79             require WebService::Cmis::AtomFeed::Objects;
80             return new WebService::Cmis::AtomFeed::Objects(repository=>$this->{repository}, xmlDoc=>$result);
81             }
82              
83             =item getChildrenLink() -> $href
84              
85             gets the Atom link that knows how to return this object's children.
86              
87             =cut
88              
89             sub getChildrenLink {
90             my $this = shift;
91              
92             my $url = $this->getLink(DOWN_REL, ATOM_XML_FEED_TYPE_P, 1);
93              
94             unless ($url) {
95             if ($ENV{CMIS_DEBUG}) {
96             _writeCmisDebug("Coulnd not find the children url in\n".$this->{xmlDoc}->toString(1)."\n");
97             }
98             throw Error::Simple("Could not find the children url"); # SMELL: do a custom exception
99             }
100              
101             return $url;
102             }
103              
104             =item getDescendantsLink -> $href
105              
106             returns the 'down' link of type CMIS_TREE_TYPE
107              
108             =cut
109              
110             sub getDescendantsLink {
111             my $this = shift;
112              
113             my $url = $this->getLink(DOWN_REL, CMIS_TREE_TYPE_P, 1);
114              
115             throw Error::Simple("Could not find the descendants url") unless $url; # SMELL: do a custom exception
116              
117             return $url;
118             }
119              
120             =item getDescendants(%params) -> $atomFeed
121              
122             gets the descendants of this folder. The descendants are returned as
123             a paged result set object. The result set contains a list of
124             cmis objects where the actual type of each object
125             returned will vary depending on the object's base type id.
126              
127             See CMIS specification document 2.2.3.2 getDescendants
128              
129             The following optional argument is supported:
130              
131             =over 4
132              
133             =item * depth:
134             Use depth=-1 for all descendants, which is the default if no
135             depth is specified.
136              
137             =item * filter
138              
139             =item * includeAllowableActions
140              
141             =item * includePathSegment
142              
143             =item * includeRelationships
144              
145             =item * renditionFilter
146              
147             =item * types
148              
149             =back
150              
151             =cut
152              
153             sub getDescendants {
154             my $this = shift;
155             my %params = @_;
156              
157             unless ($this->{repository}->getCapabilities()->{'GetDescendants'}) {
158             throw WebService::Cmis::NotSupportedException("This repository does not support getDescendants");
159             }
160              
161             # default the depth to -1, which is all descendants
162             $params{depth} = -1 unless defined $params{depth};
163              
164             # get the appropriate 'down' link
165             my $descendantsUrl = $this->getDescendantsLink;
166              
167             # invoke the URL
168             my $result = $this->{repository}{client}->get($descendantsUrl, %params);
169              
170             # return the result set
171             return new WebService::Cmis::AtomFeed::Objects(repository=>$this->{repository}, xmlDoc=>$result);
172             }
173              
174             =item getFolderParent -> $folderObj
175              
176             See CMIS specification document 2.2.3.4 getFolderParent
177              
178             =cut
179              
180             sub getFolderParent {
181             my $this = shift;
182              
183             # get the appropriate 'up' link
184             my $parentUrl = $this->getLink(UP_REL, undef, 1);
185              
186             return unless $parentUrl;
187              
188             # invoke the URL
189             my $result = $this->{repository}{client}->get($parentUrl, @_);
190              
191             my $nodeName = $result->documentElement->nodeName;
192             $nodeName =~ s/^([^:]+)://;
193              
194             # return the result
195             return new WebService::Cmis::Folder(repository => $this->{repository}, xmlDoc => $result)
196             if $nodeName eq 'entry';
197              
198             # some vendors (e.g. nuxeo) return a one-element AtomFeed instead of an
199             # AtomEntry even though the specs are clear in that respect
200              
201             throw Error::Simple("invalid result getting a folder parent")
202             unless $nodeName eq 'feed';
203              
204             my $feed = new WebService::Cmis::AtomFeed::Objects(
205             repository => $this->{repository},
206             xmlDoc => $result
207             );
208              
209             return $feed->getFirst;
210             }
211              
212             =item getFolderTree -> $atomFeed
213              
214             unlike getChildren or getDescendants this method returns only the descendant
215             objects that are folders. The results do not include the current folder.
216              
217             See CMIS specification document 2.2.3.3 getFolderTree
218              
219             The following optional arguments are supported:
220              
221             =over 4
222              
223             =item * depth
224              
225             =item * filter
226              
227             =item * includeRelationships
228              
229             =item * renditionFilter
230              
231             =item * includeAllowableActions
232              
233             =item * includePathSegment
234              
235             =back
236              
237             =cut
238              
239             sub getFolderTree {
240             my $this = shift;
241              
242             # Get the descendants link and do a GET against it
243             my $url = $this->getLink(FOLDER_TREE_REL, undef, 1);
244              
245             unless (defined $url) {
246             throw Error::Simple("Unable to determin folder tree link"); # SMELL: use custom exceptions
247             }
248              
249             # invoke
250             my $result = $this->{repository}{client}->get($url, @_);
251              
252             # return the result set
253             require WebService::Cmis::AtomFeed::Objects;
254             return new WebService::Cmis::AtomFeed::Objects(repository=>$this->{repository}, xmlDoc=>$result);
255             }
256              
257              
258             =item createDocument(
259             $name,
260             properties=>$propsList,
261             contentFile=>$filename,
262             contentData=>$data,
263             contentType=>$type,
264             contentEncoding=>$encoding,
265             %params
266             ) -> $cmisDocument
267              
268             creates a new Document object in the current Folder using
269             the properties provided.
270              
271             See Repository::createDocument
272              
273             =cut
274              
275             sub createDocument {
276             my $this = shift;
277             my $name = shift;
278              
279             return $this->{repository}->createDocument($name, folder=>$this, @_);
280             }
281              
282             =item createFolder(
283             $name,
284             properties=>$propertyList,
285             %params
286             ) -> $cmisFolder
287              
288             creates a new CMIS Folder using the properties provided.
289              
290             To specify a custom folder type, pass in a property called
291             cmis:objectTypeId representing the type ID
292             of the instance you want to create. If you do not pass in an object
293             type ID, an instance of 'cmis:folder' will be created.
294              
295              
296             =cut
297              
298             sub createFolder {
299             my $this = shift;
300             my $name = shift;
301              
302             return $this->{repository}->createFolder($name, folder=>$this, @_);
303             }
304              
305             =item addObject($obj)
306              
307             Adds an existing fileable non-folder object to a folder.
308             This is the same as moving the object to this folder. See
309             Object::moveTo.
310              
311             See CMIS specification document 2.2.5.1 addObjectToFolder
312              
313             =cut
314              
315             sub addObject {
316             return $_[1]->moveTo($_[0]);
317             }
318              
319             =item removeObject($obj)
320              
321             removes an object from this folder. this is done by posting it
322             to the unfiled collection, providing the current folderId.
323             See Object::unfile
324              
325             See CMIS specification document 2.2.5.2
326              
327             =cut
328              
329             sub removeObject {
330             return $_[1]->unfile($_[0]);
331             }
332              
333             =item deleteTree
334              
335             Deletes the folder and all of its descendant objects.
336              
337             my $resultSet = $folder->getDescendants()
338             my $size = $resultSet->getSize();
339             my $failedToDelete = $folder.deleteTree()
340             if ($failedToDelete) {
341             ...
342             }
343            
344              
345             The following optional arguments are supported:
346              
347             =over 4
348              
349             =item * allVersions
350              
351             =item * unfileObjects
352              
353             =item * continueOnFailure
354              
355             =back
356              
357             See CMIS specification document 2.2.4.15
358              
359             =cut
360              
361             sub deleteTree {
362             my $this = shift;
363              
364             unless ($this->{repository}->getCapabilities()->{'GetDescendants'}) {
365             throw WebService::Cmis::NotSupportedException("This repository does not support getDescendants");
366             }
367              
368             my $url = $this->getDescendantsLink;
369             my $result = $this->{repository}{client}->delete($url, @_); # here go the params
370              
371             return unless $result;
372              
373             # failedToDelete: A list of identifiers of objects in the folder tree that were not deleted.
374             require WebService::Cmis::AtomFeed::Objects;
375             return new WebService::Cmis::AtomFeed::Objects(repository=>$this->{repository}, xmlDoc=>$result);
376             }
377              
378              
379             =back
380              
381             =head1 COPYRIGHT AND LICENSE
382              
383             Copyright 2012-2013 Michael Daum
384              
385             This module is free software; you can redistribute it and/or modify it under
386             the same terms as Perl itself. See F.
387              
388             =cut
389              
390             1;