Commit cd1dd332a955198fef4052ac4c9b545d872912f6

Authored by Elena.Budnik
1 parent 50fd9404

getTimeTable

Showing 2 changed files with 199 additions and 201 deletions   Show diff stats
php/XML/xml2vot.xsl 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +<xsl:stylesheet version="1.0"
  2 +xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3 +
  4 +<xsl:output method="xml"/>
  5 +
  6 +<xsl:template match="/timetable">
  7 + <VOTABLE version='1.1'>
  8 + <DESCRIPTION>
  9 + Name: <xsl:value-of select="name"/>;
  10 + Description: <xsl:value-of select="description"/>;
  11 + Historic: <xsl:value-of select="history"/>;
  12 + Creation Date : <xsl:value-of select="created"/>;
  13 + </DESCRIPTION>
  14 +<RESOURCE>
  15 +<DESCRIPTION>
  16 + AMDA @ CDPP
  17 +</DESCRIPTION>
  18 +<TABLE>
  19 +<FIELD datatype='char' name='Start Time' ID='TimeIntervalStart' ucd='time.start'>
  20 + <DESCRIPTION>time tag for beginning of interval</DESCRIPTION>
  21 +</FIELD>
  22 +<FIELD datatype='char' name='Stop Time' ID='TimeIntervalStop' ucd='time.stop'>
  23 + <DESCRIPTION>time tag for end of interval</DESCRIPTION>
  24 +</FIELD>
  25 +<DATA>
  26 + <TABLEDATA>
  27 + <xsl:for-each select="intervals">
  28 + <TR>
  29 + <TD><xsl:value-of select="start"/></TD>
  30 + <TD><xsl:value-of select="stop"/></TD>
  31 + </TR>
  32 + </xsl:for-each>
  33 + </TABLEDATA>
  34 + </DATA>
  35 + </TABLE>
  36 + </RESOURCE>
  37 + </VOTABLE>
  38 +</xsl:template>
  39 +</xsl:stylesheet>
... ...
php/classes/WebServer.php
... ... @@ -17,7 +17,6 @@ class WebServer
17 17 function __construct()
18 18 {
19 19 if (!is_dir(WSConfigClass::getWsResultDir())) mkdir(WSConfigClass::getWsResultDir(), 0775);
20   -
21 20 }
22 21  
23 22 protected function init($data)
... ... @@ -72,6 +71,29 @@ class WebServer
72 71 return array("error" => $msg);
73 72 }
74 73  
  74 + private function xsl2vot($inputName, $outputName)
  75 + {
  76 + // Load Time table
  77 + $xml = new DomDocument("1.0");
  78 + if (!@$xml->load($inputName))
  79 + $this->throwError("wokrspaceError", "Cannot load time table $inputName for ".$this->userID);
  80 +
  81 + // Load XSL file
  82 + $xsl = new DomDocument("1.0");
  83 + if (!@$xsl->load(WSConfigClass::getXslDir()."xml2vot.xsl"))
  84 + $this->throwError("systemError", "Cannot load xsl file");
  85 +
  86 + // Import XSL and write output file in vot format
  87 + $xslt = new XSLTProcessor();
  88 + $xslt->importStylesheet($xsl);
  89 + $vot = new DomDocument("1.0");
  90 + if (!@$vot->loadXML($xslt->transformToXML($xml)))
  91 + $this->throwError("systemError", "Cannot convert time table to VOtable");
  92 +
  93 + if (!$vot->save(WSConfigClass::getWsResultDir().$outputName))
  94 + $this->throwError("systemError", "Cannot save time table to result dir");
  95 + }
  96 +
