KT_cmis_atom_server.services.inc.php
32.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<?php
/**
* Any feed must be a valid atom Feed document and conform to the guidelines below:
1. Updated will be the latest time the folder or its contents was updated. If unknown by the underlying repository, it should be the current time.
2. Author/name will be the CMIS property createdBy
3. Title will be the CMIS property name
4. App:edited will be the CMIS property lastModifiedDate
5. Link with relation self will be generated to return the uri of the feed
*/
/**
* At any point where an Atom document of type Entry is sent or returned, it must be a valid Atom Entry document and conform to the guidelines below:
1. Atom:Title will be best efforts by the repository. The repository should chose a property closest to Title.
2. App:edited will be CMIS:lastModifiedDate
3. Link with relation self will be the URI that returns the Atom Entry document
4. Published will be CMIS:createdDate
5. Atom:author will be CMIS:creator
6. For content tags
7. Documents with content
a. Leverage the src attribute to point to the same link as stream
b. The repository SHOULD populate the summary tag with text that at best efforts represents the documents. For example, an HTML table containing the properties and their values for simple feed readers
i. Other (Content-less document, Folder, Relationship, Type, etc) โ best efforts at generating HTML text that represents the object. That text would normally go into the summary tag, but since there is no content, goes in the content tag.
8. If content src is specified, the summary SHOULD contain a text or html representation of the object.
9. Links will be used to provide URIs to CMIS functionality
10. Link relations may be omitted if the function is not allowed and that function would not show up on getAllowableActions.
11. Links may be omitted if the repository does not support that capability
12. All CMIS properties will be exposed in CMIS properties tag even if they are duplicated in an atom element
When POSTing an Atom Document, the atom fields take precedence over the CMIS property field for writeable properties. For example, atom:title will overwrite cmis:name
*/
// load all available CMIS services
include_once CMIS_API . '/ktRepositoryService.inc.php';
include_once CMIS_API . '/ktNavigationService.inc.php';
include_once CMIS_API . '/ktObjectService.inc.php';
include_once CMIS_API . '/ktVersioningService.inc.php';
include_once 'KT_cmis_atom_service_helper.inc.php';
// TODO proper first/last links
// FIXME any incorrect or missing links
// FIXME ContentStreamAllowed tag is empty (at least sometimes)
/**
* AtomPub Service: folder
*/
class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
/**
* Deals with GET actions for folders.
* This includes children and tree/descendant listings as well as individual folder retrieval
*/
public function GET_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
// TODO implement full path/node separation as with Alfresco - i.e. path requests come in on path/ and node requests come in on node/
// path request e.g.: path/Root Folder/DroppedDocuments
// node request e.g.: node/F1/children
// node request e.g.: node/F2/parent
// node request e.g.: node/F2
if (urldecode($this->params[0]) == 'Root Folder')
{
$folderId = CMISUtil::encodeObjectId(FOLDER, 1);
$folderName = urldecode($this->params[0]);
}
else if ($this->params[0] == 'path')
{
$ktapi =& KT_cmis_atom_service_helper::getKt();
$folderId = KT_cmis_atom_service_helper::getFolderId($this->params, $ktapi);
}
else if (($this->params[1] == 'children') || ($this->params[1] == 'descendants'))
{
$folderId = $this->params[0];
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
$response = $ObjectService->getProperties($repositoryId, $folderId, false, false);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response['message']);
$this->responseFeed = $feed;
return null;
}
else {
$response = $response['results'];
}
$folderName = $response['properties']['name']['value'];
}
// NOTE parent changes to parents in later specification
// TODO update when updating to later specification
// TODO this only returns one parent, need to implement returnToRoot also
else if ($this->params[1] == 'parent')
{
// abstract this to be used also by the document service (and the PWC service?) ???
// alternatively use getFolderParent here makes sense and use getObjectParents when document service?
$folderId = $this->params[0];
$NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt());
$response = $NavigationService->getFolderParent($repositoryId, $folderId, false, false, false);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response['message']);
$this->responseFeed = $feed;
return null;
}
else {
$response = $response['results'];
}
// we know that a folder will only have one parent, so we can assume element 0
$folderId = $response[0]['properties']['objectId']['value'];
$folderName = $response[0]['properties']['name']['value'];
}
else {
$folderId = $this->params[0];
}
if (!empty($this->params[1]) && (($this->params[1] == 'children') || ($this->params[1] == 'descendants')))
{
$NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt());
$feed = $this->getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $this->params[1]);
}
else
{
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $folderId);
}
// Expose the responseFeed
$this->responseFeed = $feed;
}
/**
* Deals with folder service POST actions.
* This includes creation/moving of both folders and documents.
*/
public function POST_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
// set default action, objectId and typeId
$action = 'create';
$objectId = null;
$typeId = null;
$folderId = $this->params[0];
$title = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'title');
$summary = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'summary');
// determine whether this is a folder or a document action
// document action create will have a content tag <atom:content> or <content> containing base64 encoding of the document
// move action will have an existing id supplied as a parameter - not sure how this works yet as the CMIS clients we are
// testing don't support move functionality at this time (2009/07/23) and so we are presuming the following format:
// /folder/<folderId>/children/<objectId>
// also possible that there will be an existing ObjectId property, try to cater for both until we know how it really works
// check for existing object id as parameter in url
if (isset($this->params[2]))
{
$action = 'move';
$objectId = $this->params[2];
}
// get object properties - todo send through original properties array and not modified version
$cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->rawContent);
$properties = array('name' => $title, 'summary' => $summary, 'objectTypeId' => $cmisObjectProperties['cmis:objectTypeId']);
// check for existing object id as property of submitted object data
if (!empty($cmisObjectProperties['cmis:objectId']))
{
$action = 'move';
$objectId = $cmisObjectProperties['cmis:objectId'];
}
// TODO there may be more to do for the checking of an existing object.
// e.g. verifying that it does indeed exist, and throwing an exception if it does not:
// "If the objected property is present but not valid an exception will be thrown" (from CMIS specification)
// NOTE this exception should be thrown in the service API code and not here.
// determine type if object is being moved
if (!is_null($objectId)) {
CMISUtil::decodeObjectId($objectId, $typeId);
}
// check for content stream
$content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent);
// NOTE not sure about the text type, will need testing, most content will be base64
$cmisContent = (isset($content['cmisra:base64'])
? $content['cmisra:base64']
: ((isset($content['cmisra:text']))
? $content['cmisra:text']
: null));
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
$success = false;
$error = null;
if ($action == 'create')
{
// TODO detection and passing of optional parameters (policies, ACEs, etc...) as well as support for other object-types
if ($cmisObjectProperties['cmis:objectTypeId'] == 'folder') {
$newObjectId = $ObjectService->createFolder($repositoryId, ucwords($cmisObjectProperties['cmis:objectTypeId']),
$properties, $folderId);
}
else {
// NOTE for the moment only creation in minor versioning state
$newObjectId = $ObjectService->createDocument($repositoryId, $properties, $folderId, $cmisContent, 'minor');
}
if ($newObjectId['status_code'] == 0) {
$newObjectId = $newObjectId['results'];
// check if returned Object Id is a valid CMIS Object Id
CMISUtil::decodeObjectId($newObjectId, $typeId);
if ($typeId != 'Unknown') {
$success = true;
}
else {
$error = 'Unknown Object Type';
}
}
else {
$error = $newObjectId['message'];
}
}
else if ($action == 'move')
{
$response = $ObjectService->moveObject($repositoryId, $objectId, '', $folderId);
if ($response['status_code'] == 0) {
$success = true;
}
else {
$error = $response['message'];
}
// same object as before
$newObjectId = $objectId;
// FIXME why set this? it does not appear to get used
$typeId = ucwords($cmisObjectProperties['cmis:objectTypeId']);
}
if ($success)
{
$this->setStatus(($action == 'create') ? self::STATUS_CREATED : self::STATUS_UPDATED);
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $newObjectId, 'POST');
}
else {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $error);
}
// Expose the responseFeed
$this->responseFeed = $feed;
}
/**
* Deals with DELETE actions for folders.
* This includes deleting a single folder (with no content) and deleting an entire folder tree
*
* @return 204 on success, 500 on error
*/
public function DELETE_action()
{
// NOTE due to the way KnowledgeTree works with folders this is always going to call deleteTree.
// we COULD call deleteObject but when we delete a folder we expect to be trying to delete
// the folder and all content.
// TODO determine whether client is requesting deleteObject or deleteTree
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
// attempt delete - last parameter sets $deleteAllVersions true
$response = $ObjectService->deleteTree($repositoryId, $this->params[0], 'delete', true);
// error?
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']);
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
else {
$response = $response['results'];
}
// list of failed objects?
if (is_array($response))
{
$this->setStatus(self::STATUS_SERVER_ERROR);
$feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
$feed->newField('title', 'Error: Failed to delete all objects in tree: ' . self::STATUS_SERVER_ERROR, $feed);
foreach($response as $failed)
{
$entry = $feed->newEntry();
$objectElement = $feed->newElement('cmisra:object');
$propertiesElement = $feed->newElement('cmis:properties');
$propElement = $feed->newElement('cmis:propertyId');
$propElement->appendChild($feed->newAttr('cmis:name', 'objectId'));
$feed->newField('cmis:value', $failed, $propElement);
$propertiesElement->appendChild($propElement);
$objectElement->appendChild($propertiesElement);
$entry->appendChild($objectElement);
}
$this->responseFeed = $feed;
return null;
}
// success
$this->setStatus(self::STATUS_NO_CONTENT);
}
/**
* Retrieves children/descendants of the specified folder
* TODO this currently only works in children mode, add descendants
*
* @param string $repositoryId
* @param string $folderId folder id for which children/descendants are requested
* @param string $feedType children or descendants
* @return string CMIS AtomPub feed
*/
private function getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $feedType = 'children')
{
if ($feedType == 'children') {
$entries = $NavigationService->getChildren($repositoryId, $folderId, false, false);
}
else if ($feedType == 'descendants') {
// TODO how will client request depth?
$entries = $NavigationService->getDescendants($repositoryId, $folderId);
}
else {
// error, we shouldn't be here, if we are then the wrong service/function was called
}
// hack, for removing one level of access
$entries = $entries['results'];
// $baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL
$feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
$workspace = $feed->getWorkspace();
$feed->newField('title', $folderName . ' ' . ucwords($feedType), $feed);
// TODO dynamic?
$feedElement = $feed->newField('author');
$element = $feed->newField('name', 'System', $feedElement);
$feed->appendChild($feedElement);
// id
$feed->newField('id', 'urn:uuid:' . $folderId . '-' . $feedType, $feed);
// TODO get actual most recent update time, only use current if no other available
$feed->newField('updated', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel', 'self'));
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' . $folderId . '/' . $feedType));
$feed->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel', 'source'));
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' . $folderId));
$feed->appendChild($link);
KT_cmis_atom_service_helper::createObjectFeed($feed, $entries, $folderName);
$feed->newField('cmis:hasMoreItems', 'false', $feed);
return $feed;
}
}
/**
* AtomPub Service: document
*/
// TODO confirm that an error response is sent when a document has status "deleted"
class KT_cmis_atom_service_document extends KT_cmis_atom_service {
/**
* Deals with GET actions for documents.
* This includes individual document retrieval
*/
public function GET_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
$objectId = $this->params[0];
// TODO this is "parents" in later versions of the specification
// update accordingly when updating to newer specification
if ($this->params[1] == 'parent')
{
// abstract this to be used also by the document service (and the PWC service?) ???
// alternatively use getFolderParent here makes sense and use getObjectParents when document service?
$NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt());
$response = $NavigationService->getObjectParents($repositoryId, $objectId, false, false);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response['message']);
$this->responseFeed = $feed;
return null;
}
else {
$response = $response['results'];
}
// for now a document will only have one parent as KnowledgeTree does not support multi-filing
// TODO update this code if/when multi-filing support is added
$objectId = $response[0]['properties']['objectId']['value'];
}
// determine whether we want the document entry feed or the actual physical document content.
// this depends on $this->params[1]
else if (!empty($this->params[1]))
{
KT_cmis_atom_service_helper::downloadContentStream($this, $ObjectService, $repositoryId);
return null;
}
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $objectId);
// Expose the responseFeed
$this->responseFeed = $feed;
}
/**
* Deals with DELETE actions for documents.
* This includes deletion of a specific version of a document (latest version) via deleteObject
* as well as deleteAllVersions
*
* @return 204 on success, 500 on error
*/
public function DELETE_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt());
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
// attempt delete
$response = $ObjectService->deleteObject($repositoryId, $this->params[0]);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']);
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
// success
$this->setStatus(self::STATUS_NO_CONTENT);
}
}
class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
protected $serviceType = 'PWC';
/**
* Deals with GET actions for Private Working Copies.
* This includes individual Private Working Copy retrieval
*/
public function GET_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
// determine whether we want the Private Working Copy entry feed or the actual physical Private Working Copy content.
// this depends on $this->params[1]
if (!empty($this->params[1]))
{
KT_cmis_atom_service_helper::downloadContentStream($this, $ObjectService, $repositoryId);
return null;
}
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]);
// Expose the responseFeed
$this->responseFeed = $feed;
}
/**
* Deals with DELETE actions for Private Working Copies.
* This includes deletion of a specific version of a document (latest version) via deleteObject
* as well as deleteAllVersions
*
* @return 204 on success, 500 on error
*/
public function DELETE_action()
{
// call the cancel checkout function
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt());
$response = $VersioningService->cancelCheckout($repositoryId, $this->params[0]);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']);
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
$this->setStatus(self::STATUS_NO_CONTENT);
$this->responseFeed = null;
}
public function PUT_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt());
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
// get object properties
$cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->rawContent);
// check for content stream
$content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent);
// NOTE not sure about the text type, will need testing, most content will be base64
$cmisContent = (isset($content['cmisra:base64'])
? $content['cmisra:base64']
: ((isset($content['cmisra:text']))
? $content['cmisra:text']
: null));
// if we haven't found it now, the hack begins - retrieve the EXISTING content and submit this as the contentStream
// this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly
// other CMIS clients are the same, does not send a content stream on checkin nor does it offer the user a method to choose one)
// NOTE that if the content is INTENDED to be empty this and all the above checks will FAIL!
// FIXME this is horrible, terrible, ugly and bad!
if (empty($cmisContent)) {
$cmisContent = base64_encode(KT_cmis_atom_service_helper::getContentStream($this, $ObjectService, $repositoryId));
}
// and if we don't have the content stream by now, we give up...but leave the error to be generated by the underlying KnowledgeTree code
// checkin function call
// TODO dynamically detect version change type - leaving this for now as the CMIS clients tested do not appear to
// offer the choice to the user - perhaps it will turn out that this will come from somewhere else but for now
// we assume minor version updates only
$major = false;
$checkinComment = '';
$response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']);
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]);
// Expose the responseFeed
$this->responseFeed = $feed;
}
}
/**
* AtomPub Service: checkedout
*/
class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
/**
* Deals with GET actions for checkedout documents.
*/
public function GET_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt());
$checkedout = $NavigationService->getCheckedOutDocs($repositoryId);
// hack, for removing one level of access
$checkedout = $checkedout['results'];
//Create a new response feed
$feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
$workspace = $feed->getWorkspace();
$feed->newField('title', 'Checked out Documents', $feed);
// TODO dynamic?
$feedElement = $feed->newField('author');
$element = $feed->newField('name', 'admin', $feedElement);
$feed->appendChild($feedElement);
$feed->appendChild($feed->newElement('id', 'urn:uuid:checkedout'));
// TODO get actual most recent update time, only use current if no other available
$feed->appendChild($feed->newElement('updated', KT_cmis_atom_service_helper::formatDatestamp()));
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel', 'self'));
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout'));
$feed->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','first'));
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
$link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
$feed->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','last'));
// TODO set page number correctly - to be done when we support paging the the API
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
$link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
$feed->appendChild($link);
foreach($checkedout as $cmisEntry) {
KT_cmis_atom_service_helper::createObjectEntry($feed, $cmisEntry, $folderName, true);
}
$feed->newField('cmis:hasMoreItems', 'false', $feed);
// Expose the responseFeed
$this->responseFeed = $feed;
}
public function POST_action()
{
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt());
$ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
$cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->rawContent);
// check for existing object id as property of submitted object data
if (empty($cmisObjectProperties['cmis:objectId']))
{
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
$response = $VersioningService->checkOut($repositoryId, $cmisObjectProperties['cmis:objectId']);
if ($response['status_code'] == 1) {
$feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
// Expose the responseFeed
$this->responseFeed = $feed;
return null;
}
$this->setStatus(self::STATUS_CREATED);
$feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $cmisObjectProperties['cmis:objectId'], 'POST');
// Expose the responseFeed
$this->responseFeed = $feed;
}
}
/**
* AtomPub Service: types
*/
class KT_cmis_atom_service_types extends KT_cmis_atom_service {
public function GET_action()
{
$RepositoryService = new KTRepositoryService();
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
$types = $RepositoryService->getTypes($repositoryId);
// hack for removing one level of access
$types = $types['results'];
$type = ((empty($this->params[0])) ? 'all' : $this->params[0]);
$feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
// Expose the responseFeed
$this->responseFeed = $feed;
}
}
/**
* AtomPub Service: type
*/
class KT_cmis_atom_service_type extends KT_cmis_atom_service {
public function GET_action()
{
$RepositoryService = new KTRepositoryService();
$repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
if (!isset($this->params[1])) {
// For easier return in the wanted format, we call getTypes instead of getTypeDefinition.
// Calling this with a single type specified returns an array containing the definition of
// just the requested type.
// NOTE could maybe be more efficient to call getTypeDefinition direct and then place in
// an array on this side? or directly expose the individual entry response code and
// call directly from here rather than via getTypeFeed.
$type = ucwords($this->params[0]);
$types = $RepositoryService->getTypes($repositoryId, $type);
// hack for removing one level of access
$types = $types['results'];
$feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
}
else {
// TODO dynamic dates, as needed everywhere
// NOTE children of types not yet implemented and we don't support any non-basic types at this time
$feed = $this->getTypeChildrenFeed($this->params[1]);
}
// Expose the responseFeed
$this->responseFeed=$feed;
}
/**
* Retrieves a list of child types for the supplied type
*
* NOTE this currently returns a hard coded empty list, since we do not currently support child types
* TODO make dynamic if/when we support checking for child types (we don't actually need to support child types themselves)
*
* @param string $type
* @return string CMIS AtomPub feed
*/
private function getTypeChildrenFeed()
{
//Create a new response feed
$feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
$feed->newField('title', 'Child Types of ' . ucwords($this->params[0]), $feed);
$feed->newField('id', $this->params[0] . '-children', $feed);
// TODO fetch child types - to be implemented when we support child types in the API
// links
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','first'));
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
$link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','last'));
// TODO set page number correctly - to be done when we support paging the the API
$link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
$link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
$feed->newField('updated', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
$feed->newField('cmis:hasMoreItems', 'false', $feed);
return $feed;
}
}
?>