Commit 5cf993962614282e8389f05c6137a8193c8bf3ff

Authored by Benjamin Renard
1 parent a2a949d6

Add SAMP export in Download view

src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php
1 1 <?php
2 2  
3 3 define ("DOWNLOAD_RESULT_FILE_KEY","download");
  4 +define ("DOWNLOAD_SAMP_RESULT_FILE_KEY","download-samp");
4 5  
5 6 /**
6 7 * @class IHMInputOutputParamsDownloadClass
... ... @@ -22,6 +23,16 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas
22 23  
23 24 $paramsNode = $requestNode->getParamsNode();
24 25  
  26 + //Send to SAMP
  27 + $this->sendToSamp = isset($input->sendToSamp) ? $input->sendToSamp : FALSE;
  28 + if ($this->sendToSamp) {
  29 + $input->disablebatch = FALSE;
  30 + $input->timeformat = 'YYYY-MM-DDThh:mm:ss';
  31 + $input->fileformat = 'vot';
  32 + $input->compression = '';
  33 + $input->fileprefix = 'amda-samp';
  34 + }
  35 +
25 36 //unmarshall time definition
26 37 $this->unmarshallTimeDefinition($input, 0);
27 38  
... ... @@ -188,13 +199,21 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas
188 199 throw new Exception('Compression type not implemented.');
189 200 }
190 201  
191   - $resultFile = "result_".$this->requestID;
192   - $this->paramsData->addWaitingResult(DOWNLOAD_RESULT_FILE_KEY, $resultFile);
  202 + if (!$this->sendToSamp) {
  203 + $resultFile = "result_".$this->requestID;
  204 + $this->paramsData->addWaitingResult(DOWNLOAD_RESULT_FILE_KEY, $resultFile);
193 205  
194   - $postProcessCmd = "mv ".$resultFilePrefix."*";
  206 + $postProcessCmd = "mv ".$resultFilePrefix."*";
195 207  
196   - $postProcessCmd .= $extension;
197   - $postProcessCmd .= " ".$resultFile.$extension;
  208 + $postProcessCmd .= $extension;
  209 + $postProcessCmd .= " ".$resultFile.$extension;
  210 + }
  211 + else {
  212 + $resultFile = $input->fileprefix.".list";
  213 + $this->paramsData->addWaitingResult(DOWNLOAD_SAMP_RESULT_FILE_KEY, $resultFile);
  214 +
  215 + $postProcessCmd = "ls ".$input->fileprefix."* > ".$resultFile;
  216 + }
198 217  
199 218 $this->paramsData->setPostCmd($postProcessCmd);
200 219  
... ... @@ -209,7 +228,10 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas
209 228 */
210 229 protected function marshallResult($data)
211 230 {
212   - return $this->commonMarshallResult($data,DOWNLOAD_RESULT_FILE_KEY);
  231 + if ($this->sendToSamp)
  232 + return $this->commonMarshallResult($data,DOWNLOAD_SAMP_RESULT_FILE_KEY);
  233 + else
  234 + return $this->commonMarshallResult($data,DOWNLOAD_RESULT_FILE_KEY);
213 235 }
214 236 }
215 237 ?>
... ...
src/InputOutput/IHMImpl/Params/IHMInputOutputParamsAbstractClass.php
... ... @@ -15,6 +15,7 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
15 15 protected $requestID = "";
16 16 protected $requestDirPrefix = "";
17 17 private $input = null;
  18 + protected $sendToSamp = FALSE;
18 19  
19 20 /*
20 21 * @brief Constructor
... ... @@ -116,13 +117,20 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
116 117 */
117 118 protected function addToJobsFile($data,$resultKey)
118 119 {
  120 + $waitingResult = $data->getWaitingResult($resultKey);
  121 + if ($this->sendToSamp && ($data->getStatus() == ProcessStatusEnumClass::DONE)) {
  122 + $waitingResult = explode("\n", file_get_contents(IHMConfigClass::getRequestPath()."/".$this->getWorkingDirName()."/".$waitingResult));
  123 + $waitingResult = implode(',', $waitingResult);
  124 + $waitingResult = rtrim($waitingResult, ',');
  125 + }
  126 +
119 127 return $this->jobsManager->addJob(
120 128 $this->input,
121 129 $data->getId(),
122 130 $this->getWorkingDirName(),
123 131 $data->getStatus() == ProcessStatusEnumClass::RUNNING,
124 132 $data->getStart(),
125   - $data->getWaitingResult($resultKey),
  133 + $waitingResult,
126 134 $data->getErrorCode());
127 135 }
128 136  
... ...
src/InputOutput/IHMImpl/Tools/IHMJobsManagerClass.php
... ... @@ -224,6 +224,13 @@ class IHMJobsManagerClass {
224 224 if (isset($request_obj->compression))
225 225 $compression = strtolower($request_obj->compression);
226 226 }
  227 + $sendToSamp = $job->getAttribute('sendToSamp');
  228 + if (empty($sendToSamp)) {
  229 + $sendToSamp = false;
  230 + }
  231 + else {
  232 + $sendToSamp = ($sendToSamp == "true");
  233 + }
227 234 }
228 235 return array(
229 236 'success' => true,
... ... @@ -237,7 +244,9 @@ class IHMJobsManagerClass {
237 244 'folder' => $folder,
238 245 'result' => $result,
239 246 'format' => $format,
240   - 'compression' => $compression);
  247 + 'compression' => $compression,
  248 + 'sendToSamp' => $sendToSamp,
  249 + );
241 250 }
242 251  
243 252 /*
... ... @@ -307,6 +316,11 @@ class IHMJobsManagerClass {
307 316 //to know if know if it's an immediate job or not
308 317 $newJob->setAttribute('immediate', !$running);
309 318  
  319 + $sendToSamp = isset($obj->sendToSamp) ? $obj->sendToSamp : FALSE;
  320 + if ($sendToSamp) {
  321 + $newJob->setAttribute('sendToSamp', "true");
  322 + }
  323 +
310 324 if ($running)
311 325 {
312 326 $rootJobNode = $this->jobXml->getElementById($this->bkgRootNode[$obj->nodeType]);
... ...