75 97 private function setID()
76 98 {
77 99 $nb_min = 10000;
... ... @@ -137,60 +159,7 @@ class WebServer
137 159  
138 160 return WSConfigClass::getUrl().$ttListResult;
139 161 }
140   -
141   - public function getTimeTable($data)
142   - {
143   - $res = $this->init($data);
144   -
145   - $vars = $res['vars'];
146   - $ttID = $vars['ttID'];
147   -
148   - if ($this->userID == 'impex') {
149   - $sharedObjMgr = new SharedObjectsMgr();
150   - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
151   - }
152   - else
153   - $ttSrc = USERPATH.$this->userID.'/TT/'.$ttID.'.xml';
154   -
155   - if (!file_exists($ttSrc)) {
156   - $this->throwError("workspaceError", "No such table ".$ttID.".xml");
157   - }
158   -
159   - $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID,$ttID);
160   -
161   - if (!copy($ttSrc,$ttWSresult)){
162   - $this->throwError("workspaceError", "Cannot copy ".$ttID.".xml");
163   - }
164   -
165   - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID, $ttWSresult);
166   -
167   - $myTimeTableMgr = new TimeTableMgr($this->userID);
168   - $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult);
169   -
170   - if(file_exists($ttWSresultVot)){
171   - copy($ttWSresultVot, $ttWSresult);
172   - unlink( $ttWSresultVot ) ;
173   - }
174   -
175   - return array('success' => true, 'ttFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttWSresult));
176   - }
177 162  
178   -/*
179   -* public data only : user impex
180   -*/
181   - public function getObsDataTree()
182   - {
183   - $res = $this->init();
184   - $this->initUserMgr();
185   -
186   - $locParamSrc = USERWSDIR.'LocalParams.xml';
187   - $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
188   -
189   - if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst))
190   - $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file');
191   -
192   - return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst));
193   - }
194 163  
195 164 public function getPlot($data)
196 165 {
... ... @@ -311,111 +280,6 @@ class WebServer
311 280 else
312 281 return array('success' => false);
313 282 }
314   -
315   -/*
316   -* get status for jobs in batch
317   -*/
318   - public function getStatus($data)
319   - {
320   - $result = $this->init($data);
321   -
322   - $id = $result['vars']['id'];
323   -
324   - if (!isset($this->requestManager))
325   - $this->requestManager = new RequestManagerClass();
326   -
327   - try
328   - {
329   - $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id);
330   - }
331   - catch (Exception $e)
332   - {
333   -// if ($e->getMessage() == "Exception detected : Request execution error : Cannot get process from id" )
334   -// {
335   - // after first getStatus() call process is deleted
336   - $jobsManager = new WSJobsManagerClass();
337   -
338   - try
339   - {
340   - $res = $jobsManager->getResultFromProcessId($id);
341   - if (!$res['success']) {
342   - $this->throwError("processError","Cannot retrieve process $id info");
343   - }
344   -
345   - return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
346   - }
347   - catch (Exception $e)
348   - {
349   - $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage());
350   - }
351   -// }
352   -// else
353   -// {
354   -// $this->throwError("getStatusError", "Exception detected : ".$e->getMessage());
355   -// }
356   - }
357   -
358   - if (!$res['success']) {
359   - $this->throwError("processError","Cannot retrieve process $id info");
360   - }
361   -
362   - if ($res['status'] == 'in_progress') {
363   - return array('success' => true, 'status' => 'in progress');
364   - }
365   -
366   - if ($res['error']) {
367   - $this->throwError("processError","Process $id error code");
368   - }
369   -
370   -// [success] => 1
371   -// [id] => process_jckrDz_1520873370_11632
372   -// [name] => download_1520873382
373   -// [status] => done
374   -// [jobType] => download
375   -// [info] => imf
376   -// [start] => 12-03-2018 16:49:30
377   -// [stop] => 12-03-2018 16:51:49
378   -// [folder] => DDfqlbZr_
379   -// [result] => download_imf_1484352000_1494806400.txt
380   -// [format] =>
381   -// [compression] => 0
382   - $this->deleteProcess($res['id']);
383   - return array('success' => true, 'status' => $res['status'], 'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
384   - }
385   -
386   -
387   - public function getParameterList($data)
388   - {
389   - $res = $this->init($data);
390   -
391   - $resMgr = $this->initUserMgr();
392   -
393   - $vars = $res['vars'];
394   -
395   - $locParamSrc = USERWSDIR.'/LocalParams.xml';
396   - $wsParamSrc = USERWSDIR.'/WsParams.xml';
397   - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams');
398   - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams');
399   -
400   - if (!copy($locParamSrc,$locParamResult))
401   - $locParamResult = '';
402   -
403   - if (!copy($wsParamSrc,$wsParamResult))
404   - $wsParamResult = '';
405   -
406   - if ($locParamResult !='')
407   - $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult);
408   - if ($wsParamResult !='')
409   - $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult);
410   -
411   - if (($locParamResult =='') && ($wsParamResult =='')){
412   - $this->throwError("workspaceError", "No params descriptions for ".$this->userID);
413   - }
414   -
415   - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult.";".$remoteParamResult);
416   -
417   - return array('success' => true,'ParameterList' => array("UserDefinedParameters"=>$wsParamResult, "LocalDataBaseParameters"=>$locParamResult, "RemoteDataBaseParameters"=>$remoteParamResult));
418   - }
419 283  
420 284 /*
421 285 * generate AUTH token for access to REST services
... ... @@ -537,47 +401,6 @@ class WebServer
537 401 return array('success' => false, 'message' => "Orbits file doesn't exist");
538 402 }
539 403 }
540   -
541   - private function getFormatInfo($fileFormat, $timeFormat, $gzip)
542   - {
543   - switch ($fileFormat) {
544   - case 'netCDF' :
545   - $this->throwError("serverError", "netCDF format not implemented");
546   - break;
547   - case 'VOTable' :
548   - $fileFormat = "vot";
549   - $kernelExtension = ".vot";
550   - $wsExtension = ".xml";
551   - break;
552   - case 'ASCII' :
553   - default :
554   - $fileFormat = "ASCII";
555   - $kernelExtension = ".txt";
556   - $wsExtension = ".txt";
557   - }
558   -
559   - switch ($timeFormat) {
560   - case 'unixtime' :
561   - $timeFormat = 'Timestamp';
562   - break;
563   - default :
564   - $timeFormat = 'YYYY-MM-DDThh:mm:ss';
565   - }
566   -
567   - if ($gzip == 1) {
568   - $compression = "gzip";
569   - $kernelExtension .= ".gz";
570   - $wsExtension .= ".gz";
571   - } else
572   - $compression = "";
573   -
574   - return ['success' => true,
575   - 'kernelExtension' => $kernelExtension,
576   - 'wsExtension' => $wsExtension,
577   - 'fileFormat' => $fileFormat,
578   - 'timeFormat' => $timeFormat,
579   - 'compression' => $compression];
580   - }
581 404  
582 405 protected function doDownloadRequest($interval, $paramList, $formatInfo)
583 406 {
... ... @@ -698,6 +521,52 @@ class WebServer
698 521 }
699 522  
700 523 /************************** WEB SERVICES **************************************/
  524 +
  525 +/*
  526 +* public data only : user impex
  527 +*/
  528 + public function getObsDataTree()
  529 + {
  530 + $res = $this->init();
  531 + $this->initUserMgr();
  532 +
  533 + $locParamSrc = USERWSDIR.'LocalParams.xml';
  534 + $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
  535 +
  536 + if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst))
  537 + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file');
  538 +
  539 + return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst));
  540 + }
  541 +
  542 +/*
  543 +* get Parameter List for given user
  544 +*/
  545 + public function getParameterList($data)
  546 + {
  547 + $res = $this->init($data);
  548 + $this->initUserMgr();
  549 +
  550 + $vars = $res['vars'];
  551 +
  552 + $locParamSrc = USERWSDIR.'LocalParams.xml';
  553 + $wsParamSrc = USERWSDIR.'WsParams.xml';
  554 +
  555 + $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
  556 + $wsParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml';
  557 +
  558 + if (!copy($locParamSrc, WSConfigClass::getWsResultDir().$locParamDst))
  559 + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file for '.$this->userID);
  560 +
  561 + if (!copy($wsParamSrc, WSConfigClass::getWsResultDir().$wsParamDst))
  562 + $this->throwError('workspaceError', 'No User Defined Parameters description file for '.$this->userID);
  563 +
  564 + return array('success' => true,'ParameterList' =>
  565 + array("UserDefinedParameters" => WSConfigClass::getUrl().$wsParamDst,
  566 + "LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst,
  567 + "RemoteDataBaseParameters" => "not implemented"));
  568 + }
  569 +
