Commit b8502f4dbc59fce649d8f6b09e9b5ad79172b28b

Authored by Elena.Budnik
1 parent 38ee7afc

getStatus(), throwError(), clean up code

php/AMDA_METHODS_WSDL.php
... ... @@ -2,17 +2,14 @@
2 2  
3 3 /**
4 4 * @file AMDA_METHODS_WSDL.php
5   -* @brief PHP SoapServer for IMPEx WebServices
6   -*
7   -* @version $Id: $
8   -*
  5 +* @brief PHP SoapServer for IMPEx WebServices
9 6 */
10 7  
11   - require_once 'config.php';
12   -
13   - ini_set("soap.wsdl_cache_enabled", "0"); // desactive le cache WSDL
14   - $server = new SoapServer('../public/wsdl/Methods_AMDA.wsdl');
15   - $server->setClass('WebServer');
16   - $server->handle();
  8 + require_once 'config.php';
17 9  
  10 + ini_set("soap.wsdl_cache_enabled", "0"); // desactive le cache WSDL
  11 + $server = new SoapServer('../public/wsdl/Methods_AMDA.wsdl');
  12 + $server->setClass('WebServer');
  13 + $server->handle();
  14 +
18 15 ?>
19 16 \ No newline at end of file
... ...
php/classes/WSUserMgr.php
... ... @@ -8,7 +8,15 @@
8 8 class WSUserMgr extends UserMgr
9 9 {
10 10 protected $isSoap;
11   -
  11 +
  12 + private function throwError($errorType, $msg)
  13 + {
  14 + if ($this->isSoap)
  15 + throw new SoapFault($errorType, $msg);
  16 + else
  17 + return array("error" => $msg);
  18 + }
  19 +
12 20 /*****************************************************************
13 21 * PUBLIC FUNCTIONS
14 22 *****************************************************************/
... ... @@ -25,14 +33,11 @@ class WSUserMgr extends UserMgr
25 33 if ($this->ddCheckUser() != 0)
26 34 {
27 35 if ($this->ddLogin() != 0) { // DD Login if user is not registered
28   - if ($this->isSoap) throw new SoapFault("error", "Login procedure failed");
29   - else return array("error" => "Login procedure failed");
  36 + $this->throwError("loginError", "Login procedure failed");
30 37 }
31 38  
32   - if ($this->ddCheckUser() != 0)
33   - {
34   - if ($this->isSoap) throw new SoapFault("error", "CheckUser procedure failed");
35   - else return array("error" => "CheckUser procedure failed");
  39 + if ($this->ddCheckUser() != 0) {
  40 + $this->throwError("loginError", "CheckUser procedure failed");
36 41 }
37 42 }
38 43  
... ... @@ -41,8 +46,7 @@ class WSUserMgr extends UserMgr
41 46 if (!is_dir($this->userdir))
42 47 {
43 48 if (!$this->createDir()) {
44   - if ($this->isSoap) throw new SoapFault("error", "Cannot create UserDir");
45   - else return array("error" => "Cannot create UserDir");
  49 + $this->throwError("loginError", "Cannot create UserDir");
46 50 }
47 51 }
48 52  
... ... @@ -57,11 +61,7 @@ class WSUserMgr extends UserMgr
57 61  
58 62 public function makeUserWS()
59 63 {
60   - if (file_exists(USERWSDIR.'LocalParams.xml'))
61   - unlink(USERWSDIR.'LocalParams.xml');
62   - // if (!file_exists(USERWSDIR.'LocalParams.xml'))
63   - symlink(DATAPATH.'/LocalData/LocalParams.xml', USERWSDIR.'LocalParams.xml');
64   - // $this->makeLocalTree();
  64 + $this->makeLocalTree();
65 65 $this->makeRemoteTree();
66 66  
67 67 return $this->user;
... ...
php/classes/WebServer.php
1 1 <?php
2   -/**
3   - * @file WebServer.php
4   - * @brief Web services AMDA
5   - *
6   - * @version $Id: WebServer.php 2968 2015-06-29 13:17:00Z natacha $
7   - */
8   -
  2 +/**
  3 +* @file WebServer.php
  4 +* @brief Web services AMDA
  5 +*/
9 6 class WebResultMgr
10 7 {
11   - private $resDOM;
12   - private $rootEl;
13   - private $resXP;
14   - private $requestManager = null;
15   - private $paramLoader = null;
16   -
17   - function __construct()
18   - {
19   - if (!is_dir(WSRESULT))
20   - mkdir(WSRESULT);
21   - chmod(WSRESULT, 0775);
22   -
23   - $this->resDOM = new DOMDocument("1.0");
24   - $this->resDOM->formatOutput = TRUE;
25   - $this->resDOM->preserveWhiteSpace = FALSE;
26   -
27   - if (!file_exists(wsResultsXml)) {
28   - $this->rootEl = $this->resDOM->createElement('wsresults');
29   - $this->resDOM->appendChild($this->rootEl);
30   - $this->resDOM->save(wsResultsXml);
31   - }
32   -
33   - $this->resDOM->load(wsResultsXml);
34   -
35   - $this->resXP = new DOMXPath($this->resDOM);
36   -
37   - $this->rootEl = $this->resDOM->documentElement;
38   - }
39   -
40   - public function addResult($function_name, $vars, $user, $IP, $output)
41   - {
42   - $nodes = $this->rootEl->getElementsByTagName($function_name);
43   - if ($nodes->length < 1) {
44   - $funcNode = $this->resDOM->createElement($function_name);
45   - $this->rootEl->appendChild($funcNode);
46   - } else
47   - $funcNode = $nodes->item(0);
48   -
49   - $oldOutput = $this->resXP->query('//' . $function_name . '/result[@output="' . $output . '"]');
50   - if ($oldOutput->length > 0)
51   - $funcNode->removeChild($oldOutput->item(0));
52   -
53   - $resNode = $this->resDOM->createElement('result');
54   - $resNode->setAttribute('date', time());
55   - $resNode->setAttribute('user', $user);
56   -// $resNode->setAttribute('IP',$IP);
57   - $resNode->setAttribute('input', json_encode($vars));
58   - $resNode->setAttribute('output', $output);
59   - $funcNode->appendChild($resNode);
60   -
61   - $this->resDOM->save(wsResultsXml);
62   -
63   - return $resNode;
64   - }
65   -
66   - public function getResOutputName($function_name, $user, $suffixe, $extension)
67   - {
68   - $outputFile = WSRESULT . $function_name . "_" . $user;
69   - if (isset($suffixe))
70   - $outputFile .= ("_" . $suffixe);
71   - if (isset($extension))
72   - $outputFile .= ("." . $extension);
73   - else
74   - $outputFile .= ".xml";
75   - return $outputFile;
76   - }
  8 + private $resDOM;
  9 + private $rootEl;
  10 + private $resXP;
  11 + private $requestManager = null;
  12 + private $paramLoader = null;
  13 +
  14 + function __construct()
  15 + {
  16 + if (!is_dir(WSRESULT))
  17 + mkdir(WSRESULT);
  18 +
  19 + chmod(WSRESULT,0775);
  20 +
  21 + $this->resDOM = new DOMDocument("1.0");
  22 + $this->resDOM->formatOutput = TRUE;
  23 + $this->resDOM->preserveWhiteSpace = FALSE;
  24 +
  25 + if (!file_exists(wsResultsXml))
  26 + {
  27 + $this->rootEl = $this->resDOM->createElement('wsresults');
  28 + $this->resDOM->appendChild($this->rootEl);
  29 + $this->resDOM->save(wsResultsXml);
  30 + }
  31 +
  32 + $this->resDOM->load(wsResultsXml);
  33 +
  34 + $this->resXP = new DOMXPath($this->resDOM);
  35 +
  36 + $this->rootEl = $this->resDOM->documentElement;
  37 + }
  38 +
  39 + public function addResult($function_name,$vars,$user,$IP,$output)
  40 + {
  41 + $nodes = $this->rootEl->getElementsByTagName($function_name);
  42 + if($nodes->length < 1){
  43 + $funcNode = $this->resDOM->createElement($function_name);
  44 + $this->rootEl->appendChild($funcNode);
  45 + }
  46 + else
  47 + $funcNode = $nodes->item(0);
  48 +
  49 + $oldOutput = $this->resXP->query('//'.$function_name.'/result[@output="'.$output.'"]');
  50 + if ($oldOutput->length > 0)
  51 + $funcNode->removeChild($oldOutput->item(0));
  52 +
  53 + $resNode = $this->resDOM->createElement('result');
  54 + $resNode->setAttribute('date',time());
  55 + $resNode->setAttribute('user',$user);
  56 + // $resNode->setAttribute('IP',$IP);
  57 + $resNode->setAttribute('input',json_encode($vars));
  58 + $resNode->setAttribute('output',$output);
  59 + $funcNode->appendChild($resNode);
  60 +
  61 + $this->resDOM->save(wsResultsXml);
  62 +
  63 + return $resNode;
  64 + }
  65 +
  66 + public function getResOutputName($function_name,$user,$suffixe,$extension)
  67 + {
  68 + $outputFile = WSRESULT.$function_name."_".$user;
  69 + if (isset($suffixe))
  70 + $outputFile .= ("_".$suffixe);
  71 + if (isset($extension))
  72 + $outputFile .= (".".$extension);
  73 + else
  74 + $outputFile .= ".xml";
  75 + return $outputFile;
  76 + }
77 77 }
78 78  
79 79 class WebServer
80 80 {
81   - private $isSoap = false;
82   - private $userID, $userPWD, $sessionID;
83   - private $wsUserMgr;
84   - private $resultMgr, $myParamsInfoMgr;
85   - private $dataFileName;
86   -
87   - function __construct()
88   - {
89   - $this->userID = 'impex';
90   - $this->userPWD = 'impexfp7';
91   - $this->sessionID = $this->userID;
92   - $this->myParamsInfoMgr = new ParamsInfoMgr();
93   - $this->resultMgr = new WebResultMgr();
94   - }
95   -
96   - protected function init($data)
97   - {
98   - if (is_object($data)) {
99   - $vars = get_object_vars($data);
100   - $this->isSoap = true;
101   - } else
102   - $vars = $data;
103   -
104   - if (isset($vars['userID'])) {
105   - $this->userID = $vars['userID'];
106   - $this->sessionID = $this->userID;
107   - } else {
108   - $this->userID = 'impex';
109   - $this->sessionID = $this->userID;
110   - }
111   - if (isset($vars['password']))
112   - $this->userPWD = $vars['password'];
113   - else
114   - $this->userPWD = 'impexfp7';
115   -
116   - return array('success' => true, 'vars' => $vars);
117   - }
118   -
119   - private function setID()
120   - {
121   -
122   - $nb_min = 10000;
123   - $nb_max = 99999;
124   - $nombre = mt_rand($nb_min, $nb_max);
125   -
126   - $this->IP = $this->getIPclient();
127   -
128   - return "PP" . $nombre;
129   - }
130   -
131   - /**
132   - * Function getIPclient return the IP client sent a request for needs DD scripts (DDHtmlLogin, DDCheckUser, DD_Search)
133   - *
134   - * @param void
135   - * @return string
136   - */
137   - private function getIPclient()
138   - {
139   -
140   - if (getenv('REMOTE_ADDR')) {
141   - $realIP = getenv('REMOTE_ADDR');
142   - } else {
143   - //get local IP
144   - $command = "hostname -i";
145   - $realIP = exec($command);
146   - }
147   -
148   - return $realIP;
149   - }
150   -
151   - private function timeInterval2Days($TimeInterval)
152   - {
153   -
154   - $divDays = 60 * 60 * 24;
155   - $nbDays = floor($TimeInterval / $divDays);
156   - $divHours = 60 * 60;
157   - $nbHours = floor(($TimeInterval - $divDays * $nbDays) / $divHours);
158   - $nbMin = floor(($TimeInterval - $divDays * $nbDays - $divHours * $nbHours) / 60);
159   - $nbSec = $TimeInterval - $divDays * $nbDays - $divHours * $nbHours - $nbMin * 60;
160   -
161   - $DD = sprintf("%03d", $nbDays); // format ex. 005 not 5
162   - $HH = sprintf("%02d", $nbHours); // format ex. 25
163   - $MM = sprintf("%02d", $nbMin); // format ex. 03 not 3
164   - $SS = sprintf("%02d", $nbSec); // format ex. 02 not 2
165   -
166   - return $DD . ':' . $HH . ':' . $MM . ':' . $SS;
167   -
168   - }
169   -
170   - /* Start Time into AMDA format YYYY:DOY-1:HH:MM:SS */
171   - private function startTime2Days($startTime)
172   - {
173   -
174   - $ddStart = getdate($startTime);
175   - $date_start = sprintf("%04d", $ddStart["year"]) . ":" . sprintf("%03d", $ddStart["yday"]) . ":"
176   - . sprintf("%02d", $ddStart["hours"]) . ":" . sprintf("%02d", $ddStart["minutes"]) . ":"
177   - . sprintf("%02d", $ddStart["seconds"]);
178   - return $date_start;
179   - }
180   -
181   - private function rrmdir($dir)
182   - {
183   - if (is_dir($dir)) {
184   - $objects = scandir($dir);
185   -
186   - foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory
187   - if ($object != "." && $object != "..") { // If object isn't a directory recall recursively this function
188   - if (filetype($dir . "/" . $object) == "dir")
189   - $this->rrmdir($dir . "/" . $object);
190   - else
191   - unlink($dir . "/" . $object);
192   - }
193   - }
194   - reset($objects);
195   - rmdir($dir);
196   - }
197   - }
198   -
199   - protected function initUserMgr()
200   - {
201   - if (isset($this->wsUserMgr)) {
202   - return array('success' => true);
203   - }
204   - $this->wsUserMgr = new WSUserMgr($this->userID, $this->userPWD, $this->sessionID);
205   - $this->wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $this->isSoap);
206   -
207   - return array('success' => true);
208   - }
209   -
210   - public function getTimeTablesList($data)
211   - {
212   - if (is_object($data)) {
213   - $vars = get_object_vars($data);
214   - $this->isSoap = true;
215   - } else
216   - $vars = $data;
217   - if (isset($vars['userID']) && $vars['userID'] == 'impex') {
218   - if ($this->isSoap) throw new SoapFault("server00", "Server Error: AMDA Login procedure failed");
219   - else return array("error" => "Server Error: AMDA Login procedure failed");
220   - }
221   -
222   -
223   - $res = $this->init($data);
224   - $vars = $res['vars'];
225   -
226   - $ttListWSresult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID);
227   -
228   - $dom = new DOMDocument("1.0");
229   - if ($this->userID == 'impex') {
230   - $sharedObjMgr = new SharedObjectsMgr();
231   - $loadDom = $dom->load($sharedObjMgr->getTreeFilePath());
232   - } else
233   - $loadDom = $dom->load(USERPATH . $this->userID . '/WS/Tt.xml');
234   -
235   - if ($loadDom == FALSE) {
236   - if ($this->isSoap) throw new SoapFault("server00", "Server Error: AMDA Login procedure failed");
237   - else return array("error" => "Server Error: AMDA Login procedure failed");
238   - }
239   -
240   - $timetabNode = $dom->documentElement->getElementsByTagName('timetabList');
241   -
242   - if ($timetabNode->length < 1) {
243   - if ($this->isSoap) throw new SoapFault("server03", "Cannot reach TT list");
244   - else return array('success' => false, 'message' => "Server Error: Cannot reach TT list");
245   - }
246   - $outDOM = new DOMDocument("1.0");
247   - $outDOM->formatOutput = TRUE;
248   - $outDOM->preserveWhiteSpace = FALSE;
249   -
250   - $newNode = $outDOM->importNode($timetabNode->item(0), TRUE);
251   - $outDOM->appendChild($newNode);
252   -
253   -
254   - $outXP = new domxpath($outDOM);
255   - $ttNodes = $outXP->query('//timetab');
256   -
257   - $outDOM->save($ttListWSresult);
  81 + private $isSoap = false;
  82 + private $userID, $userPWD, $sessionID;
  83 + private $wsUserMgr;
  84 + private $resultMgr, $myParamsInfoMgr;
  85 + private $dataFileName;
258 86  
259   - $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $ttListWSresult);
260   -
261   - $ttListResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $ttListWSresult);
262   -
263   - $timeTablesList = array('success' => true, 'TimeTablesList' => $ttListResult);
264   -
265   - return $timeTablesList;
266   -
267   - }
268   -
269   - public function getTimeTable($data)
270   - {
271   - $res = $this->init($data);
272   -
273   - $vars = $res['vars'];
274   - $ttID = $vars['ttID'];
275   -
276   - if ($this->userID == 'impex') {
277   - $sharedObjMgr = new SharedObjectsMgr();
278   - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
279   - } else
280   - $ttSrc = USERPATH . $this->userID . '/TT/' . $ttID . '.xml';
281   -
282   - if (!file_exists($ttSrc)) {
283   - if ($this->isSoap) throw new SoapFault("server03", "Cannot reach time table");
284   - else return array('success' => false, 'message' => "Cannot reach time table");
285   - }
286   -
287   - $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID, $ttID);
288   -
289   - if (!copy($ttSrc, $ttWSresult)) {
290   - if ($this->isSoap) throw new SoapFault("server04", "Cannot copy time table");
291   - else return array('success' => false, 'message' => "Cannot copy time table");
292   - }
293   -
294   - $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $ttWSresult);
  87 + function __construct()
  88 + {
  89 + $this->userID = 'impex';
  90 + $this->userPWD = 'impexfp7';
  91 + $this->sessionID = $this->userID;
  92 +// $this->myParamsInfoMgr = new ParamsInfoMgr();
  93 + $this->resultMgr = new WebResultMgr();
  94 + }
  95 +
  96 +// [startTime] => 2016-01-14T00:00:00
  97 +// [stopTime] => 2017-02-15T00:00:00
  98 +// [parameterID] => imf
  99 +// [userID] => budnik
  100 +// [password] => Sacre-Cour
  101 +// [outputFormat] => ASCII
  102 +// [timeFormat] => ISO8601
  103 +// [gzip] => 0
  104 +
  105 + protected function init($data)
  106 + {
  107 + if(is_object($data)){
  108 + $vars = get_object_vars($data);
  109 + $this->isSoap = true;
  110 + }
  111 + else {
  112 + $vars = $data;
  113 + }
295 114  
296   - $myTimeTableMgr = new TimeTableMgr($this->userID);
297   - $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult);
298   - if (file_exists($ttWSresultVot)) {
299   - copy($ttWSresultVot, $ttWSresult);
300   - unlink($ttWSresultVot);
301   - }
302   - return array('success' => true, 'ttFileURL' => 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $ttWSresult));
  115 + if (isset($vars['userID'])){
  116 + $this->userID = $vars['userID'];
  117 + }
  118 + else {
  119 + $this->userID = 'impex';
  120 + }
  121 +
  122 + $this->sessionID = $this->userID;
  123 +
  124 + if (isset($vars['password']))
  125 + $this->userPWD = $vars['password'];
  126 + else
  127 + $this->userPWD = 'impexfp7';
  128 +
  129 + return array('success' => true, 'vars' => $vars);
  130 + }
  131 +
  132 + private function throwError($errorType, $msg)
  133 + {
  134 + if ($this->isSoap)
  135 + throw new SoapFault($errorType, $msg);
  136 + else
  137 + return array("error" => $msg);
  138 + }
  139 +
  140 + private function setID()
  141 + {
  142 + $nb_min = 10000;
  143 + $nb_max = 99999;
303 144  
304   - }
  145 + $this->IP = $this->getIPclient();
