Commit c6178eae9244d7a2e3e78b1414ff971e35447d76
Exists in
master
and in
73 other branches
Merge branch 'ws_get_catalog' into amdadev
Showing
4 changed files
with
145 additions
and
16 deletions
Show diff stats
php/WebServices/WebServer.php
... | ... | @@ -616,43 +616,91 @@ class WebServer |
616 | 616 | |
617 | 617 | return array('success' => true, 'status' => $res['status'], $resultTag => WSConfigClass::getUrl().$res['result']); |
618 | 618 | } |
619 | - | |
619 | + | |
620 | 620 | /* |
621 | 621 | * TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! |
622 | 622 | * TODO Think about this if merge/union will be also done by AMDA_Kernel |
623 | 623 | * |
624 | 624 | * get Time Table : shared for anonymous user (impex) ; user' for user |
625 | 625 | */ |
626 | - public function getTimeTable($data) | |
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 | + $format = !empty($res['vars']['outputFormat']) ? $res['vars']['outputFormat'] : 'VOTable'; | |
636 | + | |
637 | + return $this->getTimeTableCatalog('timeTable', $ttID, $format); | |
638 | + } | |
639 | + | |
640 | +/* | |
641 | +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! | |
642 | +* TODO Think about this if merge/union will be also done by AMDA_Kernel | |
643 | +* | |
644 | +* get Time Table : shared for anonymous user (impex) ; user' for user | |
645 | +*/ | |
646 | + public function getCatalog($data) | |
627 | 647 | { |
628 | 648 | $res = $this->init($data); |
629 | - | |
649 | + | |
630 | 650 | if (!$res['success']){ |
631 | - $this->throwError("requestError", "Cannot parse request"); | |
651 | + $this->throwError("requestError", "Cannot parse request"); | |
632 | 652 | } |
633 | - | |
653 | + | |
654 | + $catID = $res['vars']['catID']; | |
655 | + $format = !empty($res['vars']['outputFormat']) ? $res['vars']['outputFormat'] : 'VOTable'; | |
656 | + | |
657 | + return $this->getTimeTableCatalog('catalog', $catID, $format); | |
658 | + } | |
659 | + | |
660 | +/* | |
661 | +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! | |
662 | +* TODO Think about this if merge/union will be also done by AMDA_Kernel | |
663 | +* | |
664 | +* get Time Table : shared for anonymous user (impex) ; user' for user | |
665 | +*/ | |
666 | + private function getTimeTableCatalog($type, $id, $format) | |
667 | + { | |
634 | 668 | $this->initUserMgr(); |
635 | 669 | |
636 | - $ttID = $res['vars']['ttID']; | |
637 | - | |
638 | 670 | if ($this->userID == WSConfigClass::getAnonymousUserName()) { |
639 | 671 | $sharedObjMgr = new SharedObjectsMgr(); |
640 | - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); | |
672 | + $objSrc = $sharedObjMgr->getDataFilePath($type, $id); | |
641 | 673 | } |
642 | 674 | else |
643 | - $ttSrc = USERTTDIR.$ttID.'.xml'; | |
675 | + $objSrc = USERTTDIR.$id.'.xml'; | |
644 | 676 | |
645 | - if (!file_exists($ttSrc)) { | |
646 | - $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID); | |
677 | + if (!file_exists($objSrc)) { | |
678 | + $this->throwError("workspaceError", "No such object ".$id." for user ".$this->userID); | |
647 | 679 | } |
648 | 680 | |
649 | - $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml"; | |
681 | + $prefix = ($type == 'catalog') ? 'catalog' : 'timetable'; | |
682 | + | |
683 | + $extension = (strtolower($format) == 'votable') ? "xml" : "txt"; | |
684 | + | |
685 | + $objDst = $prefix."_".$this->userID."_".$this->requestTime."_$id.$extension"; | |
686 | + | |
687 | + if (!isset($this->requestManager)) | |
688 | + $this->requestManager = new RequestManagerClass(); | |
689 | + | |
690 | + try { | |
691 | + $obj = array( | |
692 | + 'inputFile' => $objSrc, | |
693 | + 'outputFormat' => $format, | |
694 | + 'outputFileName' => $objDst, | |
695 | + ); | |
696 | + $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::TTCONVERT, $this->service, $obj); | |
697 | + } catch (Exception $e) { | |
698 | + return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); | |
699 | + } | |
650 | 700 | |
651 | - //TODO can be done by | |
652 | - // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID); | |
653 | - $this->xsl2vot($ttSrc,$ttDst); | |
701 | + $resKey = ($type == 'catalog') ? 'catFileURL' : 'ttFileURL'; | |
654 | 702 | |
655 | - return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst); | |
703 | + return array('success' => true, $resKey => WSConfigClass::getUrl().$objDst); | |
656 | 704 | } |
657 | 705 | |
658 | 706 | /* |
... | ... |
... | ... | @@ -0,0 +1,40 @@ |
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 | + * @apiParam {String} [outputFormat] Format of the returned file (VOTable by default). Available options: `VOTable`, `ASCII` and `HPEvent`. | |
13 | + * | |
14 | + * @apiSuccess {String} success `true` | |
15 | + * @apiSuccess {String} catFileURL URL of the XML file containing the Catalog (VOTable format) | |
16 | + * | |
17 | + * @apiSuccessExample Success-Response: | |
18 | + * HTTP/1.1 200 OK | |
19 | + * [success] => 1 | |
20 | + * [ttFileURL] => http://amda.irap.omp.eu/AMDA/data/WSRESULT/catalog_userID_20180919_cat_0.xml | |
21 | + * | |
22 | + * @apiErrorExample Error-Response: | |
23 | + * {"error":"No such table sharedcatalog_100 for user impex"} | |
24 | + */ | |
25 | + | |
26 | +require_once '../config.php'; | |
27 | + | |
28 | + $amda_ws = new WebServer(); | |
29 | + | |
30 | + $result = $amda_ws->getCatalog($_GET); | |
31 | + | |
32 | + if ($result['success']){ | |
33 | + echo $result['catFileURL']; | |
34 | + } | |
35 | + else { | |
36 | + echo $result['message']; | |
37 | + } | |
38 | +?> | |
39 | + | |
40 | + | |
... | ... |
... | ... | @@ -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 | +?> | |
... | ... |
php/rest/getTimeTable.php
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | * @apiParam {String} ttID Identifier of the Time Table, as defined in the file returned by the « getTimeTableList » service. |
10 | 10 | * @apiParam {String} [userID] Identifier of the user in AMDA (*mandatory for user owned data*) |
11 | 11 | * @apiParam {String} [password] Password of the user in AMDA (*mandatory for user owned data*) |
12 | + * @apiParam {String} [outputFormat] Format of the returned file (VOTable by default). Available options: `VOTable`, `ASCII` and `HPEvent`. | |
12 | 13 | * |
13 | 14 | * @apiSuccess {String} success `true` |
14 | 15 | * @apiSuccess {String} ttFileURL URL of the XML file containing the Time Table (VOTable format) |
... | ... |