701 570 /*
702 571 * getParameter
703 572 */
... ... @@ -862,5 +731,95 @@ class WebServer
862 731  
863 732 $this->throwError("serverError", $res['message']);
864 733 }
  734 +
  735 +/*
  736 +* get status for jobs in batch
  737 +*/
  738 + public function getStatus($data)
  739 + {
  740 + $result = $this->init($data);
  741 +
  742 + $id = $result['vars']['id'];
  743 +
  744 + if (!isset($this->requestManager))
  745 + $this->requestManager = new RequestManagerClass();
  746 +
  747 + try
  748 + {
  749 + $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id);
  750 + }
  751 + catch (Exception $e)
  752 + {
  753 + // after first getStatus() call process is deleted
  754 + $jobsManager = new WSJobsManagerClass();
  755 +
  756 + try
  757 + {
  758 + $res = $jobsManager->getResultFromProcessId($id);
  759 + if (!$res['success']) {
  760 + $this->throwError("processError","Cannot retrieve process $id info");
  761 + }
  762 +
  763 + return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
  764 + }
  765 + catch (Exception $e)
  766 + {
  767 + $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage());
  768 + }
  769 + }
  770 +
  771 + if (!$res['success']) {
  772 + $this->throwError("processError","Cannot retrieve process $id info");
  773 + }
  774 +
  775 + if ($res['status'] == 'in_progress') {
  776 + return array('success' => true, 'status' => 'in progress');
  777 + }
  778 +
  779 + if ($res['error']) {
  780 + $this->throwError("processError","Process $id error code");
  781 + }
  782 +
  783 + $this->deleteProcess($res['id']);
  784 + return array('success' => true, 'status' => $res['status'], 'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
  785 + }
  786 +
  787 +/*
  788 +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!!
  789 +* TODO Think about this if merge/union will be also done by AMDA_Kernel
  790 +*
  791 +* get Time Table : shared for impex ; user' for user
  792 +*/
  793 + public function getTimeTable($data)
  794 + {
  795 + $res = $this->init($data);
  796 +
  797 + if (!$res['success']){
  798 + $this->throwError("requestError", "Cannot parse request");
  799 + }
  800 +
  801 + $this->initUserMgr(true);
  802 +
  803 + $ttID = $res['vars']['ttID'];
  804 +
  805 + if ($this->userID == 'impex') {
  806 + $sharedObjMgr = new SharedObjectsMgr();
  807 + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
  808 + }
  809 + else
  810 + $ttSrc = USERTTDIR.$ttID.'.xml';
  811 +
  812 + if (!file_exists($ttSrc)) {
  813 + $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID);
  814 + }
  815 +
  816 + $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml";
  817 +
  818 + //TODO can be done by
  819 + // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID);
  820 + $this->xsl2vot($ttSrc,$ttDst);
  821 +
  822 + return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst);
  823 + }
865 824 }
866   -?>
867 825 \ No newline at end of file
  826 +?>
... ...