305 146  
  147 + return "PP".mt_rand($nb_min,$nb_max);
  148 + }
306 149  
307   - public function isAlive()
308   - {
309   - $res = $this->init($data);
310   - return true;
311   - }
  150 +/**
  151 + * Function getIPclient return the IP client sent a request for needs DD scripts (DDHtmlLogin, DDCheckUser, DD_Search)
  152 + *
  153 + * @param void
  154 + * @return string
  155 + */
  156 + private function getIPclient()
  157 + {
  158 + if (getenv('REMOTE_ADDR')) {
  159 + $realIP = getenv('REMOTE_ADDR');
  160 + }
  161 + else {
  162 + //get local IP
  163 + $command="hostname -i";
  164 + $realIP = exec($command);
  165 + }
312 166  
  167 + return $realIP;
  168 + }
313 169  
314   - public function getObsDataTree()
315   - {
  170 + private function timeInterval2Days($TimeInterval)
  171 + {
  172 + $divDays = 60*60*24;
  173 + $nbDays = floor($TimeInterval / $divDays);
  174 + $divHours = 60*60;
  175 + $nbHours = floor(($TimeInterval - $divDays*$nbDays)/$divHours);
  176 + $nbMin = floor(($TimeInterval - $divDays*$nbDays - $divHours*$nbHours)/60);
  177 + $nbSec = $TimeInterval - $divDays*$nbDays - $divHours*$nbHours - $nbMin*60;
  178 +
  179 + $DD = sprintf("%03d", $nbDays); // format ex. 005 not 5
  180 + $HH = sprintf("%02d", $nbHours); // format ex. 25
  181 + $MM = sprintf("%02d", $nbMin); // format ex. 03 not 3
  182 + $SS = sprintf("%02d", $nbSec); // format ex. 02 not 2
  183 +
  184 + return $DD.':'.$HH.':'.$MM.':'.$SS;
  185 + }
316 186  
317   - $res = $this->init();
  187 + /* Start Time into AMDA format YYYY:DOY-1:HH:MM:SS */
  188 + private function startTime2Days($startTime)
  189 + {
  190 + $ddStart = getdate($startTime);
  191 + $date_start = sprintf("%04d",$ddStart["year"]).":".sprintf("%03d", $ddStart["yday"]).":"
  192 + .sprintf("%02d",$ddStart["hours"]).":".sprintf("%02d",$ddStart["minutes"]).":"
  193 + .sprintf("%02d",$ddStart["seconds"]);
  194 + return $date_start;
  195 + }
318 196  
319   - $resMgr = $this->initUserMgr();
  197 + private function rrmdir($dir)
  198 + {
  199 + if (is_dir($dir)) {
  200 + $objects = scandir($dir);
  201 +
  202 + foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory
  203 + if ($object != "." && $object != "..") { // If object isn't a directory recall recursively this function
  204 + if (filetype($dir."/".$object) == "dir")
  205 + $this->rrmdir($dir."/".$object);
  206 + else
  207 + unlink($dir."/".$object);
  208 + }
  209 + }
  210 + reset($objects);
  211 + rmdir($dir);
  212 + }
  213 + }
