Commit 0123b9fece777e8e7315e99b4eccfb83453f390a

Authored by Benjamin Renard
1 parent a478e892

Add APIs getCatalog & getCatalogsList

php/WebServices/WebServer.php
... ... @@ -616,43 +616,85 @@ class WebServer
616 616  
617 617 return array('success' => true, 'status' => $res['status'], $resultTag => WSConfigClass::getUrl().$res['result']);
618 618 }
619   -
  619 +
  620 +/*
  621 +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!!
  622 +* TODO Think about this if merge/union will be also done by AMDA_Kernel
  623 +*
  624 +* get Time Table : shared for anonymous user (impex) ; user' for user
  625 +*/
  626 + public function getTimeTable($data)
  627 + {
  628 + $res = $this->init($data);
  629 +
  630 + if (!$res['success']){
  631 + $this->throwError("requestError", "Cannot parse request");
  632 + }
  633 +
  634 + $ttID = $res['vars']['ttID'];
  635 +
  636 + return $this->getTimeTableCatalog('timeTable', $ttID);
  637 + }
  638 +
620 639 /*
621 640 * TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!!
622 641 * TODO Think about this if merge/union will be also done by AMDA_Kernel
623 642 *
624 643 * get Time Table : shared for anonymous user (impex) ; user' for user
625 644 */
626   - public function getTimeTable($data)
  645 + public function getCatalog($data)
627 646 {
628 647 $res = $this->init($data);
629   -
  648 +
630 649 if (!$res['success']){
631   - $this->throwError("requestError", "Cannot parse request");
  650 + $this->throwError("requestError", "Cannot parse request");
632 651 }
633   -
  652 +
  653 + $catID = $res['vars']['catID'];
  654 +
  655 + return $this->getTimeTableCatalog('catalog', $catID);
  656 + }
  657 +
  658 +/*
  659 +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!!
  660 +* TODO Think about this if merge/union will be also done by AMDA_Kernel
  661 +*
  662 +* get Time Table : shared for anonymous user (impex) ; user' for user
  663 +*/
  664 + private function getTimeTableCatalog($type, $id)
  665 + {
634 666 $this->initUserMgr();
635 667  
636   - $ttID = $res['vars']['ttID'];
637   -
638 668 if ($this->userID == WSConfigClass::getAnonymousUserName()) {
639 669 $sharedObjMgr = new SharedObjectsMgr();
640   - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
  670 + $objSrc = $sharedObjMgr->getDataFilePath($type, $id);
641 671 }
642 672 else
643   - $ttSrc = USERTTDIR.$ttID.'.xml';
  673 + $objSrc = USERTTDIR.$id.'.xml';
644 674  
645   - if (!file_exists($ttSrc)) {
646   - $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID);
  675 + if (!file_exists($objSrc)) {
  676 + $this->throwError("workspaceError", "No such object ".$id." for user ".$this->userID);
647 677 }
648 678  
649   - $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml";
  679 + $objDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$id.xml";
  680 +
  681 + if (!isset($this->requestManager))
  682 + $this->requestManager = new RequestManagerClass();
  683 +
  684 + try {
  685 + $obj = array(
  686 + 'inputFile' => $objSrc,
  687 + 'outputFormat' => 'VOTABLE',
  688 + 'outputFileName' => $objDst,
  689 + );
  690 + $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::TTCONVERT, $this->service, $obj);
  691 + } catch (Exception $e) {
  692 + return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
  693 + }
650 694  
651   - //TODO can be done by
652   - // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID);
653   - $this->xsl2vot($ttSrc,$ttDst);
  695 + $resKey = ($type == 'catalog') ? 'catFileURL' : 'ttFileURL';
654 696  
655   - return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst);
  697 + return array('success' => true, $resKey => WSConfigClass::getUrl().$objDst);
656 698 }
657 699  
658 700 /*
... ...
php/rest/getCatalog.php 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @api {get} getCatalog.php getCatalog
  5 + * @apiDescription Provides the contents of a Time Table (TT).
  6 + * @apiName getCatalog
  7 + * @apiGroup webservices
  8 + *
  9 + * @apiParam {String} catID Identifier of the Catalog, as defined in the file returned by the « getCatalogsList » service.
  10 + * @apiParam {String} [userID] Identifier of the user in AMDA (*mandatory for user owned data*)
  11 + * @apiParam {String} [password] Password of the user in AMDA (*mandatory for user owned data*)
  12 + *
  13 + * @apiSuccess {String} success `true`
  14 + * @apiSuccess {String} catFileURL URL of the XML file containing the Catalog (VOTable format)
  15 + *
  16 + * @apiSuccessExample Success-Response:
  17 + * HTTP/1.1 200 OK
  18 + * [success] => 1
  19 + * [ttFileURL] => http://amda.irap.omp.eu/AMDA/data/WSRESULT/catalog_userID_20180919_cat_0.xml
  20 + *
  21 + * @apiErrorExample Error-Response:
  22 + * {"error":"No such table sharedcatalog_100 for user impex"}
  23 + */
  24 +
  25 +require_once '../config.php';
  26 +
  27 + $amda_ws = new WebServer();
  28 +
  29 + $result = $amda_ws->getCatalog($_GET);
  30 +
  31 + if ($result['success']){
  32 + echo $result['catFileURL'];
  33 + }
  34 + else {
  35 + echo $result['message'];
  36 + }
  37 +?>
  38 +
  39 +
... ...
php/rest/getCatalogsList.php 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @api {get} getCatalogsList.php getCatalogsList
  5 + * @apiDescription Provides the private list of Catalogs owned by a user. When called without
  6 + * userID, this web-service returns the list of shared Catalogs.
  7 + *
  8 + * @apiName getCatalogsList
  9 + * @apiGroup webservices
  10 + *
  11 + * @apiParam {String} [userID] Identifier of the user in AMDA.
  12 + * @apiParam {String} [password] Password of the user in AMDA.
  13 + *
  14 + * @apiSuccess {String} success `true`
  15 + * @apiSuccess {String} CatalogsList URL of the XML file, which contains the list of Catalogs.
  16 + *
  17 + * @apiSuccessExample Success-Response:
  18 + * HTTP/1.1 200 OK
  19 + * [success] => 1
  20 + * [CatalogsList] => http://amda.irap.omp.eu/data/WSRESULT/catalogs_impex_20180905.xml
  21 + *
  22 + * @apiErrorExample Error-Response:
  23 + * {"error": "Workspace Error : Cannot load Catalogs list for userID"}
  24 + */
  25 +
  26 + require_once '../config.php';
  27 +
  28 + $amda_ws = new WebServer();
  29 +
  30 + $result = $amda_ws->getCatalogsList($_GET);
  31 +
  32 + if ($result['success'])
  33 + {
  34 + echo $result['CatalogsList'];
  35 + }
  36 + else
  37 + {
  38 + echo $result['message'];
  39 + }
  40 +?>
... ...