Commit 90d3ad6086ac444af4354b97482066f1130a3791

Authored by Paul Barrett
1 parent 2af67809

Clean up of CMIS webservice code

Story ID:2713417. CMIS working with PHP client

Committed by: Paul Barrett
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
... ... @@ -147,7 +147,6 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
147 147  
148 148 if (!empty($this->params[1]) && (($this->params[1] == 'children') || ($this->params[1] == 'descendants')))
149 149 {
150   - print_r($this->params);exit;
151 150 $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt());
152 151 $feed = $this->getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $this->params[1]);
153 152 }
... ... @@ -340,7 +339,6 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
340 339 */
341 340 private function getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $feedType = 'children')
342 341 {
343   - print_r($this->params);exit;
344 342 if ($feedType == 'children') {
345 343 try {
346 344 $entries = $NavigationService->getChildren($repositoryId, $folderId, false, false);
... ... @@ -555,10 +553,10 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
555 553 $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent);
556 554 // NOTE not sure about the text type, will need testing, most content will be base64
557 555 $cmisContent = (isset($content['cmisra:base64'])
558   - ? $content['cmisra:base64']
559   - : ((isset($content['cmisra:text']))
560   - ? $content['cmisra:text']
561   - : null));
  556 + ? $content['cmisra:base64']
  557 + : ((isset($content['cmisra:text']))
  558 + ? $content['cmisra:text']
  559 + : null));
562 560  
563 561 // if we haven't found it now, the hack begins - retrieve the EXISTING content and submit this as the contentStream
564 562 // this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly
... ... @@ -576,12 +574,11 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
576 574 // we assume minor version updates only
577 575 $major = false;
578 576 $checkinComment = '';
579   - $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment);
580   -
581   - if ($response['status_code'] == 1) {
582   - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']);
583   - // Expose the responseFeed
584   - $this->responseFeed = $feed;
  577 + try {
  578 + $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment);
  579 + }
  580 + catch (Exception $e) {
  581 + $this->responseFeed = KT_cmis_atom_service_helper::getErrorFeed($this, $this->getStatusCode($e), $e->getMessage());
585 582 return null;
586 583 }
587 584  
... ... @@ -670,9 +667,12 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
670 667 // check for existing object id as property of submitted object data
671 668 if (empty($cmisObjectProperties['cmis:objectId']))
672 669 {
673   - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
674   - // Expose the responseFeed
675   - $this->responseFeed = $feed;
  670 + // not sure this is the best way to deal with this (new InvalidArgumentException) rather than actually throwing an exception
  671 + // in the helper code, but I don't feel that throwing an exception is necessary or always wanted;
  672 + // alternative is to send the name of the Exception but not an instance, and do an is_a check on the other side,
  673 + // but since it will only be needed to this and similar calls, it seems wasteful to do that for every other case
  674 + $this->responseFeed = KT_cmis_atom_service_helper::getErrorFeed($this, $this->getStatusCode(new InvalidArgumentException()),
  675 + 'No object was specified for checkout');
676 676 return null;
677 677 }
678 678  
... ...
webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php
... ... @@ -474,9 +474,18 @@ class KT_cmis_atom_service_helper {
474 474  
475 475 static public function getErrorFeed(&$service, $status, $message)
476 476 {
477   - // this seems to cause problems as it sets an http header, and if that header is
478   - // "404 Not Found" we get html output instead of atompub
479   -// $service->setStatus($status);
  477 + // TODO determine whether the client needs to see the AtomPub response or if a 404 header is enough.
  478 + // reason: when this status header is set and the status is 404 Not Found then the AtomPub response does not
  479 + // appear to be seen by browser based clients (I am not sure of non-browser clients)
  480 + // NOTE just added a check and only send back the header containing 404, no text, and this works, we get a 404 header
  481 + // plus a readable AtomPub response
  482 + if (!strstr($status, '404')) {
  483 + $service->setStatus($status);
  484 + }
  485 + else {
  486 + $service->setStatus('404');
  487 + }
  488 +
480 489 $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
481 490  
482 491 $feed->newField('title', 'Error: ' . $status, $feed);
... ... @@ -507,7 +516,7 @@ class KT_cmis_atom_service_helper {
507 516 $numObjects = $numQ;
508 517 $start = 0;
509 518 $type = CMIS_FOLDER;
510   -
  519 +
511 520 while($start < $numObjects)
512 521 {
513 522 $name = $path[$numQ - $numObjects + $start];
... ... @@ -529,7 +538,7 @@ class KT_cmis_atom_service_helper {
529 538 $objectId = $object->get_folderid();
530 539 $lastFolderId = $objectId;
531 540 }
532   -
  541 +
533 542 ++$start;
534 543 }
535 544  
... ... @@ -716,10 +725,6 @@ class KT_cmis_atom_service_helper {
716 725 }
717 726  
718 727 $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]);
719   -
720   - // hack for removing one level of access
721   - $contentStream = $contentStream['results'];
722   -
723 728 return $contentStream;
724 729 }
725 730 /**
... ... @@ -755,9 +760,6 @@ class KT_cmis_atom_service_helper {
755 760  
756 761 $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]);
757 762  
758   - // hack for removing one level of access
759   - $contentStream = $contentStream['results'];
760   -
761 763 // headers specific to output
762 764 $service->setEtag($eTag);
763 765 $service->setHeader('Last-Modified', $response['properties']['lastModificationDate']['value']);
... ...
webservice/classes/atompub/KT_atom_service.inc.php
... ... @@ -151,7 +151,7 @@ class KT_atom_service{
151 151  
152 152 // TODO why is this setting an http header for an atompub response? this causes problems with a "404 Not Found" status message
153 153 public function setStatus($status=NULL){
154   - header("HTTP/1.1 ".$status);
  154 + header("HTTP/1.1 ".$status."");
155 155 }
156 156  
157 157 public function setEtag($etagValue=NULL){
... ...