320 214  
321   - $vars = $res['vars'];
  215 + protected function initUserMgr()
  216 + {
  217 + if (isset($this->wsUserMgr))
  218 + return array('success' => true);
  219 +
  220 + $this->wsUserMgr = new WSUserMgr();
  221 + $this->wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $this->isSoap);
  222 +
  223 + return array('success' => true);
  224 + }
322 225  
323   - $locParamSrc = USERPATH . $this->userID . '/WS/LocalParams.xml';
324   -// $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml';
325   - $wsParamSrc = USERPATH . $this->userID . '/WS/WsParams.xml';
326   - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'LocalParams');
327   -// $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams');
328   - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'WsParams');
  226 + public function getTimeTablesList($data)
  227 + {
  228 + if(is_object($data))
  229 + {
  230 + $vars = get_object_vars($data);
  231 + $this->isSoap = true;
  232 + }
  233 + else
  234 + $vars = $data;
  235 +
  236 + if (isset($vars['userID']) && $vars['userID'] == 'impex'){
  237 + $this->throwError('requestError', "Request Error: no time tables for anonymous");
  238 + }
  239 +
  240 + $res = $this->init($data);
  241 + $vars = $res['vars'];
  242 +
  243 + $ttListWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID);
  244 +
  245 + $dom = new DOMDocument("1.0");
  246 + if ($this->userID == 'impex') {
  247 + $sharedObjMgr = new SharedObjectsMgr();
  248 + if (!@$dom->load($sharedObjMgr->getTreeFilePath()))
  249 + $this->throwError("workspaceError", "Workspace Error : Cannot load Shared Time Table list");
  250 + }
  251 + else {
  252 + if (!@$dom->load(USERPATH.$this->userID.'/WS/Tt.xml'))
  253 + $this->throwError("workspaceError", "Workspace Error : Cannot load Shared Time Table list for ".$this->userID);
  254 + }
  255 +
  256 + $timetabNode = $dom->getElementsByTagName('timetabList');
329 257  
330   - if (!copy($locParamSrc, $locParamResult))
331   - $locParamResult = '';
332   - else {
333   - $piBase = new DomDocument("1.0");
334   - $piBase->formatOutput = true;
335   - $piBase->preserveWhiteSpace = false;
  258 + if ($timetabNode->length < 1){
  259 + $this->throwError("workspaceWarning", "Workspace Warning : No Time Tables");
  260 + }
  261 +
  262 + $outDOM = new DOMDocument("1.0");
  263 + $outDOM->formatOutput = TRUE;
  264 + $outDOM->preserveWhiteSpace = FALSE;
  265 +
  266 + $newNode = $outDOM->importNode($timetabNode->item(0),TRUE);
  267 + $outDOM->appendChild($newNode);
  268 +
  269 +// $outXP = new domxpath($outDOM);
  270 +// $ttNodes = $outXP->query('//timetab');
336 271  
337   - $dom = new DomDocument("1.0");
338   - $dom->load($locParamResult);
  272 + $outDOM->save($ttListWSresult);
339 273  
340   - $xsl = new DomDocument("1.0");
341   - $xsl->load(XMLPATH . 'dd2WStree.xsl');
  274 + $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$ttListWSresult);
342 275  
343   - $xslt = new XSLTProcessor();
344   - $xslt->importStylesheet($xsl);
  276 + $ttListResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttListWSresult);
345 277  
346   - $dom->loadXML($xslt->transformToXML($dom));
  278 + $timeTablesList = array('success' => true, 'TimeTablesList' => $ttListResult);
347 279  
348   - $dom->formatOutput = true;
349   - $dom->preserveWhiteSpace = false;
350   - $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");
351   - if ($chum_ger != NULL) $chum_ger->setAttribute("target", "Churyumov-Gerasimenko");
  280 + return $timeTablesList;
  281 + }
352 282  
353   - $dom->save($locParamResult);
354   - }
355   -// if (!copy($remoteParamSrc,$remoteParamResult))
356   -// $remoteParamResult = '';
357   - if (!copy($wsParamSrc, $wsParamResult))
358   - $wsParamResult = '';
  283 + public function getTimeTable($data)
  284 + {
  285 + $res = $this->init($data);
359 286  
360   - if ($locParamResult != '') $locParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $locParamResult);
361   -// if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult);
362   - if ($wsParamResult != '') $wsParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $wsParamResult);
  287 + $vars = $res['vars'];
  288 + $ttID = $vars['ttID'];
363 289  
364   - if (($locParamResult == '') && ($remoteParamResult == '') && ($wsParamResult == '')) {
365   - if ($this->isSoap) throw new SoapFault("server05", "No params descriptions .xml files for " . $this->userID . " user");
366   - else return array('success' => false, 'message' => "No params descriptions .xml files for " . $this->userID . " user");
367   - }
  290 + if ($this->userID == 'impex') {
  291 + $sharedObjMgr = new SharedObjectsMgr();
  292 + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
  293 + }
  294 + else
  295 + $ttSrc = USERPATH.$this->userID.'/TT/'.$ttID.'.xml';
368 296  
369   - $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $wsParamResult . ";" . $locParamResult . ";" . $remoteParamResult);
  297 + if (!file_exists($ttSrc)) {
  298 + $this->throwError("workspaceError", "No such table ".$ttID.".xml");
  299 + }
370 300  
371   - return array('success' => true, 'WorkSpace' => array("LocalDataBaseParameters" => $locParamResult, "RemoteDataBaseParameters" => $remoteParamResult));
372   - }
  301 + $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID,$ttID);
373 302  
374   - public function getPlot($data)
375   - {
  303 + if (!copy($ttSrc,$ttWSresult)){
  304 + $this->throwError("workspaceError", "Cannot copy ".$ttID.".xml");
  305 + }
  306 +
  307 + $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID, $ttWSresult);
  308 +
  309 + $myTimeTableMgr = new TimeTableMgr($this->userID);
  310 + $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult);
  311 +
  312 + if(file_exists($ttWSresultVot)){
  313 + copy($ttWSresultVot, $ttWSresult);
  314 + unlink( $ttWSresultVot ) ;
  315 + }
  316 +
  317 + return array('success' => true, 'ttFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttWSresult));
  318 + }
  319 +
  320 + public function isAlive()
  321 + {
  322 + $res = $this->init($data);
  323 + return true;
  324 + }
  325 +
  326 +
  327 + public function getObsDataTree()
  328 + {
  329 + $res = $this->init();
  330 +
  331 + $resMgr = $this->initUserMgr();
  332 +
  333 + $vars = $res['vars'];
  334 +
  335 + $locParamSrc = USERPATH.$this->userID.'/WS/LocalParams.xml';
  336 + $wsParamSrc = USERPATH.$this->userID.'/WS/WsParams.xml';
  337 + $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams');
  338 + $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams');
  339 +
  340 + if (!copy($locParamSrc,$locParamResult))
  341 + $locParamResult = '';
  342 +
  343 + if (!copy($wsParamSrc,$wsParamResult))
  344 + $wsParamResult = '';
  345 +
  346 + if ($locParamResult !='') $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult);
  347 + if ($wsParamResult !='') $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult);
  348 +
  349 + if (($locParamResult =='') && ($wsParamResult ==''))
  350 + {
  351 + $this->throwError("workspaceError", "No parameter description file");
  352 + }
  353 +
  354 + $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult);
  355 +
  356 + return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters"=>$locParamResult));
  357 + }
