diff --git a/php/XML/xml2vot.xsl b/php/XML/xml2vot.xsl new file mode 100644 index 0000000..b6d7df9 --- /dev/null +++ b/php/XML/xml2vot.xsl @@ -0,0 +1,39 @@ +<xsl:stylesheet version="1.0" +xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + +<xsl:output method="xml"/> + +<xsl:template match="/timetable"> + <VOTABLE version='1.1'> + <DESCRIPTION> + Name: <xsl:value-of select="name"/>; + Description: <xsl:value-of select="description"/>; + Historic: <xsl:value-of select="history"/>; + Creation Date : <xsl:value-of select="created"/>; + </DESCRIPTION> +<RESOURCE> +<DESCRIPTION> + AMDA @ CDPP +</DESCRIPTION> +<TABLE> +<FIELD datatype='char' name='Start Time' ID='TimeIntervalStart' ucd='time.start'> + <DESCRIPTION>time tag for beginning of interval</DESCRIPTION> +</FIELD> +<FIELD datatype='char' name='Stop Time' ID='TimeIntervalStop' ucd='time.stop'> + <DESCRIPTION>time tag for end of interval</DESCRIPTION> +</FIELD> +<DATA> + <TABLEDATA> + <xsl:for-each select="intervals"> + <TR> + <TD><xsl:value-of select="start"/></TD> + <TD><xsl:value-of select="stop"/></TD> + </TR> + </xsl:for-each> + </TABLEDATA> + </DATA> + </TABLE> + </RESOURCE> + </VOTABLE> +</xsl:template> +</xsl:stylesheet> diff --git a/php/classes/WebServer.php b/php/classes/WebServer.php index 2001a3d..ad6c873 100644 --- a/php/classes/WebServer.php +++ b/php/classes/WebServer.php @@ -17,7 +17,6 @@ class WebServer function __construct() { if (!is_dir(WSConfigClass::getWsResultDir())) mkdir(WSConfigClass::getWsResultDir(), 0775); - } protected function init($data) @@ -72,6 +71,29 @@ class WebServer return array("error" => $msg); } + private function xsl2vot($inputName, $outputName) + { + // Load Time table + $xml = new DomDocument("1.0"); + if (!@$xml->load($inputName)) + $this->throwError("wokrspaceError", "Cannot load time table $inputName for ".$this->userID); + + // Load XSL file + $xsl = new DomDocument("1.0"); + if (!@$xsl->load(WSConfigClass::getXslDir()."xml2vot.xsl")) + $this->throwError("systemError", "Cannot load xsl file"); + + // Import XSL and write output file in vot format + $xslt = new XSLTProcessor(); + $xslt->importStylesheet($xsl); + $vot = new DomDocument("1.0"); + if (!@$vot->loadXML($xslt->transformToXML($xml))) + $this->throwError("systemError", "Cannot convert time table to VOtable"); + + if (!$vot->save(WSConfigClass::getWsResultDir().$outputName)) + $this->throwError("systemError", "Cannot save time table to result dir"); + } + private function setID() { $nb_min = 10000; @@ -137,60 +159,7 @@ class WebServer return WSConfigClass::getUrl().$ttListResult; } - - public function getTimeTable($data) - { - $res = $this->init($data); - - $vars = $res['vars']; - $ttID = $vars['ttID']; - - if ($this->userID == 'impex') { - $sharedObjMgr = new SharedObjectsMgr(); - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); - } - else - $ttSrc = USERPATH.$this->userID.'/TT/'.$ttID.'.xml'; - - if (!file_exists($ttSrc)) { - $this->throwError("workspaceError", "No such table ".$ttID.".xml"); - } - - $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID,$ttID); - - if (!copy($ttSrc,$ttWSresult)){ - $this->throwError("workspaceError", "Cannot copy ".$ttID.".xml"); - } - - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID, $ttWSresult); - - $myTimeTableMgr = new TimeTableMgr($this->userID); - $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult); - - if(file_exists($ttWSresultVot)){ - copy($ttWSresultVot, $ttWSresult); - unlink( $ttWSresultVot ) ; - } - - return array('success' => true, 'ttFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttWSresult)); - } -/* -* public data only : user impex -*/ - public function getObsDataTree() - { - $res = $this->init(); - $this->initUserMgr(); - - $locParamSrc = USERWSDIR.'LocalParams.xml'; - $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; - - if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst)) - $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file'); - - return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst)); - } public function getPlot($data) { @@ -311,111 +280,6 @@ class WebServer else return array('success' => false); } - -/* -* get status for jobs in batch -*/ - public function getStatus($data) - { - $result = $this->init($data); - - $id = $result['vars']['id']; - - if (!isset($this->requestManager)) - $this->requestManager = new RequestManagerClass(); - - try - { - $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id); - } - catch (Exception $e) - { -// if ($e->getMessage() == "Exception detected : Request execution error : Cannot get process from id" ) -// { - // after first getStatus() call process is deleted - $jobsManager = new WSJobsManagerClass(); - - try - { - $res = $jobsManager->getResultFromProcessId($id); - if (!$res['success']) { - $this->throwError("processError","Cannot retrieve process $id info"); - } - - return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$res['result']); - } - catch (Exception $e) - { - $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage()); - } -// } -// else -// { -// $this->throwError("getStatusError", "Exception detected : ".$e->getMessage()); -// } - } - - if (!$res['success']) { - $this->throwError("processError","Cannot retrieve process $id info"); - } - - if ($res['status'] == 'in_progress') { - return array('success' => true, 'status' => 'in progress'); - } - - if ($res['error']) { - $this->throwError("processError","Process $id error code"); - } - -// [success] => 1 -// [id] => process_jckrDz_1520873370_11632 -// [name] => download_1520873382 -// [status] => done -// [jobType] => download -// [info] => imf -// [start] => 12-03-2018 16:49:30 -// [stop] => 12-03-2018 16:51:49 -// [folder] => DDfqlbZr_ -// [result] => download_imf_1484352000_1494806400.txt -// [format] => -// [compression] => 0 - $this->deleteProcess($res['id']); - return array('success' => true, 'status' => $res['status'], 'dataFileURLs' => WSConfigClass::getUrl().$res['result']); - } - - - public function getParameterList($data) - { - $res = $this->init($data); - - $resMgr = $this->initUserMgr(); - - $vars = $res['vars']; - - $locParamSrc = USERWSDIR.'/LocalParams.xml'; - $wsParamSrc = USERWSDIR.'/WsParams.xml'; - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams'); - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams'); - - if (!copy($locParamSrc,$locParamResult)) - $locParamResult = ''; - - if (!copy($wsParamSrc,$wsParamResult)) - $wsParamResult = ''; - - if ($locParamResult !='') - $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult); - if ($wsParamResult !='') - $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult); - - if (($locParamResult =='') && ($wsParamResult =='')){ - $this->throwError("workspaceError", "No params descriptions for ".$this->userID); - } - - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult.";".$remoteParamResult); - - return array('success' => true,'ParameterList' => array("UserDefinedParameters"=>$wsParamResult, "LocalDataBaseParameters"=>$locParamResult, "RemoteDataBaseParameters"=>$remoteParamResult)); - } /* * generate AUTH token for access to REST services @@ -537,47 +401,6 @@ class WebServer return array('success' => false, 'message' => "Orbits file doesn't exist"); } } - - private function getFormatInfo($fileFormat, $timeFormat, $gzip) - { - switch ($fileFormat) { - case 'netCDF' : - $this->throwError("serverError", "netCDF format not implemented"); - break; - case 'VOTable' : - $fileFormat = "vot"; - $kernelExtension = ".vot"; - $wsExtension = ".xml"; - break; - case 'ASCII' : - default : - $fileFormat = "ASCII"; - $kernelExtension = ".txt"; - $wsExtension = ".txt"; - } - - switch ($timeFormat) { - case 'unixtime' : - $timeFormat = 'Timestamp'; - break; - default : - $timeFormat = 'YYYY-MM-DDThh:mm:ss'; - } - - if ($gzip == 1) { - $compression = "gzip"; - $kernelExtension .= ".gz"; - $wsExtension .= ".gz"; - } else - $compression = ""; - - return ['success' => true, - 'kernelExtension' => $kernelExtension, - 'wsExtension' => $wsExtension, - 'fileFormat' => $fileFormat, - 'timeFormat' => $timeFormat, - 'compression' => $compression]; - } protected function doDownloadRequest($interval, $paramList, $formatInfo) { @@ -698,6 +521,52 @@ class WebServer } /************************** WEB SERVICES **************************************/ + +/* +* public data only : user impex +*/ + public function getObsDataTree() + { + $res = $this->init(); + $this->initUserMgr(); + + $locParamSrc = USERWSDIR.'LocalParams.xml'; + $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; + + if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst)) + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file'); + + return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst)); + } + +/* +* get Parameter List for given user +*/ + public function getParameterList($data) + { + $res = $this->init($data); + $this->initUserMgr(); + + $vars = $res['vars']; + + $locParamSrc = USERWSDIR.'LocalParams.xml'; + $wsParamSrc = USERWSDIR.'WsParams.xml'; + + $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; + $wsParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml'; + + if (!copy($locParamSrc, WSConfigClass::getWsResultDir().$locParamDst)) + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file for '.$this->userID); + + if (!copy($wsParamSrc, WSConfigClass::getWsResultDir().$wsParamDst)) + $this->throwError('workspaceError', 'No User Defined Parameters description file for '.$this->userID); + + return array('success' => true,'ParameterList' => + array("UserDefinedParameters" => WSConfigClass::getUrl().$wsParamDst, + "LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst, + "RemoteDataBaseParameters" => "not implemented")); + } + /* * getParameter */ @@ -862,5 +731,95 @@ class WebServer $this->throwError("serverError", $res['message']); } + +/* +* get status for jobs in batch +*/ + public function getStatus($data) + { + $result = $this->init($data); + + $id = $result['vars']['id']; + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try + { + $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id); + } + catch (Exception $e) + { + // after first getStatus() call process is deleted + $jobsManager = new WSJobsManagerClass(); + + try + { + $res = $jobsManager->getResultFromProcessId($id); + if (!$res['success']) { + $this->throwError("processError","Cannot retrieve process $id info"); + } + + return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$res['result']); + } + catch (Exception $e) + { + $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage()); + } + } + + if (!$res['success']) { + $this->throwError("processError","Cannot retrieve process $id info"); + } + + if ($res['status'] == 'in_progress') { + return array('success' => true, 'status' => 'in progress'); + } + + if ($res['error']) { + $this->throwError("processError","Process $id error code"); + } + + $this->deleteProcess($res['id']); + return array('success' => true, 'status' => $res['status'], 'dataFileURLs' => 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 impex ; user' for user +*/ + public function getTimeTable($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(true); + + $ttID = $res['vars']['ttID']; + + if ($this->userID == 'impex') { + $sharedObjMgr = new SharedObjectsMgr(); + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); + } + else + $ttSrc = USERTTDIR.$ttID.'.xml'; + + if (!file_exists($ttSrc)) { + $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID); + } + + $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml"; + + //TODO can be done by + // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID); + $this->xsl2vot($ttSrc,$ttDst); + + return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst); + } } -?> \ No newline at end of file +?> -- libgit2 0.21.2