Commit dfe8da739ede177317d5565b4048c39da2fde2fb

Authored by Paul Barrett
1 parent 5c7d6464

Added preliminary parent return support for CMIS document service - one parent o…

…nly as we don't currently support multi-filing.

Story ID:1434265. CMIS patch contributions

Committed by: Paul Barrett
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
... ... @@ -90,6 +90,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
90 90 }
91 91 // NOTE parent changes to parents in later specification
92 92 // TODO update when updating to later specification
  93 + // TODO this only returns one parent, need to implement returnToRoot also
93 94 else if ($this->params[1] == 'parent')
94 95 {
95 96 // abstract this to be used also by the document service (and the PWC service?) ???
... ... @@ -357,206 +358,6 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service {
357 358 }
358 359  
359 360 /**
360   - * AtomPub Service: types
361   - */
362   -class KT_cmis_atom_service_types extends KT_cmis_atom_service {
363   -
364   - public function GET_action()
365   - {
366   - $RepositoryService = new RepositoryService();
367   - $repositories = $RepositoryService->getRepositories();
368   - $repositoryId = $repositories[0]['repositoryId'];
369   -
370   - $types = $RepositoryService->getTypes($repositoryId);
371   - $type = ((empty($this->params[0])) ? 'all' : $this->params[0]);
372   - $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
373   -
374   - // Expose the responseFeed
375   - $this->responseFeed = $feed;
376   - }
377   -
378   -}
379   -
380   -/**
381   - * AtomPub Service: type
382   - */
383   -class KT_cmis_atom_service_type extends KT_cmis_atom_service {
384   -
385   - public function GET_action()
386   - {
387   - $RepositoryService = new RepositoryService();
388   -
389   - // fetch repository id
390   - $repositories = $RepositoryService->getRepositories();
391   - $repositoryId = $repositories[0]['repositoryId'];
392   -
393   - if (!isset($this->params[1])) {
394   - // For easier return in the wanted format, we call getTypes instead of getTypeDefinition.
395   - // Calling this with a single type specified returns an array containing the definition of
396   - // just the requested type.
397   - // NOTE could maybe be more efficient to call getTypeDefinition direct and then place in
398   - // an array on this side? or directly expose the individual entry response code and
399   - // call directly from here rather than via getTypeFeed.
400   - $type = ucwords($this->params[0]);
401   - $types = $RepositoryService->getTypes($repositoryId, $type);
402   - $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
403   - }
404   - else {
405   - // TODO dynamic dates, as needed everywhere
406   - // NOTE children of types not yet implemented and we don't support any non-basic types at this time
407   - $feed = $this->getTypeChildrenFeed($this->params[1]);
408   - }
409   -
410   - // Expose the responseFeed
411   - $this->responseFeed=$feed;
412   - }
413   -
414   - /**
415   - * Retrieves a list of child types for the supplied type
416   - *
417   - * NOTE this currently returns a hard coded empty list, since we do not currently support child types
418   - * TODO make dynamic if/when we support checking for child types (we don't actually need to support child types themselves)
419   - *
420   - * @param string $type
421   - * @return string CMIS AtomPub feed
422   - */
423   - private function getTypeChildrenFeed()
424   - {
425   - //Create a new response feed
426   - // $baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL
427   - $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
428   -
429   - $feed->newField('title', 'Child Types of ' . ucwords($this->params[0]), $feed);
430   - $feed->newField('id', $this->params[0] . '-children', $feed);
431   -
432   - // TODO fetch child types - to be implemented when we support child types in the API
433   -
434   - // links
435   - $link = $feed->newElement('link');
436   - $link->appendChild($feed->newAttr('rel','first'));
437   - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
438   - $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
439   -
440   - $link = $feed->newElement('link');
441   - $link->appendChild($feed->newAttr('rel','last'));
442   - // TODO set page number correctly - to be done when we support paging the the API
443   - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
444   - $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
445   -
446   - $feed->newField('updated', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
447   - $feed->newField('cmis:hasMoreItems', 'false', $feed);
448   -
449   - return $feed;
450   - }
451   -
452   -}
453   -
454   -/**
455   - * AtomPub Service: checkedout
456   - */
457   -class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
458   -
459   - /**
460   - * Deals with GET actions for checkedout documents.
461   - */
462   - public function GET_action()
463   - {
464   - $RepositoryService = new RepositoryService();
465   - $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt());
466   -
467   - $repositories = $RepositoryService->getRepositories();
468   - $repositoryId = $repositories[0]['repositoryId'];
469   -
470   - $checkedout = $NavigationService->getCheckedOutDocs($repositoryId);
471   -
472   - //Create a new response feed
473   - $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
474   - $workspace = $feed->getWorkspace();
475   -
476   - $feed->newField('title', 'Checked out Documents', $feed);
477   -
478   - // TODO dynamic?
479   - $feedElement = $feed->newField('author');
480   - $element = $feed->newField('name', 'admin', $feedElement);
481   - $feed->appendChild($feedElement);
482   -
483   - $feed->appendChild($feed->newElement('id', 'urn:uuid:checkedout'));
484   -
485   - // TODO get actual most recent update time, only use current if no other available
486   - $feed->appendChild($feed->newElement('updated', KT_cmis_atom_service_helper::formatDatestamp()));
487   -
488   - $link = $feed->newElement('link');
489   - $link->appendChild($feed->newAttr('rel', 'self'));
490   - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout'));
491   - $feed->appendChild($link);
492   -
493   - $link = $feed->newElement('link');
494   - $link->appendChild($feed->newAttr('rel','first'));
495   - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
496   - $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
497   - $feed->appendChild($link);
498   -
499   - $link = $feed->newElement('link');
500   - $link->appendChild($feed->newAttr('rel','last'));
501   - // TODO set page number correctly - to be done when we support paging the the API
502   - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
503   - $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
504   - $feed->appendChild($link);
505   -
506   - foreach($checkedout as $cmisEntry)
507   - {
508   - KT_cmis_atom_service_helper::createObjectEntry($feed, $cmisEntry, $folderName, true);
509   -
510   -// // after each entry, add app:edited tag
511   -// $feed->newField('app:edited', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
512   - }
513   -
514   - $feed->newField('cmis:hasMoreItems', 'false', $feed);
515   -
516   - // Expose the responseFeed
517   - $this->responseFeed = $feed;
518   - }
519   -
520   - public function POST_action()
521   - {
522   - $RepositoryService = new RepositoryService();
523   - $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
524   - $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
525   -
526   - $repositories = $RepositoryService->getRepositories();
527   - $repositoryId = $repositories[0]['repositoryId'];
528   -
529   - $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->parsedXMLContent['@children']);
530   -
531   - // check for existing object id as property of submitted object data
532   - if (empty($cmisObjectProperties['ObjectId']))
533   - {
534   - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
535   - // Expose the responseFeed
536   - $this->responseFeed = $feed;
537   - return null;
538   - }
539   -
540   - $response = $VersioningService->checkOut($repositoryId, $cmisObjectProperties['ObjectId']);
541   -
542   - if (PEAR::isError($response))
543   - {
544   - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
545   - // Expose the responseFeed
546   - $this->responseFeed = $feed;
547   - return null;
548   - }
549   -
550   - $this->setStatus(self::STATUS_CREATED);
551   - $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $cmisObjectProperties['ObjectId'], 'POST');
552   -
553   - // Expose the responseFeed
554   - $this->responseFeed = $feed;
555   - }
556   -
557   -}
558   -
559   -/**
560 361 * AtomPub Service: document
561 362 */
562 363 // TODO confirm that an error response is sent when a document has status "deleted"
... ... @@ -574,15 +375,36 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service {
574 375 $repositories = $RepositoryService->getRepositories();
575 376 $repositoryId = $repositories[0]['repositoryId'];
576 377  
  378 + $objectId = $this->params[0];
  379 +
  380 + // TODO this is "parents" in later versions of the specification
  381 + // update accordingly when updating to newer specification
  382 + if ($this->params[1] == 'parent')
  383 + {
  384 + // abstract this to be used also by the document service (and the PWC service?) ???
  385 + // alternatively use getFolderParent here makes sense and use getObjectParents when document service?
  386 + $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt());
  387 + $response = $NavigationService->getObjectParents($repositoryId, $objectId, false, false);
  388 +
  389 + if (PEAR::isError($response)) {
  390 + $feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response->getMessage());
  391 + $this->responseFeed = $feed;
  392 + return null;
  393 + }
  394 +
  395 + // for now a document will only have one parent as KnowledgeTree does not support multi-filing
  396 + // TODO update this code if/when multi-filing support is added
  397 + $objectId = $response[0]['properties']['ObjectId']['value'];
  398 + }
