Blame view

src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php 6.28 KB
22521f1c   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

define ("DOWNLOAD_RESULT_FILE_KEY","download");

/**
 * @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,"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}

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

		//unmarshall time definition
8c57155b   Benjamin Renard   Integration for t...
26
		$this->unmarshallTimeDefinition($input, 0);
22521f1c   Benjamin Renard   First commit
27
28

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

d6410187   Benjamin Renard   Complete download...
32
		//timeformatData    : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['DD Time', 'DD Time'], ['Timestamp', 'Timestamp']],
22521f1c   Benjamin Renard   First commit
33
34
35
36
37
		switch ($input->timeformat)
		{
			case 'YYYY-MM-DDThh:mm:ss' :
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::ISO);
				break;
d6410187   Benjamin Renard   Complete download...
38
39
40
41
42
43
			case 'DD Time' :
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::DDTIME);
				break;
			case 'Timestamp' :
				$downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::TIMESTAMP);
				break;
22521f1c   Benjamin Renard   First commit
44
45
46
47
			default :
				throw new Exception('Time format not implemented.');
		}

d6410187   Benjamin Renard   Complete download...
48
		//formatData    : [['ASCII', 'ASCII'],['vot', 'VOTable'],['cdf', 'CDF'],['json', 'JSON']],
22521f1c   Benjamin Renard   First commit
49
50
51
52
		switch ($input->fileformat)
		{
			case "ASCII" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII);
02abc780   Benjamin Renard   Support request f...
53
				$formatExtension = ".txt";
22521f1c   Benjamin Renard   First commit
54
				break;
d6410187   Benjamin Renard   Complete download...
55
56
			case "vot" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE);
02abc780   Benjamin Renard   Support request f...
57
				$formatExtension = ".vot";
d6410187   Benjamin Renard   Complete download...
58
59
60
				break;
			case "cdf" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::CDF);
02abc780   Benjamin Renard   Support request f...
61
				$formatExtension = ".cdf";
d6410187   Benjamin Renard   Complete download...
62
63
64
				break;
			case "json" :
				$downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::JSON);
02abc780   Benjamin Renard   Support request f...
65
				$formatExtension = ".json";
22521f1c   Benjamin Renard   First commit
66
67
68
69
70
				break;
			default :
				throw new Exception('File format not implemented.');
		}

574ec9ed   Benjamin Renard   Use file prefix f...
71
72
		if ($input->fileprefix != "")
			$downloadNode->setFileName($input->fileprefix);
22521f1c   Benjamin Renard   First commit
73
74
75
76

		//add params to output
		foreach ($input->list as $param)
		{
3182799a   Benjamin Renard   Use param indexes...
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
			$paramInfo = $this->paramManager->addExistingParam($param->name,$this->paramsData);
			switch ($param->type) {
				case 0:
					//scalar - nothing to do
					break;
				case 1:
					//Tab1D
					if (isset($param->dim1) && ($param->dim1 != '') && ($param->dim1 != '*')) {
						$paramInfo['indexes'] = array();
						$paramInfo['indexes'][] = $param->dim1;
					}
					else if (isset($param->dim2) && ($param->dim2 != '') && ($param->dim2 != '*')) {
						$paramInfo['indexes'] = array();
						$paramInfo['indexes'][] = $param->dim2;
					}
					break;
				case 2:
					if (($param->dim1 != '*') || ($param->dim2 != '*')) {
						$paramInfo['indexes'] = array();
						$paramInfo['indexes'][] = "[".$param->dim1.",".$param->dim2."]";
					}
					break;
			}
22521f1c   Benjamin Renard   First commit
100
101
102
103
104
105
106
107
			$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" :
d6410187   Benjamin Renard   Complete download...
108
109
110
111
112
113
114
				if (!$input->refparamSampling)
				{
					$downloadNode->setSamplingTime($input->sampling);
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE);
				}
				else
					$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_REFPARAM);
22521f1c   Benjamin Renard   First commit
115
116
				break;
			case "1" :
d6410187   Benjamin Renard   Complete download...
117
118
119
120
121
122
123
				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
124
125
126
127
128
129
130
131
132
133
				break;
			case "2" :
				$downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_PARAMETER_PER_INTERVAL);
				break;
			default :
				throw new Exception('Structure type not implemented.');
		}

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

		$resultFile = "result_".$this->requestID;
		$this->paramsData->addWaitingResult(DOWNLOAD_RESULT_FILE_KEY, $resultFile);

02abc780   Benjamin Renard   Support request f...
170
171
		$postProcessCmd  = "mv ".$resultFilePrefix."*";
		
22521f1c   Benjamin Renard   First commit
172
173
174
175
		$postProcessCmd .= $extension;
		$postProcessCmd .= " ".$resultFile.$extension;

		$this->paramsData->setPostCmd($postProcessCmd);
02abc780   Benjamin Renard   Support request f...
176
177
178
		
		if (isset($input->disablebatch))
			$this->paramsData->setBatchEnable(!$input->disablebatch);
22521f1c   Benjamin Renard   First commit
179
180
181
182
183
184
185
186
187
188
189
190

		return $this->paramsData;
	}

	/*
	 * @brief method to marshall the result of a download request
	*/
	protected function marshallResult($data)
	{
		return $this->commonMarshallResult($data,DOWNLOAD_RESULT_FILE_KEY);
	}
}
d6410187   Benjamin Renard   Complete download...
191
?>