Blame view

src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php 7.56 KB
22521f1c   Benjamin Renard   First commit
1
2
3
<?php

define ("DOWNLOAD_RESULT_FILE_KEY","download");
5cf99396   Benjamin Renard   Add SAMP export i...
4
define ("DOWNLOAD_SAMP_RESULT_FILE_KEY","download-samp");
22521f1c   Benjamin Renard   First commit
5
6
7
8
9
10
11
12
13
14
15
16
17

/**
 * @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)
	{
0c0b5ee3   Benjamin Renard   structure in down...
18
		//{"nodeType":"download","type":"Download","downloadSrc":"0","filestructure":"2","sampling":600,"separateInfoFile":false,"output":"",
22521f1c   Benjamin Renard   First commit
19
20
21
		// "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}

7d14181a   Benjamin Renard   Fix multi-request...
22
		$requestNode = $this->paramsData->addRequestNode(0);
8c57155b   Benjamin Renard   Integration for t...
23
24
		
		$paramsNode = $requestNode->getParamsNode();
22521f1c   Benjamin Renard   First commit
25

5cf99396   Benjamin Renard   Add SAMP export i...
26
27
28
		//Send to SAMP
		$this->sendToSamp = isset($input->sendToSamp) ? $input->sendToSamp : FALSE;
		if ($this->sendToSamp) {
522bdbd6   Benjamin Renard   Fix typo
29
			$input->disablebatch = TRUE;
5cf99396   Benjamin Renard   Add SAMP export i...
30
31
32
33
34
35
			$input->timeformat = 'YYYY-MM-DDThh:mm:ss';
			$input->fileformat = 'vot';
			$input->compression = '';
			$input->fileprefix = 'amda-samp';
		}

22521f1c   Benjamin Renard   First commit
36
		//unmarshall time definition
8c57155b   Benjamin Renard   Integration for t...
37
		$this->unmarshallTimeDefinition($input, 0);
22521f1c   Benjamin Renard   First commit
38
39

		//unmarshall download output definition
8c57155b   Benjamin Renard   Integration for t...
40
		$outputsNode = $requestNode->getOutputsNode();
22521f1c   Benjamin Renard   First commit
41
42
		$downloadNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::DOWNLOAD);

570d7d45   Benjamin Renard   Add option to sel...
43
44
45
46
		if (isset($input->scientificformat) && $input->scientificformat) {
			$downloadNode->setPrecision("true");
		}

d6410187   Benjamin Renard   Complete download...
47
		//timeformatData    : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['DD Time', 'DD Time'], ['Timestamp', 'Timestamp']],
22521f1c   Benjamin Renard   First commit
48
49
50
51
52
		switch ($input->timeformat)
		{
			case 'YYYY-MM-DDThh:mm:ss' :
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::ISO);
				break;
270b4468   Menouard AZIB   I missed to push ...
53
			case 'DOY TIME' :
815676b7   Hacene SI HADJ MOHAND   I have changed DD...
54
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::DOYTIME);
d6410187   Benjamin Renard   Complete download...
55
56
57
58
				break;
			case 'Timestamp' :
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::TIMESTAMP);
				break;
a51cd0e9   Benjamin Renard   rm ok
59
60
61
62
63
64
65
                        case 'Timestamp-with-milliseconds' :
                                $downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::MS);
                                break;
                        case 'YYYY MM DD hh mm ss' :
                                $downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::SPACES);
                                break;

22521f1c   Benjamin Renard   First commit
66
67
68
69
			default :
				throw new Exception('Time format not implemented.');
		}

d6410187   Benjamin Renard   Complete download...
70
		//formatData    : [['ASCII', 'ASCII'],['vot', 'VOTable'],['cdf', 'CDF'],['json', 'JSON']],
22521f1c   Benjamin Renard   First commit
71
72
73
74
		switch ($input->fileformat)
		{
			case "ASCII" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII);
02abc780   Benjamin Renard   Support request f...
75
				$formatExtension = ".txt";
22521f1c   Benjamin Renard   First commit
76
				break;
ffc5cb81   Elena.Budnik   temporary commit
77
78
			case "vot" :				
			case "VOT" :
d6410187   Benjamin Renard   Complete download...
79
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE);
02abc780   Benjamin Renard   Support request f...
80
				$formatExtension = ".vot";
d6410187   Benjamin Renard   Complete download...
81
82
83
				break;
			case "cdf" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::CDF);
02abc780   Benjamin Renard   Support request f...
84
				$formatExtension = ".cdf";
d6410187   Benjamin Renard   Complete download...
85
				break;
9d62f847   Benjamin Renard   Add CDF_ISTP form...
86
87
88
89
90
			case "cdf-istp":
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::CDF_ISTP);
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::TT2000);
				$formatExtension = ".cdf";
				break;
d6410187   Benjamin Renard   Complete download...
91
92
			case "json" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::JSON);
02abc780   Benjamin Renard   Support request f...
93
				$formatExtension = ".json";
22521f1c   Benjamin Renard   First commit
94
95
				break;
			default :
ffc5cb81   Elena.Budnik   temporary commit
96
				throw new Exception('File format '.$input->fileformat.' not implemented.');
22521f1c   Benjamin Renard   First commit
97
98
		}

574ec9ed   Benjamin Renard   Use file prefix f...
99
100
		if ($input->fileprefix != "")
			$downloadNode->setFileName($input->fileprefix);
22521f1c   Benjamin Renard   First commit
101
102
103
104

		//add params to output
		foreach ($input->list as $param)
		{
e4545ed5   Benjamin Renard   Implement templat...
105
			$paramInfo = $this->paramManager->addExistingParam($param->paramid, $this->paramsData, $param->template_args);
93c50989   Benjamin Renard   Support Tab2D par...
106
107
			$paramInfo['indexes'] = array();
			$this->paramManager->applyRangesAndIndexes($this->paramsData, $param, FALSE, $paramInfo);
8d0b7234   Hacene SI HADJ MOHAND   templeting filter
108
                                                            $this->paramManager->applyFilter($this->paramsData, $param,$paramInfo);
22521f1c   Benjamin Renard   First commit
109
110
111
112
113
			$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']],
0c0b5ee3   Benjamin Renard   structure in down...
114
		switch ($input->filestructure)
22521f1c   Benjamin Renard   First commit
115
116
		{
			case "0" :
d6410187   Benjamin Renard   Complete download...
117
118
119
120
121
122
123
				if (!$input->refparamSampling)
				{
					$downloadNode->setSamplingTime($input->sampling);
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE);
				}
				else
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_REFPARAM);
22521f1c   Benjamin Renard   First commit
124
125
				break;
			case "1" :
d6410187   Benjamin Renard   Complete download...
126
127
128
129
130
131
132
				if (!$input->refparamSampling)
				{
					$downloadNode->setSamplingTime($input->sampling);
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_INTERVAL);
				}
				else
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_INTERVAL_REFPARAM);
22521f1c   Benjamin Renard   First commit
133
134
135
136
137
138
139
140
				break;
			case "2" :
				$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_PARAMETER_PER_INTERVAL);
				break;
			default :
				throw new Exception('Structure type not implemented.');
		}

6139c32c   Benjamin Renard   Give the possibil...
141
142
143
		//separateInfoFile
                $downloadNode->setSeparateInfoFile(isset($input->separateInfoFile) ? $input->separateInfoFile : FALSE);

22521f1c   Benjamin Renard   First commit
144
145
		//filecompressData  : [['zip', 'zip'], ['tar+gzip', 'tar+gzip']],
		$extension = "";
02abc780   Benjamin Renard   Support request f...
146
		$resultFilePrefix = "";
22521f1c   Benjamin Renard   First commit
147
148
149
150
151
		switch ($input->compression)
		{
			case "zip" :
				$extension = ".zip";
				$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP);
02abc780   Benjamin Renard   Support request f...
152
				$resultFilePrefix = "download_";
22521f1c   Benjamin Renard   First commit
153
154
155
156
157
				break;
			case "tar+gzip" :
				$extension = ".tar.gz";
				$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR);
				$downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP);
02abc780   Benjamin Renard   Support request f...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
				$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-";
22521f1c   Benjamin Renard   First commit
174
175
176
177
178
				break;
			default :
				throw new Exception('Compression type not implemented.');
		}

5cf99396   Benjamin Renard   Add SAMP export i...
179
180
181
		if (!$this->sendToSamp) {
			$resultFile = "result_".$this->requestID;
			$this->paramsData->addWaitingResult(DOWNLOAD_RESULT_FILE_KEY, $resultFile);
22521f1c   Benjamin Renard   First commit
182

5cf99396   Benjamin Renard   Add SAMP export i...
183
			$postProcessCmd  = "mv ".$resultFilePrefix."*";
02abc780   Benjamin Renard   Support request f...
184
		
5cf99396   Benjamin Renard   Add SAMP export i...
185
186
187
188
189
190
191
192
193
			$postProcessCmd .= $extension;
			$postProcessCmd .= " ".$resultFile.$extension;
		}
		else {
			$resultFile = $input->fileprefix.".list";
			$this->paramsData->addWaitingResult(DOWNLOAD_SAMP_RESULT_FILE_KEY, $resultFile);

			$postProcessCmd  = "ls ".$input->fileprefix."* > ".$resultFile;
		}
22521f1c   Benjamin Renard   First commit
194
195

		$this->paramsData->setPostCmd($postProcessCmd);
02abc780   Benjamin Renard   Support request f...
196
197
198
		
		if (isset($input->disablebatch))
			$this->paramsData->setBatchEnable(!$input->disablebatch);
22521f1c   Benjamin Renard   First commit
199
200
201
202
203
204
205
206
207

		return $this->paramsData;
	}

	/*
	 * @brief method to marshall the result of a download request
	*/
	protected function marshallResult($data)
	{
5cf99396   Benjamin Renard   Add SAMP export i...
208
209
210
211
		if ($this->sendToSamp)
			return $this->commonMarshallResult($data,DOWNLOAD_SAMP_RESULT_FILE_KEY);
		else
			return $this->commonMarshallResult($data,DOWNLOAD_RESULT_FILE_KEY);
22521f1c   Benjamin Renard   First commit
212
213
	}
}
d6410187   Benjamin Renard   Complete download...
214
?>