WsrParamMgr.php
5.01 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
<?php
/**
* @class WsrParamMgr
* @version $Id: $
*
*/
class WsrParamMgr
{
protected $startTime, $stopTime;
protected $productor;
protected $parameterID;
protected $dataProducteur;
function __construct() {
ini_set("soap.wsdl_cache_enabled", "0");
}
public function setParams($data){
$this->parameterID = $data['paramID'];
$this->startTime = $data['startDate'];
$this->stopTime = $data['stopDate'];
$this->dataProducteur = $this->getDataProducteur();
}
public function updateInterval($start, $stop){
$this->startTime = gmdate("Y-m-d\TH:i:s\Z", $start);
$this->stopTime = gmdate("Y-m-d\TH:i:s\Z", $stop);
}
protected function getDataProducteur(){
// TODO tests
if (isset($this->parameterID)){
$tmp = explode( '_', $this->parameterID);
return $tmp[0];
}
else return false;
}
protected function makeRequest(){
// genaration webservice request
$tree = tree_CLWEB;
$xml = RemoteData.$tree;
$dom = new DOMDocument('1.0', 'utf-8');
if($dom->load($xml)){
$paramByID = $dom->getElementById($this->parameterID);
if ($paramByID != NULL)
$param = $paramByID->getAttribute('cl_id');
if ($param != ''){
$params = array('parameterID' => $param,
'startTime' => $this->startTime,
'stopTime' => $this->stopTime,
'outputFormat' => 'netCDF'
);
return $params;
}
else return false;
}
else return false;
}
protected function getDataProducteurWSDL(){
if ($this->dataProducteur){
$wsdl = wsdl_CLWEB;
return $wsdl;
}
else return false;
}
protected function addFile($fileName){
$myBaseManager = new BaseManager();
$start = strtotime($this->startTime);
$stop = strtotime($this->stopTime);
$mask = $myBaseManager->addWsFile($fileName, $start, $stop);
if ($mask != null) {
$startstop = $myBaseManager->getStartStop($myBaseManager->getVi($mask));
}
$file = getenv('USER_DATA_PATH').$fileName;
$status = $this->reformatNcTime($file);
if ($status <= 0) {
unlink($this->fileName);
return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
}
return array( 'success' => true, 'file' => $fileName);
}
protected function reformatNcTime($file) {
exec('nctimestring2double '.$file, $results);
return $results[0];
}
public function getFileName(){
// file name generation with parameter ID(frome [DataProducteur]/base.xml), start & stop time in unix format
if ($this->parameterID && $this->parameterID != ''){
$fileName = $this->parameterID.'_'.strtotime($this->startTime).'_'.strtotime($this->stopTime).'.nc';
return $fileName;
}
else return false;
}
public function getMask(){
if ($this->parameterID && $this->parameterID != ''){
$mask = $this->parameterID.'_*.nc';
return $mask;
}
else return false;
}
public function getData(){
$fileName = $this->getFileName();
$newfile = getenv('USER_DATA_PATH').$fileName;
if ($fileName){
try {
$client = new SoapClient(wsdl_CLWEB,
array(
'wsdl_cache' => 0,
'trace' => 1,
// 'exceptions' => 0,
'soap_version'=>SOAP_1_2
));
}
catch (SoapFault $exception) {//
error_log("Problem with WSDL".PHP_EOL.$exception->getMessage().PHP_EOL.$exception->getTraceAsString().PHP_EOL."File = ".$exception->getFile(),1,email);
return false;
}
$params = $this->makeRequest($this->parameterID);
// call WS
try {
$file = $client->getParameter($params);
}
catch (SoapFault $exception) {
error_log("Problem with query".PHP_EOL.$exception->getMessage().PHP_EOL.$exception->getTraceAsString().PHP_EOL."File = ".$exception->getFile(),1,email);
return false;
}
// copy result file to user DATA directory
if (!copy($file->dataFileURLs, $newfile)) {
error_log('Can\'t copy '.$file,1,email);
return false;
}
else {
chmod($fileName, 0775);
$this->addFile($fileName);
$wsrFilenames[$this->parameterID] = $fileName;
}
return $wsrFilenames;
} //end if ($fileName)
else
return false;
}
}
?>