Commit a0d6e95386478a5fe4f7124b54b94903c84b9e84
1 parent
e4eba677
Exists in
master
and in
56 other branches
Update TT/Catalog conversion
Showing
4 changed files
with
82 additions
and
57 deletions
Show diff stats
src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | /** | 3 | /** |
4 | - * @class IHMInputOutputTTClass | 4 | + * @class IHMInputOutputConvertTTClass |
5 | * @brief | 5 | * @brief |
6 | * @details | 6 | * @details |
7 | */ | 7 | */ |
8 | -class IHMInputOutputTTClass implements InputOutputInterface | 8 | +class IHMInputOutputConvertTTClass implements InputOutputInterface |
9 | { | 9 | { |
10 | + private $processData = NULL; | ||
11 | + | ||
12 | + | ||
10 | /* | 13 | /* |
11 | * @brief Constructor | 14 | * @brief Constructor |
12 | - */ | 15 | + */ |
13 | function __construct() | 16 | function __construct() |
14 | { | 17 | { |
15 | - //$this->jobsManager = new IHMJobsManagerClass(); | 18 | + |
16 | } | 19 | } |
17 | 20 | ||
18 | /* | 21 | /* |
19 | - * @brief translate input data from IHM client to AMDA_Integration module for a tt process request | ||
20 | - */ | 22 | + * @brief translate input data from AMDA IHM to AMDA_Integration module for a tt process request |
23 | + */ | ||
21 | public function getInputData($input, $function, $requestId="") | 24 | public function getInputData($input, $function, $requestId="") |
22 | { | 25 | { |
23 | - if (isset($this->processDatas)) | ||
24 | - unset($this->processDatas); | 26 | + if (isset($this->processData)) |
27 | + unset($this->processData); | ||
25 | 28 | ||
26 | - if (!$res['success']) | ||
27 | - throw new Exception($res['message']); | ||
28 | - | ||
29 | - | ||
30 | - foreach($input->list as $tt) | ||
31 | - { | ||
32 | - //create a list of data to treat | ||
33 | - $processData = new TTRequestDataClass(); | ||
34 | - | ||
35 | - $processData->setInputTimeTable($tt); | ||
36 | - $processData->setInputFormat($input); | ||
37 | - $processData->setOutputDir(); | ||
38 | - $processData->setOutputTimeTable($tt); | ||
39 | - $processData->setOutputFormat(); | ||
40 | - | ||
41 | - $processData->setCompression(); | ||
42 | - | ||
43 | - $this->processDatas[] = $processData; | 29 | + $processData = new TTRequestDataClass(); |
30 | + $processData->setInputFileName($input['inputFile']); | ||
31 | + switch ($input['inputFormat']) { | ||
32 | + case 'ASCII': | ||
33 | + $processData->setInputFileFormat(TTRequestFileFormatEnum::ASCII); | ||
34 | + break; | ||
35 | + case 'VOTABLE': | ||
36 | + $processData->setInputFileFormat(TTRequestFileFormatEnum::VOTABLE); | ||
37 | + break; | ||
38 | + case 'INTERNAL': | ||
39 | + $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL); | ||
40 | + break; | ||
41 | + default: | ||
42 | + throw new Exception('Unknown input format'); | ||
44 | } | 43 | } |
44 | + $processData->setOutputDir($input['outputDir']); | ||
45 | + $processData->setOutputFileFormat(TTRequestFileFormatEnum::INTERNAL); | ||
46 | + $processData->setOutputFileName($input['outputFileName']); | ||
47 | + $processData->setType($function); | ||
48 | + $processData->setCmd("ttConversion"); | ||
45 | 49 | ||
46 | - return $this->processDatas; | 50 | + $this->processData = $processData; |
51 | + | ||
52 | + return $this->processData; | ||
47 | } | 53 | } |
48 | 54 | ||
49 | /* | 55 | /* |
50 | - * @brief translate output data from AMDA_Integration module to IHM client request | ||
51 | - */ | 56 | + * @brief translate output data from AMDA_Integration module to AMDA IHM request |
57 | + */ | ||
52 | public function getOutput($data) | 58 | public function getOutput($data) |
53 | { | 59 | { |
54 | - $result = array(); | ||
55 | - | ||
56 | - foreach ($data as $d) | ||
57 | - { | ||
58 | - | ||
59 | - | ||
60 | - if (!$d->getSuccess()) | ||
61 | - continue; | ||
62 | - | 60 | + $result = array('success' => $data->getSuccess()); |
61 | + if ($result['success']) { | ||
62 | + $result['file'] = $data->getOutputDir()."/".$data->getOutputFileName(); | ||
63 | } | 63 | } |
64 | - | ||
65 | return $result; | 64 | return $result; |
66 | } | 65 | } |
67 | } | 66 | } |
68 | - | ||
69 | -} | 67 | + |
70 | ?> | 68 | ?> |
src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php
@@ -26,7 +26,9 @@ class IHMInputOutputTTClass implements InputOutputInterface | @@ -26,7 +26,9 @@ class IHMInputOutputTTClass implements InputOutputInterface | ||
26 | 26 | ||
27 | $sendToSamp = isset($input->sendToSamp) && $input->sendToSamp; | 27 | $sendToSamp = isset($input->sendToSamp) && $input->sendToSamp; |
28 | $compression = !$sendToSamp && ($input->compression !== 'none'); | 28 | $compression = !$sendToSamp && ($input->compression !== 'none'); |
29 | - $format = $sendToSamp ? 'vot' : $input->fileformat; | 29 | + $formatstr = $sendToSamp ? 'vot' : $input->fileformat; |
30 | + $tmp = new TTRequestDataClass(); // just to be sure that TTRequestDataClass is loaded with the 'autoload' => TTRequestDataClass is defined | ||
31 | + $outputformat = $this->getFormatFromString(!empty($formatstr) ? $formatstr : 'vot'); | ||
30 | 32 | ||
31 | $final = ""; | 33 | $final = ""; |
32 | 34 | ||
@@ -34,38 +36,46 @@ class IHMInputOutputTTClass implements InputOutputInterface | @@ -34,38 +36,46 @@ class IHMInputOutputTTClass implements InputOutputInterface | ||
34 | foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename); | 36 | foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename); |
35 | foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename); | 37 | foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename); |
36 | } | 38 | } |
37 | - | 39 | + |
38 | foreach($input->list as $tt) | 40 | foreach($input->list as $tt) |
39 | { | 41 | { |
40 | //create a list of data to treat | 42 | //create a list of data to treat |
41 | $processData = new TTRequestDataClass(); | 43 | $processData = new TTRequestDataClass(); |
42 | - | ||
43 | - if (strpos($tt->id,"sharedtimeTable_") === 0 || strpos($tt->id,"sharedcatalog_") === 0) { | 44 | + |
45 | + if (!isset($tt->id) && !empty($tt->path)) { | ||
46 | + $ttName = $tt->path; | ||
47 | + $inputformat = $this->getFormatFromString(!empty($tt->format) ? $tt->format : 'internal'); | ||
48 | + } | ||
49 | + else if (strpos($tt->id,"sharedtimeTable_") === 0 || strpos($tt->id,"sharedcatalog_") === 0) { | ||
44 | //Shared TimeTable /Catalog | 50 | //Shared TimeTable /Catalog |
45 | $objectType = strpos($tt->id,"timeTable") != 0 ? "timeTable" : "catalog"; | 51 | $objectType = strpos($tt->id,"timeTable") != 0 ? "timeTable" : "catalog"; |
46 | $result = IHMSharedObjectsClass::getPath($objectType, $tt->id); | 52 | $result = IHMSharedObjectsClass::getPath($objectType, $tt->id); |
47 | if (!$result['success']) | 53 | if (!$result['success']) |
48 | throw new Exception('Shared '.$objectType.' '.$tt->name.' not found'); | 54 | throw new Exception('Shared '.$objectType.' '.$tt->name.' not found'); |
49 | $ttName = $result['path']; | 55 | $ttName = $result['path']; |
56 | + $inputformat = TTRequestFileFormatEnum::INTERNAL; | ||
50 | } | 57 | } |
51 | else { | 58 | else { |
52 | //User TimeTable / Catalog | 59 | //User TimeTable / Catalog |
53 | $ttName = IHMConfigClass::getUserTTPath().$tt->id.'.xml'; | 60 | $ttName = IHMConfigClass::getUserTTPath().$tt->id.'.xml'; |
61 | + $inputformat = TTRequestFileFormatEnum::INTERNAL; | ||
54 | } | 62 | } |
55 | if (!file_exists($ttName)) | 63 | if (!file_exists($ttName)) |
56 | - throw new Exception('TimeTable '.$tt->name.' not found'); | 64 | + throw new Exception('TimeTable or Catalog '.$tt->name.' not found'); |
57 | $processData->setInputFileName($ttName); | 65 | $processData->setInputFileName($ttName); |
58 | - $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL); | 66 | + $processData->setInputFileFormat($inputformat); |
59 | $processData->setOutputDir(IHMConfigClass::getDownloadTmpPath()); | 67 | $processData->setOutputDir(IHMConfigClass::getDownloadTmpPath()); |
68 | + $processData->setOutputFileFormat($outputformat); | ||
60 | 69 | ||
61 | - switch ($format) { | ||
62 | - case 'vot' : | ||
63 | - $processData->setOutputFileFormat(TTRequestFileFormatEnum::VOTABLE); | 70 | + switch ($outputformat) { |
71 | + case TTRequestFileFormatEnum::VOTABLE : | ||
64 | $outputName = $tt->name.'.xml'; | 72 | $outputName = $tt->name.'.xml'; |
65 | break; | 73 | break; |
74 | + case TTRequestFileFormatEnum::ASCII : | ||
75 | + $outputName = $tt->name.'.txt'; | ||
76 | + break; | ||
66 | default : | 77 | default : |
67 | - $processData->setOutputFileFormat(TTRequestFileFormatEnum::ASCII); | ||
68 | - $outputName = $tt->name; | 78 | + $outputName = $tt->name.'.xml'; |
69 | } | 79 | } |
70 | 80 | ||
71 | // $processData->setOutputTimeFormat($input->timeformat); | 81 | // $processData->setOutputTimeFormat($input->timeformat); |
@@ -103,6 +113,23 @@ class IHMInputOutputTTClass implements InputOutputInterface | @@ -103,6 +113,23 @@ class IHMInputOutputTTClass implements InputOutputInterface | ||
103 | return $this->processDatas; | 113 | return $this->processDatas; |
104 | } | 114 | } |
105 | 115 | ||
116 | + /* | ||
117 | + * @brief Get format from input string | ||
118 | + */ | ||
119 | + private function getFormatFromString($str) { | ||
120 | + switch (strtolower($str)) { | ||
121 | + case 'vot': | ||
122 | + case 'votable': | ||
123 | + return TTRequestFileFormatEnum::VOTABLE; | ||
124 | + case 'ascii': | ||
125 | + case 'text': | ||
126 | + case 'txt': | ||
127 | + case 'asc': | ||
128 | + return TTRequestFileFormatEnum::ASCII; | ||
129 | + } | ||
130 | + return TTRequestFileFormatEnum::INTERNAL; | ||
131 | + } | ||
132 | + | ||
106 | /* | 133 | /* |
107 | * @brief translate output data from AMDA_Integration module to IHM client request | 134 | * @brief translate output data from AMDA_Integration module to IHM client request |
108 | */ | 135 | */ |
src/Request/TTRequestImpl/TTRequestClass.php
@@ -60,9 +60,9 @@ class TTRequestClass extends RequestAbstractClass | @@ -60,9 +60,9 @@ class TTRequestClass extends RequestAbstractClass | ||
60 | case FunctionTypeEnumClass::TTCONVERT : | 60 | case FunctionTypeEnumClass::TTCONVERT : |
61 | //run process | 61 | //run process |
62 | 62 | ||
63 | - $args = $this->requestData->getInputFileName()." ".$this->requestData->getInputFileFormat() | ||
64 | - ." ".$this->requestData->getOutputDir()." ".$this->requestData->getOutputFileName() | ||
65 | - ." ".$this->requestData->getOutputFileFormat(); | 63 | + $args = "\"".$this->requestData->getInputFileName()."\" ".$this->requestData->getInputFileFormat() |
64 | + ." \"".$this->requestData->getOutputDir()."\" \"".$this->requestData->getOutputFileName() | ||
65 | + ."\" ".$this->requestData->getOutputFileFormat(); | ||
66 | 66 | ||
67 | $cmd = $this->requestData->getCmd()." ".$args; | 67 | $cmd = $this->requestData->getCmd()." ".$args; |
68 | 68 | ||
@@ -93,4 +93,4 @@ class TTRequestClass extends RequestAbstractClass | @@ -93,4 +93,4 @@ class TTRequestClass extends RequestAbstractClass | ||
93 | } | 93 | } |
94 | 94 | ||
95 | } | 95 | } |
96 | -?> | ||
97 | \ No newline at end of file | 96 | \ No newline at end of file |
97 | +?> |
src/Request/TTRequestImpl/TTRequestDataClass.php
@@ -90,7 +90,7 @@ class TTRequestDataClass extends RequestDataClass | @@ -90,7 +90,7 @@ class TTRequestDataClass extends RequestDataClass | ||
90 | $this->sendToSamp = $sendToSamp; | 90 | $this->sendToSamp = $sendToSamp; |
91 | } | 91 | } |
92 | 92 | ||
93 | - public function getSendToSamp($sendToSamp) | 93 | + public function getSendToSamp() |
94 | { | 94 | { |
95 | return $this->sendToSamp; | 95 | return $this->sendToSamp; |
96 | } | 96 | } |