Commit ffc5cb816f6e1c869e840b47a7a89824e447abc0
1 parent
e4cf87dc
Exists in
master
and in
66 other branches
temporary commit
Showing
14 changed files
with
615 additions
and
52 deletions
Show diff stats
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
... | ... | @@ -50,7 +50,11 @@ class IHMConfigClass |
50 | 50 | private static $userParamMgrFile = "WsParams.xml"; |
51 | 51 | |
52 | 52 | private static $userName; |
53 | - | |
53 | + | |
54 | + private static $userHost; | |
55 | + | |
56 | + public static $remoteDataDir = "/home/budnik/RemoteDataCenter/MAJ/"; | |
57 | + | |
54 | 58 | public static function setUserName($userName) |
55 | 59 | { |
56 | 60 | self::$userName = $userName; |
... | ... | @@ -60,7 +64,17 @@ class IHMConfigClass |
60 | 64 | { |
61 | 65 | return self::$userName; |
62 | 66 | } |
67 | + | |
68 | + public static function setUserHost($userHost) | |
69 | + { | |
70 | + self::$userHost = $userHost; | |
71 | + } | |
63 | 72 | |
73 | + public static function getUserHost() | |
74 | + { | |
75 | + return self::$userHost; | |
76 | + } | |
77 | + | |
64 | 78 | public static function getUserPath() |
65 | 79 | { |
66 | 80 | $userPath = IHM_SRC_DIR.self::$dataDir.self::$userName.'/'; |
... | ... | @@ -198,6 +212,14 @@ class IHMConfigClass |
198 | 212 | return $localBasePath; |
199 | 213 | } |
200 | 214 | |
215 | + public static function getRemoteParamsFile() | |
216 | + { | |
217 | + $remoteBasePath = self::getUserPath().self::$wsDir; | |
218 | + | |
219 | + | |
220 | + return $remoteBasePath.'RemoteParams.xml'; | |
221 | + } | |
222 | + | |
201 | 223 | public static function getRequestPath() |
202 | 224 | { |
203 | 225 | $requestPath = self::getUserPath().self::$requestDir; |
... | ... |
src/InputOutput/IHMImpl/IHMInputOutputClass.php
... | ... | @@ -12,9 +12,10 @@ class IHMInputOutputClass implements InputOutputInterface |
12 | 12 | /* |
13 | 13 | * @brief Constructor |
14 | 14 | */ |
15 | - function __construct($userName) | |
15 | + function __construct($userName, $userHost) | |
16 | 16 | { |
17 | 17 | IHMConfigClass::setUserName($userName); |
18 | + IHMConfigClass::setUserHost($userHost); | |
18 | 19 | } |
19 | 20 | |
20 | 21 | /* |
... | ... |
src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php
... | ... | @@ -9,6 +9,7 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface |
9 | 9 | { |
10 | 10 | private $paramInfoData = null; |
11 | 11 | private $paramTemplateMgr = null; |
12 | + private $paramImpexMgr = null; | |
12 | 13 | |
13 | 14 | /* |
14 | 15 | * @brief Constructor |
... | ... | @@ -27,6 +28,7 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface |
27 | 28 | |
28 | 29 | switch ($input->type) { |
29 | 30 | case 'plot_init' : |
31 | + | |
30 | 32 | $this->paramInfoData->setType(ParamInfoTypeEnumClass::PLOTINIT); |
31 | 33 | |
32 | 34 | if (!isset($input->paramId) || empty($input->paramId)) |
... | ... | @@ -37,13 +39,35 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface |
37 | 39 | $paramFilePath = $this->paramTemplateMgr->getTemplatePath($input->paramId); |
38 | 40 | else |
39 | 41 | $paramFilePath = IHMConfigClass::getLocalParamDBPath().$input->paramId.".xml"; |
42 | + | |
43 | + if (!file_exists("$paramFilePath")) | |
44 | + throw new Exception("Cannot find parameter definition file"); | |
45 | + | |
46 | + $this->paramInfoData->setFilePath($paramFilePath); | |
47 | + break; | |
40 | 48 | |
41 | - if (!file_exists($paramFilePath)) | |
49 | + case 'impex_plot_init' : | |
50 | + | |
51 | + $this->paramInfoData->setType(ParamInfoTypeEnumClass::IMPEXPLOTINIT); | |
52 | + | |
53 | + if (!isset($input->paramId) || empty($input->paramId)) | |
54 | + throw new Exception("Param info request need a param id as argument"); | |
55 | + | |
56 | + if (!$this->paramImpexMgr) | |
57 | + { | |
58 | + $this->paramImpexMgr = new IHMImpexParamClass(); | |
59 | + } | |
60 | + | |
61 | + $paramFilePath = $this->paramImpexMgr->getParamInfoPlotPath($input->paramId); | |
62 | + | |
63 | + if (!$paramFilePath || !file_exists($paramFilePath)) | |
42 | 64 | throw new Exception("Cannot find parameter definition file"); |
43 | 65 | |
44 | 66 | $this->paramInfoData->setFilePath($paramFilePath); |
45 | 67 | break; |
68 | + | |
46 | 69 | case 'param_info' : |
70 | + | |
47 | 71 | $this->paramInfoData->setType(ParamInfoTypeEnumClass::PARAMINFO); |
48 | 72 | |
49 | 73 | if (!isset($input->paramId) || empty($input->paramId)) |
... | ... | @@ -61,8 +85,31 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface |
61 | 85 | |
62 | 86 | $this->paramInfoData->setFilePath($paramInfoFilePath); |
63 | 87 | break; |
88 | + | |
89 | + case 'impex_param_info' : | |
90 | + | |
91 | + $this->paramInfoData->setType(ParamInfoTypeEnumClass::IMPEXINFO); | |
92 | + if (!isset($input->paramId) || empty($input->paramId)) | |
93 | + throw new Exception("Param info request need a param id as argument"); | |
94 | + | |
95 | + if (!$this->paramImpexMgr) | |
96 | + { | |
97 | + $this->paramImpexMgr = new IHMImpexParamClass(); | |
98 | + } | |
99 | + $this->paramImpexMgr->setParamTemplateListFilePath($input->paramId); | |
100 | + $templatedParams = $this->paramImpexMgr->getParamTemplates(); | |
101 | + | |
102 | + $simRegion = $this->paramImpexMgr->getSimulationRegion($input->paramId); | |
103 | + | |
104 | + // No SimulationRuns (LESIA) | |
105 | + if ($simRegion == "UNKNOWN") | |
106 | + $simRegion = $this->paramImpexMgr->getResourceID($input->paramId); | |
107 | + | |
108 | + $this->paramInfoData->setTemplateInfo($templatedParams[$simRegion]); | |
109 | + | |
110 | + break; | |
64 | 111 | default : |
65 | - throw new Exception("Para info request type '".$input->type."' not yet implemented"); | |
112 | + throw new Exception("Param info request type '".$input->type."' not yet implemented"); | |
66 | 113 | } |
67 | 114 | |
68 | 115 | $this->paramInfoData->setParamId($input->paramId); |
... | ... | @@ -80,10 +127,18 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface |
80 | 127 | $result = array("success" => false, "message" => "Cannot get plot init"); |
81 | 128 | $this->getOutputPlotInit($data, $result); |
82 | 129 | break; |
130 | + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : | |
131 | + $result = array("success" => false, "message" => "Cannot get impex plot init"); | |
132 | + $this->getOutputPlotInit($data, $result); | |
133 | + break; | |
83 | 134 | case ParamInfoTypeEnumClass::PARAMINFO : |
84 | 135 | $result = array("success" => false, "message" => "Cannot get param info"); |
85 | 136 | $this->getOutputParamInfo($data, $result); |
86 | 137 | break; |
138 | + case ParamInfoTypeEnumClass::IMPEXINFO : | |
139 | + $result = array("success" => false, "message" => "Cannot get impex param info"); | |
140 | + $this->getOutputParamInfo($data, $result); | |
141 | + break; | |
87 | 142 | default: |
88 | 143 | //Nothing ToDo |
89 | 144 | } |
... | ... |
src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php
... | ... | @@ -52,7 +52,8 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas |
52 | 52 | $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII); |
53 | 53 | $formatExtension = ".txt"; |
54 | 54 | break; |
55 | - case "vot" : | |
55 | + case "vot" : | |
56 | + case "VOT" : | |
56 | 57 | $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE); |
57 | 58 | $formatExtension = ".vot"; |
58 | 59 | break; |
... | ... | @@ -65,7 +66,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas |
65 | 66 | $formatExtension = ".json"; |
66 | 67 | break; |
67 | 68 | default : |
68 | - throw new Exception('File format not implemented.'); | |
69 | + throw new Exception('File format '.$input->fileformat.' not implemented.'); | |
69 | 70 | } |
70 | 71 | |
71 | 72 | if ($input->fileprefix != "") |
... | ... |
src/InputOutput/IHMImpl/Tools/CommonClass.php
... | ... | @@ -34,6 +34,57 @@ class CommonClass |
34 | 34 | $t = date("His",$timeStamp)."000"; |
35 | 35 | return $y.$d.$t; |
36 | 36 | } |
37 | + /* | |
38 | + * @brief DDTime to timestamp conversion | |
39 | + */ | |
40 | + public static function DDTimeToTimeStamp($DDTime) | |
41 | + { | |
42 | + date_default_timezone_set('UTC'); | |
43 | + $date = DateTime::createFromFormat('YzHisu', $DDTime); | |
44 | + | |
45 | + return strtotime($date->format("Y-m-d\TH:i:s")); | |
46 | + } | |
47 | + | |
48 | + /* | |
49 | + * @brief DDTime to ISO conversion | |
50 | + */ | |
51 | + public static function DDTimeToIso($DDTime) | |
52 | + { | |
53 | + $date = DateTime::createFromFormat('YzHisu', $DDTime); | |
54 | + | |
55 | + return $date->format("Y-m-d\TH:i:s"); | |
56 | + } | |
57 | + | |
58 | + /* | |
59 | + * @brief DDTime to ISO conversion | |
60 | + */ | |
61 | + public static function DDStartIntervalToStopIso($DDStart, $DDInterval) | |
62 | + { | |
63 | + $startStamp = self::DDTimeToTimeStamp($DDStart); | |
64 | + $intStamp = self::DDTimeToTimeStamp($DDInterval); | |
65 | + | |
66 | + return date("Y-m-d\TH:i:s", $startStamp + $intStamp); | |
67 | + } | |
68 | + | |
69 | + public static function rrmdir($dir) | |
70 | + { | |
71 | + if (is_dir($dir)) | |
72 | + { | |
73 | + $objects = scandir($dir); | |
74 | + foreach ($objects as $object) | |
75 | + { // Recursively delete a directory that is not empty and directorys in directory | |
76 | + if ($object != "." && $object != "..") | |
77 | + { // If object isn't a directory recall recursively this function | |
78 | + if (filetype($dir."/".$object) == "dir") | |
79 | + self::rrmdir($dir."/".$object); | |
80 | + else | |
81 | + unlink($dir."/".$object); | |
82 | + } | |
83 | + } | |
84 | + reset($objects); | |
85 | + rmdir($dir); | |
86 | + } | |
87 | + } | |
37 | 88 | } |
38 | 89 | |
39 | 90 | ?> |
40 | 91 | \ No newline at end of file |
... | ... |
src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php
... | ... | @@ -45,6 +45,7 @@ class IHMExpressionParserClass |
45 | 45 | private $functionsArray; |
46 | 46 | |
47 | 47 | private $templatedParamMgr = NULL; |
48 | + private $impexParamMgr = NULL; | |
48 | 49 | |
49 | 50 | private $isTest = FALSE; |
50 | 51 | |
... | ... | @@ -143,30 +144,45 @@ class IHMExpressionParserClass |
143 | 144 | |
144 | 145 | //group elements in tree |
145 | 146 | $tree = $this->buildTreeElements($elements); |
146 | - | |
147 | + | |
147 | 148 | //translate |
148 | 149 | $params_full = array(); |
149 | 150 | $translated = $this->translate($tree,$params_full); |
150 | - | |
151 | + | |
151 | 152 | //keep only params id |
152 | 153 | $params = array(); |
153 | - foreach ($params_full as $param_full) { | |
154 | + foreach ($params_full as $param_full) { | |
154 | 155 | if (array_key_exists("template_args", $param_full)) { |
155 | 156 | $params[] = array( |
156 | 157 | "paramid" => $param_full['id'], |
157 | 158 | "fullparamid" => $param_full['fullparamid'], |
158 | 159 | "template_args" => $param_full['template_args'] |
159 | - ); | |
160 | + ); | |
160 | 161 | } |
161 | 162 | else if (!$this->isTest && (($templated_param_info = $this->templatedParamMgr->parseTemplatedParam($param_full["id"])) !== FALSE)) { |
162 | - $params[] = $templated_param_info; | |
163 | + $params[] = $templated_param_info; | |
164 | + } | |
165 | + else if ($this->isImpexParam($param_full["id"])) | |
166 | + { | |
167 | + if (!$this->impexParamMgr) | |
168 | + { | |
169 | + $this->impexParamMgr = new IHMImpexParamClass(); | |
170 | + } | |
171 | + $templated_param_info = $this->impexParamMgr->parseImpexParam($param_full["id"]); | |
172 | + $params[] = $templated_param_info; | |
163 | 173 | } |
164 | 174 | else |
165 | 175 | $params[] = array("paramid" => $param_full["id"]); |
166 | 176 | } |
177 | + | |
167 | 178 | return array("expression" => $translated, "params" => $params); |
168 | 179 | } |
169 | - | |
180 | + | |
181 | + private function isImpexParam($paramID) | |
182 | + { | |
183 | + return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$paramID); | |
184 | + } | |
185 | + | |
170 | 186 | /* |
171 | 187 | * @brief clean expression |
172 | 188 | */ |
... | ... |
... | ... | @@ -0,0 +1,288 @@ |
1 | +<?php | |
2 | + | |
3 | +/** | |
4 | + * @class IHMImpexParamClass | |
5 | + * @brief Class used to manage impex parameters | |
6 | + * @details | |
7 | + */ | |
8 | +class IHMImpexParamClass extends IHMParamTemplateClass | |
9 | +{ | |
10 | + private $dataProducer = 'UNKNOWN'; | |
11 | + private $simulationRegion = 'UNKNOWN'; | |
12 | + private $dom; | |
13 | + private $filePath; | |
14 | + | |
15 | + public static $paramPrefix = "spase___IMPEX_NumericalOutput_"; | |
16 | + | |
17 | + /* | |
18 | + * @brief Constructor | |
19 | + */ | |
20 | + function __construct() | |
21 | + { | |
22 | + $this->filePath = IHMConfigClass::getRemoteParamsFile(); | |
23 | + $this->dom = new DomDocument("1.0"); | |
24 | + | |
25 | + if (!file_exists($this->filePath)) | |
26 | + throw new Exception("no RemoteParams File ".$this->filePath); | |
27 | + | |
28 | + $this->dom->load($this->filePath); | |
29 | + | |
30 | + } | |
31 | + | |
32 | + public function param2dd($paramID) | |
33 | + { | |
34 | + $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); | |
35 | + return strtr($paramID,$pairs); | |
36 | + } | |
37 | + | |
38 | + public function getDataProducer($paramId) | |
39 | + { | |
40 | + $paramNode = $this->dom->getElementById($paramId); | |
41 | + | |
42 | + while ($paramNode->tagName !== 'dataCenter') | |
43 | + { | |
44 | + $paramNode = $paramNode->parentNode; | |
45 | + } | |
46 | + | |
47 | + if ( $paramNode ) | |
48 | + $this->dataProducer = $paramNode->getAttribute('xml:id'); | |
49 | + | |
50 | + return $this->dataProducer; | |
51 | + } | |
52 | + | |
53 | + public function getResourceID($paramId) | |
54 | + { | |
55 | + $paramNode = $this->dom->getElementById($paramId); | |
56 | + | |
57 | + while ($paramNode->tagName !== 'dataset') | |
58 | + { | |
59 | + $paramNode = $paramNode->parentNode; | |
60 | + } | |
61 | + | |
62 | + if ( $paramNode ) | |
63 | + $resourceID = $paramNode->getAttribute('xml:id'); | |
64 | + | |
65 | + return $resourceID; | |
66 | + } | |
67 | + | |
68 | + public function getTranslatedResourceID($paramId) | |
69 | + { | |
70 | + return $this->param2dd($this->getResourceID($paramId)); | |
71 | + } | |
72 | + | |
73 | + public function getSimulationRegion($paramId) | |
74 | + { | |
75 | + $paramNode = $this->dom->getElementById($paramId); | |
76 | + | |
77 | + while ($paramNode->tagName !== 'simulationRegion') | |
78 | + { | |
79 | + $paramNode = $paramNode->parentNode; | |
80 | + if ( $paramNode->tagName == 'simulationModel') break; | |
81 | + | |
82 | + } | |
83 | + | |
84 | + if ( $paramNode && $paramNode->tagName == 'simulationRegion') | |
85 | + $this->simulationRegion = $paramNode->getAttribute('xml:id'); | |
86 | + | |
87 | + return $this->simulationRegion; | |
88 | + } | |
89 | + | |
90 | + public function getParameterKey($paramId) | |
91 | + { | |
92 | + $parameterKey = 'UNKNOWN'; | |
93 | + | |
94 | + $paramNode = $this->dom->getElementById($paramId); | |
95 | + | |
96 | + if ( $paramNode ) | |
97 | + $parameterKey = $paramNode->getAttribute('shortName'); | |
98 | + | |
99 | + return $parameterKey; | |
100 | + } | |
101 | + | |
102 | + | |
103 | + public function getParameterSize($paramId) | |
104 | + { | |
105 | + $parameterSize = 'UNKNOWN'; | |
106 | + | |
107 | + $paramNode = $this->dom->getElementById($paramId); | |
108 | + | |
109 | + if ( $paramNode ) | |
110 | + $parameterSize = $paramNode->getAttribute('size'); | |
111 | + | |
112 | + return $parameterSize; | |
113 | + } | |
114 | + | |
115 | + public function getAccessUrl($paramId) | |
116 | + { | |
117 | + $url = 'UNKNOWN'; | |
118 | + | |
119 | + $paramNode = $this->dom->getElementById($paramId); | |
120 | + | |
121 | + while ($paramNode->tagName !== 'dataset') | |
122 | + { | |
123 | + $paramNode = $paramNode->parentNode; | |
124 | + | |
125 | + } | |
126 | + | |
127 | + if ( $paramNode && $paramNode->hasAttribute('accessUrl')) | |
128 | + $url = $paramNode->getAttribute('accessUrl'); | |
129 | + | |
130 | + return $url; | |
131 | + } | |
132 | + | |
133 | + public function setParamTemplateListFilePath($paramId) | |
134 | + { | |
135 | + $this->paramTemplateListFilePath = IHMConfigClass::$remoteDataDir.$this->getDataProducer($paramId).'_Templates.xml'; | |
136 | + } | |
137 | + | |
138 | + /* | |
139 | + * | |
140 | + */ | |
141 | + public function getImpexFullParamId($param_id, $templateArgs = NULL) { | |
142 | + | |
143 | + if (!$templateArgs) | |
144 | + return $param_id; | |
145 | + | |
146 | + $fullParamId = $param_id; | |
147 | + foreach ($templateArgs as $key => $value) | |
148 | + $fullParamId .= "_".$value; | |
149 | + | |
150 | + return $fullParamId; | |
151 | + } | |
152 | + | |
153 | + public function getImpexParamId($fullParamId) | |
154 | + { | |
155 | + $pos = strrpos($fullParamId,'_'); | |
156 | + $id = $fullParamId; | |
157 | + | |
158 | + $find = false; | |
159 | + | |
160 | + while ($pos && !$find) | |
161 | + { | |
162 | + $id = substr($id,0,$pos); | |
163 | + $param = $this->dom->getElementById($id); | |
164 | + if ($param) $find = true; | |
165 | + $pos = strrpos($id,'_'); | |
166 | + } | |
167 | + if (!$find) | |
168 | + throw new Exception("Can not find IMPEX parameter ".$fullParamId); | |
169 | + | |
170 | + return $id; | |
171 | + } | |
172 | + | |
173 | + public function parseImpexParam($param_expression) | |
174 | + { | |
175 | + $paramId = $this->getImpexParamId($param_expression); | |
176 | + $this->getDataProducer($paramId); | |
177 | + $this->getSimulationRegion($paramId); | |
178 | + $this->setParamTemplateListFilePath($paramId); | |
179 | + | |
180 | + $templateArgsString = substr($param_expression,strlen($paramId."_")); | |
181 | + | |
182 | + $allTemplatedParams = $this->getParamTemplates(); | |
183 | + $templatedParams = $allTemplatedParams[$this->simulationRegion]; | |
184 | + $args = $templatedParams['arguments']; | |
185 | + | |
186 | + $templateArgs = array(); | |
187 | + foreach ($args as $key => $value) | |
188 | + { | |
189 | + /*$r = print_r($templatedParams,true); */ | |
190 | + switch($value["type"]) | |
191 | + { | |
192 | + case 'float' : | |
193 | + case 'double' : | |
194 | + case 'int': | |
195 | + $pos = strpos($templateArgsString,'_'); | |
196 | + $arg_value = substr($templateArgsString,0,$pos); | |
197 | + $templateArgsString = substr($templateArgsString,$pos+1); | |
198 | + break; | |
199 | + case 'list' : | |
200 | + $arg_items = $value['items']; | |
201 | + foreach ($arg_items as $arg_key => $arg_val) | |
202 | + { | |
203 | + if ( strncmp($arg_key, $templateArgsString, strlen($arg_key)) === 0) | |
204 | + { | |
205 | + $arg_value = $arg_key; | |
206 | + $templateArgsString = substr($templateArgsString,strlen($arg_key)+1); | |
207 | + break; | |
208 | + } | |
209 | + } | |
210 | + break; | |
211 | + default: | |
212 | + } | |
213 | + | |
214 | + $templateArgs[$key] = $arg_value; | |
215 | + } | |
216 | + | |
217 | + $params = array( | |
218 | + "paramid" => $paramId, | |
219 | + "fullparamid" => $param_expression, | |
220 | + "template_args" => $templateArgs | |
221 | + ); | |
222 | + | |
223 | + return $params; | |
224 | + } | |
225 | + | |
226 | + /* | |
227 | + * List of Vector params in this data set | |
228 | + */ | |
229 | + public function getVectorList($resourceId) | |
230 | + { | |
231 | + $vectorList = array(); | |
232 | + | |
233 | + $datasetNode = $this->dom->getElementById($resourceId); | |
234 | + if ($datasetNode) | |
235 | + { | |
236 | + $params = $datasetNode->getElementsByTagName('parameter'); | |
237 | + foreach ($params as $param) | |
238 | + { | |
239 | + if ($param->hasAttribute('size')) | |
240 | + if ($param->getAttribute('size') == '3') | |
241 | + $vectorList[] = $param->getAttribute('shortName'); | |
242 | + } | |
243 | + } | |
244 | + | |
245 | + return $vectorList; | |
246 | + } | |
247 | + | |
248 | + //IMPEXPLOTINIT - predefined plot output | |
249 | + public function getParamInfoPlotPath($paramId) | |
250 | + { | |
251 | + | |
252 | + if ($this->getDataProducer($paramId) != "IPIM" && !$this->isSpectra($paramId)) | |
253 | + return null; | |
254 | + | |
255 | + $templateXml = IHMConfigClass::$remoteDataDir.$this->getDataProducer($paramId).'_PlotSettings.xml'; | |
256 | + | |
257 | + if (!file_exists($templateXml)) | |
258 | + throw new Exception("No $templateXml"); | |
259 | + | |
260 | + $dom = new DomDocument("1.0"); | |
261 | + if (!$dom->load($templateXml)) | |
262 | + throw new Exception("Cannot load $templateXml"); | |
263 | + | |
264 | + $paramNode = $dom->documentElement; | |
265 | + $paramNode->setAttribute("xml:id", $paramId); | |
266 | + | |
267 | + $plotParamNode = $paramNode->getElementsByTagName('param'); | |
268 | + if ($plotParamNode->length == 0) | |
269 | + throw new Exception("No Plot Param Node in $templateXml"); | |
270 | + | |
271 | + $plotParamNode->item(0)->setAttribute("id", $paramId); | |
272 | + | |
273 | + $filePath = IHMConfigClass::getUserWSPath().$paramId."_plot.xml"; | |
274 | + | |
275 | + $dom->save($filePath); | |
276 | + | |
277 | + return $filePath; | |
278 | + | |
279 | + } | |
280 | + | |
281 | + public function isSpectra($paramId) | |
282 | + { | |
283 | + $paramNode = $this->dom->getElementById($paramId); | |
284 | + | |
285 | + return $paramNode->hasAttribute('isSpectra'); | |
286 | + | |
287 | + } | |
288 | +} | |
0 | 289 | \ No newline at end of file |
... | ... |
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
... | ... | @@ -10,6 +10,7 @@ class IHMParamManagerClass |
10 | 10 | protected $userParameterLoader = null; |
11 | 11 | protected $expressionParser = null; |
12 | 12 | protected $templateParamsManager = null; |
13 | + protected $paramImpexMgr = null; | |
13 | 14 | |
14 | 15 | /* |
15 | 16 | * @brief Constructor |
... | ... | @@ -23,13 +24,15 @@ class IHMParamManagerClass |
23 | 24 | * @brief Add an existing parameter |
24 | 25 | */ |
25 | 26 | public function addExistingParam($param, $paramsData, $templateArgs = NULL) |
26 | - { | |
27 | + { | |
27 | 28 | if ($this->isDerivedParam($param)) |
28 | 29 | return $this->addDerivedParam($param,$paramsData); |
29 | 30 | else if ($this->isUploadedParam($param)) |
30 | 31 | return $this->addUploadedParam($param,$paramsData); |
32 | + else if ($this->isImpexParam($param)) | |
33 | + return $this->addImpexParam($param,$paramsData,$templateArgs); | |
31 | 34 | else |
32 | - return $this->addLocalParam($param,$paramsData, $templateArgs); | |
35 | + return $this->addLocalParam($param,$paramsData,$templateArgs); | |
33 | 36 | return ""; |
34 | 37 | } |
35 | 38 | |
... | ... | @@ -37,13 +40,15 @@ class IHMParamManagerClass |
37 | 40 | * @brief Add a process parameter |
38 | 41 | */ |
39 | 42 | public function addProcessParam($paramId,$expression,$params,$sampling,$gap,$dateModif,$paramsData) |
40 | - { | |
41 | - $paramsData->addProcessParamToCreate($paramId, $expression, $params, $sampling, $gap,$dateModif); | |
42 | - | |
43 | + { | |
44 | + $paramsData->addProcessParamToCreate($paramId, $expression, $params, $sampling, $gap,$dateModif); | |
45 | + | |
43 | 46 | foreach ($params as $param) { |
44 | - $template_args = NULL; | |
47 | + $template_args = NULL; | |
48 | + | |
45 | 49 | if (array_key_exists("template_args", $param)) |
46 | 50 | $template_args = $param["template_args"]; |
51 | + | |
47 | 52 | $this->addExistingParam($param["paramid"],$paramsData,$template_args); |
48 | 53 | } |
49 | 54 | |
... | ... | @@ -65,6 +70,14 @@ class IHMParamManagerClass |
65 | 70 | { |
66 | 71 | return preg_match("#^wsd_#",$param); |
67 | 72 | } |
73 | + | |
74 | + /* | |
75 | + * @brief Detect if it's IMPEX parameter | |
76 | + */ | |
77 | + private function isImpexParam($param) | |
78 | + { | |
79 | + return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param); | |
80 | + } | |
68 | 81 | |
69 | 82 | /* |
70 | 83 | * @brief Add a local parameter |
... | ... | @@ -84,12 +97,13 @@ class IHMParamManagerClass |
84 | 97 | } |
85 | 98 | else |
86 | 99 | $paramId = $param; |
87 | - | |
100 | + | |
88 | 101 | //check templated parameter |
89 | 102 | $real_param_id = $paramId; |
90 | 103 | if ($this->templateParamsManager->isTemplatedParam($paramId)) { |
91 | 104 | $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); |
92 | 105 | $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); |
106 | + | |
93 | 107 | if (empty($paramPath) || !file_exists($paramPath)) |
94 | 108 | throw new Exception('Cannot generate parameter template file '.$paramId); |
95 | 109 | } |
... | ... | @@ -184,7 +198,58 @@ class IHMParamManagerClass |
184 | 198 | |
185 | 199 | return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); |
186 | 200 | } |
187 | - | |
201 | + | |
202 | + /* | |
203 | + * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS | |
204 | + */ | |
205 | + private function addImpexParam($param,$paramsData,$templateArgs = NULL) | |
206 | + { | |
207 | + if (!isset($this->paramImpexMgr)) | |
208 | + $this->paramImpexMgr = new ImpexParamManager(); | |
209 | + | |
210 | + $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); | |
211 | + | |
212 | + $requestNodes = $paramsData->getRequestNodes(); | |
213 | + | |
214 | + // it is PARAMSGEN | |
215 | + if (!$requestNodes) { | |
216 | + return array("id" => $parameterID); | |
217 | + } | |
218 | + | |
219 | + $timesNode = $requestNodes[0]->getTimesNode(); | |
220 | + $intervals = $timesNode->getIntervals(); | |
221 | + $originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml"; | |
222 | + | |
223 | + if (!file_exists($originFile)) { | |
224 | + // create IMPEX parameter info and data | |
225 | + $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); | |
226 | + | |
227 | + if (!$res["success"]) | |
228 | + throw new Exception('Error to create IMPEX parameter : '.$res["message"]); | |
229 | + | |
230 | + $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], | |
231 | + $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], | |
232 | + $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], | |
233 | + $res["param"]["info"]["type"],$res["param"]["info"]["size"], | |
234 | + $res["param"]["dateModif"],true); | |
235 | + | |
236 | + $tableDef = $res["param"]["info"]["tableDef"]; | |
237 | + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) | |
238 | + { | |
239 | + | |
240 | + } | |
241 | + | |
242 | + return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); | |
243 | + } | |
244 | + else { | |
245 | + // add IMPEX parameter data | |
246 | + $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); | |
247 | + $paramsData->addParamToCopy($parameterID, $originFile); | |
248 | + | |
249 | + return array("id" => $parameterID); | |
250 | + } | |
251 | + } | |
252 | + | |
188 | 253 | /* |
189 | 254 | * @brief Add uploaded parameter |
190 | 255 | */ |
... | ... |
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
... | ... | @@ -8,25 +8,27 @@ |
8 | 8 | class IHMParamTemplateClass |
9 | 9 | { |
10 | 10 | protected $paramTemplateList = null; |
11 | + protected $paramTemplateListFilePath; | |
11 | 12 | |
12 | - private static $paramTemplateNode = 'paramTemplate'; | |
13 | - private static $paramTemplateIdAtt = 'paramId'; | |
14 | - private static $paramTemplateFileNameAtt = 'fileName'; | |
15 | - private static $paramTemplateArgumentsNode = 'arguments'; | |
16 | - private static $paramTemplateArgumentNode = 'argument'; | |
17 | - private static $paramTemplateArgumentKeyAtt = 'key'; | |
18 | - private static $paramTemplateArgumentNameAtt = 'name'; | |
19 | - private static $paramTemplateArgumentTypeAtt = 'type'; | |
20 | - private static $paramTemplateArgumentDefaultAtt = 'default'; | |
21 | - private static $paramTemplateArgumentListItemNode = 'item'; | |
22 | - private static $paramTemplateArgumentListItemKeyAtt = 'key'; | |
23 | - private static $paramTemplateArgumentListItemNameAtt = 'name'; | |
13 | + protected static $paramTemplateNode = 'paramTemplate'; | |
14 | + protected static $paramTemplateIdAtt = 'paramId'; | |
15 | + protected static $paramTemplateFileNameAtt = 'fileName'; | |
16 | + protected static $paramTemplateArgumentsNode = 'arguments'; | |
17 | + protected static $paramTemplateArgumentNode = 'argument'; | |
18 | + protected static $paramTemplateArgumentKeyAtt = 'key'; | |
19 | + protected static $paramTemplateArgumentNameAtt = 'name'; | |
20 | + protected static $paramTemplateArgumentTypeAtt = 'type'; | |
21 | + protected static $paramTemplateArgumentDefaultAtt = 'default'; | |
22 | + protected static $paramTemplateArgumentListItemNode = 'item'; | |
23 | + protected static $paramTemplateArgumentListItemKeyAtt = 'key'; | |
24 | + protected static $paramTemplateArgumentListItemNameAtt = 'name'; | |
24 | 25 | |
25 | 26 | /* |
26 | 27 | * @brief Constructor |
27 | 28 | */ |
28 | 29 | function __construct() |
29 | 30 | { |
31 | + $this->paramTemplateListFilePath = IHMConfigClass::getParamTemplateListFilePath(); | |
30 | 32 | } |
31 | 33 | |
32 | 34 | /* |
... | ... | @@ -227,27 +229,27 @@ class IHMParamTemplateClass |
227 | 229 | /* |
228 | 230 | * @brief Load list of templated parameters |
229 | 231 | */ |
230 | - private function loadUserParamManagerFile() | |
232 | + protected function loadUserParamManagerFile() | |
231 | 233 | { |
232 | 234 | if (isset($this->paramTemplateList)) |
233 | 235 | return; |
234 | 236 | |
235 | 237 | $this->paramTemplateList = array(); |
236 | - | |
238 | + | |
237 | 239 | //load xml file |
238 | 240 | $dom = new DomDocument("1.0"); |
239 | - if (!$dom->load(IHMConfigClass::getParamTemplateListFilePath())) | |
241 | + if (!$dom->load($this->paramTemplateListFilePath)) | |
240 | 242 | return; |
241 | - | |
243 | + | |
242 | 244 | $paramTemplateNodes = $dom->getElementsByTagName(self::$paramTemplateNode); |
243 | - | |
245 | + | |
244 | 246 | foreach ($paramTemplateNodes as $paramTemplateNode) { |
245 | 247 | $paramId = $paramTemplateNode->getAttribute(self::$paramTemplateIdAtt); |
246 | 248 | $paramFileName = $paramTemplateNode->getAttribute(self::$paramTemplateFileNameAtt); |
247 | 249 | |
248 | 250 | if (empty($paramId) || empty($paramFileName)) |
249 | 251 | continue; |
250 | - | |
252 | + | |
251 | 253 | $arguments = array(); |
252 | 254 | |
253 | 255 | $argumentsNode = $paramTemplateNode->getElementsByTagName(self::$paramTemplateArgumentsNode); |
... | ... |
src/Request/ParamInfoRequestClass.php
... | ... | @@ -14,7 +14,8 @@ class ParamInfoRequestClass extends RequestAbstractClass |
14 | 14 | if (!isset($this->requestData)) |
15 | 15 | return false; |
16 | 16 | |
17 | - if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT) { | |
17 | + if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT | |
18 | + || $this->requestData->getType() == ParamInfoTypeEnumClass::IMPEXPLOTINIT) { | |
18 | 19 | //Force load of node files to init the NodeFactory |
19 | 20 | foreach (glob(dirname(__FILE__)."/ParamsRequestImpl/Nodes/Requests/*NodeClass.php") as $filename) { |
20 | 21 | require_once $filename; |
... | ... | @@ -29,6 +30,21 @@ class ParamInfoRequestClass extends RequestAbstractClass |
29 | 30 | */ |
30 | 31 | public function run() |
31 | 32 | { |
33 | + | |
34 | + if ($this->requestData->getType() == ParamInfoTypeEnumClass::IMPEXINFO) | |
35 | + { | |
36 | + $this->requestData->setSuccess(true); | |
37 | + | |
38 | + $result = array(); | |
39 | + $result['dimensions'] = array( | |
40 | + 'dim1' => 1, | |
41 | + 'dim2' => 1 | |
42 | + ); | |
43 | + | |
44 | + $this->requestData->setResult($result); | |
45 | + return $this->requestData->getSuccess(); | |
46 | + } | |
47 | + | |
32 | 48 | $dom = new DOMDocument("1.0","UTF-8"); |
33 | 49 | $dom->preserveWhiteSpace = false; |
34 | 50 | $dom->formatOutput = true; |
... | ... | @@ -41,20 +57,22 @@ class ParamInfoRequestClass extends RequestAbstractClass |
41 | 57 | $this->requestData->setLastErrorMessage("Cannot load file"); |
42 | 58 | return false; |
43 | 59 | } |
44 | - | |
60 | + | |
45 | 61 | switch ($this->requestData->getType()) { |
46 | - case ParamInfoTypeEnumClass::PLOTINIT : | |
62 | + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : | |
63 | + case ParamInfoTypeEnumClass::PLOTINIT : | |
47 | 64 | $this->runFromParamFile($dom); |
48 | - break; | |
65 | + break; | |
49 | 66 | case ParamInfoTypeEnumClass::PARAMINFO : |
50 | 67 | $this->runFromParamInfoFile($dom); |
51 | 68 | break; |
52 | 69 | default : |
53 | - $this->requestData->setLastErrorMessage("Unknown ParamInfo type"); | |
70 | + $this->requestData->setLastErrorMessage("Unknown ParamInfo type "); | |
54 | 71 | } |
55 | 72 | |
56 | 73 | return $this->requestData->getSuccess(); |
57 | 74 | } |
75 | + | |
58 | 76 | |
59 | 77 | private function runFromParamFile($dom) { |
60 | 78 | $paramNode = new ParamNodeClass(); |
... | ... | @@ -67,17 +85,18 @@ class ParamInfoRequestClass extends RequestAbstractClass |
67 | 85 | } |
68 | 86 | |
69 | 87 | switch ($this->requestData->getType()) { |
88 | + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : | |
70 | 89 | case ParamInfoTypeEnumClass::PLOTINIT : |
71 | 90 | $outputNode = $paramNode->getOutput(); |
72 | 91 | if (!isset($outputNode)) { |
73 | 92 | $this->requestData->setLastErrorMessage("Cannot parse output node"); |
74 | 93 | return false; |
75 | - } | |
94 | + } | |
76 | 95 | $plotNode = $outputNode->getChildInstanceByName("plot"); |
77 | 96 | if (!isset($plotNode)) { |
78 | 97 | $this->requestData->setLastErrorMessage("Cannot parse plot node"); |
79 | 98 | return false; |
80 | - } | |
99 | + } | |
81 | 100 | $this->requestData->setResult($plotNode); |
82 | 101 | $this->requestData->setSuccess(true); |
83 | 102 | return true; |
... | ... |
src/Request/ParamInfoRequestDataClass.php
src/Request/ParamsRequestImpl/ParamsRequestClass.php
... | ... | @@ -177,10 +177,35 @@ class ParamsRequestClass extends ProcessRequestClass |
177 | 177 | |
178 | 178 | touch($destinationFile, $value["dateModif"]); |
179 | 179 | } |
180 | + //create and copy local params files | |
181 | + foreach ($this->requestData->getLocalParamsToCreateAndCopy() as $key => $value) | |
182 | + { | |
183 | + $doc = new DOMDocument("1.0", "UTF-8"); | |
184 | + $doc->preserveWhiteSpace = false; | |
185 | + $doc->formatOutput = true; | |
180 | 186 | |
187 | + if (!$xmlNode = $value["param"]->toXMLNode($doc)) | |
188 | + { | |
189 | + $this->requestData->setLastErrorMessage('Cannot create params XML file for '.$key); | |
190 | + return false; | |
191 | + } | |
192 | + | |
193 | + $doc->appendChild($xmlNode); | |
194 | + | |
195 | + $originFile = IHMConfigClass::getUserWSPath().$key.".xml"; | |
196 | + $destinationFile = KernelConfigClass::getRequestParamsPath($this->requestData->getWorkingPath()).$key.".xml"; | |
197 | + | |
198 | + if (!$doc->save($destinationFile) || !$doc->save($originFile)) | |
199 | + { | |
200 | + $this->requestData->setLastErrorMessage('Cannot save params XML file for '.$key); | |
201 | + return false; | |
202 | + } | |
203 | + | |
204 | + touch($originFile, $value["dateModif"]); | |
205 | + touch($destinationFile, $value["dateModif"]); | |
206 | + } | |
181 | 207 | return true; |
182 | 208 | } |
183 | - | |
184 | 209 | /* |
185 | 210 | * @brief Run a params request |
186 | 211 | */ |
... | ... |
src/Request/ParamsRequestImpl/ParamsRequestDataClass.php
... | ... | @@ -26,6 +26,7 @@ class ParamsRequestDataClass extends ProcessRequestDataClass |
26 | 26 | private $waitingResults = array(); |
27 | 27 | private $processParamsToCreate = array(); |
28 | 28 | private $localParamsToCreate = array(); |
29 | + private $localParamsToCreateAndCopy = array(); | |
29 | 30 | private $paramsToCopy = array(); |
30 | 31 | private $paramId = ""; |
31 | 32 | |
... | ... | @@ -133,6 +134,7 @@ class ParamsRequestDataClass extends ProcessRequestDataClass |
133 | 134 | } |
134 | 135 | $newParam->setProcess($expression); |
135 | 136 | $newParam->setOutput(); |
137 | + | |
136 | 138 | $this->processParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); |
137 | 139 | } |
138 | 140 | |
... | ... | @@ -141,7 +143,12 @@ class ParamsRequestDataClass extends ProcessRequestDataClass |
141 | 143 | return $this->localParamsToCreate; |
142 | 144 | } |
143 | 145 | |
144 | - public function addLocalParamToCreate($paramId, $viId, $realVarId, $minSampling, $maxSampling, $type, $size, $dateModif) | |
146 | + public function getLocalParamsToCreateAndCopy() | |
147 | + { | |
148 | + return $this->localParamsToCreateAndCopy; | |
149 | + } | |
150 | + | |
151 | + public function addLocalParamToCreate($paramId, $viId, $realVarId, $minSampling, $maxSampling, $type, $size, $dateModif, $isImpex = false) | |
145 | 152 | { |
146 | 153 | $newParam = new ParamNodeClass(); |
147 | 154 | $newParam->setId($paramId); |
... | ... | @@ -155,7 +162,15 @@ class ParamsRequestDataClass extends ProcessRequestDataClass |
155 | 162 | |
156 | 163 | $newParam->setProcess(""); |
157 | 164 | $newParam->setOutput(); |
158 | - $this->localParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); | |
165 | + | |
166 | + if ($isImpex) | |
167 | + { | |
168 | + $this->localParamsToCreateAndCopy[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); | |
169 | + } | |
170 | + else | |
171 | + { | |
172 | + $this->localParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); | |
173 | + } | |
159 | 174 | |
160 | 175 | return $newParam; |
161 | 176 | } |
... | ... |
src/RequestManager.php
... | ... | @@ -27,7 +27,8 @@ function amdaintegration_autoload($class_name) |
27 | 27 | 'Request/ParamsRequestImpl/Nodes/Requests', |
28 | 28 | 'Request/ProcessRequestImpl', |
29 | 29 | 'Request/ProcessRequestImpl/Process', |
30 | - 'Request/TTRequestImpl' | |
30 | + 'Request/TTRequestImpl', | |
31 | + 'RemoteDataCenter' | |
31 | 32 | ); |
32 | 33 | |
33 | 34 | foreach($dirs as $dir) |
... | ... | @@ -137,12 +138,12 @@ Class RequestManagerClass |
137 | 138 | /* |
138 | 139 | * @brief Create an instance of the InputOutput interface in relation with the client |
139 | 140 | */ |
140 | - private function createInputOutput($user,$client) | |
141 | + private function createInputOutput($user,$userHost = null,$client) | |
141 | 142 | { |
142 | 143 | switch ($client) |
143 | 144 | { |
144 | 145 | case ClientTypeEnumClass::IHM : |
145 | - return new IHMInputOutputClass($user); | |
146 | + return new IHMInputOutputClass($user, $userHost); | |
146 | 147 | case ClientTypeEnumClass::TEST : |
147 | 148 | return new TestInputOutputClass($user); |
148 | 149 | default : |
... | ... | @@ -156,7 +157,7 @@ Class RequestManagerClass |
156 | 157 | private function runGenericRequest($client,$user,$userHost,$function,$input) |
157 | 158 | { |
158 | 159 | //create an instance of the InputOutput interface |
159 | - $inputOutput = $this->createInputOutput($user, $client); | |
160 | + $inputOutput = $this->createInputOutput($user, $userHost, $client); | |
160 | 161 | |
161 | 162 | //get the input data from the request input data by using the InputOutput interface |
162 | 163 | $inputdata = $inputOutput->getInputData($input,$function); |
... | ... |