From 0123b9fece777e8e7315e99b4eccfb83453f390a Mon Sep 17 00:00:00 2001 From: Benjamin Renard <benjamin.renard@akka.eu> Date: Mon, 19 Jul 2021 16:16:19 +0200 Subject: [PATCH] Add APIs getCatalog & getCatalogsList --- php/WebServices/WebServer.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- php/rest/getCatalog.php | 39 +++++++++++++++++++++++++++++++++++++++ php/rest/getCatalogsList.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 php/rest/getCatalog.php create mode 100644 php/rest/getCatalogsList.php diff --git a/php/WebServices/WebServer.php b/php/WebServices/WebServer.php index e830095..447e146 100644 --- a/php/WebServices/WebServer.php +++ b/php/WebServices/WebServer.php @@ -616,43 +616,85 @@ class WebServer return array('success' => true, 'status' => $res['status'], $resultTag => WSConfigClass::getUrl().$res['result']); } - + +/* +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! +* TODO Think about this if merge/union will be also done by AMDA_Kernel +* +* get Time Table : shared for anonymous user (impex) ; user' for user +*/ + public function getTimeTable($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $ttID = $res['vars']['ttID']; + + return $this->getTimeTableCatalog('timeTable', $ttID); + } + /* * TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! * TODO Think about this if merge/union will be also done by AMDA_Kernel * * get Time Table : shared for anonymous user (impex) ; user' for user */ - public function getTimeTable($data) + public function getCatalog($data) { $res = $this->init($data); - + if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); + $this->throwError("requestError", "Cannot parse request"); } - + + $catID = $res['vars']['catID']; + + return $this->getTimeTableCatalog('catalog', $catID); + } + +/* +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! +* TODO Think about this if merge/union will be also done by AMDA_Kernel +* +* get Time Table : shared for anonymous user (impex) ; user' for user +*/ + private function getTimeTableCatalog($type, $id) + { $this->initUserMgr(); - $ttID = $res['vars']['ttID']; - if ($this->userID == WSConfigClass::getAnonymousUserName()) { $sharedObjMgr = new SharedObjectsMgr(); - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); + $objSrc = $sharedObjMgr->getDataFilePath($type, $id); } else - $ttSrc = USERTTDIR.$ttID.'.xml'; + $objSrc = USERTTDIR.$id.'.xml'; - if (!file_exists($ttSrc)) { - $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID); + if (!file_exists($objSrc)) { + $this->throwError("workspaceError", "No such object ".$id." for user ".$this->userID); } - $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml"; + $objDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$id.xml"; + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try { + $obj = array( + 'inputFile' => $objSrc, + 'outputFormat' => 'VOTABLE', + 'outputFileName' => $objDst, + ); + $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::TTCONVERT, $this->service, $obj); + } catch (Exception $e) { + return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); + } - //TODO can be done by - // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID); - $this->xsl2vot($ttSrc,$ttDst); + $resKey = ($type == 'catalog') ? 'catFileURL' : 'ttFileURL'; - return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst); + return array('success' => true, $resKey => WSConfigClass::getUrl().$objDst); } /* diff --git a/php/rest/getCatalog.php b/php/rest/getCatalog.php new file mode 100644 index 0000000..aaf3540 --- /dev/null +++ b/php/rest/getCatalog.php @@ -0,0 +1,39 @@ +<?php + +/** + * @api {get} getCatalog.php getCatalog + * @apiDescription Provides the contents of a Time Table (TT). + * @apiName getCatalog + * @apiGroup webservices + * + * @apiParam {String} catID Identifier of the Catalog, as defined in the file returned by the « getCatalogsList » service. + * @apiParam {String} [userID] Identifier of the user in AMDA (*mandatory for user owned data*) + * @apiParam {String} [password] Password of the user in AMDA (*mandatory for user owned data*) + * + * @apiSuccess {String} success `true` + * @apiSuccess {String} catFileURL URL of the XML file containing the Catalog (VOTable format) + * + * @apiSuccessExample Success-Response: + * HTTP/1.1 200 OK + * [success] => 1 + * [ttFileURL] => http://amda.irap.omp.eu/AMDA/data/WSRESULT/catalog_userID_20180919_cat_0.xml + * + * @apiErrorExample Error-Response: + * {"error":"No such table sharedcatalog_100 for user impex"} + */ + +require_once '../config.php'; + + $amda_ws = new WebServer(); + + $result = $amda_ws->getCatalog($_GET); + + if ($result['success']){ + echo $result['catFileURL']; + } + else { + echo $result['message']; + } +?> + + diff --git a/php/rest/getCatalogsList.php b/php/rest/getCatalogsList.php new file mode 100644 index 0000000..8f6a85c --- /dev/null +++ b/php/rest/getCatalogsList.php @@ -0,0 +1,40 @@ +<?php + +/** + * @api {get} getCatalogsList.php getCatalogsList + * @apiDescription Provides the private list of Catalogs owned by a user. When called without + * userID, this web-service returns the list of shared Catalogs. + * + * @apiName getCatalogsList + * @apiGroup webservices + * + * @apiParam {String} [userID] Identifier of the user in AMDA. + * @apiParam {String} [password] Password of the user in AMDA. + * + * @apiSuccess {String} success `true` + * @apiSuccess {String} CatalogsList URL of the XML file, which contains the list of Catalogs. + * + * @apiSuccessExample Success-Response: + * HTTP/1.1 200 OK + * [success] => 1 + * [CatalogsList] => http://amda.irap.omp.eu/data/WSRESULT/catalogs_impex_20180905.xml + * + * @apiErrorExample Error-Response: + * {"error": "Workspace Error : Cannot load Catalogs list for userID"} + */ + + require_once '../config.php'; + + $amda_ws = new WebServer(); + + $result = $amda_ws->getCatalogsList($_GET); + + if ($result['success']) + { + echo $result['CatalogsList']; + } + else + { + echo $result['message']; + } +?> -- libgit2 0.21.2