Commit fa62036c541e0da4cccb1cca97a274fc09e4e197

Authored by Paul Barrett
1 parent f2a56a99

Update getObjectParents

Story ID:2295472. Update KT CMIS implementation to 1.0 compliance

Committed by: Paul Barrett
lib/api/ktcmis/ktNavigationService.inc.php
@@ -195,10 +195,18 @@ class KTNavigationService extends KTCMISBase { @@ -195,10 +195,18 @@ class KTNavigationService extends KTCMISBase {
195 */ 195 */
196 function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') 196 function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '')
197 { 197 {
198 - $ancestryResult = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions,  
199 - $includeRelationships); 198 + try {
  199 + $ancestry = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions,
  200 + $includeRelationships);
  201 + }
  202 + catch (Exception $e) {
  203 + return array(
  204 + "status_code" => 1,
  205 + "message" => $e->getMessage()
  206 + );
  207 + }
200 208
201 - if (PEAR::isError($ancestryResult)) 209 + if (PEAR::isError($ancestry))
202 { 210 {
203 return array( 211 return array(
204 "status_code" => 1, 212 "status_code" => 1,
@@ -206,8 +214,6 @@ class KTNavigationService extends KTCMISBase { @@ -206,8 +214,6 @@ class KTNavigationService extends KTCMISBase {
206 ); 214 );
207 } 215 }
208 216
209 - $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'children');  
210 -  
211 return array( 217 return array(
212 "status_code" => 0, 218 "status_code" => 0,
213 "results" => $ancestry 219 "results" => $ancestry
lib/api/ktcmis/services/CMISNavigationService.inc.php
@@ -195,7 +195,7 @@ class CMISNavigationService { @@ -195,7 +195,7 @@ class CMISNavigationService {
195 if (PEAR::isError($ktapiFolder)) { 195 if (PEAR::isError($ktapiFolder)) {
196 throw new RuntimeException($ktapiFolder->getMessage()); 196 throw new RuntimeException($ktapiFolder->getMessage());
197 } 197 }
198 - 198 +
199 $parentId = $ktapiFolder->get_parent_folder_id(); 199 $parentId = $ktapiFolder->get_parent_folder_id();
200 $parent = new CMISFolderObject(CMISUtil::encodeObjectId($parentId, FOLDER), $this->ktapi); 200 $parent = new CMISFolderObject(CMISUtil::encodeObjectId($parentId, FOLDER), $this->ktapi);
201 201
@@ -203,43 +203,70 @@ class CMISNavigationService { @@ -203,43 +203,70 @@ class CMISNavigationService {
203 } 203 }
204 204
205 /** 205 /**
206 - * Fetches the parent(s) of the specified object 206 + * Gets the parent folder(s) for the specified non-folder, fileable object.
207 * Multiple parents may exist if a repository supports multi-filing 207 * Multiple parents may exist if a repository supports multi-filing
208 * It is also possible that linked documents/folders may qualify as having multiple parents 208 * It is also possible that linked documents/folders may qualify as having multiple parents
209 * as they are essentially the same object 209 * as they are essentially the same object
210 * 210 *
211 * @param string $repositoryId 211 * @param string $repositoryId
212 * @param string $objectId 212 * @param string $objectId
213 - * @param boolean $includeAllowableActions  
214 - * @param boolean $includeRelationships  
215 - * @param string $filter  
216 - * @return array $parents 213 + * @param string $filter [optional]
  214 + * @param enum $includeRelationships [optional]
  215 + * @param string $renditionFilter [optional]
  216 + * @param boolean $includeAllowableActions [optional]
  217 + * @param boolean $includeRelativePathSegment [optional]
  218 + * @return array $parents - empty for unfiled objects or the root folder
  219 + * MUST include (unless not requested) for each object:
  220 + * array $properties
  221 + * array $relationships
  222 + * array $renditions
  223 + * $allowableActions
  224 + * string $relativePathSegment
217 */ 225 */
218 - // TODO ConstraintViolationException: The Repository SHALL throw this exception if this method is invoked  
219 - // on an object who Object-Type Definition specifies that it is not fileable.  
220 - // FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid.  
221 - function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') 226 + // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid.
  227 + function getObjectParents($repositoryId, $objectId, $filter = '', $includeRelationships = null, $renditionFilter = '',
  228 + $includeAllowableActions = false, $includeRelativePathSegment = false)
222 { 229 {
223 $ancestry = array(); 230 $ancestry = array();
224 231
225 $objectId = CMISUtil::decodeObjectId($objectId, $typeId); 232 $objectId = CMISUtil::decodeObjectId($objectId, $typeId);
  233 +
  234 + // if type is a folder, this function does not apply
  235 + if ($typeId == 'cmis:folder') {
  236 + throw new InvalidArgumentException('Cannot call this function for a folder object');
  237 + }
  238 +
  239 + $objectTypeId = ucwords(str_replace('cmis:', '', $typeId));
  240 + $object = 'CMIS' . $objectTypeId . 'Object';
  241 +
  242 + if (!file_exists(CMIS_DIR . '/objecttypes/' . $object . '.inc.php')) {
  243 + throw new InvalidArgumentException('Type ' . $typeId . ' is not supported');
  244 + }
  245 +
  246 + require_once(CMIS_DIR . '/objecttypes/' . $object . '.inc.php');
  247 + $cmisObject = new $object;
  248 +
  249 + if (!$cmisObject->getAttribute('fileable')) {
  250 + throw new ConstraintViolationException('Unable to get parents of non-filable object');
  251 + }
226 252
227 // TODO - what about other types? only implementing folders and documents at the moment so ignore for now 253 // TODO - what about other types? only implementing folders and documents at the moment so ignore for now
  254 + // NOTE this will change if we implement multi-filing and/or unfiling
228 switch($typeId) 255 switch($typeId)
229 { 256 {
230 case 'cmis:document': 257 case 'cmis:document':
231 $document = $this->ktapi->get_document_by_id($objectId); 258 $document = $this->ktapi->get_document_by_id($objectId);
232 - $parent = $document->ktapi_folder;  
233 - $ancestry[] = $parent;  
234 - break;  
235 - case 'cmis:folder':  
236 - $folder = $this->ktapi->get_folder_by_id($objectId);  
237 - $parent = $this->ktapi->get_folder_by_id($folder->get_parent_folder_id());  
238 - $ancestry[] = $parent;  
239 - break; 259 + if ($document->is_deleted()) {
  260 + throw new InvalidArgumentException('The requested object has been deleted');
  261 + }
  262 + $ancestry[] = $document->ktapi_folder->get_folderid();
  263 + break;
  264 + }
  265 +
  266 + foreach ($ancestry as $key => $parentId) {
  267 + $CMISObject = new CMISFolderObject($parentId, $this->ktapi, $repositoryURI);
  268 + $ancestry[$key] = CMISUtil::createObjectPropertiesEntry($CMISObject->getProperties());
240 } 269 }
241 -  
242 - $ancestry = CMISUtil::createParentObjectHierarchy($ancestry, $repository->getRepositoryURI, $this->ktapi);  
243 270
244 return $ancestry; 271 return $ancestry;
245 } 272 }
@@ -266,8 +293,8 @@ class CMISNavigationService { @@ -266,8 +293,8 @@ class CMISNavigationService {
266 */ 293 */
267 // TODO exceptions: • FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid. 294 // TODO exceptions: • FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid.
268 // TODO $filter and paging 295 // TODO $filter and paging
269 - function getCheckedOutDocs($repositoryId, $folderId = null, $maxItems = 0, $skipCount = 0, $orderBy = '',  
270 - $filter = '', $includeRelationships = null, $includeAllowableActions = false, $renditionFilter = '') 296 + function getCheckedOutDocs($repositoryId, $folderId = null, $maxItems = 0, $skipCount = 0, $orderBy = '',
  297 + $filter = '', $includeRelationships = null, $includeAllowableActions = false, $renditionFilter = '')
271 { 298 {
272 $checkedout = array(); 299 $checkedout = array();
273 300
lib/api/ktcmis/services/CMISRepositoryService.inc.php
@@ -101,9 +101,12 @@ class CMISRepositoryService { @@ -101,9 +101,12 @@ class CMISRepositoryService {
101 * @param boolean $hasMoreItems TRUE if there are more items to return than were requested 101 * @param boolean $hasMoreItems TRUE if there are more items to return than were requested
102 * @return array $objectTypes 102 * @return array $objectTypes
103 */ 103 */
104 - // NOTE this code may fit better within the Repository Class  
105 // TODO return for specific type when $typeId is specified 104 // TODO return for specific type when $typeId is specified
106 // TODO other optional parameters 105 // TODO other optional parameters
  106 + // This code is superseded by getTypeChildren and getTypeDescendants - when implementing those, check
  107 + // whether it is possible to entirely remove this function or if it is to remain and be shared by the
  108 + // other two functions (when no type is specified they will return base types [children] amd all types
  109 + // [descendants] respectively
107 public function getTypes($repositoryId, $typeId = '', $returnPropertyDefinitions = false, 110 public function getTypes($repositoryId, $typeId = '', $returnPropertyDefinitions = false,
108 $maxItems = 0, $skipCount = 0, &$hasMoreItems = false) 111 $maxItems = 0, $skipCount = 0, &$hasMoreItems = false)
109 { 112 {
lib/api/ktcmis/util/CMISUtil.inc.php
@@ -213,6 +213,7 @@ class CMISUtil { @@ -213,6 +213,7 @@ class CMISUtil {
213 * @return array $CMISArray 213 * @return array $CMISArray
214 */ 214 */
215 // NOTE this will have to change if we implement multi-filing 215 // NOTE this will have to change if we implement multi-filing
  216 + // NOTE this function probably serves no purpose, the parents are to be returned as a flat array
216 static public function createParentObjectHierarchy($input, $repositoryURI, &$ktapi) 217 static public function createParentObjectHierarchy($input, $repositoryURI, &$ktapi)
217 { 218 {
218 $CMISArray = array(); 219 $CMISArray = array();
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 { @@ -401,7 +401,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service {
401 // update accordingly when updating to newer specification 401 // update accordingly when updating to newer specification
402 if ($this->params[1] == 'parent') 402 if ($this->params[1] == 'parent')
403 { 403 {
404 - $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt()); 404 + $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt());
405 $response = $NavigationService->getObjectParents($repositoryId, $objectId, false, false); 405 $response = $NavigationService->getObjectParents($repositoryId, $objectId, false, false);
406 406
407 if ($response['status_code'] == 1) { 407 if ($response['status_code'] == 1) {