376 358  
377   - $res = $this->init($data);
378   - $resMgr = $this->initUserMgr();
  359 + public function getPlot($data)
  360 + {
  361 + $res = $this->init($data);
  362 + $resMgr = $this->initUserMgr();
  363 +
  364 + $vars = $res['vars'];
  365 + $mission = $vars["missionID"];
  366 +
  367 + $ID = $this->setID(); // unique JobID
  368 + $resDirName = WSRESULT.$ID; // Define a temporary directory for results
  369 +
  370 + if (is_dir($resDirName))
  371 + $this->rrmdir($resDirName);
  372 +
  373 + mkdir($resDirName);
  374 + chmod($resDirName,0775);
  375 +
  376 + $dom = new DomDocument("1.0");
  377 + $dom->load(plotsXml);
  378 +
  379 + $missionTag = $dom->getElementById($mission);
  380 + $params = $missionTag->getElementsByTagName('param');
  381 +
  382 + $paramsList = array();
  383 + foreach ($params as $param)
  384 + $paramsList[] = $param->getAttribute('name');
  385 +
  386 + $requestObject = (Object) array(
  387 + "nodeType" => "request",
  388 + "file-format" => "PNG",
  389 + "file-output" => "WS",
  390 + "ws-result-file" => $resDirName."/request.list.png",
  391 + "last-plotted-tab" => 1,
  392 + "timesrc" => "Interval",
  393 + "startDate" => $vars["startTime"],
  394 + "stopDate" => $vars["stopTime"],
  395 + "tabs" => array()
  396 + );
  397 +
  398 + $pageObject = (Object) array(
  399 + "id" => 1,
  400 + "multi-plot-linked" => true,
  401 + "page-margins-activated" => true,
  402 + "page-margin-x" => 5,
  403 + "page-margin-y" => 5,
  404 + "page-orientation" => "portrait",
  405 + "page-dimension" => "ISO A4",
  406 + "page-layout-type" => "vertical",
  407 + "page-layout-object" => (Object) array(
  408 + "layout-panel-height" => 0.25,
  409 + "layout-panel-spacing" => 0,
  410 + "layout-expand" => false
  411 + ),
  412 + "panels" => array()
  413 + );
  414 +
  415 + foreach ($paramsList as $paramToPlot)
  416 + {
  417 + $panelObject = (Object) array(
  418 + "panel-plot-type" => "timePlot",
  419 + "axes" => array(),
  420 + "params" => array()
  421 + );
  422 +
  423 + $timeAxisObject = (Object) array(
  424 + "id" => "time",
  425 + "axis-type" => "time",
  426 + "axis-range-extend" => true
  427 + );
  428 + $panelObject->{"axes"}[] = $timeAxisObject;
  429 +
  430 + $yAxisObject = (Object) array(
  431 + "id" => "y-left",
  432 + "axis-type" => "y-left",
  433 + "axis-range-extend" => true
  434 + );
  435 + $panelObject->{"axes"}[] = $yAxisObject;
  436 +
  437 + $paramObject = (Object) array(
  438 + "id" => 1,
  439 + "param-id" => $paramToPlot,
  440 + "param-drawing-type" => "serie",
  441 + "param-drawing-object" => (Object) array(
  442 + "serie-yaxis" => "y-left",
  443 + "serie-lines-activated" => true
  444 + )
  445 + );
  446 + $panelObject->{"params"}[] = $paramObject;
  447 +
  448 + $pageObject->{"panels"}[] = $panelObject;
  449 + }
  450 +
  451 + $requestObject->{"tabs"}[] = $pageObject;
  452 +
  453 + if (!isset($this->requestManager))
  454 + $this->requestManager = new RequestManagerClass();
  455 +
  456 + try {
  457 + $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $requestObject);
  458 + } catch (Exception $e) {
  459 + $this->throwError("plotError", "Exeption detected : ".$e->getMessage());
  460 + }
379 461  
380   - $vars = $res['vars'];
381   - $mission = $vars["missionID"];
  462 + return array('success' => true, 'plotDirectoryURL' => $ID);
  463 + }
382 464  
383   - $ID = $this->setID(); // unique JobID
384   - $resDirName = WSRESULT . $ID; // Define a temporary directory for results
  465 + public function getResultPlot($data)
  466 + {
  467 + $res = $this->init($data);
  468 + $vars = $res['vars'];
  469 + $ID = $vars["plotDirectoryURL"];
  470 + $filename = WSRESULT.$ID."/request.list.png";
  471 + if (file_exists($filename)) {
  472 + $plotWSresult=WSRESULT.$ID."/request.list.png";
  473 + return array('success' => true, 'plotFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$plotWSresult));
  474 + }
  475 + else
  476 + return array('success' => false);
  477 + }
385 478  
386   - if (is_dir($resDirName))
387   - $this->rrmdir($resDirName);
388   - mkdir($resDirName);
389   - chmod($resDirName, 0775);
  479 + public function getStatus($id)
  480 + {
  481 + $processManager = new ProcessManagerClass(IHMConfigClass::getProcessManagerFilePath());
  482 +
  483 + try {
  484 + $res = $processManager->getProcessInfo($id, true);
  485 + } catch (Exception $e) {
  486 + $this->throwError("serverError","Exception detected : ".$e->getMessage());
  487 + }
  488 +// [success] => 1
  489 +// [result] => Array
  490 +// (
  491 +// [id] => process_ADBCw1_1519836455_19505
  492 +// [cmd] => /home/budnik/AMDA/AMDA_Kernel/build/Debug/bin/amdaXMLRequestorTool /home/budnik/AMDA/AMDA_IHM/data/budnik/RES/DDnT8PLR_/request_0.xml
  493 +// [outputfile] => cmd_output
  494 +// [exitcodefile] => cmd_exitcode
  495 +// [processfile] => cmd_process
  496 +// [exitcode] => 0
  497 +// [PID] => 19505
  498 +// [runningpath] => /home/budnik/AMDA/AMDA_IHM/data/budnik/RES/DDnT8PLR_/
  499 +// [runningstart] => 1519836455
  500 +// [isrunning] =>
  501 +// [iskilled] =>
  502 +// [lastupdate] => 1519837450
  503 +// )
  504 +
  505 + if (!$res['success']) {
  506 + $this->throwError("processError","Cannot retrieve process $id info");
  507 + }
  508 +
  509 + $result = $res['result'];
  510 +
  511 + if ($result['isrunning']) {
  512 + return array('success' => true, 'status' => 'in_progress');
  513 + }
  514 +
  515 + if ($result['iskilled']) {
  516 + $this->throwError("processError","Process $id was killed");
  517 + }
  518 +
  519 + if ($result['exitcode'] !== 0) {
  520 + $this->throwError("processError","Process $id error code: ".$result['exitcode']);
  521 + }
  522 +
  523 + $vars = $this->getVarsFromRunningPath($result['runningpath']);
  524 +
  525 + if (!$vars['success']) {
  526 + $this->throwError("processError","Process $id : cannot generate file name for result : ".$vars['message']);
  527 + }
  528 +
  529 + $resultFile = glob($result['runningpath']."result_*");
  530 +
  531 + $tempFilePath = $result['runningpath'].$resultFile.$vars['kernelExtension'];
  532 +
  533 + $outputFilePath = WSRESULT.$vars['dataFileName'].$vars['wsExtension'];
  534 +
  535 + return $this->finishDownloadRequest($id, $tempFilePath, $outputFilePath);
  536 + }
  537 +
  538 +
  539 + public function getParameterList($data)
  540 + {
  541 + $res = $this->init($data);
  542 +
  543 + $resMgr = $this->initUserMgr();
  544 +
  545 + $vars = $res['vars'];
  546 +
  547 + $locParamSrc = USERWSDIR.'/LocalParams.xml';
  548 + $wsParamSrc = USERWSDIR.'/WsParams.xml';
  549 + $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams');
  550 + $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams');
  551 +
  552 + if (!copy($locParamSrc,$locParamResult))
  553 + $locParamResult = '';
  554 +
  555 + if (!copy($wsParamSrc,$wsParamResult))
  556 + $wsParamResult = '';
  557 +
  558 + if ($locParamResult !='')
  559 + $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult);
  560 + if ($wsParamResult !='')
  561 + $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult);
  562 +
  563 + if (($locParamResult =='') && ($wsParamResult =='')){
  564 + $this->throwError("workspaceError", "No params descriptions for ".$this->userID);
  565 + }
  566 +
  567 + $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult.";".$remoteParamResult);
  568 +
  569 + return array('success' => true,'ParameterList' => array("UserDefinedParameters"=>$wsParamResult, "LocalDataBaseParameters"=>$locParamResult, "RemoteDataBaseParameters"=>$remoteParamResult));
  570 + }
  571 +
  572 + public function getNewToken()
  573 + {
  574 + $timeStamp = (new DateTime())->getTimestamp();
  575 + // generate token from timeStamp and some salt
  576 + $newToken = md5(1321 * (int)($timeStamp / timeLimitQuery));
  577 + return array('success' => true, 'token' => $newToken);
  578 + }
