Commit 144f91fbc7e484ed155c2eda1689c1edfbaefa62

Authored by Paul Barrett
1 parent 85808014

Update CMIS Create Folder, AtomPub level Move Folder

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

Committed by: Paul Barrett
lib/api/ktcmis/exceptions/NameConstraintViolationException.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +class NameConstraintViolationException extends Exception {
  4 +
  5 +}
  6 +
  7 +?>
... ...
lib/api/ktcmis/ktObjectService.inc.php
... ... @@ -144,17 +144,19 @@ class KTObjectService extends KTCMISBase {
144 144 * Creates a new folder within the repository
145 145 *
146 146 * @param string $repositoryId The repository to which the folder must be added
147   - * @param string $typeId Object Type id for the folder object being created
148 147 * @param array $properties Array of properties which must be applied to the created folder object
149 148 * @param string $folderId The id of the folder which will be the parent of the created folder object
  149 + * @param array $policies List of policy ids that MUST be applied
  150 + * @param $addACEs List of ACEs that MUST be added
  151 + * @param $removeACEs List of ACEs that MUST be removed
150 152 * @return string $objectId The id of the created folder object
151 153 */
152   - public function createFolder($repositoryId, $typeId, $properties, $folderId)
  154 + public function createFolder($repositoryId, $properties, $folderId, $policies = array(), $addACEs = array(), $removeACEs = array())
153 155 {
154 156 $objectId = null;
155 157  
156 158 try {
157   - $objectId = $this->ObjectService->createFolder($repositoryId, $typeId, $properties, $folderId);
  159 + $objectId = $this->ObjectService->createFolder($repositoryId, $properties, $folderId, $policies, $addACEs, $removeACEs);
158 160 }
159 161 catch (Exception $e)
160 162 {
... ...
lib/api/ktcmis/services/CMISObjectService.inc.php
... ... @@ -4,6 +4,7 @@ require_once(KT_DIR . &#39;/ktapi/ktapi.inc.php&#39;);
4 4 require_once(KT_DIR . '/ktwebservice/KTUploadManager.inc.php');
5 5 require_once(CMIS_DIR . '/exceptions/ConstraintViolationException.inc.php');
6 6 require_once(CMIS_DIR . '/exceptions/ContentAlreadyExistsException.inc.php');
  7 +require_once(CMIS_DIR . '/exceptions/NameConstraintViolationException.inc.php');
7 8 require_once(CMIS_DIR . '/exceptions/ObjectNotFoundException.inc.php');
8 9 require_once(CMIS_DIR . '/exceptions/StorageException.inc.php');
9 10 require_once(CMIS_DIR . '/exceptions/StreamNotSupportedException.inc.php');
... ... @@ -136,9 +137,6 @@ class CMISObjectService {
136 137 if (!$typeDefinition['attributes']['controllableACL'] && (count($addACEs) || count($removeACEs))) {
137 138 throw new ConstraintViolationException('This object-type does not support ACLs');
138 139 }
139   -
140   - // TODO throw NameConstraintViolation if there is a violation with the given cmis:name property value
141   - // OR choose a name which does not conflict
142 140  
143 141 // TODO deal with $versioningState when supplied
144 142  
... ... @@ -150,9 +148,10 @@ class CMISObjectService {
150 148 $properties['name'] = $properties['title'];
151 149 }
152 150  
153   - // if name is blank throw exception (check type) - using invalidArgument Exception for now
  151 + // throw NameConstraintViolation if there is a violation with the given cmis:name property value
  152 + // OR choose a name which does not conflict
154 153 if (trim($properties['name']) == '') {
155   - throw new InvalidArgumentException('Refusing to create an un-named document');
  154 + throw new NameConstraintViolationException('Refusing to create an un-named document');
156 155 }
157 156  
158 157 // TODO also set to Default if a non-supported type is submitted
... ... @@ -293,22 +292,28 @@ class CMISObjectService {
293 292 * Creates a new folder within the repository
294 293 *
295 294 * @param string $repositoryId The repository to which the folder must be added
296   - * @param string $typeId Object Type id for the folder object being created
297 295 * @param array $properties Array of properties which must be applied to the created folder object
298 296 * @param string $folderId The id of the folder which will be the parent of the created folder object
  297 + * @param array $policies List of policy ids that MUST be applied
  298 + * @param $addACEs List of ACEs that MUST be added
  299 + * @param $removeACEs List of ACEs that MUST be removed
299 300 * @return string $objectId The id of the created folder object
300 301 */
301 302 // TODO throw ConstraintViolationException if:
302 303 // value of any of the properties violates the min/max/required/length constraints
303 304 // specified in the property definition in the Object-Type.
304   - public function createFolder($repositoryId, $typeId, $properties, $folderId)
  305 + // TODO throw ConstraintViolationException if At least one of the permissions is used in
  306 + // an ACE provided which is not supported by the repository.
  307 + public function createFolder($repositoryId, $properties, $folderId, $policies = array(), $addACEs = array(), $removeACEs = array())
305 308 {
  309 + global $default;
  310 + $default->log->info('try create folder');
306 311 $objectId = null;
307 312  
308 313 // fetch type definition of supplied type and check for base type "folder", if not true throw exception
309 314 $RepositoryService = new CMISRepositoryService();
310 315 try {
311   - $typeDefinition = $RepositoryService->getTypeDefinition($repositoryId, $typeId);
  316 + $typeDefinition = $RepositoryService->getTypeDefinition($repositoryId, $properties['objectTypeId']);
312 317 }
313 318 // NOTE Not sure that we should throw this specific exception, maybe just let the underlying
314 319 // exception propogate upward...
... ... @@ -331,21 +336,37 @@ class CMISObjectService {
331 336 // if parent folder is not allowed to hold this type, throw exception
332 337 $CMISFolder = new CMISFolderObject($folderId, $this->ktapi);
333 338 $allowed = $CMISFolder->getProperty('allowedChildObjectTypeIds');
334   - if (!is_array($allowed) || !in_array($typeId, $allowed)) {
335   - throw new ConstraintViolationException('Parent folder may not hold objects of this type (' . $typeId . ')');
  339 + if (!is_array($allowed) || !in_array($properties['objectTypeId'], $allowed)) {
  340 + throw new ConstraintViolationException('Parent folder may not hold objects of this type (' . $properties['objectTypeId'] . ')');
336 341 }
337   -
338   - // TODO if name is blank! throw another exception (check type) - using invalidArgument Exception for now
  342 +
  343 + if (!$typeDefinition['attributes']['controllablePolicy'] && count($policies)) {
  344 + throw new ConstraintViolationException('This object-type does not support policies');
  345 + }
  346 +
  347 + if (!$typeDefinition['attributes']['controllableACL'] && (count($addACEs) || count($removeACEs))) {
  348 + throw new ConstraintViolationException('This object-type does not support ACLs');
  349 + }
  350 + $default->log->info(print_r($properties, true));
  351 + // set title and name identical if only one submitted
  352 + if ($properties['title'] == '') {
  353 + $properties['title'] = $properties['name'];
  354 + }
  355 + else if ($properties['name'] == '') {
  356 + $properties['name'] = $properties['title'];
  357 + }
  358 +
  359 + // throw NameConstraintViolation if there is a violation with the given cmis:name property value
  360 + // OR choose a name which does not conflict
339 361 if (trim($properties['name']) == '') {
340   - throw new InvalidArgumentException('Refusing to create an un-named folder');
  362 + throw new NameConstraintViolationException('Refusing to create an un-named folder');
341 363 }
342 364  
343 365 $response = $this->ktapi->create_folder((int)$folderId, $properties['name'], $sig_username = '', $sig_password = '', $reason = '');
344 366 if ($response['status_code'] != 0) {
345 367 throw new StorageException('The repository was unable to create the folder: ' . $response['message']);
346 368 }
347   - else
348   - {
  369 + else {
349 370 $objectId = CMISUtil::encodeObjectId(FOLDER, $response['results']['id']);
350 371 }
351 372  
... ...
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
... ... @@ -134,7 +134,10 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
134 134 * This includes creation/moving of both folders and documents.
135 135 */
136 136 public function POST_action()
137   - {
  137 + {
  138 + global $default;
  139 + $default->log->info($this->rawContent);
  140 +
138 141 $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService);
139 142  
140 143 // set default action, objectId and typeId
... ... @@ -155,10 +158,10 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
155 158 // NOTE this also applies to the source folder id, see above
156 159  
157 160 // check for existing object id as parameter in url
158   - // if sourceFolderId parameter is submitted, this is a move
159   - if (isset($this->params[1])) {
  161 + // if sourceFolderId parameter is submitted (expected as parameter 3, or params[2]) then this is a move
  162 + if (isset($this->params[2])) {
160 163 $action = 'move';
161   - $sourceFolderId = $this->params[1];
  164 + $sourceFolderId = $this->params[2];
162 165 }
163 166  
164 167 // get object properties - todo send through original properties array and not modified version
... ... @@ -190,15 +193,17 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
190 193 : null));
191 194  
192 195 $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt());
  196 +
  197 + $default->log->info('here: '.$action);
193 198  
194 199 $success = false;
195 200 $error = null;
196 201 if ($action == 'create')
197 202 {
198 203 // TODO detection and passing of optional parameters (policies, ACEs, etc...) as well as support for other object-types
199   - if ($cmisObjectProperties['cmis:objectTypeId'] == 'folder') {
200   - $newObjectId = $ObjectService->createFolder($repositoryId, ucwords($cmisObjectProperties['cmis:objectTypeId']),
201   - $properties, $folderId);
  204 + if ($cmisObjectProperties['cmis:objectTypeId'] == 'cmis:folder') {
  205 + $default->log->info($cmisObjectProperties['cmis:objectTypeId']);
  206 + $newObjectId = $ObjectService->createFolder($repositoryId, $properties, $folderId);
202 207 }
203 208 else {
204 209 // NOTE for the moment only creation in minor versioning state
... ...