Commit 1922ad04b8d2c33886da04783aa48864eb087788

Authored by Elena.Budnik
1 parent cd1dd332

getOrbites()

Showing 2 changed files with 119 additions and 143 deletions   Show diff stats
php/classes/WebServer.php
... ... @@ -120,6 +120,21 @@ class WebServer
120 120 }
121 121 }
122 122  
  123 + private function getDatasetInfo($id)
  124 + {
  125 + $dataSetXml = WSConfigClass::getDataSetInfoDir().$id.".xml";
  126 +
  127 + if (!file_exists($dataSetXml))
  128 + $this->throwError("systemError", "Cannot find info file for dataset ".$id);
  129 +
  130 + $dataSetDom = new DomDocument("1.0");
  131 +
  132 + if (!@$dataSetDom->load($dataSetXml))
  133 + $this->throwError("systemError", "Cannot load info file for dataset ".$id);
  134 +
  135 + return $dataSetXml;
  136 + }
  137 +
123 138 /*
124 139 * get user TimeTables list; Shared for impex
125 140 */
... ... @@ -291,118 +306,49 @@ class WebServer
291 306 $newToken = md5(1321 * (int)($timeStamp / timeLimitQuery));
292 307 return array('success' => true, 'token' => $newToken);
293 308 }
294   -
  309 +
295 310 /*
296   -* get Orbites
297   -*/
298   - public function getOrbites($data)
  311 +* Get corresponding orbit parameter ID
  312 +*/
  313 + private function getOrbitParameter($orbitRequest)
299 314 {
300   - $res = $this->init($data);
301   -
302   - $resMgr = $this->initUserMgr();
303   -
304   - if (!$resMgr['success']){
305   - $this->throwError("serverError", "Cannot init user manager");
306   - }
307   -
308   - $vars = $res['vars'];
309   -
310   - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){
311   - $this->throwError("requestError", "Requested time interval should be greater than 0");
312   - }
313   -
314   - $spacecraft = $vars["spacecraft"];
315   - $coordinateSystem = $vars["coordinateSystem"];
316   -
317   - if ($spacecraft == "GALILEO") $spacecraft = ucfirst(strtolower($spacecraft));
318   - if (!$vars["units"])
319   - $units = "km";
320   - else
321   - $units = $vars["units"];
  315 + if (!file_exists(WSConfigClass::getOrbitsXml()))
  316 + $this->throwError('systemError', "No AMDA system orbits file");
  317 +
  318 + $orbitsXml = new DomDocument();
322 319  
323   - $orbitRequest = array("startTime" => $vars["startTime"],
324   - "stopTime" => $vars["stopTime"],
325   - "spacecraft" => $spacecraft,
326   - "coordinateSystem" => $coordinateSystem,
327   - "units" => $units
328   - );
329   -
330   - $orbitesParam = $this->getOrbitesParameter($orbitRequest);
  320 + if (!@$orbitsXml->load(WSConfigClass::getOrbitsXml()))
  321 + $this->throwError('systemError', "Cannot load AMDA system orbits file");
  322 +
  323 + $spacecraft = strtolower($orbitRequest['spacecraft']);
  324 + $spacecraft = str_replace('-', '', $spacecraft);
331 325  
332   - if ($orbitesParam['success']) {
333   - $orbParam = $orbitesParam['parameterID'];
334   - }
335   - else {
336   - $this->throwError("requestError", $orbitesParam['message']);
337   - }
338   -
339   - $dataFileName = $this->getDataFileName($orbitesParam);
  326 + $xpath = new DOMXpath($orbitsXml);
  327 + $path = '//orbites[@mission="'.$spacecraft.'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] ';
340 328  
341   - if ($dataFileName['success']) {
342   - $this->dataFileName = $dataFileName['fileName'];
343   - }
344   - else {
345   - $this->throwError("requestError", $dataFileName['message']);
346   - }
  329 + $orbits = $xpath->query($path);