390 579  
391   - $dom = new DomDocument("1.0");
392   - $dom->load(plotsXml);
  580 +/*
  581 +* getParameter
  582 +*/
  583 + public function getParameter($data)
  584 + {
  585 + $multiParam = false;
393 586  
394   - $missionTag = $dom->getElementById($mission);
395   - $params = $missionTag->getElementsByTagName('param');
  587 + $res = $this->init($data);
  588 +
  589 + $resMgr = $this->initUserMgr();
396 590  
397   - $paramsList = array();
398   - foreach ($params as $param)
399   - $paramsList[] = $param->getAttribute('name');
  591 + if (!$res['success']){
  592 + $this->throwError("requestError", "Cannot parse request");
  593 + }
400 594  
401   - $requestObject = (Object)array(
402   - "nodeType" => "request",
403   - "file-format" => "PNG",
404   - "file-output" => "WS",
405   - "ws-result-file" => $resDirName . "/request.list.png",
406   - "last-plotted-tab" => 1,
407   - "timesrc" => "Interval",
408   - "startDate" => $vars["startTime"],
409   - "stopDate" => $vars["stopTime"],
410   - "tabs" => array()
411   - );
  595 + $vars = $res['vars'];
  596 +
  597 + $startTime = strtotime($vars["startTime"]);
  598 + $stopTime = strtotime($vars["stopTime"]);
412 599  
413   - $pageObject = (Object)array(
414   - "id" => 1,
415   - "multi-plot-linked" => true,
416   - "page-margins-activated" => true,
417   - "page-margin-x" => 5,
418   - "page-margin-y" => 5,
419   - "page-orientation" => "portrait",
420   - "page-dimension" => "ISO A4",
421   - "page-layout-type" => "vertical",
422   - "page-layout-object" => (Object)array(
423   - "layout-panel-height" => 0.25,
424   - "layout-panel-spacing" => 0,
425   - "layout-expand" => false
426   - ),
427   - "panels" => array()
428   - );
  600 + if ($stopTime <= $startTime){
  601 + $this->throwError("requestError", "Requested time interval should be greater than 0");
  602 + }
  603 +
  604 + $dataFileName = $this->getDataFileName($vars, $multiParam);
429 605  
430   - foreach ($paramsList as $paramToPlot) {
431   - $panelObject = (Object)array(
432   - "panel-plot-type" => "timePlot",
433   - "axes" => array(),
434   - "params" => array()
435   - );
436   -
437   - $timeAxisObject = (Object)array(
438   - "id" => "time",
439   - "axis-type" => "time",
440   - "axis-range-extend" => true
441   - );
442   - $panelObject->{"axes"}[] = $timeAxisObject;
443   -
444   - $yAxisObject = (Object)array(
445   - "id" => "y-left",
446   - "axis-type" => "y-left",
447   - "axis-range-extend" => true
448   - );
449   - $panelObject->{"axes"}[] = $yAxisObject;
450   -
451   - $paramObject = (Object)array(
452   - "id" => 1,
453   - "param-id" => $paramToPlot,
454   - "param-drawing-type" => "serie",
455   - "param-drawing-object" => (Object)array(
456   - "serie-yaxis" => "y-left",
457   - "serie-lines-activated" => true
458   - )
459   - );
460   - $panelObject->{"params"}[] = $paramObject;
461   -
462   - $pageObject->{"panels"}[] = $panelObject;
463   - }
464   -
465   - $requestObject->{"tabs"}[] = $pageObject;
466   -
467   - require_once(INTEGRATION_SRC_DIR . "RequestManager.php");
468   - if (!isset($this->requestManager))
469   - $this->requestManager = new RequestManagerClass();
470   -
471   - try {
472   - $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $requestObject);
473   - } catch (Exception $e) {
474   - if ($this->isSoap) throw new SoapFault("plot01", 'Exception detected : ' . $e->getMessage());
475   - else return array('success' => false, 'message' => 'Exception detected : ' . $e->getMessage());
476   - }
477   -
478   - return array('success' => true, 'plotDirectoryURL' => $ID);
479   - }
480   -
481   - public function getResultPlot($data)
482   - {
483   -
484   - $res = $this->init($data);
485   - $vars = $res['vars'];
486   - $ID = $vars["plotDirectoryURL"];
487   - $filename = WSRESULT . $ID . "/request.list.png";
488   - if (file_exists($filename)) {
489   - $plotWSresult = WSRESULT . $ID . "/request.list.png";
490   - return array('success' => true, 'plotFileURL' => 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $plotWSresult));
491   - } else
492   - return array('success' => false);
493   -
494   - }
495   -
496   - public function getStatus($id) {
497   - $obj = (object)array(
498   - "username" => $this->userID,
499   - "password" => $this->userPWD,
500   - "sessionID" => $this->sessionID
501   - );
  606 + if ($dataFileName['success']) {
  607 + $this->dataFileName = $dataFileName['fileName'];
  608 + }
  609 + else {
  610 + $this->throwError("requestError", $dataFileName['message']);
  611 + }
502 612  
503   - $aa = new AmdaAction();
504   - $jobs = $aa->getJobs($obj);
505   -
506   -// job =
507   -// {
508   -// "success":true,
509   -// "id":"process_aiaoh7_1517403874_1372",
510   -// "name":"download_data_1517403886",
511   -// "status":"in_progress",
512   -// "jobType":"download",
513   -// "info":" ",
514   -// "start":"31-01-2018 13:04:34",
515   -// "stop":"unknown",
516   -// "folder":"DDpTDRrk_",
517   -// "result":"result_pTDRrk",
518   -// "format":"unknown",
519   -// "compression":"",
520   -// "sendToSamp":false
521   -// }
522   -
523   - if (intval($jobs['nInProgress']) > 0) {
524   - foreach ($jobs['jobsInProgress'] as $job) {
525   - if ($job['id'] == $id) {
526   - return ['success' => true, 'status' => 'in_progress'];
527   - }
528   - }
529   - }
530   - if (intval($jobs['nFinished']) > 0) {
531   - foreach ($jobs['jobsFinished'] as $job) {
532   - if ($job['id'] == $id) {
533   - $vars = $this->getVarsFromRunningPath($job['runningPath']);
534   - $resTempFilePath = USERPATH . $this->userID . '/RES/' . $job['folder'] . '/' . $job['result'] . $vars['kernelExtension'];
535   - $resOutputFilePath = WSRESULT.$vars['dataFileName'].$vars['wsExtension'];
536   - return $this->finishDownloadRequest($job['id'], $resTempFilePath, $resOutputFilePath);
537   - }
538   - }
539   - }
540   - return ['success' => false, 'message' => 'No job found for this id.'];
541   - }
  613 + $paramId = array();
  614 + array_push($paramId, $vars["parameterID"]);
  615 +
  616 + if (!$vars["timeFormat"])
  617 + $timeFormat = "ISO8601";
  618 + else
  619 + $timeFormat = $vars["timeFormat"];
  620 +
  621 + if (!$vars["gzip"])
  622 + $gzip = 0;
  623 + else
  624 + $gzip = $vars["gzip"];
  625 +/*
  626 + if (!$vars["stream"])
  627 + $stream = 0;
  628 + else
  629 + $stream = $vars["stream"];*/
  630 +
  631 + $res = $this->doDownloadRequest(
  632 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
  633 + array("params" => $paramId),
  634 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  635 + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),
  636 + $dataFileName);
  637 +
  638 +
  639 + if ($res['success'])
  640 + return $res;
  641 +
  642 + $this->throwError("serverError", $res['message']);
  643 +
  644 + }
  645 +
  646 +/*
  647 +* get Orbites
  648 +*/
  649 + public function getOrbites($data)
  650 + {
  651 + $multiParam = false;
542 652  
543   - public function getParameterList($data)
544   - {
  653 + $res = $this->init($data);
545 654  
546   - $res = $this->init($data);
  655 + $resMgr = $this->initUserMgr();
547 656  
548   - $resMgr = $this->initUserMgr();
  657 + if (!$resMgr['success']){
  658 + $this->throwError("serverError", "Cannot init user manager");
  659 + }
549 660  
550   - $vars = $res['vars'];
551   -
552   - $locParamSrc = USERPATH . $this->userID . '/WS/LocalParams.xml';
553   -// $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml';
554   - $wsParamSrc = USERPATH . $this->userID . '/WS/WsParams.xml';
555   - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'LocalParams');
556   -// $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams');
557   - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'WsParams');
558   -
559   - if (!copy($locParamSrc, $locParamResult))
560   - $locParamResult = '';
561   - else {
562   - $piBase = new DomDocument("1.0");
563   - $piBase->formatOutput = true;
564   - $piBase->preserveWhiteSpace = false;
565   -
566   - $dom = new DomDocument("1.0");
567   - $dom->load($locParamResult);
568   -
569   - $xsl = new DomDocument("1.0");
570   - $xsl->load(XMLPATH . 'dd2WStree.xsl');
571   -
572   - $xslt = new XSLTProcessor();
573   - $xslt->importStylesheet($xsl);
574   -
575   - $dom->loadXML($xslt->transformToXML($dom));
576   -
577   - $dom->formatOutput = true;
578   - $dom->preserveWhiteSpace = false;
579   - $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");
580   - if ($chum_ger != NULL) $chum_ger->setAttribute("target", "Churyumov-Gerasimenko");
581   - $dom->save($locParamResult);
582   - }
583   -// if (!copy($remoteParamSrc,$remoteParamResult))
584   -// $remoteParamResult = '';
585   - if (!copy($wsParamSrc, $wsParamResult))
586   - $wsParamResult = '';
587   -
588   - if ($locParamResult != '') $locParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $locParamResult);
589   -// if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult);
590   - if ($wsParamResult != '') $wsParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $wsParamResult);
591   -
592   - if (($locParamResult == '') && ($remoteParamResult == '') && ($wsParamResult == '')) {
593   - if ($this->isSoap) throw new SoapFault("server05", "No params descriptions .xml files for " . $this->userID . " user");
594   - else return array('success' => false, 'message' => "No params descriptions .xml files for " . $this->userID . " user");
595   - }
596   -
597   - $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $wsParamResult . ";" . $locParamResult . ";" . $remoteParamResult);
598   -
599   - return array('success' => true, 'ParameterList' => array("UserDefinedParameters" => $wsParamResult, "LocalDataBaseParameters" => $locParamResult, "RemoteDataBaseParameters" => $remoteParamResult));
600   - }
601   -
602   - public function getNewToken()
603   - {
604   - require_once(INTEGRATION_SRC_DIR."RequestManager.php");
605   -
606   - $timeStamp = (new DateTime())->getTimestamp();
607   - // generate token from timeStamp and some salt
608   - $newToken = md5(1321 * (int)($timeStamp / timeLimitQuery));
609   - return array('success' => true, 'token' => $newToken);
610   - }
611   -
612   -///////////////////////////////////////START GET DATASET ///////////////////////////////
613   - public function getParameter($data)
614   - {
615   - $multiParam = false;
616   -
617   - $res = $this->init($data);
618   - $resMgr = $this->initUserMgr();
619   -
620   - if (!$res['success']) {
621   - if ($this->isSoap) throw new SoapFault("server01", "Cannot init user manager");
622   - else return array('success' => false, 'message' => "Cannot init user manager");
623   - }
624   -
625   - $vars = $res['vars'];
626   -
627   - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
628   - if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
629   - else return array('success' => false, 'message' => "Start time must be higher than stop time");
630   - } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
631   - if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0 start is " . $vars["stopTime"] . " stop is " . $vars["startTime"]);
632   - else return array('success' => false, 'message' => "You time interval equal 0");
633   - }
634   -
635   - $dataFileName = $this->getDataFileName($vars, $multiParam);
636   -
637   - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
638   - else {
639   - if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
640   - else return array('success' => false, 'message' => $dataFileName['message']);
641   - }
642   -
643   -
644   - $paramId = array();
645   - array_push($paramId, $vars["parameterID"]);
646   -// $paramId[] = $vars["parameterID"];
647   -
648   - $sampling = key_exists("sampling", $vars) ? $vars["sampling"] : false;
649   - $gzip = key_exists("gzip", $vars) ? $vars["gzip"] : 0;
650   - $outputFormat = key_exists("outputFormat", $vars) ? $vars["outputFormat"] : false;
651   - $timeFormat = key_exists("timeFormat", $vars) ? $vars["timeFormat"] : "ISO8601";
652   - $stream = key_exists("stream", $vars) ? $vars["stream"] : 0;
653   -
654   - $res = $this->doDownloadRequest(
655   - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling),
656   - array("params" => $paramId),
657   - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
658   - array("format" => $outputFormat, "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
659   - $dataFileName);
660   -
661   - if ($res['success']) {
662   - return $res;
663   - } else {
664   - if ($this->isSoap) {
665   - throw new SoapFault("request03", $res['message']);
666   - } else {
667   - return array('success' => false, 'message' => $res['message']);
668   - }
669   - }
670   - }
671   -
672   -///////////////////////////////////////START GET ORBITES ///////////////////////////////
673   - public function getOrbites($data)
674   - {
675   -
676   - $multiParam = false;
677   -
678   - $res = $this->init($data);
679   -
680   - $resMgr = $this->initUserMgr();
681   -
682   - if (!$resMgr['success']) {
683   - if ($this->isSoap) throw new SoapFault("server01", "Cannot init user manager");
684   - else return array('success' => false, 'message' => "Cannot init user manager");
685   - }
686   -
687   - $vars = $res['vars'];
688   -
689   - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
690   - if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
691   - else return array('success' => false, 'message' => "Start time must be higher than stop time");
692   - } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
693   - if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0 start is " . $vars["stopTime"] . " stop is " . $vars["startTime"]);
694   - else return array('success' => false, 'message' => "You time interval equal 0");
695   - }
696   -
697   -
698   - $spacecraft = $vars["spacecraft"];
699   - $coordinateSystem = $vars["coordinateSystem"];
700   - if ($spacecraft == "GALILEO") $spacecraft = ucfirst(strtolower($spacecraft));
701   - if (!$vars["units"])
702   - $units = "km";
703   - else
704   - $units = $vars["units"];
705   -
706   - $paramId = array();
707   -
708   - $orbitRequest = array("startTime" => $vars["startTime"],
709   - "stopTime" => $vars["stopTime"],
710   - "spacecraft" => $spacecraft,
711   - "coordinateSystem" => $coordinateSystem,
712   - "units" => $units
713   - );
  661 + $vars = $res['vars'];
  662 +
  663 + $startTime = strtotime($vars["startTime"]);
  664 + $stopTime = strtotime($vars["stopTime"]);
