From fa62036c541e0da4cccb1cca97a274fc09e4e197 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Wed, 3 Mar 2010 16:19:46 +0200 Subject: [PATCH] Update getObjectParents --- lib/api/ktcmis/ktNavigationService.inc.php | 16 +++++++++++----- lib/api/ktcmis/services/CMISNavigationService.inc.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++---------------------- lib/api/ktcmis/services/CMISRepositoryService.inc.php | 5 ++++- lib/api/ktcmis/util/CMISUtil.inc.php | 1 + webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php | 2 +- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/lib/api/ktcmis/ktNavigationService.inc.php b/lib/api/ktcmis/ktNavigationService.inc.php index 15e2575..1cf65ea 100644 --- a/lib/api/ktcmis/ktNavigationService.inc.php +++ b/lib/api/ktcmis/ktNavigationService.inc.php @@ -195,10 +195,18 @@ class KTNavigationService extends KTCMISBase { */ function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') { - $ancestryResult = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions, - $includeRelationships); + try { + $ancestry = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions, + $includeRelationships); + } + catch (Exception $e) { + return array( + "status_code" => 1, + "message" => $e->getMessage() + ); + } - if (PEAR::isError($ancestryResult)) + if (PEAR::isError($ancestry)) { return array( "status_code" => 1, @@ -206,8 +214,6 @@ class KTNavigationService extends KTCMISBase { ); } - $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'children'); - return array( "status_code" => 0, "results" => $ancestry diff --git a/lib/api/ktcmis/services/CMISNavigationService.inc.php b/lib/api/ktcmis/services/CMISNavigationService.inc.php index 394da51..7fe2d21 100644 --- a/lib/api/ktcmis/services/CMISNavigationService.inc.php +++ b/lib/api/ktcmis/services/CMISNavigationService.inc.php @@ -195,7 +195,7 @@ class CMISNavigationService { if (PEAR::isError($ktapiFolder)) { throw new RuntimeException($ktapiFolder->getMessage()); } - + $parentId = $ktapiFolder->get_parent_folder_id(); $parent = new CMISFolderObject(CMISUtil::encodeObjectId($parentId, FOLDER), $this->ktapi); @@ -203,43 +203,70 @@ class CMISNavigationService { } /** - * Fetches the parent(s) of the specified object + * Gets the parent folder(s) for the specified non-folder, fileable object. * Multiple parents may exist if a repository supports multi-filing * It is also possible that linked documents/folders may qualify as having multiple parents * as they are essentially the same object * * @param string $repositoryId * @param string $objectId - * @param boolean $includeAllowableActions - * @param boolean $includeRelationships - * @param string $filter - * @return array $parents + * @param string $filter [optional] + * @param enum $includeRelationships [optional] + * @param string $renditionFilter [optional] + * @param boolean $includeAllowableActions [optional] + * @param boolean $includeRelativePathSegment [optional] + * @return array $parents - empty for unfiled objects or the root folder + * MUST include (unless not requested) for each object: + * array $properties + * array $relationships + * array $renditions + * $allowableActions + * string $relativePathSegment */ - // TODO ConstraintViolationException: The Repository SHALL throw this exception if this method is invoked - // on an object who Object-Type Definition specifies that it is not fileable. - // FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid. - function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') + // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid. + function getObjectParents($repositoryId, $objectId, $filter = '', $includeRelationships = null, $renditionFilter = '', + $includeAllowableActions = false, $includeRelativePathSegment = false) { $ancestry = array(); $objectId = CMISUtil::decodeObjectId($objectId, $typeId); + + // if type is a folder, this function does not apply + if ($typeId == 'cmis:folder') { + throw new InvalidArgumentException('Cannot call this function for a folder object'); + } + + $objectTypeId = ucwords(str_replace('cmis:', '', $typeId)); + $object = 'CMIS' . $objectTypeId . 'Object'; + + if (!file_exists(CMIS_DIR . '/objecttypes/' . $object . '.inc.php')) { + throw new InvalidArgumentException('Type ' . $typeId . ' is not supported'); + } + + require_once(CMIS_DIR . '/objecttypes/' . $object . '.inc.php'); + $cmisObject = new $object; + + if (!$cmisObject->getAttribute('fileable')) { + throw new ConstraintViolationException('Unable to get parents of non-filable object'); + } // TODO - what about other types? only implementing folders and documents at the moment so ignore for now + // NOTE this will change if we implement multi-filing and/or unfiling switch($typeId) { case 'cmis:document': $document = $this->ktapi->get_document_by_id($objectId); - $parent = $document->ktapi_folder; - $ancestry[] = $parent; - break; - case 'cmis:folder': - $folder = $this->ktapi->get_folder_by_id($objectId); - $parent = $this->ktapi->get_folder_by_id($folder->get_parent_folder_id()); - $ancestry[] = $parent; - break; + if ($document->is_deleted()) { + throw new InvalidArgumentException('The requested object has been deleted'); + } + $ancestry[] = $document->ktapi_folder->get_folderid(); + break; + } + + foreach ($ancestry as $key => $parentId) { + $CMISObject = new CMISFolderObject($parentId, $this->ktapi, $repositoryURI); + $ancestry[$key] = CMISUtil::createObjectPropertiesEntry($CMISObject->getProperties()); } - - $ancestry = CMISUtil::createParentObjectHierarchy($ancestry, $repository->getRepositoryURI, $this->ktapi); return $ancestry; } @@ -266,8 +293,8 @@ class CMISNavigationService { */ // TODO exceptions: • FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid. // TODO $filter and paging - function getCheckedOutDocs($repositoryId, $folderId = null, $maxItems = 0, $skipCount = 0, $orderBy = '', - $filter = '', $includeRelationships = null, $includeAllowableActions = false, $renditionFilter = '') + function getCheckedOutDocs($repositoryId, $folderId = null, $maxItems = 0, $skipCount = 0, $orderBy = '', + $filter = '', $includeRelationships = null, $includeAllowableActions = false, $renditionFilter = '') { $checkedout = array(); diff --git a/lib/api/ktcmis/services/CMISRepositoryService.inc.php b/lib/api/ktcmis/services/CMISRepositoryService.inc.php index 4af8e94..4c4e820 100644 --- a/lib/api/ktcmis/services/CMISRepositoryService.inc.php +++ b/lib/api/ktcmis/services/CMISRepositoryService.inc.php @@ -101,9 +101,12 @@ class CMISRepositoryService { * @param boolean $hasMoreItems TRUE if there are more items to return than were requested * @return array $objectTypes */ - // NOTE this code may fit better within the Repository Class // TODO return for specific type when $typeId is specified // TODO other optional parameters + // This code is superseded by getTypeChildren and getTypeDescendants - when implementing those, check + // whether it is possible to entirely remove this function or if it is to remain and be shared by the + // other two functions (when no type is specified they will return base types [children] amd all types + // [descendants] respectively public function getTypes($repositoryId, $typeId = '', $returnPropertyDefinitions = false, $maxItems = 0, $skipCount = 0, &$hasMoreItems = false) { diff --git a/lib/api/ktcmis/util/CMISUtil.inc.php b/lib/api/ktcmis/util/CMISUtil.inc.php index 7eb02db..8008bab 100644 --- a/lib/api/ktcmis/util/CMISUtil.inc.php +++ b/lib/api/ktcmis/util/CMISUtil.inc.php @@ -213,6 +213,7 @@ class CMISUtil { * @return array $CMISArray */ // NOTE this will have to change if we implement multi-filing + // NOTE this function probably serves no purpose, the parents are to be returned as a flat array static public function createParentObjectHierarchy($input, $repositoryURI, &$ktapi) { $CMISArray = array(); diff --git a/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php b/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php index adbc523..88628d5 100644 --- a/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php +++ b/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php @@ -401,7 +401,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { // update accordingly when updating to newer specification if ($this->params[1] == 'parent') { - $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt()); + $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt()); $response = $NavigationService->getObjectParents($repositoryId, $objectId, false, false); if ($response['status_code'] == 1) { -- libgit2 0.21.4