Commit 1de29d078e9b3a84d2f836846a7e12c6b5547d93

Authored by Paul Barrett
1 parent e5942d35

Removed unwanted parent link in CMIS object properties response for the root folder

KTS-4447. CMIS folder properties for root folder should not include a link to the parent

Fixed

Committed by: Paul Barrett

Reviewed by: Jarrett Jordaan
lib/api/ktcmis/classes/CMISRepository.inc.php
... ... @@ -61,7 +61,7 @@ class CMISRepository {
61 61 */
62 62 private $objectTypes;
63 63  
64   - function CMISRepository($repositoryId, $config = null)
  64 + function __construct($repositoryId, $config = null)
65 65 {
66 66 $this->repositoryId = $repositoryId;
67 67 $this->RepositoryInfo = new CMISRepositoryInfo();
... ... @@ -94,6 +94,9 @@ class CMISRepository {
94 94 // set info
95 95 foreach($config->repositoryInfo[0] as $field => $value)
96 96 {
  97 +// if ($field == 'rootFolderId') {
  98 +// $value = CMISUtil::encodeObjectId(FOLDER, $value);
  99 +// }
97 100 $this->setRepositoryInfoField($field, (string)$value);
98 101 }
99 102  
... ...
lib/api/ktcmis/util/CMISUtil.inc.php
... ... @@ -178,14 +178,14 @@ class CMISUtil {
178 178 // if sub-array
179 179 if (count($object['items']) > 0)
180 180 {
181   - $CMISArray[$count]['items'] = CMISUtil::createChildObjectHierarchy($object['items'], $repositoryURI, $ktapi);
  181 + $CMISArray[$count]['items'] = self::createChildObjectHierarchy($object['items'], $repositoryURI, $ktapi);
182 182 }
183 183 }
184 184 else
185 185 {
186 186 // NOTE why is this necessary? That's what you get for not commenting it at the time
187 187 // TODO comment this properly
188   - $CMISArray[$count] = CMISUtil::createChildObjectHierarchy($object, $repositoryURI, $ktapi);
  188 + $CMISArray[$count] = self::createChildObjectHierarchy($object, $repositoryURI, $ktapi);
189 189 }
190 190 }
191 191 }
... ... @@ -222,7 +222,7 @@ class CMISUtil {
222 222 // if more parent elements
223 223 if (count($input) > 0)
224 224 {
225   - $CMISElement['items'] = CMISUtil::createParentObjectHierarchy($input, $repositoryURI, $ktapi);
  225 + $CMISElement['items'] = self::createParentObjectHierarchy($input, $repositoryURI, $ktapi);
226 226 }
227 227  
228 228 $CMISArray[] = $CMISElement;
... ... @@ -252,7 +252,7 @@ class CMISUtil {
252 252 $object = $entry['object'];
253 253 $properties = $object->getProperties();
254 254  
255   - $hierarchy[$key] = CMISUtil::createObjectPropertiesEntry($properties);
  255 + $hierarchy[$key] = self::createObjectPropertiesEntry($properties);
256 256 }
257 257  
258 258 return $hierarchy;
... ... @@ -293,7 +293,7 @@ class CMISUtil {
293 293 'value' => $properties->getValue('Name'));
294 294  
295 295 $object['properties']['ParentId'] = array('type' => $properties->getFieldType('ParentId'),
296   - 'value' => CMISUtil::encodeObjectId('Folder',
  296 + 'value' => self::encodeObjectId('Folder',
297 297 $properties->getValue('ParentId')));
298 298  
299 299 $object['properties']['Uri'] = array('type' => $properties->getFieldType('Uri'),
... ... @@ -350,7 +350,7 @@ class CMISUtil {
350 350 /*
351 351 // if we have found a child/parent with one or more children/parents, recurse into the child/parent object
352 352 if (count($entry['items']) > 0) {
353   - $object[$linkText] = CMISUtil::decodeObjectHierarchy($entry['items'], $linkText);
  353 + $object[$linkText] = self::decodeObjectHierarchy($entry['items'], $linkText);
354 354 }
355 355 // NOTE may need to set a null value here in case webservices don't like it unset
356 356 // so we'll set it just in case...
... ... @@ -602,7 +602,7 @@ class CMISUtil {
602 602 // TODO consider checking whether content is encoded (currently we expect encoded)
603 603 // TODO choose between this and the alternative decode function (see CMISUtil class)
604 604 // this will require some basic benchmarking
605   - $contentStream = CMISUtil::decodeChunkedContentStream($contentStream);
  605 + $contentStream = self::decodeChunkedContentStream($contentStream);
606 606  
607 607 // NOTE There is a function in CMISUtil to do this, written for the unit tests but since KTUploadManager exists
608 608 // and has more functionality which could come in useful at some point I decided to go with that instead
... ... @@ -613,6 +613,22 @@ class CMISUtil {
613 613  
614 614 return $tempfilename;
615 615 }
  616 +
  617 + static public function getIdFromName($name, &$ktapi)
  618 + {
  619 + $folder = $ktapi->get_folder_by_name($name);
  620 +
  621 + return self::encodeObjectId(FOLDER, $folder->get_folderid());
  622 + }
  623 +
  624 + static public function isRootFolder($repositoryId, $folderId, &$ktapi)
  625 + {
  626 + $repository = new CMISRepository($repositoryId);
  627 + $repositoryInfo = $repository->getRepositoryInfo();
  628 + $rootFolder = self::getIdFromName($repositoryInfo->getRootFolderId(), $ktapi);
  629 +
  630 + return $folderId == $rootFolder;
  631 + }
616 632  
617 633 }
618 634  
... ...
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
... ... @@ -54,11 +54,9 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
54 54 * This includes children and tree/descendant listings as well as individual folder retrieval
55 55 */
56 56 public function GET_action()
57   - {
58   - $RepositoryService = new RepositoryService();
59   - $repositories = $RepositoryService->getRepositories();
60   - $repositoryId = $repositories[0]['repositoryId'];
61   -
  57 + {
  58 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  59 +
62 60 // TODO implement full path/node separation as with Alfresco - i.e. path requests come in on path/ and node requests come in on node/
63 61 // path request e.g.: path/Root Folder/DroppedDocuments
64 62 // node request e.g.: node/F1/children
... ... @@ -134,9 +132,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
134 132 */
135 133 public function POST_action()
136 134 {
137   - $RepositoryService = new RepositoryService();
138   - $repositories = $RepositoryService->getRepositories();
139   - $repositoryId = $repositories[0]['repositoryId'];
  135 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
140 136  
141 137 // set default action, objectId and typeId
142 138 $action = 'create';
... ... @@ -246,12 +242,10 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
246 242 // we COULD call deleteObject but when we delete a folder we expect to be trying to delete
247 243 // the folder and all content.
248 244  
249   - $RepositoryService = new RepositoryService();
  245 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  246 +
250 247 $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
251 248  
252   - $repositories = $RepositoryService->getRepositories();
253   - $repositoryId = $repositories[0]['repositoryId'];
254   -
255 249 // attempt delete
256 250 $response = $ObjectService->deleteTree($repositoryId, $this->params[0]);
257 251  
... ... @@ -369,12 +363,10 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service {
369 363 */
370 364 public function GET_action()
371 365 {
372   - $RepositoryService = new RepositoryService();
  366 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  367 +
373 368 $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
374 369  
375   - $repositories = $RepositoryService->getRepositories();
376   - $repositoryId = $repositories[0]['repositoryId'];
377   -
378 370 $objectId = $this->params[0];
379 371  
380 372 // TODO this is "parents" in later versions of the specification
... ... @@ -422,12 +414,10 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service {
422 414 // NOTE due to the way KnowledgeTree works with documents this is always going to call deleteAllVersions.
423 415 // we do not have support for deleting only specific versions (this may be added in the future.)
424 416  
425   - $RepositoryService = new RepositoryService();
  417 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  418 +
426 419 $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
427 420  
428   - $repositories = $RepositoryService->getRepositories();
429   - $repositoryId = $repositories[0]['repositoryId'];
430   -
431 421 // attempt delete
432 422 $response = $VersioningService->deleteAllVersions($repositoryId, $this->params[0]);
433 423  
... ... @@ -456,12 +446,10 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
456 446 */
457 447 public function GET_action()
458 448 {
459   - $RepositoryService = new RepositoryService();
  449 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  450 +
460 451 $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
461 452  
462   - $repositories = $RepositoryService->getRepositories();
463   - $repositoryId = $repositories[0]['repositoryId'];
464   -
465 453 // determine whether we want the Private Working Copy entry feed or the actual physical Private Working Copy content.
466 454 // this depends on $this->params[1]
467 455 if (!empty($this->params[1]))
... ... @@ -486,12 +474,11 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
486 474 public function DELETE_action()
487 475 {
488 476 // call the cancel checkout function
489   - $RepositoryService = new RepositoryService();
  477 +
  478 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  479 +
490 480 $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
491 481  
492   - $repositories = $RepositoryService->getRepositories();
493   - $repositoryId = $repositories[0]['repositoryId'];
494   -
495 482 $response = $VersioningService->cancelCheckout($repositoryId, $this->params[0]);
496 483  
497 484 if (PEAR::isError($response))
... ... @@ -508,13 +495,11 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
508 495  
509 496 public function PUT_action()
510 497 {
511   - $RepositoryService = new RepositoryService();
  498 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  499 +
512 500 $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
513 501 $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
514 502  
515   - $repositories = $RepositoryService->getRepositories();
516   - $repositoryId = $repositories[0]['repositoryId'];
517   -
518 503 // check for content stream
519 504 // NOTE this is a hack! will not work with CMISSpaces at least, probably not with any client except RestTest and similar
520 505 // where we can manually modify the input
... ... @@ -573,12 +558,10 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
573 558 */
574 559 public function GET_action()
575 560 {
576   - $RepositoryService = new RepositoryService();
  561 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  562 +
577 563 $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt());
578 564  
579   - $repositories = $RepositoryService->getRepositories();
580   - $repositoryId = $repositories[0]['repositoryId'];
581   -
582 565 $checkedout = $NavigationService->getCheckedOutDocs($repositoryId);
583 566  
584 567 //Create a new response feed
... ... @@ -631,13 +614,11 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
631 614  
632 615 public function POST_action()
633 616 {
634   - $RepositoryService = new RepositoryService();
  617 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
  618 +
635 619 $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
636 620 $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
637 621  
638   - $repositories = $RepositoryService->getRepositories();
639   - $repositoryId = $repositories[0]['repositoryId'];
640   -
641 622 $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->parsedXMLContent['@children']);
642 623  
643 624 // check for existing object id as property of submitted object data
... ... @@ -676,8 +657,7 @@ class KT_cmis_atom_service_types extends KT_cmis_atom_service {
676 657 public function GET_action()
677 658 {
678 659 $RepositoryService = new RepositoryService();
679   - $repositories = $RepositoryService->getRepositories();
680   - $repositoryId = $repositories[0]['repositoryId'];
  660 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
681 661  
682 662 $types = $RepositoryService->getTypes($repositoryId);
683 663 $type = ((empty($this->params[0])) ? 'all' : $this->params[0]);
... ... @@ -697,10 +677,7 @@ class KT_cmis_atom_service_type extends KT_cmis_atom_service {
697 677 public function GET_action()
698 678 {
699 679 $RepositoryService = new RepositoryService();
700   -
701   - // fetch repository id
702   - $repositories = $RepositoryService->getRepositories();
703   - $repositoryId = $repositories[0]['repositoryId'];
  680 + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
704 681  
705 682 if (!isset($this->params[1])) {
706 683 // For easier return in the wanted format, we call getTypes instead of getTypeDefinition.
... ...
webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php
1 1 <?php
2 2  
  3 +// initialise ktapi instance
  4 +KT_cmis_atom_service_helper::$ktapi = KT_cmis_atom_service_helper::getKt();
  5 +
3 6 class KT_cmis_atom_service_helper {
4 7  
5   - protected static $kt = null;
  8 + public static $ktapi = null;
  9 + public static $repositoryId = null;
  10 +
  11 + /**
  12 + * Helper function to set internal repository id
  13 + *
  14 + * @param object $RepositoryService
  15 + */
  16 + static public function setRepositoryId(&$RepositoryService = null)
  17 + {
  18 + if (is_null($RepositoryService)) {
  19 + $RepositoryService = new RepositoryService();
  20 + }
  21 +
  22 + $repositories = $RepositoryService->getRepositories();
  23 +
  24 + // TODO handle multiple repositories
  25 + self::$repositoryId = $repositories[0]['repositoryId'];
  26 + }
  27 +
  28 + /**
  29 + * Helper function to fetch internal repository id
  30 + *
  31 + * Calls set function automatically, use $set = false to prevent this and return the current setting, if any
  32 + *
  33 + * NOTE the function will automatically call the setRepositoryId function if no previous repository id was set
  34 + *
  35 + * @param object $RepositoryService
  36 + * @param boolean $RepositoryService
  37 + * @return string
  38 + */
  39 + static public function getRepositoryId(&$RepositoryService = null, $set = true)
  40 + {
  41 + if (empty(self::$repositoryId) || $set) {
  42 + self::setRepositoryId($RepositoryService);
  43 + }
  44 +
  45 + return self::$repositoryId;
  46 + }
6 47  
7 48 /**
8 49 * Retrieves data about a specific folder OR document within a folder
... ... @@ -14,6 +55,8 @@ class KT_cmis_atom_service_helper {
14 55 */
15 56 static public function getObjectFeed(&$service, $ObjectService, $repositoryId, $objectId, $method = 'GET')
16 57 {
  58 + self::$repositoryId = $repositoryId;
  59 +
17 60 $serviceType = $service->getServiceType();
18 61 $response = $ObjectService->getProperties($repositoryId, $objectId, false, false);
19 62  
... ... @@ -58,7 +101,7 @@ class KT_cmis_atom_service_helper {
58 101 * @param string $parent The parent folder
59 102 */
60 103 static public function createObjectEntry(&$response, $cmisEntry, $parent, $pwc = false, $method = 'GET')
61   - {
  104 + {
62 105 $workspace = $response->getWorkspace();
63 106 $type = strtolower($cmisEntry['properties']['ObjectTypeId']['value']);
64 107  
... ... @@ -143,13 +186,19 @@ class KT_cmis_atom_service_helper {
143 186 . $cmisEntry['properties']['ObjectId']['value'] . '/rels'));
144 187 $entry->appendChild($link);
145 188  
146   - // TODO check parent link is correct, fix if needed
147   - // TODO leave out if at root folder
148   - $link = $response->newElement('link');
149   - $link->appendChild($response->newAttr('rel', 'parents'));
150   - $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/'
151   - . $cmisEntry['properties']['ObjectId']['value'] . '/parent'));
152   - $entry->appendChild($link);
  189 + // if there is no parent or parent is 0, do not add the parent link
  190 + // also if this is specifically the root folder, do not add the parent link
  191 +// if (!empty($cmisEntry['properties']['ParentId']['value']) && !CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['ObjectId']['value']))
  192 +
  193 + if (!CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['ObjectId']['value'], self::$ktapi))
  194 + {
  195 + // TODO check parent link is correct, fix if needed
  196 + $link = $response->newElement('link');
  197 + $link->appendChild($response->newAttr('rel', 'parents'));
  198 + $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/'
  199 + . $cmisEntry['properties']['ObjectId']['value'] . '/parent'));
  200 + $entry->appendChild($link);
  201 + }
153 202  
154 203 // Folder/Document specific links
155 204 if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'folder')
... ... @@ -480,12 +529,12 @@ class KT_cmis_atom_service_helper {
480 529 */
481 530 public static function getKt()
482 531 {
483   - if(!isset(self::$kt))
  532 + if(!isset(self::$ktapi))
484 533 {
485   - self::$kt = new KTAPI();
486   - self::$kt->get_active_session(session_id());
  534 + self::$ktapi = new KTAPI();
  535 + self::$ktapi->get_active_session(session_id());
487 536 }
488   - return self::$kt;
  537 + return self::$ktapi;
489 538 }
490 539  
491 540 // TODO adjust for time zones?
... ...