714 665  
  666 + if ($stopTime <= $startTime){
  667 + $this->throwError("requestError", "Requested time interval should be greater than 0");
  668 + }
  669 +
  670 + $spacecraft = $vars["spacecraft"];
  671 + $coordinateSystem = $vars["coordinateSystem"];
  672 +
  673 + if ($spacecraft == "GALILEO") $spacecraft = ucfirst(strtolower($spacecraft));
  674 + if (!$vars["units"])
  675 + $units = "km";
  676 + else
  677 + $units = $vars["units"];
  678 +
  679 + $orbitRequest = array("startTime" => $vars["startTime"],
  680 + "stopTime" => $vars["stopTime"],
  681 + "spacecraft" => $spacecraft,
  682 + "coordinateSystem" => $coordinateSystem,
  683 + "units" => $units
  684 + );
  685 +
  686 + $orbitesParam = $this->getOrbitesParameter($orbitRequest);
  687 +
  688 + if ($orbitesParam['success']) {
  689 + $orbParam = $orbitesParam['parameterID'];
  690 + }
  691 + else {
  692 + //$orbParam = 'successEstfalse';
  693 + $this->throwError("requestError", $orbitesParam['message']);
  694 + }
  695 +
  696 + $dataFileName = $this->getDataFileName($orbitesParam, $multiParam);
715 697  
716   - $orbitesParam = $this->getOrbitesParameter($orbitRequest);
717   - if ($orbitesParam['success']) $orbParam = $orbitesParam['parameterID'];
718   - else {
719   - $orbParam = 'successEstfalse';
720   - if ($this->isSoap) throw new SoapFault("request03", $orbitesParam['message']);
721   - else return array('success' => false, 'message' => $orbitesParam['message']);
722   - }
  698 + if ($dataFileName['success']) {
  699 + $this->dataFileName = $dataFileName['fileName'];
  700 + }
  701 + else {
  702 + $this->throwError("requestError", $dataFileName['message']);
  703 + }
  704 +
  705 + $paramId = array();
  706 + array_push($paramId, $orbParam);
  707 +
  708 + if (!$vars["timeFormat"])
  709 + $timeFormat = "ISO8601";
  710 + else
  711 + $timeFormat = $vars["timeFormat"];
  712 +
  713 + if (!$vars["gzip"])
  714 + $gzip = 0;
  715 + else
  716 + $gzip = $vars["gzip"];
  717 +
  718 + $res = $this->doDownloadRequest(
  719 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
  720 + array("params" => $paramId),
  721 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  722 + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),
  723 + $dataFileName);
  724 +
  725 + if ($res['success']) return $res;
  726 +
  727 + $this->throwError("serverError",$res['message']);
  728 + }
  729 +
  730 +/*
  731 +* get Dataset
  732 +*/
  733 + public function getDataset($data)
  734 + {
  735 + $multiParam = true;
723 736  
  737 + $res = $this->init($data);
  738 +
  739 + $resMgr = $this->initUserMgr();
724 740  
725   - $dataFileName = $this->getDataFileName($orbitesParam, $multiParam);
  741 + $vars = $res['vars'];
  742 +
  743 + $startTime = strtotime($vars["startTime"]);
  744 + $stopTime = strtotime($vars["stopTime"]);
726 745  
727   - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
728   - else {
729   - if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
730   - else return array('success' => false, 'message' => $dataFileName['message']);
731   - }
  746 + if ($stopTime <= $startTime){
  747 + $this->throwError("requestError", "Requested time interval should be greater than 0");
  748 + }
  749 +
  750 + $dataFileName = $this->getDataFileName($vars, $multiParam);
732 751  
733   - array_push($paramId, $orbParam);
734   -// $paramId[] = $vars["parameterID"];
  752 + if ($dataFileName['success']) {
  753 + $this->dataFileName = $dataFileName['fileName'];
  754 + }
  755 + else {
  756 + $this->throeError("requestError",$dataFileName['message']);
  757 + }
  758 +
  759 + $paramId = array();
  760 + $localData = simplexml_load_file(USERPATH.$this->userID.'/WS/LocalParams.xml');
  761 +
  762 + if (!$vars["sampling"])
  763 + {
  764 + $xpath = "//dataset[@xml:id='".$vars['datasetID']."']/@sampling";
  765 + $tmp = $localData->xpath($xpath);
  766 + $vars["sampling"] = (string)$tmp[0];
  767 +
  768 + $matches=array();
  769 + preg_match("/([a-z])$/", $vars["sampling"], $matches);
  770 +
  771 + $dataFileName = $this->getDataFileName($vars, $multiParam);
  772 +
  773 + if ($dataFileName['success']) {
  774 + $this->dataFileName = $dataFileName['fileName'];
  775 + }
  776 + else {
  777 + $this->throwError("requestError",$dataFileName['message']);
  778 + }
  779 +
  780 + $vars["sampling"] = strtr($vars["sampling"], array($matches[1] => ""));
  781 + switch ($matches[1]) {
  782 + case 's':
  783 + $sampling = floatval($vars["sampling"]);
  784 + break;
  785 + case 'm':
  786 + $sampling = floatval($vars["sampling"])*60;
  787 + break;
  788 + case 'h':
  789 + $sampling = floatval($vars["sampling"])*60*60;
  790 + break;
  791 + default:
  792 + }
  793 + }
735 794  
736   - if (!$vars["timeFormat"])
737   - $timeFormat = "ISO8601";
738   - else
739   - $timeFormat = $vars["timeFormat"];
  795 + $xpath = "//dataset[@xml:id='".$vars['datasetID']."']/parameter/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']";
  796 + $pars = $localData->xpath($xpath);
  797 +
  798 + foreach ($pars as $p)
  799 + $paramId[] = (string)$p[0];
  800 +
  801 + if (!$vars["timeFormat"])
  802 + $timeFormat = "ISO8601";
  803 + else
  804 + $timeFormat = $vars["timeFormat"];
  805 +
  806 + if (!$vars["gzip"])
  807 + $gzip = 0;
  808 + else
  809 + $gzip = $vars["gzip"];
  810 +
  811 + $res = $this->doDownloadRequest(
  812 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling),
  813 + array("params" => $paramId),
  814 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  815 + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),
  816 + $dataFileName);
  817 +
  818 + if ($res['success']) return $res;
  819 +
  820 + $this->throwError("serverError", $res['message']);
  821 + }