347 330  
348   - $paramId = array();
349   - array_push($paramId, $orbParam);
350   -
351   - if (!$vars["timeFormat"])
352   - $timeFormat = "ISO8601";
353   - else
354   - $timeFormat = $vars["timeFormat"];
  331 + foreach ($orbits as $orbit)
  332 + {
  333 + $datasetID = strtr($orbit->getAttribute('dataset'),"_","-");
  334 + $dataSetDom = $this->getDatasetInfo($datasetID);
  335 +
  336 + $paramStart = strtotime($dataSetDom->getElementsByTagName('global_start')->item(0)->nodeValue);
  337 + $paramStop = strtotime($dataSetDom->getElementsByTagName('global_stop')->item(0)->nodeValue);
355 338  
356   - if (!$vars["gzip"])
357   - $gzip = 0;
358   - else
359   - $gzip = $vars["gzip"];
360   -
361   - $res = $this->doDownloadRequest(
362   - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
363   - array("params" => $paramId),
364   - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream));
365   -
366   - if ($res['success']) return $res;
367   -
368   - $this->throwError("serverError",$res['message']);
369   - }
  339 + if(($paramStart <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= $paramStop)) {
370 340  
371   - protected function getOrbitesParameter($orbitRequest)
372   - {
373   - $orbitesXml = new DomDocument();
374   -
375   - if (file_exists(orbitesXml))
376   - {
377   - $orbitesXml->load(orbitesXml);
378   - $xpath = new DOMXpath($orbitesXml);
379   - $path = '//orbites[@mission="'.$orbitRequest['spacecraft'].'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] ';
380   -
381   - $orbites = $xpath->query($path);
382   - foreach ($orbites as $orbite){
383   - $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($orbite->getAttribute('xml:id'));
384   - $paramStart = $paramInfo['dataset']['starttime'];
385   - $paramStop = $paramInfo['dataset']['stoptime'];
386   -
387   - if((strtotime($paramStart) <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= strtotime($paramStop))) {
388   -
389   - return array('success' => true,
390   - 'parameterID' => $orbite->getAttribute('xml:id'),
391   - 'startTime' => $orbitRequest['startTime'],
392   - 'stopTime' => $orbitRequest['stopTime']
393   - );
394   - }
  341 + return array('success' => true,
  342 + 'parameterID' => $orbit->getAttribute('xml:id')
  343 + );
395 344 }
396   - return array('success' => false,
397   - 'message' =>
398   - "Cannot find orbites for ".$orbitRequest['spacecraft']." between ".$orbitRequest['startTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']." and ".$orbitRequest['stopTime']." ($paramStart - $paramStop) ");
399 345 }
400   - else {
401   - return array('success' => false, 'message' => "Orbits file doesn't exist");
402   - }
  346 +
  347 + $this->throwError('systemError',
  348 + "Cannot find orbit data for ".$orbitRequest['spacecraft']." for ".$orbitRequest['startTime']."-".$orbitRequest['stopTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']."($paramStart - $paramStop)");
403 349 }
404   -
405   - protected function doDownloadRequest($interval, $paramList, $formatInfo)
  350 +
  351 + private function doDownloadRequest($interval, $paramList, $formatInfo)
406 352 {
407 353 if (!isset($this->paramLoader))
408 354 $this->paramLoader = new IHMUserParamLoaderClass();
... ... @@ -492,34 +438,6 @@ class WebServer
492 438 }
493 439 }
494 440  
495   - protected function getDataFileName($vars, $multiParam = false)
496   - {
497   - if ($vars['startTime'] && $vars['stopTime'] && $vars['parameterID'] && !$multiParam){
498   - $fileName = $vars['parameterID']."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);
499   - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
500   - $fileName .= "-".$vars['sampling'];
501   - return array('success' => true, 'fileName' => $fileName);
502   - }
503   - else if ($vars['startTime'] && $vars['stopTime'] && $vars['datasetID'] && $multiParam){
504   - $datasetName = strtr($vars["datasetID"], array(":" => "_"));
505   - $fileName = $datasetName."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);
506   - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
507   - $fileName .= "-".$vars['sampling'];
508   - return array('success' => true, 'fileName' => $fileName);
509   - }
510   - else {
511   - if (!$vars['startTime'])
512   - $message="Start time not specified";
513   - if (!$vars['stopTime'])
514   - $message="Stop time not specified";
515   - if (!$vars['parameterID'] && !$multiParam)
516   - $message="Parameter not specified";
517   - if (!$vars['datasetID'] && $multiParam)
518   - $message="DataSet not specified";
519   - return array('success' => false, 'message' => $message);
520   - }
521   - }
522   -
523 441 /************************** WEB SERVICES **************************************/
524 442  
525 443 /*
... ... @@ -531,7 +449,7 @@ class WebServer
531 449 $this->initUserMgr();
532 450  
533 451 $locParamSrc = USERWSDIR.'LocalParams.xml';
534   - $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
  452 + $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
535 453  
536 454 if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst))
537 455 $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file');
... ... @@ -552,8 +470,8 @@ class WebServer
552 470 $locParamSrc = USERWSDIR.'LocalParams.xml';
553 471 $wsParamSrc = USERWSDIR.'WsParams.xml';
554 472  
555   - $locParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
556   - $wsParamDst = strtolower(__FUNCTION__).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml';
  473 + $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml';
  474 + $wsParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml';
557 475  
558 476 if (!copy($locParamSrc, WSConfigClass::getWsResultDir().$locParamDst))
559 477 $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file for '.$this->userID);
... ... @@ -661,16 +579,8 @@ class WebServer
661 579 $this->throwError("requestError", "Requested time interval should be greater than 0");
662 580 }
663 581  
664   - $dataSetXml = WSConfigClass::getDataSetInfoDir().$vars['datasetID'].".xml";
665   -
666   - if (!file_exists($dataSetXml))
667   - $this->throwError("systemError", "Cannot find info file for dataset ".$vars['datasetID']);
668   -
669   - $dataSetDom = new DomDocument("1.0");
  582 + $dataSetDom = $this->getDatasetInfo($vars['datasetID']);
670 583  
671   - if (!@$dataSetDom->load($dataSetXml))
672   - $this->throwError("systemError", "Cannot load info file for dataset ".$vars['datasetID']);
673   -
674 584 $params = $dataSetDom->getElementsByTagName("parameter");
675 585  
676 586 if ($params->length == 0)
... ... @@ -821,5 +731,66 @@ class WebServer
821 731  
822 732 return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst);
823 733 }
  734 +
  735 +/*
  736 +* get Orbits
  737 +*/
  738 + public function getOrbites($data)
  739 + {
  740 + $res = $this->init($data);
  741 +
  742 + if (!$res['success']){
  743 + $this->throwError("requestError", "Cannot parse request");
  744 + }
  745 +
  746 + $this->initUserMgr();
  747 +
  748 + $vars = $res['vars'];
  749 +
  750 + if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){
  751 + $this->throwError("requestError", "Requested time interval should be greater than 0");
  752 + }
  753 +
  754 + $spacecraft = $vars["spacecraft"];
  755 + $coordinateSystem = $vars["coordinateSystem"];
  756 +
  757 + if (!$vars["units"])
  758 + $units = "km";
  759 + else
  760 + $units = $vars["units"];
  761 +
  762 + $orbitRequest = array("startTime" => $vars["startTime"],
  763 + "stopTime" => $vars["stopTime"],
  764 + "spacecraft" => $spacecraft,
  765 + "coordinateSystem" => $coordinateSystem,
  766 + "units" => $units
  767 + );
  768 +
  769 + $orbitParam = $this->getOrbitParameter($orbitRequest);
  770 +
  771 + $paramId = array();
  772 + array_push($paramId, $orbitParam['parameterID']);
  773 +
  774 + if (!$vars["timeFormat"])
  775 + $timeFormat = "ISO8601";
  776 + else
  777 + $timeFormat = $vars["timeFormat"];
  778 +
  779 + if (!$vars["gzip"])
  780 + $gzip = 0;
  781 + else
  782 + $gzip = $vars["gzip"];
  783 +
  784 + $this->service = strtolower(__FUNCTION__);
  785 +
  786 + $res = $this->doDownloadRequest(
  787 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
  788 + array("params" => $paramId),
  789 + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream));
  790 +
  791 + if ($res['success']) return $res;
  792 +
  793 + $this->throwError("serverError",$res['message']);
  794 + }