577 399 // determine whether we want the document entry feed or the actual physical document content.
578 400 // this depends on $this->params[1]
579   - if (!empty($this->params[1]))
  401 + else if (!empty($this->params[1]))
580 402 {
581 403 KT_cmis_atom_service_helper::downloadContentStream($this, $ObjectService, $repositoryId);
582 404 return null;
583 405 }
584 406  
585   - $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]);
  407 + $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $objectId);
586 408  
587 409 // Expose the responseFeed
588 410 $this->responseFeed = $feed;
... ... @@ -741,4 +563,204 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service {
741 563  
742 564 }
743 565  
  566 +/**
  567 + * AtomPub Service: checkedout
  568 + */
  569 +class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service {
  570 +
  571 + /**
  572 + * Deals with GET actions for checkedout documents.
  573 + */
  574 + public function GET_action()
  575 + {
  576 + $RepositoryService = new RepositoryService();
  577 + $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt());
  578 +
  579 + $repositories = $RepositoryService->getRepositories();
  580 + $repositoryId = $repositories[0]['repositoryId'];
  581 +
  582 + $checkedout = $NavigationService->getCheckedOutDocs($repositoryId);
  583 +
  584 + //Create a new response feed
  585 + $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
  586 + $workspace = $feed->getWorkspace();
  587 +
  588 + $feed->newField('title', 'Checked out Documents', $feed);
  589 +
  590 + // TODO dynamic?
  591 + $feedElement = $feed->newField('author');
  592 + $element = $feed->newField('name', 'admin', $feedElement);
  593 + $feed->appendChild($feedElement);
  594 +
  595 + $feed->appendChild($feed->newElement('id', 'urn:uuid:checkedout'));
  596 +
  597 + // TODO get actual most recent update time, only use current if no other available
  598 + $feed->appendChild($feed->newElement('updated', KT_cmis_atom_service_helper::formatDatestamp()));
  599 +
  600 + $link = $feed->newElement('link');
  601 + $link->appendChild($feed->newAttr('rel', 'self'));
  602 + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout'));
  603 + $feed->appendChild($link);
  604 +
  605 + $link = $feed->newElement('link');
  606 + $link->appendChild($feed->newAttr('rel','first'));
  607 + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
  608 + $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
  609 + $feed->appendChild($link);
  610 +
  611 + $link = $feed->newElement('link');
  612 + $link->appendChild($feed->newAttr('rel','last'));
  613 + // TODO set page number correctly - to be done when we support paging the the API
  614 + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0'));
  615 + $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
  616 + $feed->appendChild($link);
  617 +
  618 + foreach($checkedout as $cmisEntry)
  619 + {
  620 + KT_cmis_atom_service_helper::createObjectEntry($feed, $cmisEntry, $folderName, true);
  621 +
  622 +// // after each entry, add app:edited tag
  623 +// $feed->newField('app:edited', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
  624 + }
  625 +
  626 + $feed->newField('cmis:hasMoreItems', 'false', $feed);
  627 +
  628 + // Expose the responseFeed
  629 + $this->responseFeed = $feed;
  630 + }
  631 +
  632 + public function POST_action()
  633 + {
  634 + $RepositoryService = new RepositoryService();
  635 + $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt());
  636 + $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt());
  637 +
  638 + $repositories = $RepositoryService->getRepositories();
  639 + $repositoryId = $repositories[0]['repositoryId'];
  640 +
  641 + $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->parsedXMLContent['@children']);
  642 +
  643 + // check for existing object id as property of submitted object data
  644 + if (empty($cmisObjectProperties['ObjectId']))
  645 + {
  646 + $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
  647 + // Expose the responseFeed
  648 + $this->responseFeed = $feed;
  649 + return null;
  650 + }
  651 +
  652 + $response = $VersioningService->checkOut($repositoryId, $cmisObjectProperties['ObjectId']);
  653 +
  654 + if (PEAR::isError($response))
  655 + {
  656 + $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout');
  657 + // Expose the responseFeed
  658 + $this->responseFeed = $feed;
  659 + return null;
  660 + }
  661 +
  662 + $this->setStatus(self::STATUS_CREATED);
  663 + $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $cmisObjectProperties['ObjectId'], 'POST');
  664 +
  665 + // Expose the responseFeed
  666 + $this->responseFeed = $feed;
  667 + }
  668 +
  669 +}
  670 +
  671 +/**
  672 + * AtomPub Service: types
  673 + */
  674 +class KT_cmis_atom_service_types extends KT_cmis_atom_service {
  675 +
  676 + public function GET_action()
  677 + {
  678 + $RepositoryService = new RepositoryService();
  679 + $repositories = $RepositoryService->getRepositories();
  680 + $repositoryId = $repositories[0]['repositoryId'];
  681 +
  682 + $types = $RepositoryService->getTypes($repositoryId);
  683 + $type = ((empty($this->params[0])) ? 'all' : $this->params[0]);
  684 + $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
  685 +
  686 + // Expose the responseFeed
  687 + $this->responseFeed = $feed;
  688 + }
  689 +
  690 +}
  691 +
  692 +/**
  693 + * AtomPub Service: type
  694 + */
  695 +class KT_cmis_atom_service_type extends KT_cmis_atom_service {
  696 +
  697 + public function GET_action()
  698 + {
  699 + $RepositoryService = new RepositoryService();
  700 +
  701 + // fetch repository id
  702 + $repositories = $RepositoryService->getRepositories();
  703 + $repositoryId = $repositories[0]['repositoryId'];
  704 +
  705 + if (!isset($this->params[1])) {
  706 + // For easier return in the wanted format, we call getTypes instead of getTypeDefinition.
  707 + // Calling this with a single type specified returns an array containing the definition of
  708 + // just the requested type.
  709 + // NOTE could maybe be more efficient to call getTypeDefinition direct and then place in
  710 + // an array on this side? or directly expose the individual entry response code and
  711 + // call directly from here rather than via getTypeFeed.
  712 + $type = ucwords($this->params[0]);
  713 + $types = $RepositoryService->getTypes($repositoryId, $type);
  714 + $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types);
  715 + }
  716 + else {
  717 + // TODO dynamic dates, as needed everywhere
  718 + // NOTE children of types not yet implemented and we don't support any non-basic types at this time
  719 + $feed = $this->getTypeChildrenFeed($this->params[1]);
  720 + }
  721 +
  722 + // Expose the responseFeed
  723 + $this->responseFeed=$feed;
  724 + }
  725 +
  726 + /**
  727 + * Retrieves a list of child types for the supplied type
  728 + *
  729 + * NOTE this currently returns a hard coded empty list, since we do not currently support child types
  730 + * TODO make dynamic if/when we support checking for child types (we don't actually need to support child types themselves)
  731 + *
  732 + * @param string $type
  733 + * @return string CMIS AtomPub feed
  734 + */
  735 + private function getTypeChildrenFeed()
  736 + {
  737 + //Create a new response feed
  738 + // $baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL
  739 + $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI);
  740 +
  741 + $feed->newField('title', 'Child Types of ' . ucwords($this->params[0]), $feed);
  742 + $feed->newField('id', $this->params[0] . '-children', $feed);
  743 +
  744 + // TODO fetch child types - to be implemented when we support child types in the API
  745 +
  746 + // links
  747 + $link = $feed->newElement('link');
  748 + $link->appendChild($feed->newAttr('rel','first'));
  749 + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
  750 + $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
  751 +
  752 + $link = $feed->newElement('link');
  753 + $link->appendChild($feed->newAttr('rel','last'));
  754 + // TODO set page number correctly - to be done when we support paging the the API
  755 + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'type/' . $this->params[0] . '/' . $this->params[1] . '?pageNo=1&pageSize=0'));
  756 + $link->appendChild($feed->newAttr('type', 'application/atom+xml;type=feed'));
  757 +
  758 + $feed->newField('updated', KT_cmis_atom_service_helper::formatDatestamp(), $feed);
  759 + $feed->newField('cmis:hasMoreItems', 'false', $feed);
  760 +
  761 + return $feed;
  762 + }
  763 +
  764 +}
  765 +
744 766 ?>
745 767 \ No newline at end of file
... ...