740 822  
741   - if (!$vars["gzip"])
742   - $gzip = 0;
743   - else
744   - $gzip = $vars["gzip"];
745   -
746   - $res = $this->doDownloadRequest(
747   - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
748   - array("params" => $paramId),
749   - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
750   - array("format" => $vars["outputFormat"], "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
751   - $dataFileName);
752   -
753   -
754   - if ($res['success']) return $res;
755   - else {
756   - if ($this->isSoap) throw new SoapFault("request03", $res['message']);
757   - else return array('success' => false, 'message' => $res['message']);
758   - }
759   - }
760   -
761   -///////////////////////////////////////START GET DATASET ///////////////////////////////
762   -
763   -
764   - public function getDataset($data)
765   - {
766   - $multiParam = true;
767   -
768   - $res = $this->init($data);
769   -
770   - $resMgr = $this->initUserMgr();
771   -
772   - $vars = $res['vars'];
773   -
774   - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
775   - if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
776   - else return array('success' => false, 'message' => "Start time must be higher than stop time");
777   - } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
778   - if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0");
779   - else return array('success' => false, 'message' => "You time interval equal 0");
780   - }
781   -
782   - $dataFileName = $this->getDataFileName($vars, $multiParam);
783   -
784   - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
785   - else {
786   - if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
787   - else return array('success' => false, 'message' => $dataFileName['message']);
788   - }
789   - $paramId = array();
790   - $localData = simplexml_load_file(USERPATH . $this->userID . '/WS/LocalParams.xml');
791   -
792   - if (!$vars["sampling"]) {
793   - $xpath = "//dataset[@xml:id='" . $vars['datasetID'] . "']/@sampling";
794   - $tmp = $localData->xpath($xpath);
795   - $vars["sampling"] = (string)$tmp[0];
796   -
797   - $matches = array();
798   - preg_match("/([a-z])$/", $vars["sampling"], $matches);
799   -
800   -
801   - $dataFileName = $this->getDataFileName($vars, $multiParam);
802   -
803   - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
804   - else {
805   - if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
806   - else return array('success' => false, 'message' => $dataFileName['message']);
807   - }
808   -
809   - $vars["sampling"] = strtr($vars["sampling"], array($matches[1] => ""));
810   - switch ($matches[1]) {
811   - case 's':
812   - $sampling = floatval($vars["sampling"]);
813   - break;
814   - case 'm':
815   - $sampling = floatval($vars["sampling"]) * 60;
816   - break;
817   - case 'h':
818   - $sampling = floatval($vars["sampling"]) * 60 * 60;
819   - break;
820   - default:
821   - }
822   - }
823   -
824   - $xpath = "//dataset[@xml:id='" . $vars['datasetID'] . "']/parameter/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']";
825   - $pars = $localData->xpath($xpath);
826   -
827   - foreach ($pars as $p)
828   - $paramId[] = (string)$p[0];
829   -
830   - if (!$vars["timeFormat"])
831   - $timeFormat = "ISO8601";
832   - else
833   - $timeFormat = $vars["timeFormat"];
834   -
835   - if (!$vars["gzip"])
836   - $gzip = 0;
837   - else
838   - $gzip = $vars["gzip"];
839   -
840   - $res = $this->doDownloadRequest(
841   - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling),
842   - array("params" => $paramId),
843   - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
844   - array("format" => $vars["outputFormat"], "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
845   - $dataFileName);
846   -
847   - if ($res['success']) return $res;
848   - else {
849   - if ($this->isSoap) throw new SoapFault("request03", $res['message']);
850   - else return array('success' => false, 'message' => $res['message']);
851   - }
852   - }
853   -
854   -////////////////////////////////////////END GET PARAMETERS /////////////////////////////////
855   - protected function getOrbitesParameter($orbitRequest)
856   - {
857   -
858   - $orbitesXml = new DomDocument();
859   -
860   - if (file_exists(orbitesXml)) {
861   - $orbitesXml->load(orbitesXml);
862   - $xpath = new DOMXpath($orbitesXml);
863   - $path = '//orbites[@mission="' . $orbitRequest['spacecraft'] . '" and @coordinate_system="' . $orbitRequest['coordinateSystem'] . '" and @units="' . $orbitRequest['units'] . '" ] ';
864   -
865   - $orbites = $xpath->query($path);
866   - foreach ($orbites as $orbite) {
867   - $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($orbite->getAttribute('xml:id'));
868   - $paramStart = $paramInfo['dataset']['starttime'];
869   - $paramStop = $paramInfo['dataset']['stoptime'];
870   -
871   - if ((strtotime($paramStart) <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= strtotime($paramStop))) {
872   -
873   - return array('success' => true,
874   - 'parameterID' => $orbite->getAttribute('xml:id'),
875   - 'startTime' => $orbitRequest['startTime'],
876   - 'stopTime' => $orbitRequest['stopTime']
877   - );
878   - }
879   - }
880   - return array('success' => false,
881   - 'message' =>
882   - "Cannot find orbites for " . $orbitRequest['spacecraft'] . " between " . $orbitRequest['startTime'] . " in " . $orbitRequest['units'] . " " . $orbitRequest['coordinateSystem'] . " and " . $orbitRequest['stopTime'] . " ($paramStart - $paramStop) ");
883   - } else {
884   - return array('success' => false, 'message' => "Orbits file doesn't exist");
885   - }
886   - }
887   -
888   - private function getFormatInfo($fileFormat, $timeFormat, $gzip) {
  823 + protected function getOrbitesParameter($orbitRequest)
  824 + {
  825 + $orbitesXml = new DomDocument();
  826 +
  827 + if (file_exists(orbitesXml))
  828 + {
  829 + $orbitesXml->load(orbitesXml);
  830 + $xpath = new DOMXpath($orbitesXml);
  831 + $path = '//orbites[@mission="'.$orbitRequest['spacecraft'].'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] ';
  832 +
  833 + $orbites = $xpath->query($path);
  834 + foreach ($orbites as $orbite){
  835 + $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($orbite->getAttribute('xml:id'));
  836 + $paramStart = $paramInfo['dataset']['starttime'];
  837 + $paramStop = $paramInfo['dataset']['stoptime'];
  838 +
  839 + if((strtotime($paramStart) <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= strtotime($paramStop))) {
  840 +
  841 + return array('success' => true,
  842 + 'parameterID' => $orbite->getAttribute('xml:id'),
  843 + 'startTime' => $orbitRequest['startTime'],
  844 + 'stopTime' => $orbitRequest['stopTime']
  845 + );
  846 + }
  847 + }
  848 + return array('success' => false,
  849 + 'message' =>
  850 + "Cannot find orbites for ".$orbitRequest['spacecraft']." between ".$orbitRequest['startTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']." and ".$orbitRequest['stopTime']." ($paramStart - $paramStop) ");
  851 + }
  852 + else {
  853 + return array('success' => false, 'message' => "Orbits file doesn't exist");
  854 + }
  855 + }
  856 +
  857 + private function getFormatInfo($fileFormat, $timeFormat, $gzip)
  858 + {
889 859 switch ($fileFormat) {
890 860 case 'netCDF' :
891   - if ($this->isSoap) {
892   - throw new SoapFault("server01", "netCDF format not implemented");
893   - } else {
894   - return array('success' => false, 'message' => "netCDF format not implemented");
895   - }
  861 + $this->throwError("serverError", "netCDF format not implemented");
896 862 break;
897 863 case 'VOTable' :
898 864 $fileFormat = "vot";
... ... @@ -929,49 +895,54 @@ class WebServer
929 895 'compression' => $compression];
930 896 }
931 897  
932   - protected function doDownloadRequest($interval, $paramList, $user, $formatInfo, $dataFileName)
933   - {
934   - if ($interval['sampling'])
935   - $structure = 0;// sampling
936   - else
937   - $structure = 2; // not sampling
938   -
939   - $fileInfo = $this->getFormatInfo($formatInfo['format'], $formatInfo['timeFormat'], $formatInfo['gzip']);
940   -
941   - require_once(INTEGRATION_SRC_DIR . "RequestManager.php");
942   - IHMConfigClass::setUserName($this->userID);
943   - if (!isset($this->paramLoader))
944   - $this->paramLoader = new IHMUserParamLoaderClass();
945   -
946   - //Build parameter list
947   - $params = array();
948   -
949   - //TODO template arguments to implementer ?
950   - foreach ($paramList['params'] as $paramId) {
951   - $param = new stdClass;
952   -
953   - if (preg_match("#^ws_#", $paramId)) {
954   - $res = $this->paramLoader->getDerivedParameterNameFromId($paramId);
955   - if (!$res["success"]) {
956   - if ($this->isSoap) throw new SoapFault("server02", 'Not available derived parameter ' . $paramId);
957   - else return array('success' => false, 'message' => 'Not available derived parameter ' . $paramId);
958   - }
959   - $param->paramid = "ws_" . $res['name'];
960   - } else if (preg_match("#^wsd_#", $paramId)) {
961   - $res = $this->paramLoader->getUploadedParameterNameFromId($paramId);
962   - if (!$res["success"]) {
963   - if ($this->isSoap) throw new SoapFault("server02", 'Not available user parameter ' . $paramId);
964   - else return array('success' => false, 'message' => 'Not available user parameter ' . $paramId);
965   - }
966   - $param->paramid = "wsd_" . $res['name'];
967   - } else {
968   - $param->paramid = $paramId;
969   - }
970   -
971   - $params[] = $param;
972   - }
973   -
974   - $obj = (object)array(
  898 + protected function doDownloadRequest($interval,$paramList,$user,$formatInfo,$dataFileName)
  899 + {
  900 + if ($interval['sampling'])
  901 + $structure = 0;// sampling
  902 + else
  903 + $structure = 2; // not sampling
  904 +
  905 + $fileInfo = $this->getFormatInfo($formatInfo['format'], $formatInfo['timeFormat'], $formatInfo['gzip']);
  906 +
  907 + IHMConfigClass::setUserName($this->userID);
  908 +
  909 + if (!isset($this->paramLoader))
  910 + $this->paramLoader = new IHMUserParamLoaderClass();
  911 +
  912 + //Build parameter list
  913 + $params = array();
  914 +
  915 + //TODO template arguments to implement ?
  916 + foreach ($paramList['params'] as $paramId)
  917 + {
  918 + $param = new stdClass;
  919 +
  920 + if (preg_match("#^ws_#",$paramId))
  921 + {
  922 + $res = $this->paramLoader->getDerivedParameterNameFromId($paramId);
  923 +
  924 + if (!$res["success"]) {
  925 + $this->throwError("serverError", "Not available derived parameter $paramId");
  926 + }
  927 + $param->paramid = "ws_".$res['name'];
  928 + }
  929 + else if (preg_match("#^wsd_#",$paramId))
  930 + {
  931 + $res = $this->paramLoader->getUploadedParameterNameFromId($paramId);
  932 +
  933 + if (!$res["success"]){
  934 + $this->throwError("serverError", "Not available parameter $paramId");
  935 + }
  936 + $param->paramid = "wsd_".$res['name'];
  937 + }
  938 + else{
  939 + $param->paramid = $paramId;
  940 + }
  941 +
  942 + $params[] = $param;
  943 + }
  944 +
  945 + $obj = (object)array(
975 946 "nodeType" => "download",
976 947 "downloadSrc" => "0",
977 948 "structure" => $structure,
... ... @@ -984,118 +955,118 @@ class WebServer
984 955 "fileformat" => $fileInfo['fileFormat'],
985 956 "timeformat" => $fileInfo['timeFormat'],
986 957 "compression" => $fileInfo['compression'],
987   - "extension" => $fileInfo['wsExtension'],
  958 + "extension" => $fileInfo['wsExtension'],
988 959 "disablebatch" => false,
989   - "dataFileName" => $this->dataFileName
  960 + "dataFileName" => $this->dataFileName
990 961 );
991   -
992   - if (!isset($this->requestManager))
993   - $this->requestManager = new RequestManagerClass();
994   -
995   - try {
996   - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $obj);
997   - } catch (Exception $e) {
998   - if ($this->isSoap) throw new SoapFault("server02", 'Exception detected : ' . $e->getMessage());
999   - else return array('success' => false, 'message' => 'Exception detected : ' . $e->getMessage());
1000   - }
1001   -
1002   - if (!$downloadResult['success']) {
1003   - if ($this->isSoap) throw new SoapFault("server03", $downloadResult['message']);
1004   - else return array('success' => false, 'message' => $downloadResult['message']);
1005   - }
1006   -
1007   - if($downloadResult['status'] == 'in_progress') {
1008   - return ['success' => true, 'status' => 'in_progress', 'id' => $downloadResult['id']];
1009   - } elseif ($downloadResult['status'] == 'done') {
1010   - $resTempFilePath = USERPATH . $this->userID . '/RES/' . $downloadResult['folder'] . '/' . $downloadResult['result'] . $fileInfo['kernelExtension'];
1011   - $resOutputFilePath = WSRESULT.$this->dataFileName.$fileInfo['wsExtension'];
1012   - return $this->finishDownloadRequest($downloadResult['id'], $resTempFilePath, $resOutputFilePath);
1013   - } else {
1014   - return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status'] . '.'];
1015   - }
1016   - }
1017   -
  962 +
  963 + if (!isset($this->requestManager))
  964 + $this->requestManager = new RequestManagerClass();
  965 +
  966 + try {
  967 + $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $obj);
  968 + } catch (Exception $e) {
  969 + $this->throwError("serverError", "Exception detected : ".$e->getMessage());
  970 + }
  971 +
  972 + if (!$downloadResult['success']) {
  973 + $this->throwError("serverError", $downloadResult['message']);
  974 + }
  975 +
  976 + if($downloadResult['status'] == 'in_progress') {
  977 + return ['success' => true, 'status' => 'in_progress', 'id' => $downloadResult['id']];
  978 + } elseif ($downloadResult['status'] == 'done') {
  979 + $resTempFilePath = USERWORKINGDIR.'/'.$downloadResult['folder'].'/'.$downloadResult['result'].$fileInfo['kernelExtension'];
  980 + $resOutputFilePath = WSRESULT.$this->dataFileName.$fileInfo['wsExtension'];
  981 + return $this->finishDownloadRequest($downloadResult['id'], $resTempFilePath, $resOutputFilePath);
  982 + } else {
  983 + return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status']];
  984 + }
  985 + }
  986 +
