IHMInputOutputParamsDownloadClass.php
7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
define ("DOWNLOAD_RESULT_FILE_KEY","download");
define ("DOWNLOAD_SAMP_RESULT_FILE_KEY","download-samp");
/**
* @class IHMInputOutputParamsDownloadClass
* @brief Implementation of IHMInputOutputParamsAbstractClass to treat download request
* @details
*/
class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClass
{
/*
* @brief method to unmarshall a download request
*/
protected function unmarshallRequest($input)
{
//{"nodeType":"download","type":"Download","downloadSrc":"0","structure":"2","sampling":600,"separateInfoFile":false,"output":"",
// "header":"0","timesrc":"TimeTable","timeTables":[{"timeTableName":"rzerzer","id":"tt_1"},{"timeTableName":"sqsdq","id":"tt_0"}],
//"list":["dst"],"milli":false,"fileformat":"ASCII","timeformat":"YYYY-MM-DDThh:mm:ss","compression":"tar+gzip","leaf":true}
$requestNode = $this->paramsData->addRequestNode(0);
$paramsNode = $requestNode->getParamsNode();
//Send to SAMP
$this->sendToSamp = isset($input->sendToSamp) ? $input->sendToSamp : FALSE;
if ($this->sendToSamp) {
$input->disablebatch = TRUE;
$input->timeformat = 'YYYY-MM-DDThh:mm:ss';
$input->fileformat = 'vot';
$input->compression = '';
$input->fileprefix = 'amda-samp';
}
//unmarshall time definition
$this->unmarshallTimeDefinition($input, 0);
//unmarshall download output definition
$outputsNode = $requestNode->getOutputsNode();
$downloadNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::DOWNLOAD);
if (isset($input->scientificformat) && $input->scientificformat) {
$downloadNode->setPrecision("true");
}
//timeformatData : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['DD Time', 'DD Time'], ['Timestamp', 'Timestamp']],
switch ($input->timeformat)
{
case 'YYYY-MM-DDThh:mm:ss' :
$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::ISO);
break;
case 'DD Time' :
$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::DDTIME);
break;
case 'Timestamp' :
$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::TIMESTAMP);
break;
case 'Timestamp-with-milliseconds' :
$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::MS);
break;
case 'YYYY MM DD hh mm ss' :
$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::SPACES);
break;
default :
throw new Exception('Time format not implemented.');
}
//formatData : [['ASCII', 'ASCII'],['vot', 'VOTable'],['cdf', 'CDF'],['json', 'JSON']],
switch ($input->fileformat)
{
case "ASCII" :
$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII);
$formatExtension = ".txt";
break;
case "vot" :
case "VOT" :
$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE);
$formatExtension = ".vot";
break;
case "cdf" :
$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::CDF);
$formatExtension = ".cdf";
break;
case "json" :
$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::JSON);
$formatExtension = ".json";
break;
default :
throw new Exception('File format '.$input->fileformat.' not implemented.');
}
if ($input->fileprefix != "")
$downloadNode->setFileName($input->fileprefix);
//add params to output
foreach ($input->list as $param)
{
$paramInfo = $this->paramManager->addExistingParam($param->paramid, $this->paramsData, $param->template_args);
$paramInfo['indexes'] = array();
$this->paramManager->applyRangesAndIndexes($this->paramsData, $param, FALSE, $paramInfo);
$downloadNode->addParam($paramInfo['id'],$paramInfo['indexes'],$paramInfo['calib_infos']);
$paramsNode->addParam($paramInfo['id']);
}
//filestructureData : [['0','All In One File'], ['1','One File Per Time Interval'], ['2','One File Per Param/Interval']],
switch ($input->structure)
{
case "0" :
if (!$input->refparamSampling)
{
$downloadNode->setSamplingTime($input->sampling);
$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE);
}
else
$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_REFPARAM);
break;
case "1" :
if (!$input->refparamSampling)
{
$downloadNode->setSamplingTime($input->sampling);
$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_INTERVAL);
}
else
$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_INTERVAL_REFPARAM);
break;
case "2" :
$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_PARAMETER_PER_INTERVAL);
break;
default :
throw new Exception('Structure type not implemented.');
}
//separateInfoFile
$downloadNode->setSeparateInfoFile(isset($input->separateInfoFile) ? $input->separateInfoFile : FALSE);
//filecompressData : [['zip', 'zip'], ['tar+gzip', 'tar+gzip']],
$extension = "";
$resultFilePrefix = "";
switch ($input->compression)
{
case "zip" :
$extension = ".zip";
$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP);
$resultFilePrefix = "download_";
break;
case "tar+gzip" :
$extension = ".tar.gz";
$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR);
$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP);
$resultFilePrefix = "download_";
break;
case "gzip" :
$extension = $formatExtension.".gz";
$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP);
if ($input->fileprefix)
$resultFilePrefix = $input->fileprefix;
else
$resultFilePrefix = "output-";
break;
case "" :
$extension = $formatExtension;
if ($input->fileprefix)
$resultFilePrefix = $input->fileprefix;
else
$resultFilePrefix = "output-";
break;
default :
throw new Exception('Compression type not implemented.');
}
if (!$this->sendToSamp) {
$resultFile = "result_".$this->requestID;
$this->paramsData->addWaitingResult(DOWNLOAD_RESULT_FILE_KEY, $resultFile);
$postProcessCmd = "mv ".$resultFilePrefix."*";
$postProcessCmd .= $extension;
$postProcessCmd .= " ".$resultFile.$extension;
}
else {
$resultFile = $input->fileprefix.".list";
$this->paramsData->addWaitingResult(DOWNLOAD_SAMP_RESULT_FILE_KEY, $resultFile);
$postProcessCmd = "ls ".$input->fileprefix."* > ".$resultFile;
}
$this->paramsData->setPostCmd($postProcessCmd);
if (isset($input->disablebatch))
$this->paramsData->setBatchEnable(!$input->disablebatch);
return $this->paramsData;
}
/*
* @brief method to marshall the result of a download request
*/
protected function marshallResult($data)
{
if ($this->sendToSamp)
return $this->commonMarshallResult($data,DOWNLOAD_SAMP_RESULT_FILE_KEY);
else
return $this->commonMarshallResult($data,DOWNLOAD_RESULT_FILE_KEY);
}
}
?>