824 795 }
825 796 ?>
... ...
php/makeOrbitsList.php
... ... @@ -43,7 +43,7 @@
43 43 $instruments = $node->getElementsByTagName('instrument');
44 44 foreach ($instruments as $ins)
45 45 {
46   - if ($ins->getAttribute('name') != 'Ephemeris') continue;
  46 + if (substr($ins->getAttribute('name'),0,9) != 'Ephemeris') continue; // Ephemeris: cruise
47 47 $parameters = $ins->getElementsByTagName('parameter');
48 48 foreach ($parameters as $parameter)
49 49 {
... ... @@ -59,7 +59,12 @@
59 59 $orbitNode->setAttribute('xml:id',$parameter->getAttribute('xml:id'));
60 60 $orbitNode->setAttribute('coordinate_system', $paramXml->info->coordinates_system);
61 61 $orbitNode->setAttribute('units', $paramXml->info->units);
62   - $orbitNode->setAttribute('mission', $node->getAttribute('name'));
  62 +
  63 + $name = strtolower($node->getAttribute('name'));
  64 + $name = preg_replace('/\s+/', '', $name);
  65 + $name = str_replace('-', '', $name);
  66 +
  67 + $orbitNode->setAttribute('mission', $name);
63 68  
64 69 if ( $node->tagName == 'observatory' )
65 70 $orbitNode->setAttribute('missionGroup',$node->parentNode->getAttribute('name'));
... ...