1018 987 private function finishDownloadRequest($id, $resTempFilePath, $resOutputFilePath)
1019   - {
  988 + {
1020 989 if (!file_exists($resTempFilePath)) {
1021   - if ($this->isSoap) throw new SoapFault("server04", 'Cannot retrieve result file ' . $resTempFilePath);
1022   - else return ['success' => false, 'message' => 'Cannot retrieve result file'];
  990 + $this->throwError("serverError", "Cannot retrieve result file $resTempFilePath");
1023 991 }
1024 992  
1025   - rename($resTempFilePath, $resOutputFilePath);
1026   - chmod($resOutputFilePath, 0664);
1027   - $outputURL = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $resOutputFilePath);
  993 + rename($resTempFilePath, $resOutputFilePath);
  994 + chmod($resOutputFilePath, 0664);
  995 +
  996 + $outputURL = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $resOutputFilePath);
1028 997  
1029 998 $obj = (object)array(
1030   - 'id' => $id
1031   - );
1032   -
1033   - require_once(INTEGRATION_SRC_DIR . "RequestManager.php");
1034   - if (!isset($this->requestManager))
1035   - $this->requestManager = new RequestManagerClass();
1036   -
1037   - try {
1038   - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj);
1039   - } catch (Exception $e) {
1040   - error_log("Can not delete file $resOutputFilePath: $e");
1041   - }
  999 + 'id' => $id
  1000 + );
  1001 +
  1002 + if (!isset($this->requestManager))
  1003 + $this->requestManager = new RequestManagerClass();
  1004 +
  1005 + try {
  1006 + $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj);
  1007 + } catch (Exception $e) {
  1008 + error_log("Can not delete file $resOutputFilePath: $e");
  1009 + }
1042 1010  
1043   - return array('success' => true, 'status' => 'done', 'dataFileURLs' => $outputURL);
1044   - }
1045   -
1046   - protected function timeIntervalToDuration($startTime, $stopTime)
1047   - {
1048   - $duration = strtotime($stopTime) - strtotime($startTime);
1049   - $durationDay = intval($duration / (86400));
1050   - $duration = $duration - $durationDay * 86400;
1051   - $durationHour = intval($duration / (3600));
1052   - $duration = $duration - $durationHour * 3600;
1053   - $durationMin = intval($duration / (60));
1054   - $durationSec = $duration - $durationMin * 60;
1055   -
1056   - return array("success" => true, "days" => sprintf("%04s", strval($durationDay)),
1057   - "hours" => sprintf("%02s", strval($durationHour)),
1058   - "mins" => sprintf("%02s", strval($durationMin)),
1059   - "secs" => sprintf("%02s", strval($durationSec))
1060   - );
1061   - }
1062   -
1063   - protected function getDataFileName($vars, $multiParam)
1064   - {
1065   - if ($vars['startTime'] && $vars['stopTime'] && $vars['parameterID'] && !$multiParam) {
1066   - $fileName = $vars['parameterID'] . "-" . strtotime($vars['startTime']) . "-" . strtotime($vars['stopTime']);
1067   - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
1068   - $fileName .= "-" . $vars['sampling'];
1069   - return array('success' => true, 'fileName' => $fileName);
1070   - } else if ($vars['startTime'] && $vars['stopTime'] && $vars['datasetID'] && $multiParam) {
1071   - $datasetName = strtr($vars["datasetID"], array(":" => "_"));
1072   - $fileName = $datasetName . "-" . strtotime($vars['startTime']) . "-" . strtotime($vars['stopTime']);
1073   - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
1074   - $fileName .= "-" . $vars['sampling'];
1075   - return array('success' => true, 'fileName' => $fileName);
1076   - } else {
1077   - if (!$vars['startTime'])
1078   - $message = "Start time not specified";
1079   - if (!$vars['stopTime'])
1080   - $message = "Stop time not specified";
1081   - if (!$vars['parameterID'] && !$multiParam)
1082   - $message = "Parameter not specified";
1083   - if (!$vars['datasetID'] && $multiParam)
1084   - $message = "DataSet not specified";
1085   - return array('success' => false, 'message' => $message);
1086   - }
1087   - }
  1011 + return array('success' => true, 'status' => 'done', 'dataFileURLs' => $outputURL);
  1012 + }
  1013 +
  1014 +
  1015 + protected function timeIntervalToDuration($startTime,$stopTime)
  1016 + {
  1017 + $duration = strtotime($stopTime) - strtotime($startTime);
  1018 + $durationDay = intval($duration/(86400));
  1019 + $duration = $duration - $durationDay*86400;
  1020 + $durationHour = intval($duration/(3600));
  1021 + $duration = $duration - $durationHour*3600;
  1022 + $durationMin = intval($duration/(60));
  1023 + $durationSec = $duration - $durationMin*60;
  1024 +
  1025 + return array("success" => true, "days" => sprintf("%04s", strval($durationDay)),
  1026 + "hours" => sprintf("%02s", strval($durationHour)),
  1027 + "mins" => sprintf("%02s", strval($durationMin)),
  1028 + "secs" => sprintf("%02s", strval($durationSec))
  1029 + );
  1030 + }
1088 1031  
  1032 + protected function getDataFileName($vars, $multiParam)
  1033 + {
  1034 + if ($vars['startTime'] && $vars['stopTime'] && $vars['parameterID'] && !$multiParam){
  1035 + $fileName = $vars['parameterID']."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);
  1036 + if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
  1037 + $fileName .= "-".$vars['sampling'];
  1038 + return array('success' => true, 'fileName' => $fileName);
  1039 + }
  1040 + else if ($vars['startTime'] && $vars['stopTime'] && $vars['datasetID'] && $multiParam){
  1041 + $datasetName = strtr($vars["datasetID"], array(":" => "_"));
  1042 + $fileName = $datasetName."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);
  1043 + if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
  1044 + $fileName .= "-".$vars['sampling'];
  1045 + return array('success' => true, 'fileName' => $fileName);
  1046 + }
  1047 + else {
  1048 + if (!$vars['startTime'])
  1049 + $message="Start time not specified";
  1050 + if (!$vars['stopTime'])
  1051 + $message="Stop time not specified";
  1052 + if (!$vars['parameterID'] && !$multiParam)
  1053 + $message="Parameter not specified";
  1054 + if (!$vars['datasetID'] && $multiParam)
  1055 + $message="DataSet not specified";
  1056 + return array('success' => false, 'message' => $message);
  1057 + }
  1058 + }
  1059 +
1089 1060 private function getVarsFromRunningPath($runningPath)
1090 1061 {
1091 1062 $filePath = $runningPath . "request_0.xml";
1092   - if (file_exists($filePath)) {
1093   - $requestXml = new DOMDocument();
1094   - $requestXml->load($filePath);
1095   - } else {
1096   - return ['success' => false, 'message' => 'Failed to open request file.'];
  1063 +
  1064 + if (!file_exists($filePath)) {
  1065 + return ['success' => false, 'message' => 'Failed to open request file'];
1097 1066 }
1098   -
  1067 +
  1068 + $requestXml = new DOMDocument();
  1069 + $requestXml->load($filePath);
1099 1070 $fileFormat = $requestXml->getElementsByTagName('fileFormat')->item(0)->nodeValue;
1100 1071 $timeFormat = $requestXml->getElementsByTagName('timeFormat')->item(0)->nodeValue;
1101 1072 $gzip = 0; // todo $requestXml->getElementsByTagName('gzip')->item(0)->nodeValue;
... ... @@ -1103,7 +1074,6 @@ class WebServer
1103 1074 // get kernelExtension, wsExtension, fileFormat, timeFormat, compression:
1104 1075 $vars = $this->getFormatInfo($fileFormat, $timeFormat, $gzip);
1105 1076  
1106   - require_once(INTEGRATION_SRC_DIR . "InputOutput/IHMImpl/Tools/CommonClass.php");
1107 1077 $cc = new CommonClass();
1108 1078  
1109 1079 $vars['parameterID'] = $requestXml->getElementsByTagName('param')->item(0)->getAttribute('id');
... ... @@ -1119,30 +1089,28 @@ class WebServer
1119 1089  
1120 1090 if (in_array(null, $vars, true)) {
1121 1091 return ['success' => false,
1122   - 'message' => 'Can not create data file name because a value is missing in the request file.'];
  1092 + 'message' => 'Can not create data file name - a value is missing in the request file'];
1123 1093 }
1124 1094  
1125   - $getDataFileName = $this->getDataFileName($vars, false);
1126   - if (!$getDataFileName['success']) {
1127   - return $getDataFileName;
  1095 + $dataFileName = $this->getDataFileName($vars, false);
  1096 + if (!$dataFileName['success']) {
  1097 + return $dataFileName;
1128 1098 }
1129   - $vars['dataFileName'] = $getDataFileName['fileName'];
1130   -
  1099 + $vars['dataFileName'] = $dataFileName['fileName'];
  1100 + $vars['success'] = true;
  1101 +
1131 1102 return $vars;
1132 1103 }
  1104 +
  1105 + private function compress($srcName, $dstName)
  1106 + {
  1107 + $fp = fopen($srcName, "r");
  1108 + $data = fread($fp, filesize($srcName));
  1109 + fclose($fp);
1133 1110  
1134   - private function compress($srcName, $dstName)
1135   - {
1136   -
1137   - $fp = fopen($srcName, "r");
1138   - $data = fread($fp, filesize($srcName));
1139   - fclose($fp);
1140   -
1141   - $zp = gzopen($dstName, "w9");
1142   - gzwrite($zp, $data);
1143   - gzclose($zp);
1144   - }
1145   -
  1111 + $zp = gzopen($dstName, "w9");
  1112 + gzwrite($zp, $data);
  1113 + gzclose($zp);
  1114 + }
1146 1115 }
1147   -
1148 1116 ?>
1149 1117 \ No newline at end of file
... ...